Let LLMs interact with websites through a simple interface
Project description
🌐 Browser Use
Make websites accessible for AI agents 🤖.
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.
Quick start
With pip:
pip install browser-use
Spin up your agent:
from langchain_openai import ChatOpenAI
from browser_use import Agent
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"),
)
# ... inside an async function
await agent.run()
And don't forget to add your API keys to your .env
file.
OPENAI_API_KEY=
ANTHROPIC_API_KEY=
Demos
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)
Prompt: Search the top 3 AI companies 2024 and find what out what concrete hardware each is using for their model. (1x speed)
Features ⭐
- Vision + html extraction
- Automatic multi-tab management
- Extract clicked elements XPaths
- Add custom actions (e.g. add data to database which the LLM can use)
- Self-correcting
- Use any LLM supported by LangChain (e.g. gpt4o, gpt4o mini, claude 3.5 sonnet, llama 3.1 405b, etc.)
Register custom actions
If you want to add custom actions your agent can take, you can register them like this:
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()
@controller.action('Ask user for information')
def ask_human(question: str, display_question: bool) -> str:
return input(f'\n{question}\nInput: ')
Or define your parameters using Pydantic
class JobDetails(BaseModel):
title: str
company: str
job_link: str
salary: Optional[str] = None
@controller.action('Save job details which you found on page', param_model=JobDetails, requires_browser=True)
def save_job(params: JobDetails, browser: Browser):
print(params)
# use the browser normally
browser.driver.get(params.job_link)
and then run your agent:
model = ChatAnthropic(model_name='claude-3-5-sonnet-20240620', timeout=25, stop=None, temperature=0.3)
agent = Agent(task=task, llm=model, controller=controller)
await agent.run()
Get XPath history
To get the entire history of everything the agent has done, you can use the output of the run
method:
history: list[AgentHistory] = await agent.run()
print(history)
More examples
For more examples see the examples folder or join the Discord and show off your project.
Contributing
Contributions are welcome! Feel free to open issues for bugs or feature requests.
Local Setup
- Create a virtual environment and install dependencies:
# To install all dependencies including dev
pip install -r requirements.txt -r requirements-dev.txt
- Add your API keys to the
.env
file:
cp .env.example .env
or copy the following to your .env
file:
OPENAI_API_KEY=
ANTHROPIC_API_KEY=
You can use any LLM model supported by LangChain by adding the appropriate environment variables. See langchain models for available options.
Building the package
hatch build
Feel free to join the Discord for discussions and support.
Made with ❤️ by the Browser-Use team
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file browser_use-0.1.1.tar.gz
.
File metadata
- Download URL: browser_use-0.1.1.tar.gz
- Upload date:
- Size: 174.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.12.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 89dc30a014a941901e6c6ca9131f6871cee0edd59520097b3f7835061d7ecd3a |
|
MD5 | c1cb20fe8d0e67ecaf3d5451a5ef555e |
|
BLAKE2b-256 | 19a9ef2127dba27644f631aa5b2480dcb2d64f8d9d5a1a1b701490ce3f334fdc |
File details
Details for the file browser_use-0.1.1-py3-none-any.whl
.
File metadata
- Download URL: browser_use-0.1.1-py3-none-any.whl
- Upload date:
- Size: 31.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.12.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | e65c7e92a45c6889a2a2391d7f329172b7b73a2c13d0b61d4a756e50aff7a4cf |
|
MD5 | 87466520e1f1960f3dc4604180fa55e9 |
|
BLAKE2b-256 | 97326794d0b9c5ac6fd7150c8c035b6599c99a27198f889ea4f988ed19e1996c |