|
1 |
| -<div align="center"> |
2 |
| - |
3 |
| -# 🌐 Browser-Use |
| 1 | +# 🌐 Browser Use |
4 | 2 |
|
5 |
| -### Open-Source Web Automation with LLMs |
| 3 | +Make websites accessible for AI agents 🤖. |
6 | 4 |
|
7 | 5 | [](https://github.com/gregpr07/browser-use/stargazers)
|
8 | 6 | [](https://opensource.org/licenses/MIT)
|
9 | 7 | [](https://www.python.org/downloads/)
|
10 |
| -[](https://discord.gg/uaCtrbbv) |
| 8 | +[](https://link.browser-use.com/discord) |
11 | 9 |
|
12 |
| -</div> |
| 10 | +Browser use is the easiest way to connect your AI agents with the browser. If you have used Browser Use for your project feel free to show it off in our [Discord](https://link.browser-use.com/discord). |
13 | 11 |
|
14 |
| -Let LLMs interact with websites through a simple interface. |
| 12 | +# Quick start |
15 | 13 |
|
16 |
| -## Short Example |
| 14 | +With pip: |
17 | 15 |
|
18 | 16 | ```bash
|
19 | 17 | pip install browser-use
|
20 | 18 | ```
|
21 | 19 |
|
| 20 | +Spin up your agent: |
| 21 | + |
22 | 22 | ```python
|
23 | 23 | from langchain_openai import ChatOpenAI
|
24 | 24 | from browser_use import Agent
|
25 | 25 |
|
26 | 26 | agent = Agent(
|
27 |
| - task="Go to hackernews on show hn and give me top 10 post titles, their points and hours. Calculate for each the ratio of points per hour.", |
| 27 | + task="Find a one-way flight from Bali to Oman on 12 January 2025 on Google Flights. Return me the cheapest option.", |
28 | 28 | llm=ChatOpenAI(model="gpt-4o"),
|
29 | 29 | )
|
30 | 30 |
|
31 | 31 | # ... inside an async function
|
32 | 32 | await agent.run()
|
33 | 33 | ```
|
34 | 34 |
|
35 |
| -## Demo |
36 |
| - |
37 |
| -<div> |
38 |
| - <a href="https://www.loom.com/share/63612b5994164cb1bb36938d62fe9983"> |
39 |
| - <img style="max-width:300px;" src="https://cdn.loom.com/sessions/thumbnails/63612b5994164cb1bb36938d62fe9983-7133f9e169672e6f-full-play.gif"> |
40 |
| - </a> |
41 |
| - <p><i>Prompt: Go to hackernews on show hn and give me top 10 post titles, their points and hours. Calculate for each the ratio of points per hour. (1x speed) </i></p> |
42 |
| -</div> |
43 |
| -<div> |
44 |
| - <a href="https://www.loom.com/share/2af938b9f8024647950a9e18b3946054"> |
45 |
| - <img style="max-width:300px;" src="https://cdn.loom.com/sessions/thumbnails/2af938b9f8024647950a9e18b3946054-b99c733cf670e568-full-play.gif"> |
46 |
| - </a> |
47 |
| - <p><i>Prompt: Search the top 3 AI companies 2024 and find what out what concrete hardware each is using for their model. (1x speed)</i></p> |
48 |
| -</div> |
49 |
| - |
50 |
| - |
51 |
| - |
52 |
| -<div style="display: flex; justify-content: space-between; margin-top: 20px;"> |
53 |
| - <div style="flex: 1; margin-right: 10px;"> |
54 |
| - <img style="width: 100%;" src="./static/kayak.gif" alt="Kayak flight search demo"> |
55 |
| - <p><i>Prompt: Go to kayak.com and find a one-way flight from Zürich to San Francisco on 12 January 2025. (2.5x speed)</i></p> |
56 |
| - </div> |
57 |
| - <div style="flex: 1; margin-left: 10px;"> |
58 |
| - <img style="width: 100%;" src="./static/photos.gif" alt="Photos search demo"> |
59 |
| - <p><i>Prompt: Opening new tabs and searching for images for these people: Albert Einstein, Oprah Winfrey, Steve Jobs. (2.5x speed)</i></p> |
60 |
| - </div> |
61 |
| -</div> |
62 |
| -</div> |
63 |
| - |
64 |
| -## Local Setup |
65 |
| - |
66 |
| -1. Create a virtual environment and install dependencies: |
| 35 | +And don't forget to add your API keys to your `.env` file. |
67 | 36 |
|
68 | 37 | ```bash
|
69 |
| -# To install all dependencies including dev |
70 |
| -pip install . ."[dev]" |
| 38 | +OPENAI_API_KEY= |
| 39 | +ANTHROPIC_API_KEY= |
71 | 40 | ```
|
72 | 41 |
|
73 |
| -2. Add your API keys to the `.env` file: |
| 42 | +# Demo |
74 | 43 |
|
75 |
| -```bash |
76 |
| -cp .env.example .env |
77 |
| -``` |
| 44 | +DEMO VIDEO HERE |
78 | 45 |
|
79 |
| -E.g. for OpenAI: |
| 46 | +# Features ⭐ |
80 | 47 |
|
81 |
| -```bash |
82 |
| -OPENAI_API_KEY= |
83 |
| -``` |
| 48 | +- Vision + html extraction |
| 49 | +- Automatic multi-tab management |
| 50 | +- Extract clicked elements XPaths |
| 51 | +- Add custom actions (e.g. add data to database which the LLM can use) |
| 52 | +- Self-correcting |
| 53 | +- Use any LLM supported by LangChain (e.g. gpt4o, gpt4o mini, claude 3.5 sonnet, llama 3.1 405b, etc.) |
84 | 54 |
|
85 |
| -You can use any LLM model supported by LangChain by adding the appropriate environment variables. See [langchain models](https://python.langchain.com/docs/integrations/chat/) for available options. |
| 55 | +## Register custom actions |
86 | 56 |
|
87 |
| -## Features |
| 57 | +If you want to add custom actions your agent can take, you can register them like this: |
88 | 58 |
|
89 |
| -- Universal LLM Support - Works with any Language Model |
90 |
| -- Interactive Element Detection - Automatically finds interactive elements |
91 |
| -- Multi-Tab Management - Seamless handling of browser tabs |
92 |
| -- XPath Extraction for scraping functions - No more manual DevTools inspection |
93 |
| -- Vision Model Support - Process visual page information |
94 |
| -- Customizable Actions - Add your own browser interactions (e.g. add data to database which the LLM can use) |
95 |
| -- Handles dynamic content - dont worry about cookies or changing content |
96 |
| -- Chain-of-thought prompting with memory - Solve long-term tasks |
97 |
| -- Self-correcting - If the LLM makes a mistake, the agent will self-correct its actions |
| 59 | +```python |
| 60 | +from browser_use.agent.service import Agent |
| 61 | +from browser_use.browser.service import Browser |
| 62 | +from browser_use.controller.service import Controller |
98 | 63 |
|
99 |
| -## Advanced Examples |
| 64 | +# Initialize controller first |
| 65 | +controller = Controller() |
100 | 66 |
|
101 |
| -### Chain of Agents |
| 67 | +@controller.action('Ask user for information') |
| 68 | +def ask_human(question: str, display_question: bool) -> str: |
| 69 | + return input(f'\n{question}\nInput: ') |
| 70 | +``` |
102 | 71 |
|
103 |
| -You can persist the browser across multiple agents and chain them together. |
| 72 | +Or define your parameters using Pydantic |
104 | 73 |
|
105 | 74 | ```python
|
106 |
| -from asyncio import run |
107 |
| -from browser_use import Agent, Controller |
108 |
| -from dotenv import load_dotenv |
109 |
| -from langchain_anthropic import ChatAnthropic |
110 |
| -load_dotenv() |
111 |
| - |
112 |
| -# Persist browser state across agents |
113 |
| -controller = Controller() |
| 75 | +class JobDetails(BaseModel): |
| 76 | +title: str |
| 77 | +company: str |
| 78 | +job_link: str |
| 79 | +salary: Optional[str] = None |
| 80 | + |
| 81 | +@controller.action('Save job details which you found on page', param_model=JobDetails, requires_browser=True) |
| 82 | +def save_job(params: JobDetails, browser: Browser): |
| 83 | + print(params) |
| 84 | + |
| 85 | + # use the browser normally |
| 86 | + browser.driver.get(params.job_link) |
| 87 | +``` |
114 | 88 |
|
115 |
| -# Initialize browser agent |
116 |
| -agent1 = Agent( |
117 |
| - task="Open 3 VCs websites in the New York area.", |
118 |
| - llm=ChatAnthropic(model="claude-3-5-sonnet-20240620", timeout=25, stop=None), |
119 |
| - controller=controller) |
120 |
| -agent2 = Agent( |
121 |
| - task="Give me the names of the founders of the companies in all tabs.", |
122 |
| - llm=ChatAnthropic(model="claude-3-5-sonnet-20240620", timeout=25, stop=None), |
123 |
| - controller=controller) |
| 89 | +and then run your agent: |
124 | 90 |
|
125 |
| -run(agent1.run()) |
126 |
| -founders, history = run(agent2.run()) |
| 91 | +```python |
| 92 | +model = ChatAnthropic(model_name='claude-3-5-sonnet-20240620', timeout=25, stop=None, temperature=0.3) |
| 93 | +agent = Agent(task=task, llm=model, controller=controller) |
127 | 94 |
|
128 |
| -print(founders) |
| 95 | +await agent.run() |
129 | 96 | ```
|
130 | 97 |
|
131 |
| -You can use the `history` to run the agents again deterministically. |
| 98 | +## Get XPath history |
132 | 99 |
|
133 |
| -## Command Line Usage |
| 100 | +To get the entire history of everything the agent has done, you can use the output of the `run` method: |
134 | 101 |
|
135 |
| -Run examples directly from the command line (clone the repo first): |
| 102 | +```python |
| 103 | +history: list[AgentHistory] = await agent.run() |
136 | 104 |
|
137 |
| -```bash |
138 |
| -python examples/try.py "Your query here" --provider [openai|anthropic] |
| 105 | +print(history) |
139 | 106 | ```
|
140 | 107 |
|
141 |
| -### Anthropic |
| 108 | +## More examples |
142 | 109 |
|
143 |
| -You need to add `ANTHROPIC_API_KEY` to your environment variables. Example usage: |
| 110 | +For more examples see the [examples](examples) folder or join the [Discord](https://link.browser-use.com/discord) and show off your project. |
144 | 111 |
|
145 |
| -```bash |
| 112 | +# Contributing |
146 | 113 |
|
147 |
| -python examples/try.py "Search the top 3 AI companies 2024 and find out in 3 new tabs what hardware each is using for their models" --provider anthropic |
148 |
| -``` |
| 114 | +Contributions are welcome! Feel free to open issues for bugs or feature requests. |
149 | 115 |
|
150 |
| -### OpenAI |
| 116 | +## Setup |
151 | 117 |
|
152 |
| -You need to add `OPENAI_API_KEY` to your environment variables. Example usage: |
| 118 | +1. Create a virtual environment and install dependencies: |
153 | 119 |
|
154 | 120 | ```bash
|
155 |
| -python examples/try.py "Go to hackernews on show hn and give me top 10 post titles, their points and hours. Calculate for each the ratio of points per hour. " --provider anthropic |
| 121 | +# To install all dependencies including dev |
| 122 | +pip install -r requirements.txt -r requirements-dev.txt |
156 | 123 | ```
|
157 | 124 |
|
158 |
| -## 🤖 Supported Models |
159 |
| - |
160 |
| -All LangChain chat models are supported. Tested with: |
161 |
| - |
162 |
| -- GPT-4o |
163 |
| -- GPT-4o Mini |
164 |
| -- Claude 3.5 Sonnet |
165 |
| -- LLama 3.1 405B |
| 125 | +2. Add your API keys to the `.env` file: |
166 | 126 |
|
167 |
| -## Limitations |
| 127 | +```bash |
| 128 | +cp .env.example .env |
| 129 | +``` |
168 | 130 |
|
169 |
| -- When extracting page content, the message length increases and the LLM gets slower. |
170 |
| -- Currently one agent costs about 0.01$ |
171 |
| -- Sometimes it tries to repeat the same task over and over again. |
172 |
| -- Some elements might not be extracted which you want to interact with. |
173 |
| -- What should we focus on the most? |
174 |
| - - Robustness |
175 |
| - - Speed |
176 |
| - - Cost reduction |
| 131 | +or copy the following to your `.env` file: |
177 | 132 |
|
178 |
| -## Roadmap |
| 133 | +```bash |
| 134 | +OPENAI_API_KEY= |
| 135 | +ANTHROPIC_API_KEY= |
| 136 | +``` |
179 | 137 |
|
180 |
| -- [x] Save agent actions and execute them deterministically |
181 |
| -- [ ] Pydantic forced output |
182 |
| -- [ ] Third party SERP API for faster Google Search results |
183 |
| -- [ ] Multi-step action execution to increase speed |
184 |
| -- [ ] Test on mind2web dataset |
185 |
| -- [ ] Add more browser actions |
| 138 | +You can use any LLM model supported by LangChain by adding the appropriate environment variables. See [langchain models](https://python.langchain.com/docs/integrations/chat/) for available options. |
186 | 139 |
|
187 |
| -## Contributing |
| 140 | +### Building the package |
188 | 141 |
|
189 |
| -Contributions are welcome! Feel free to open issues for bugs or feature requests. |
| 142 | +```bash |
| 143 | +hatch build |
| 144 | +``` |
190 | 145 |
|
191 |
| -Feel free to join the [Discord](https://discord.gg/uaCtrbbv) for discussions and support. |
| 146 | +Feel free to join the [Discord](https://link.browser-use.com/discord) for discussions and support. |
192 | 147 |
|
193 | 148 | ---
|
194 | 149 |
|
|
0 commit comments