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
Resolve Rust default LLM like Browser Use
Magnus Müllerfcdb8f065440
diff --git a/RUST_AGENT_INTEGRATION_FEATURES.md b/RUST_AGENT_INTEGRATION_FEATURES.mdindex d78635db0..1777da945 100644--- a/RUST_AGENT_INTEGRATION_FEATURES.md+++ b/RUST_AGENT_INTEGRATION_FEATURES.md@@ -1041,10 +1041,15 @@ Terminal core branch: `magnus/browser-use-rust-main-integration` at terminal mai- Existing skip-verification and already-verified behavior is preserved through the shared helper, including setting `_verified_api_keys=True` when Browser Use verification is disabled.- Proof: `test_rust_agent_constructor_invokes_llm_verification`.+206. Rust Agent default LLM parity+ - Rust-backed construction now resolves `llm=None` the same way Browser Use does: `CONFIG.DEFAULT_LLM` routes through `get_llm_by_name(...)`, otherwise the default Browser Use cloud model is constructed.+ - Default construction now preserves downstream Browser Use defaults that depend on the resolved LLM, including `flash_mode=True`, `settings.page_extraction_llm is agent.llm`, and the public `agent.model` value.+ - Proof: `test_rust_agent_defaults_llm_like_browser_use`.+## Current Verification- `python3 -m py_compile browser_use/agent/service.py browser_use/rust/service.py browser_use/rust/__init__.py browser_use/__init__.py tests/ci/test_rust_agent.py examples/rust_agent/basic.py examples/rust_agent/real_v8_smoke.py`-- `uv run pytest -q tests/ci/test_rust_agent.py` (174 tests)+- `uv run pytest -q tests/ci/test_rust_agent.py` (175 tests)- `cargo build -q -p browser-use-cli` on terminal branch `magnus/browser-use-rust-main-integration`- `cargo test -q -p browser-use-cli run_codex_session_command_accepts_task_id_and_model -- --nocapture`- `CARGO_INCREMENTAL=0 cargo test -q -p browser-use-agent selected_remote_cdp_mode_allows_remote_cdp_connect -- --nocapture`diff --git a/browser_use/rust/service.py b/browser_use/rust/service.pyindex ce0b8ae8e..1714a7101 100644--- a/browser_use/rust/service.py+++ b/browser_use/rust/service.py@@ -122,6 +122,24 @@ def _llm_timeout_for_model(llm: Any | None) -> int:return 60+def _resolve_default_llm(llm: BaseChatModel | None) -> BaseChatModel:+ if llm is not None:+ return llm+ try:+ from browser_use.config import CONFIG++ default_llm_name = CONFIG.DEFAULT_LLM+ except Exception:+ default_llm_name = ''+ if default_llm_name:+ from browser_use.llm.models import get_llm_by_name++ return get_llm_by_name(default_llm_name)+ from browser_use import ChatBrowserUse++ return ChatBrowserUse()++def _extract_cdp_url(browser_session: BrowserSession | None) -> str | None:if browser_session is None:return None@@ -2514,6 +2532,7 @@ class Agent(Generic[Context, AgentStructuredOutput]):_url_shortening_limit: int = 25,**kwargs,):+ llm = _resolve_default_llm(llm)if browser and browser_session:raise ValueError('Cannot specify both "browser" and "browser_session".')if tools is not None and controller is not None:diff --git a/tests/ci/test_rust_agent.py b/tests/ci/test_rust_agent.pyindex d99fa7639..cafc32ec2 100644--- a/tests/ci/test_rust_agent.py+++ b/tests/ci/test_rust_agent.py@@ -19,6 +19,8 @@ def _disable_rust_agent_latest_version_check(monkeypatch):return Nonemonkeypatch.setattr(rust_service, 'check_latest_browser_use_version', no_latest_version)+ monkeypatch.delenv('DEFAULT_LLM', raising=False)+ monkeypatch.setenv('BROWSER_USE_API_KEY', 'test-browser-use-api-key')def _load_real_v8_smoke_module():@@ -2697,6 +2699,21 @@ def test_rust_agent_defaults_page_extraction_llm_to_main_llm():assert str(id(extraction_llm)) in override_agent.token_cost_service.registered_llms+def test_rust_agent_defaults_llm_like_browser_use():+ from browser_use.agent.service import _PythonAgent as BrowserUseAgent+ from browser_use.rust import Agent as RustAgent++ browser_use_agent = BrowserUseAgent(task='Use the default model.', directly_open_url=False)+ rust_agent = RustAgent(task='Use the default model.', directly_open_url=False)++ assert type(rust_agent.llm) is type(browser_use_agent.llm)+ assert rust_agent.llm.provider == browser_use_agent.llm.provider == 'browser-use'+ assert rust_agent.llm.model == browser_use_agent.llm.model == 'bu-1-0'+ assert rust_agent.settings.flash_mode is True+ assert rust_agent.settings.page_extraction_llm is rust_agent.llm+ assert rust_agent.model == rust_agent.llm.model++def test_rust_agent_enables_flash_mode_for_browser_use_llm_provider():from browser_use.agent.service import _PythonAgent as BrowserUseAgentfrom browser_use.rust import Agent as RustAgent@@ -4928,12 +4945,15 @@ def test_rust_agent_adds_available_files_to_task_context():assert '- ' in agent.task and 'notes.md' in agent.task-def test_rust_agent_default_codex_model_matches_chatgpt_account(monkeypatch):+def test_rust_agent_default_model_uses_browser_use_default_llm(monkeypatch):from browser_use.rust import Agent- monkeypatch.delenv('BROWSER_USE_RUST_MODEL', raising=False)+ monkeypatch.setenv('BROWSER_USE_RUST_MODEL', 'legacy-codex-default')++ agent = Agent(task='report title')- assert Agent(task='report title').model == 'gpt-5.3-codex-spark'+ assert agent.llm.provider == 'browser-use'+ assert agent.model == 'bu-1-0'def test_rust_agent_translates_followup_to_existing_terminal_session(monkeypatch):