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
Add Rust agent action model setup signature parity
Magnus Müller0864e91e4aa2
diff --git a/RUST_AGENT_INTEGRATION_FEATURES.md b/RUST_AGENT_INTEGRATION_FEATURES.mdindex 252d518b6..23c313fff 100644--- a/RUST_AGENT_INTEGRATION_FEATURES.md+++ b/RUST_AGENT_INTEGRATION_FEATURES.md@@ -516,10 +516,15 @@ Terminal core branch: `magnus/browser-use-rust-integration` at terminal main `ee- Positional constructor calls that rely on Browser Use's public signature now route those values to the same Rust wrapper fields while retaining keyword compatibility.- Proof: `test_rust_agent_constructor_signature_matches_browser_use_order`.+102. Rust Agent action-model setup signature parity+ - The Rust-backed `Agent._setup_action_models()` now preserves Browser Use's no-argument helper signature.+ - Page-specific action-model rebuilding remains available through the Rust wrapper's internal helper and `_update_action_models_for_page(...)`, so filtered tool models still work without exposing an incompatible public helper signature.+ - Proof: `test_rust_agent_setup_action_models_signature_matches_browser_use`.+## Current Verification- `python3 -m py_compile 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` (75 tests)+- `uv run pytest -q tests/ci/test_rust_agent.py` (76 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.pyindex e6cd27dbc..0bfd7ef7a 100644--- a/browser_use/rust/service.py+++ b/browser_use/rust/service.py@@ -1699,8 +1699,12 @@ class Agent(Generic[AgentStructuredOutput]):result = result.replace(shortened_url, original_url)return result- def _setup_action_models(self, page_url: str | None = None) -> None:+ def _setup_action_models(self) -> None:"""Expose Browser Use-style action model classes from the configured tools."""+ self._setup_action_models_for_page(page_url=None)++ def _setup_action_models_for_page(self, page_url: str | None) -> None:+ """Create action model classes, optionally filtered for a specific page."""registry = getattr(self.tools, 'registry', None)create_action_model = getattr(registry, 'create_action_model', None)if not callable(create_action_model):@@ -1725,7 +1729,7 @@ class Agent(Generic[AgentStructuredOutput]):async def _update_action_models_for_page(self, page_url: str) -> None:"""Update Browser Use-style action model classes for page-filtered tools."""- self._setup_action_models(page_url=page_url)+ self._setup_action_models_for_page(page_url)def _convert_initial_actions(self, actions: list[dict[str, dict[str, Any]]]) -> list[Any]:"""Convert dictionary initial actions to Browser Use action model instances when possible."""diff --git a/tests/ci/test_rust_agent.py b/tests/ci/test_rust_agent.pyindex 520d068c3..f0362cf1e 100644--- a/tests/ci/test_rust_agent.py+++ b/tests/ci/test_rust_agent.py@@ -898,6 +898,29 @@ def test_rust_agent_initializes_tools_and_action_models():assert 'done' in str(done_schema)+def test_rust_agent_setup_action_models_signature_matches_browser_use():+ from browser_use.agent.service import Agent as BrowserUseAgent+ from browser_use.rust import Agent as RustAgent++ browser_use_signature = inspect.signature(BrowserUseAgent._setup_action_models)+ rust_signature = inspect.signature(RustAgent._setup_action_models)++ assert list(rust_signature.parameters) == list(browser_use_signature.parameters) == ['self']++ agent = RustAgent(task='Rebuild action models.')+ agent.ActionModel = None+ agent.DoneActionModel = None+ agent.AgentOutput = None+ agent.DoneAgentOutput = None++ agent._setup_action_models()++ assert agent.ActionModel is not None+ assert agent.DoneActionModel is not None+ assert agent.AgentOutput is not None+ assert agent.DoneAgentOutput is not None++async def test_rust_agent_updates_action_models_for_page(monkeypatch):from browser_use.rust import Agent