Skip to content

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

Match Rust agent unannotated helper hints

Magnus Müller4d8724f9037a
diff --git a/RUST_AGENT_INTEGRATION_FEATURES.md b/RUST_AGENT_INTEGRATION_FEATURES.md
index c270df7e2..3f1b93eaa 100644
--- a/RUST_AGENT_INTEGRATION_FEATURES.md
+++ b/RUST_AGENT_INTEGRATION_FEATURES.md
@@ -586,10 +586,15 @@ Terminal core branch: `magnus/browser-use-rust-integration` at terminal main `ee
- `get_model_output(...)`, `_get_model_output_with_retry(...)`, `_handle_post_llm_processing(...)`, and `_process_messsages_and_replace_long_urls_shorter_ones(...)` now resolve to Browser Use's message-list annotations instead of loose `Any` metadata.
- Proof: `test_rust_agent_llm_message_helper_type_hints_match_browser_use`.
+116. Rust Agent unannotated helper type-hint parity
+ - The Rust-backed helper methods now mirror Browser Use's intentionally unannotated metadata for helpers where the Python Agent does not publish runtime type hints.
+ - `_log_action(...)`, `_verify_and_setup_llm()`, `close()`, and `load_and_rerun(...)` no longer expose Rust-only `Any` or return annotations that Browser Use callers would not see.
+ - Proof: `test_rust_agent_unannotated_helper_type_hints_match_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` (89 tests)
+- `uv run pytest -q tests/ci/test_rust_agent.py` (90 tests)
- `cargo build -q -p browser-use-cli`
- `CARGO_INCREMENTAL=0 cargo test -q -p browser-use-agent selected_remote_cdp_mode_allows_remote_cdp_connect -- --nocapture`
- `CARGO_INCREMENTAL=0 cargo test -q -p browser-use-agent bare_browser_connect_resolves_to_selected_managed_mode_with_launch_args -- --nocapture`
diff --git a/browser_use/rust/service.py b/browser_use/rust/service.py
index 1cf486729..518cecf5b 100644
--- a/browser_use/rust/service.py
+++ b/browser_use/rust/service.py
@@ -1280,7 +1280,7 @@ class Agent(Generic[Context, AgentStructuredOutput]):
"""Expose Browser Use version/source metadata on the Rust-backed wrapper."""
self.version, self.source = _browser_use_version_and_source(source_override)
- def _verify_and_setup_llm(self) -> bool:
+ def _verify_and_setup_llm(self):
"""Mirror Browser Use LLM verification state for callers that use the helper."""
if self.llm is None:
return True
@@ -1446,7 +1446,7 @@ class Agent(Generic[Context, AgentStructuredOutput]):
)
)
- def _log_action(self, action: Any, action_name: str, action_num: int, total_actions: int) -> None:
+ def _log_action(self, action, action_name: str, action_num: int, total_actions: int) -> None:
"""Log an action before execution with Browser Use-style structure."""
action_header = f'[{action_num}/{total_actions}] {action_name}:' if total_actions > 1 else f'{action_name}:'
action_data = action.model_dump(exclude_unset=True)
@@ -2267,7 +2267,7 @@ class Agent(Generic[Context, AgentStructuredOutput]):
result = await self.run(max_steps=self.kwargs.get('max_steps', 100))
return result.action_results()
- async def load_and_rerun(self, history_file: str | Path | None = None, **kwargs: Any) -> list[ActionResult]:
+ async def load_and_rerun(self, history_file: str | Path | None = None, **kwargs) -> list[ActionResult]:
"""Load a saved Rust-backed Browser Use history and rerun the task."""
if not history_file:
history_file = 'AgentHistory.json'
@@ -2289,7 +2289,7 @@ class Agent(Generic[Context, AgentStructuredOutput]):
self.state.stopped = True
self._external_pause_event.set()
- async def close(self) -> None:
+ async def close(self):
"""Browser Use-compatible close hook.
The Rust terminal owns browser lifecycle for managed modes, and remote CDP
diff --git a/tests/ci/test_rust_agent.py b/tests/ci/test_rust_agent.py
index 562f8b735..6cf0ddfad 100644
--- a/tests/ci/test_rust_agent.py
+++ b/tests/ci/test_rust_agent.py
@@ -177,6 +177,17 @@ def test_rust_agent_llm_message_helper_type_hints_match_browser_use():
assert rust_hints == browser_use_hints
+def test_rust_agent_unannotated_helper_type_hints_match_browser_use():
+ from browser_use.agent.service import _PythonAgent as BrowserUseAgent
+ from browser_use.rust import Agent as RustAgent
+
+ for method_name in ('_log_action', '_verify_and_setup_llm', 'close', 'load_and_rerun'):
+ browser_use_hints = get_type_hints(getattr(BrowserUseAgent, method_name))
+ rust_hints = get_type_hints(getattr(RustAgent, method_name))
+
+ assert rust_hints == browser_use_hints
+
+
def test_rust_events_reconstruct_browser_use_history():
from browser_use.rust.service import _history_from_events