Skip to content

Open-source Python library for AI browser agents, plus Browser Use Cloud: stealth browsers and a hosted agent API.

changed examples

Gregor Žuničdc90c7d9c469
diff --git a/examples/chain_of_agents.py b/examples/chain_of_agents.py
index 7f9875cf0..8b48db403 100644
--- a/examples/chain_of_agents.py
+++ b/examples/chain_of_agents.py
@@ -2,6 +2,8 @@ import logging
import os
import sys
+from langchain_openai import ChatOpenAI
+
sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
import asyncio
@@ -16,19 +18,17 @@ logging.basicConfig(level=logging.INFO)
# Persist the browser state across agents
controller = Controller()
+model = ChatOpenAI(model='gpt-4o')
+
# Initialize browser agent
agent1 = Agent(
- task='Open 5 VCs websites in the New York area.',
- llm=ChatAnthropic(
- model_name='claude-3-5-sonnet-20240620', timeout=25, stop=None, temperature=0.3
- ),
+ task='Open 3 wikipedia articles about the history of the internet.',
+ llm=model,
controller=controller,
)
agent2 = Agent(
- task='Give me the names of the founders of the companies in all tabs.',
- llm=ChatAnthropic(
- model_name='claude-3-5-sonnet-20240620', timeout=25, stop=None, temperature=0.3
- ),
+ task='Considering all open tabs give me the names of 2 founders of the companies.',
+ llm=model,
controller=controller,
)
diff --git a/src/agent/service.py b/src/agent/service.py
index 33417ba12..64bd9b115 100644
--- a/src/agent/service.py
+++ b/src/agent/service.py
@@ -39,6 +39,7 @@ class AgentService:
self.task = task
self.use_vision = use_vision
+ self.controller_injected = controller is not None
self.controller = controller or ControllerService()
self.llm = llm
@@ -81,7 +82,8 @@ class AgentService:
logger.info('=' * 50)
return None
finally:
- self.controller.browser.close()
+ if not self.controller_injected:
+ self.controller.browser.close()
@time_execution_async('--step')
async def step(self) -> tuple[AgentOutput, ControllerActionResult]: