Open-source Python library for AI browser agents, plus Browser Use Cloud: stealth browsers and a hosted agent API.
Python ai-agentsai-toolsbrowser-agentbrowser-automationbrowser-usecdpcloud-browsercomputer-useheadless-browserllmmcpplaywrightpythonremote-browserstealth-browserweb-automationweb-scraping
Merge branch 'main' into feature/mistral-support
TR-3B0b82aa7348a5
diff --cc browser_use/__init__.pyindex a219ddc51,e2e902a5d..054bd077b--- a/browser_use/__init__.py+++ b/browser_use/__init__.py@@@ -54,17 -57,22 +57,26 @@@ if TYPE_CHECKINGfrom browser_use.llm import modelsfrom browser_use.llm.anthropic.chat import ChatAnthropicfrom browser_use.llm.azure.chat import ChatAzureOpenAI+ from browser_use.llm.browser_use.chat import ChatBrowserUsefrom browser_use.llm.google.chat import ChatGooglefrom browser_use.llm.groq.chat import ChatGroq+++ from browser_use.llm.mistral.chat import ChatMistral+++ from browser_use.llm.oci_raw.chat import ChatOCIRaw++from browser_use.llm.ollama.chat import ChatOllamafrom browser_use.llm.openai.chat import ChatOpenAI+ from browser_use.llm.vercel.chat import ChatVercel+ from browser_use.sandbox import sandboxfrom browser_use.tools.service import Controller, Tools-- # Lazy imports mapping - only import when actually accessed+ # Lazy imports mapping - only import when actually accessed_LAZY_IMPORTS = {# Agent service (heavy due to dependencies)+ # 'Agent': ('browser_use.agent.service', 'Agent'),+ # Code-use agent (Jupyter notebook-like execution)+ 'CodeAgent': ('browser_use.code_use.service', 'CodeAgent'),'Agent': ('browser_use.agent.service', 'Agent'),# System prompt (moderate weight due to agent.views imports)'SystemPrompt': ('browser_use.agent.prompts', 'SystemPrompt'),@@@ -84,12 -92,16 +96,17 @@@'ChatOpenAI': ('browser_use.llm.openai.chat', 'ChatOpenAI'),'ChatGoogle': ('browser_use.llm.google.chat', 'ChatGoogle'),'ChatAnthropic': ('browser_use.llm.anthropic.chat', 'ChatAnthropic'),+ 'ChatBrowserUse': ('browser_use.llm.browser_use.chat', 'ChatBrowserUse'),'ChatGroq': ('browser_use.llm.groq.chat', 'ChatGroq'),+ 'ChatMistral': ('browser_use.llm.mistral.chat', 'ChatMistral'),'ChatAzureOpenAI': ('browser_use.llm.azure.chat', 'ChatAzureOpenAI'),+ 'ChatOCIRaw': ('browser_use.llm.oci_raw.chat', 'ChatOCIRaw'),'ChatOllama': ('browser_use.llm.ollama.chat', 'ChatOllama'),+ 'ChatVercel': ('browser_use.llm.vercel.chat', 'ChatVercel'),# LLM models module'models': ('browser_use.llm.models', None),+ # Sandbox execution+ 'sandbox': ('browser_use.sandbox', 'sandbox'),}@@@ -130,10 -144,12 +149,13 @@@ __all__ ='ChatOpenAI','ChatGoogle','ChatAnthropic',+ 'ChatBrowserUse','ChatGroq',+ 'ChatMistral','ChatAzureOpenAI',+ 'ChatOCIRaw','ChatOllama',+ 'ChatVercel','Tools','Controller',# LLM models modulediff --cc browser_use/llm/README.mdindex 39feb7421,8fbd1df47..c80fa2203--- a/browser_use/llm/README.md+++ b/browser_use/llm/README.md@@@ -8,12 -8,8 +8,16 @@@ We officially support the following LLM- Groq- Ollama- DeepSeek+++- Mistral++## Mistral specifics++Use `ChatMistral` with `MISTRAL_API_KEY` (and optional `MISTRAL_BASE_URL`). Structured outputs automatically strip unsupported JSON schema keywords (`minLength`, `maxLength`, `pattern`, `format`), and generation uses `max_tokens` plus the optional `safe_prompt` flag.++ - Cerebras+++## Migrating from LangChainBecause of how we implemented the LLMs, we can technically support anything. If you want to use a LangChain model, you can use the `ChatLangchain` (NOT OFFICIALLY SUPPORTED) class.diff --cc browser_use/llm/__init__.pyindex 38d0d498d,e8b372097..d86565947--- a/browser_use/llm/__init__.py+++ b/browser_use/llm/__init__.py@@@ -33,7 -35,7 +35,11 @@@ if TYPE_CHECKINGfrom browser_use.llm.deepseek.chat import ChatDeepSeekfrom browser_use.llm.google.chat import ChatGooglefrom browser_use.llm.groq.chat import ChatGroq+++ from browser_use.llm.mistral.chat import ChatMistral+++ from browser_use.llm.oci_raw.chat import ChatOCIRaw++from browser_use.llm.ollama.chat import ChatOllamafrom browser_use.llm.openai.chat import ChatOpenAIfrom browser_use.llm.openrouter.chat import ChatOpenRouter@@@ -82,7 -87,7 +91,11 @@@ _LAZY_IMPORTS ='ChatDeepSeek': ('browser_use.llm.deepseek.chat', 'ChatDeepSeek'),'ChatGoogle': ('browser_use.llm.google.chat', 'ChatGoogle'),'ChatGroq': ('browser_use.llm.groq.chat', 'ChatGroq'),+++ 'ChatMistral': ('browser_use.llm.mistral.chat', 'ChatMistral'),+++ 'ChatOCIRaw': ('browser_use.llm.oci_raw.chat', 'ChatOCIRaw'),++'ChatOllama': ('browser_use.llm.ollama.chat', 'ChatOllama'),'ChatOpenAI': ('browser_use.llm.openai.chat', 'ChatOpenAI'),'ChatOpenRouter': ('browser_use.llm.openrouter.chat', 'ChatOpenRouter'),@@@ -142,8 -149,10 +157,11 @@@ __all__ ='ChatAnthropicBedrock','ChatAWSBedrock','ChatGroq',+ 'ChatMistral','ChatAzureOpenAI',+ 'ChatOCIRaw','ChatOllama','ChatOpenRouter',+ 'ChatVercel',+ 'ChatCerebras',]diff --cc browser_use/llm/models.pyindex 2363d9e32,bd38be39d..a983c9ebf--- a/browser_use/llm/models.py+++ b/browser_use/llm/models.py@@@ -14,10 -15,20 +15,21 @@@ import ofrom typing import TYPE_CHECKINGfrom browser_use.llm.azure.chat import ChatAzureOpenAI+ from browser_use.llm.browser_use.chat import ChatBrowserUse+ from browser_use.llm.cerebras.chat import ChatCerebrasfrom browser_use.llm.google.chat import ChatGoogle+from browser_use.llm.mistral.chat import ChatMistralfrom browser_use.llm.openai.chat import ChatOpenAI+ # Optional OCI import+ try:+ from browser_use.llm.oci_raw.chat import ChatOCIRaw++ OCI_AVAILABLE = True+ except ImportError:+ ChatOCIRaw = None+ OCI_AVAILABLE = False+if TYPE_CHECKING:from browser_use.llm.base import BaseChatModel@@@ -53,12 -64,20 +65,25 @@@ google_gemini_2_0_pro: 'BaseChatModelgoogle_gemini_2_5_pro: 'BaseChatModel'google_gemini_2_5_flash: 'BaseChatModel'google_gemini_2_5_flash_lite: 'BaseChatModel'+mistral_large: 'BaseChatModel'+mistral_medium: 'BaseChatModel'+mistral_small: 'BaseChatModel'+codestral: 'BaseChatModel'+pixtral_large: 'BaseChatModel'+ cerebras_llama3_1_8b: 'BaseChatModel'+ cerebras_llama3_3_70b: 'BaseChatModel'+ cerebras_gpt_oss_120b: 'BaseChatModel'+ cerebras_llama_4_scout_17b_16e_instruct: 'BaseChatModel'+ cerebras_llama_4_maverick_17b_128e_instruct: 'BaseChatModel'+ cerebras_qwen_3_32b: 'BaseChatModel'+ cerebras_qwen_3_235b_a22b_instruct_2507: 'BaseChatModel'+ cerebras_qwen_3_235b_a22b_thinking_2507: 'BaseChatModel'+ cerebras_qwen_3_coder_480b: 'BaseChatModel'++ bu_latest: 'BaseChatModel'+ bu_1_0: 'BaseChatModel'+def get_llm_by_name(model_name: str):"""@@@ -127,22 -157,26 +176,45 @@@api_key = os.getenv('GOOGLE_API_KEY')return ChatGoogle(model=model, api_key=api_key)+++ # Mistral Models+ elif provider == 'mistral':+ api_key = os.getenv('MISTRAL_API_KEY')+ base_url = os.getenv('MISTRAL_BASE_URL', 'https://api.mistral.ai/v1')+ mistral_map = {+ 'large': 'mistral-large-latest',+ 'medium': 'mistral-medium-latest',+ 'small': 'mistral-small-latest',+ 'codestral': 'codestral-latest',+ 'pixtral-large': 'pixtral-large-latest',+ }+ resolved_model = mistral_map.get(model_part, model.replace('_', '-'))+ return ChatMistral(model=resolved_model, api_key=api_key, base_url=base_url)++ else:+ available_providers = ['openai', 'azure', 'google', 'mistral']+++ # OCI Models+ elif provider == 'oci':+ # OCI requires more complex configuration that can't be easily inferred from env vars+ # Users should use ChatOCIRaw directly with proper configuration+ raise ValueError('OCI models require manual configuration. Use ChatOCIRaw directly with your OCI credentials.')++ # Cerebras Models+ elif provider == 'cerebras':+ api_key = os.getenv('CEREBRAS_API_KEY')+ return ChatCerebras(model=model, api_key=api_key)++ # Browser Use Models+ elif provider == 'bu':+ # Handle bu_latest -> bu-latest conversion (need to prepend 'bu-' back)+ model = f'bu-{model_part.replace("_", "-")}'+ api_key = os.getenv('BROWSER_USE_API_KEY')+ return ChatBrowserUse(model=model, api_key=api_key)++ else:+ available_providers = ['openai', 'azure', 'google', 'oci', 'cerebras', 'bu']++raise ValueError(f"Unknown provider: '{provider}'. Available providers: {', '.join(available_providers)}")@@@ -156,9 -190,15 +228,20 @@@ def __getattr__(name: str) -> 'BaseChatreturn ChatAzureOpenAI # type: ignoreelif name == 'ChatGoogle':return ChatGoogle # type: ignore+++ elif name == 'ChatMistral':+ return ChatMistral # type: ignore++ elif name == 'ChatOCIRaw':+ if not OCI_AVAILABLE:+ raise ImportError('OCI integration not available. Install with: pip install "browser-use[oci]"')+ return ChatOCIRaw # type: ignore+ elif name == 'ChatCerebras':+ return ChatCerebras # type: ignore+ elif name == 'ChatBrowserUse':+ return ChatBrowserUse # type: ignore+++# Handle model instances - these are the main use casetry:return get_llm_by_name(name)@@@ -170,7 -211,14 +254,18 @@@ __all__ ='ChatOpenAI','ChatAzureOpenAI','ChatGoogle',+++ 'ChatMistral',+++ 'ChatCerebras',+ 'ChatBrowserUse',+ ]++ if OCI_AVAILABLE:+ __all__.append('ChatOCIRaw')++ __all__ += [++'get_llm_by_name',# OpenAI instances - created on demand'openai_gpt_4o',@@@ -204,10 -252,20 +299,29 @@@'google_gemini_2_5_pro','google_gemini_2_5_flash','google_gemini_2_5_flash_lite',+++ # Mistral instances - created on demand+ 'mistral_large',+ 'mistral_medium',+ 'mistral_small',+ 'codestral',+ 'pixtral_large',+++ # Cerebras instances - created on demand+ 'cerebras_llama3_1_8b',+ 'cerebras_llama3_3_70b',+ 'cerebras_gpt_oss_120b',+ 'cerebras_llama_4_scout_17b_16e_instruct',+ 'cerebras_llama_4_maverick_17b_128e_instruct',+ 'cerebras_qwen_3_32b',+ 'cerebras_qwen_3_235b_a22b_instruct_2507',+ 'cerebras_qwen_3_235b_a22b_thinking_2507',+ 'cerebras_qwen_3_coder_480b',+ # Browser Use instances - created on demand+ 'bu_latest',+ 'bu_1_0',++]++ # NOTE: OCI backend is optional. The try/except ImportError and conditional __all__ are required+ # so this module can be imported without browser-use[oci] installed.