Skip to content

Open-source Python library for AI browser agents, plus Browser Use Cloud: stealth browsers and a hosted agent API.

Verify Rust LLMs during construction

Magnus Müllerb19d187836fd
diff --git a/RUST_AGENT_INTEGRATION_FEATURES.md b/RUST_AGENT_INTEGRATION_FEATURES.md
index 551310b9a..d78635db0 100644
--- a/RUST_AGENT_INTEGRATION_FEATURES.md
+++ b/RUST_AGENT_INTEGRATION_FEATURES.md
@@ -1036,10 +1036,15 @@ Terminal core branch: `magnus/browser-use-rust-main-integration` at terminal mai
- Rust-backed `stop()` now logs Browser Use's stop message before setting the stopped state and unblocking paused runs.
- Proof: `test_rust_agent_control_methods_match_browser_use_user_feedback`.
+205. Rust Agent constructor LLM verification parity
+ - Rust-backed construction now invokes `_verify_and_setup_llm()` during initialization, matching Browser Use's constructor lifecycle instead of exposing the helper only for direct callers.
+ - 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`.
+
## 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` (173 tests)
+- `uv run pytest -q tests/ci/test_rust_agent.py` (174 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.py
index aa829bf30..ce0b8ae8e 100644
--- a/browser_use/rust/service.py
+++ b/browser_use/rust/service.py
@@ -2579,6 +2579,7 @@ class Agent(Generic[Context, AgentStructuredOutput]):
self.settings.save_conversation_path = Path(self.settings.save_conversation_path).expanduser().resolve()
self.logger.info(f'💬 Saving conversation to {_log_pretty_path(self.settings.save_conversation_path)}')
self._setup_action_models()
+ self._verify_and_setup_llm()
model_name = str(getattr(self.llm, 'model', self.model) or '').lower()
if 'deepseek' in model_name:
self.logger.warning('DeepSeek models do not support use_vision=True yet. Setting use_vision=False for now...')
diff --git a/tests/ci/test_rust_agent.py b/tests/ci/test_rust_agent.py
index 0e1b2df91..d99fa7639 100644
--- a/tests/ci/test_rust_agent.py
+++ b/tests/ci/test_rust_agent.py
@@ -4823,6 +4823,23 @@ def test_rust_agent_exposes_setup_helper_methods(tmp_path):
assert agent.file_system.base_dir == new_file_system_path
+def test_rust_agent_constructor_invokes_llm_verification(monkeypatch):
+ from browser_use.rust import Agent
+
+ class LLM:
+ model = 'gpt-test'
+ provider = 'test-provider'
+ _verified_api_keys = False
+
+ monkeypatch.setenv('SKIP_LLM_API_KEY_VERIFICATION', 'true')
+
+ llm = LLM()
+ agent = Agent(task='Verify LLM during construction.', llm=llm, directly_open_url=False)
+
+ assert agent.llm is llm
+ assert llm._verified_api_keys is True
+
+
def test_rust_agent_browser_profile_property_tracks_session_profile():
from browser_use.rust import Agent