Skip to content

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

Add Rust agent page action model parity

Magnus Müller80ec55d54dcd
diff --git a/RUST_AGENT_INTEGRATION_FEATURES.md b/RUST_AGENT_INTEGRATION_FEATURES.md
index 9134f5229..0daf99289 100644
--- a/RUST_AGENT_INTEGRATION_FEATURES.md
+++ b/RUST_AGENT_INTEGRATION_FEATURES.md
@@ -456,10 +456,15 @@ Terminal core branch: `magnus/browser-use-rust-integration` at terminal main `ee
- The helper preserves Browser Use-style step start/end callbacks, returns the done state, and records timeout errors in `state.last_result`.
- Proof: `test_rust_agent_execute_step_runs_one_turn_with_callbacks`.
+90. Rust Agent page action model update parity
+ - The Rust-backed `Agent` now exposes Browser Use's async `_update_action_models_for_page(...)` helper.
+ - Page updates rebuild `ActionModel`, `AgentOutput`, `DoneActionModel`, and `DoneAgentOutput` through the configured tools registry with the current page URL.
+ - Proof: `test_rust_agent_updates_action_models_for_page`.
+
## 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` (63 tests)
+- `uv run pytest -q tests/ci/test_rust_agent.py` (64 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 c3a91d836..4c13c6aef 100644
--- a/browser_use/rust/service.py
+++ b/browser_use/rust/service.py
@@ -1383,6 +1383,10 @@ class Agent(Generic[AgentStructuredOutput]):
else:
self.DoneAgentOutput = AgentOutput.type_with_custom_actions_no_thinking(self.DoneActionModel)
+ 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)
+
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."""
converted_actions: list[Any] = []
diff --git a/tests/ci/test_rust_agent.py b/tests/ci/test_rust_agent.py
index 060bc75d2..c5fab4cf2 100644
--- a/tests/ci/test_rust_agent.py
+++ b/tests/ci/test_rust_agent.py
@@ -805,6 +805,32 @@ def test_rust_agent_initializes_tools_and_action_models():
assert 'done' in str(done_schema)
+async def test_rust_agent_updates_action_models_for_page(monkeypatch):
+ from browser_use.rust import Agent
+
+ agent = Agent(task='Use page-specific tools.')
+ registry = agent.tools.registry
+ original_create_action_model = registry.create_action_model
+ seen = []
+
+ def recording_create_action_model(*args, **kwargs):
+ seen.append(kwargs)
+ return original_create_action_model(*args, **kwargs)
+
+ monkeypatch.setattr(registry, 'create_action_model', recording_create_action_model)
+
+ await agent._update_action_models_for_page('https://example.com/settings')
+
+ assert seen == [
+ {'page_url': 'https://example.com/settings'},
+ {'include_actions': ['done'], 'page_url': 'https://example.com/settings'},
+ ]
+ assert agent.ActionModel is not None
+ assert agent.DoneActionModel is not None
+ assert agent.AgentOutput is not None
+ assert agent.DoneAgentOutput is not None
+
+
def test_rust_agent_initializes_runtime_metadata_and_observability():
from browser_use.rust import Agent
from browser_use.tokens.service import TokenCost