| title | LangChain Chat Models |
|---|---|
| description | Guide to using different LangChain chat models with Browser Use |
| icon | robot |
Browser Use supports various LangChain chat models. Here's how to configure and use the most popular ones. The full list is available in the LangChain documentation.
We have yet to test performance across all models. Currently, we recommend using GPT-4o. It achieves 89% accuracy on WebVoyager Dataset.
All models require their respective API keys. Make sure to set them in your environment variables before running the agent.All LangChain chat models are supported. We will document the most popular ones here.
OpenAI's GPT-4o models are recommended for best performance.
from langchain_openai import ChatOpenAI
from browser_use import Agent
# Initialize the model
llm = ChatOpenAI(
model="gpt-4o",
temperature=0.0,
)
# Create agent with the model
agent = Agent(
task="Your task here",
llm=llm
)Required environment variables:
OPENAI_API_KEY=Claude models provide excellent performance and can handle complex tasks well.
from langchain_anthropic import ChatAnthropic
from browser_use import Agent
# Initialize the model
llm = ChatAnthropic(
model_name="claude-3-sonnet-20240229",
temperature=0.0,
timeout=100, # Increase for complex tasks
)
# Create agent with the model
agent = Agent(
task="Your task here",
llm=llm
)And add the variable:
ANTHROPIC_API_KEY=If you're using Azure OpenAI services, you can configure the model like this:
from langchain_openai import AzureChatOpenAI
from browser_use import Agent
from pydantic import SecretStr
import os
# Initialize the model
llm = AzureChatOpenAI(
model="gpt-4o",
api_version='2024-10-21',
azure_endpoint=os.getenv('AZURE_OPENAI_ENDPOINT', ''),
api_key=SecretStr(os.getenv('AZURE_OPENAI_KEY', '')),
)
# Create agent with the model
agent = Agent(
task="Your task here",
llm=llm
)Required environment variables:
AZURE_OPENAI_ENDPOINT=https://your-endpoint.openai.azure.com/
AZURE_OPENAI_KEY=Get your API key from https://aistudio.google.com/apikey Make sure to use browser-use>=0.1.18
And add the variable:
GEMINI_API_KEY=Subsequently, you can use the model as following:
import asyncio
import os
from dotenv import load_dotenv
from langchain_google_genai import ChatGoogleGenerativeAI
from pydantic import SecretStr
from browser_use import Agent
load_dotenv()
api_key = os.getenv('GEMINI_API_KEY')
if not api_key:
raise ValueError('GEMINI_API_KEY is not set')
llm = ChatGoogleGenerativeAI(model='gemini-2.0-flash-exp', api_key=SecretStr(api_key))
async def run_search():
agent = Agent(
task=(
'Go to url r/LocalLLaMA subreddit and search for "browser use" in the search bar and click on the first post and find the funniest comment'
),
llm=llm,
max_actions_per_step=4,
tool_call_in_content=False,
)
await agent.run(max_steps=25)
if __name__ == '__main__':
asyncio.run(run_search())Check Qwen example
import asyncio
import os
from langchain_ollama import ChatOllama
from browser_use import Agent
async def run_search():
agent = Agent(
task=(
'1. Go to https://www.reddit.com/r/LocalLLaMA'
"2. Search for 'browser use' in the search bar"
'3. Click search'
'4. Call done'
),
llm=ChatOllama(
# model='qwen2.5:32b-instruct-q4_K_M',
# model='qwen2.5:14b',
model='qwen2.5:latest',
num_ctx=128000,
),
max_actions_per_step=1,
tool_call_in_content=False,
)
await agent.run()
if __name__ == '__main__':
asyncio.run(run_search())Check llama example
import os
# Optional: Disable telemetry
# os.environ["ANONYMIZED_TELEMETRY"] = "false"
# Optional: Set the OLLAMA host to a remote server
# os.environ["OLLAMA_HOST"] = "http://x.x.x.x:11434"
import asyncio
from browser_use import Agent
from langchain_ollama import ChatOllama
async def run_search() -> str:
agent = Agent(
task="Search for a 'browser use' post on the r/LocalLLaMA subreddit and open it.",
llm=ChatOllama(
model="qwen2.5:32b-instruct-q4_K_M",
num_ctx=32000,
),
)
result = await agent.run()
return result
async def main():
result = await run_search()
print("\n\n", result)
if __name__ == "__main__":
asyncio.run(main())Coming soon
(Sorry, we are working on it)
- Groq
- DeepSeek
- Github