Skip to content

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

Fixed chain of agents

magmueller977d07646817
diff --git a/examples/chain_of_agents.py b/examples/chain_of_agents.py
index c37d153c1..c5246101e 100644
--- a/examples/chain_of_agents.py
+++ b/examples/chain_of_agents.py
@@ -7,30 +7,30 @@ sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
import asyncio
-from browser_use import Agent, Controller
-
-# Persist the browser state across agents
-controller = Controller()
-
-model = ChatOpenAI(model='gpt-4o')
-
-# Initialize browser agent
-agent1 = Agent(
- task='Open 2 tabs with wikipedia articles about the history of the meta and one random wikipedia article.',
- llm=model,
- controller=controller,
-)
-agent2 = Agent(
- task='Considering all open tabs give me the names of the wikipedia article.',
- llm=model,
- controller=controller,
-)
+from browser_use import Agent, Browser, Controller
# Video: https://preview.screen.studio/share/8Elaq9sm
async def main():
- await agent1.run()
- await agent2.run()
+ # Persist the browser state across agents
+
+ browser = Browser()
+ async with await browser.new_context() as context:
+ model = ChatOpenAI(model='gpt-4o')
+
+ # Initialize browser agent
+ agent1 = Agent(
+ task='Open 2 tabs with wikipedia articles about the history of the meta and one random wikipedia article.',
+ llm=model,
+ browser_context=context,
+ )
+ agent2 = Agent(
+ task='Considering all open tabs give me the names of the wikipedia article.',
+ llm=model,
+ browser_context=context,
+ )
+ await agent1.run()
+ await agent2.run()
asyncio.run(main())