Skip to content

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

Included examples to run

magmuellereacd5755488b
diff --git a/examples/amazon_search.py b/examples/amazon_search.py
new file mode 100644
index 000000000..18565113c
--- /dev/null
+++ b/examples/amazon_search.py
@@ -0,0 +1,30 @@
+"""
+Simple try of the agent.
+
+@dev You need to add OPENAI_API_KEY to your environment variables.
+"""
+
+import os
+import sys
+
+sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
+
+import asyncio
+
+from langchain_openai import ChatOpenAI
+
+from browser_use import Agent
+
+# video: https://preview.screen.studio/share/70xBqZyN
+llm = ChatOpenAI(model='gpt-4o')
+agent = Agent(
+ task='Go to amazon.com, search for laptop, sort by best rating, and give me the price of the first result',
+ llm=llm,
+)
+
+
+async def main():
+ await agent.run()
+
+
+asyncio.run(main())
diff --git a/examples/chain_of_agents.py b/examples/chain_of_agents.py
index 9209febc8..c37d153c1 100644
--- a/examples/chain_of_agents.py
+++ b/examples/chain_of_agents.py
@@ -16,23 +16,21 @@ model = ChatOpenAI(model='gpt-4o')
# Initialize browser agent
agent1 = Agent(
- task='Open 3 wikipedia articles about the history of the internet.',
+ 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 2 founders of the companies.',
+ task='Considering all open tabs give me the names of the wikipedia article.',
llm=model,
controller=controller,
)
-# Let it work its magic
+# Video: https://preview.screen.studio/share/8Elaq9sm
async def main():
await agent1.run()
- founders = await agent2.run()
-
- print(founders)
+ await agent2.run()
asyncio.run(main())
diff --git a/examples/find_and_apply_to_jobs.py b/examples/find_and_apply_to_jobs.py
new file mode 100644
index 000000000..8a16e6efa
--- /dev/null
+++ b/examples/find_and_apply_to_jobs.py
@@ -0,0 +1,64 @@
+import os
+import sys
+
+sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
+
+import asyncio
+from typing import List, Optional
+
+from langchain_openai import ChatOpenAI
+from pydantic import BaseModel
+
+from browser_use.agent.service import Agent
+from browser_use.browser.service import Browser
+from browser_use.controller.service import Controller
+
+# Initialize controller first
+controller = Controller()
+
+
+class Job(BaseModel):
+ title: str
+ link: str
+ company: str
+ salary: Optional[str] = None
+
+
+class Jobs(BaseModel):
+ jobs: List[Job]
+
+
[email protected]('Save jobs', param_model=Jobs)
+def save_jobs(params: Jobs):
+ with open('jobs.txt', 'a') as f:
+ for job in params.jobs:
+ f.write(f'{job.title} at {job.company}: {job.salary} ({job.link})\n')
+
+
+# read from file
[email protected]('Read jobs from file')
+def read_jobs():
+ with open('jobs.txt', 'r') as f:
+ return f.read()
+
+
+# Without Pydantic model - using simple parameters
[email protected]('Ask me for information')
+def ask_human(question: str) -> str:
+ return input(f'\n{question}\nInput: ')
+
+
+async def main():
+ task = (
+ 'Find machine learning engineer jobs in Berlin and '
+ 'start applying for them over in new tabs - not via linkedin. '
+ 'If you need more information, ask me for it.'
+ )
+ model = ChatOpenAI(model='gpt-4o')
+ agent = Agent(task=task, llm=model, controller=controller)
+
+ await agent.run()
+
+
+if __name__ == '__main__':
+ asyncio.run(main())
diff --git a/examples/simple_run.py b/examples/flight_search.py
similarity index 72%
rename from examples/simple_run.py
rename to examples/flight_search.py
index dd623eb45..54bdc7daf 100644
--- a/examples/simple_run.py
+++ b/examples/flight_search.py
@@ -17,8 +17,8 @@ from browser_use import Agent
llm = ChatOpenAI(model='gpt-4o')
agent = Agent(
- task='Find a one-way flight from Bali to Oman on 12 January 2025 on Google Flights. Return me the cheapest option.',
- llm=ChatOpenAI(model='gpt-4o'),
+ task='Find flights on kayak.com from Zurich to Beijing on 25.12.2024 one way, give me the cheapest among all',
+ llm=llm,
)
diff --git a/examples/hugging_face.py b/examples/hugging_face.py
new file mode 100644
index 000000000..9c332a408
--- /dev/null
+++ b/examples/hugging_face.py
@@ -0,0 +1,48 @@
+import os
+import sys
+
+sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
+
+import asyncio
+from typing import List, Optional
+
+from langchain_openai import ChatOpenAI
+from pydantic import BaseModel
+
+from browser_use.agent.service import Agent
+from browser_use.controller.service import Controller
+
+# Initialize controller first
+controller = Controller()
+
+
+class Model(BaseModel):
+ title: str
+ url: str
+ likes: int
+ license: str
+
+
+class Models(BaseModel):
+ models: List[Model]
+
+
[email protected]('Save models', param_model=Models)
+def save_models(params: Models):
+ with open('models.txt', 'a') as f:
+ for model in params.models:
+ f.write(f'{model.title} ({model.url}): {model.likes} likes, {model.license}\n')
+
+
+# video: https://preview.screen.studio/share/EtOhIk0P
+async def main():
+ task = f'Look up models with a license of cc-by-sa-4.0 and sort by most likes on Hugging face, save top 5 to file.'
+
+ model = ChatOpenAI(model='gpt-4o')
+ agent = Agent(task=task, llm=model, controller=controller)
+
+ await agent.run()
+
+
+if __name__ == '__main__':
+ asyncio.run(main())
diff --git a/examples/multi-tab_handling.py b/examples/multi-tab_handling.py
new file mode 100644
index 000000000..da0ac0a49
--- /dev/null
+++ b/examples/multi-tab_handling.py
@@ -0,0 +1,30 @@
+"""
+Simple try of the agent.
+
+@dev You need to add OPENAI_API_KEY to your environment variables.
+"""
+
+import os
+import sys
+
+sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
+
+import asyncio
+
+from langchain_openai import ChatOpenAI
+
+from browser_use import Agent
+
+# video: https://preview.screen.studio/share/clenCmS6
+llm = ChatOpenAI(model='gpt-4o')
+agent = Agent(
+ task='open 3 tabs with elon musk, trump, and steve jobs, then go back to the first and click on the first link',
+ llm=llm,
+)
+
+
+async def main():
+ await agent.run()
+
+
+asyncio.run(main())
diff --git a/examples/extend_actions.py b/examples/who_starred_my_repo.py
similarity index 92%
rename from examples/extend_actions.py
rename to examples/who_starred_my_repo.py
index 5009b5e00..dc4fcaf1d 100644
--- a/examples/extend_actions.py
+++ b/examples/who_starred_my_repo.py
@@ -67,8 +67,8 @@ class Jobs(BaseModel):
jobs: List[Job]
[email protected]('Save jobs', param_model=Jobs, requires_browser=True)
-def save_jobs(params: Jobs, browser: Browser):
[email protected]('Save jobs', param_model=Jobs)
+def save_jobs(params: Jobs):
with open('jobs.txt', 'a') as f:
for job in params.jobs:
f.write(f'{job.title} at {job.company}: {job.salary} ({job.link})\n')
@@ -76,7 +76,7 @@ def save_jobs(params: Jobs, browser: Browser):
# Without Pydantic model - using simple parameters
@controller.action('Ask user for information')
-def ask_human(question: str, display_question: bool) -> str:
+def ask_human(question: str) -> str:
return input(f'\n{question}\nInput: ')