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
Match Rust agent action helper type hints
Magnus Müllera5cd7c2ed33f
diff --git a/RUST_AGENT_INTEGRATION_FEATURES.md b/RUST_AGENT_INTEGRATION_FEATURES.mdindex 82c1fba01..71c720764 100644--- a/RUST_AGENT_INTEGRATION_FEATURES.md+++ b/RUST_AGENT_INTEGRATION_FEATURES.md@@ -571,10 +571,15 @@ Terminal core branch: `magnus/browser-use-rust-integration` at terminal main `ee- `on_step_start` and `on_step_end` resolve to Browser Use's `Callable[[Agent], Awaitable[None]] | None` hook shape instead of the previous loose `Any` callback annotation, while the runtime callback behavior remains unchanged.- Proof: `test_rust_agent_run_type_hints_match_browser_use_hooks`.+113. Rust Agent action-model helper type-hint parity+ - The Rust-backed action helper methods now expose Browser Use's action-model type metadata for callers that introspect replay and multi-action APIs.+ - `_convert_initial_actions(...)`, `_update_action_indices(...)`, and `multi_act(...)` now resolve to Browser Use's `ActionModel`, `DOMInteractedElement`, and `BrowserStateSummary` annotations instead of loose `Any` metadata.+ - Proof: `test_rust_agent_action_model_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` (86 tests)+- `uv run pytest -q tests/ci/test_rust_agent.py` (87 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 48b8a623a..f34359e62 100644--- a/browser_use/rust/service.py+++ b/browser_use/rust/service.py@@ -39,6 +39,7 @@ from browser_use.agent.views import (from browser_use.browser import BrowserProfile, BrowserSessionfrom browser_use.browser.profile import CHROME_DETERMINISTIC_RENDERING_ARGS, CHROME_DISABLE_SECURITY_ARGS, CHROME_DOCKER_ARGSfrom browser_use.browser.views import BrowserStateHistory, BrowserStateSummary, TabInfo+from browser_use.dom.views import DOMInteractedElementfrom browser_use.filesystem.file_system import FileSystemfrom browser_use.llm.base import BaseChatModelfrom browser_use.llm.messages import ContentPartImageParam, ContentPartTextParam@@ -47,6 +48,7 @@ from browser_use.telemetry.service import ProductTelemetryfrom browser_use.telemetry.views import AgentTelemetryEventfrom browser_use.tokens.service import TokenCostfrom browser_use.tokens.views import ModelUsageStats, UsageSummary+from browser_use.tools.registry.views import ActionModelfrom browser_use.tools.service import Toolsfrom browser_use.utils import URL_PATTERN, check_latest_browser_use_version, get_browser_use_version@@ -1760,7 +1762,7 @@ class Agent(Generic[Context, AgentStructuredOutput]):"""Update Browser Use-style action model classes for page-filtered tools."""self._setup_action_models_for_page(page_url)- def _convert_initial_actions(self, actions: list[dict[str, dict[str, Any]]]) -> list[Any]:+ def _convert_initial_actions(self, actions: list[dict[str, dict[str, Any]]]) -> list[ActionModel]:"""Convert dictionary initial actions to Browser Use action model instances when possible."""converted_actions: list[Any] = []registry = getattr(getattr(self.tools, 'registry', None), 'registry', None)@@ -2104,7 +2106,7 @@ class Agent(Generic[Context, AgentStructuredOutput]):_ = max_stepsreturn history.is_done()- async def multi_act(self, actions: list[Any]) -> list[ActionResult]:+ async def multi_act(self, actions: list[ActionModel]) -> list[ActionResult]:"""Execute Browser Use action models through the Rust-backed session.The Rust terminal owns browser actions, so non-`done` action batches are@@ -2201,10 +2203,10 @@ class Agent(Generic[Context, AgentStructuredOutput]):async def _update_action_indices(self,- historical_element: Any | None,- action: Any,- browser_state_summary: Any,- ) -> Any | None:+ historical_element: DOMInteractedElement | None,+ action: ActionModel,+ browser_state_summary: BrowserStateSummary,+ ) -> ActionModel | None:"""Update an action index when a historical DOM element moved."""selector_map = getattr(getattr(browser_state_summary, 'dom_state', None), 'selector_map', {})if not historical_element or not selector_map:diff --git a/tests/ci/test_rust_agent.py b/tests/ci/test_rust_agent.pyindex f16a40489..aca104a29 100644--- a/tests/ci/test_rust_agent.py+++ b/tests/ci/test_rust_agent.py@@ -139,6 +139,17 @@ def test_rust_agent_run_type_hints_match_browser_use_hooks():assert rust_hints == browser_use_hints+def test_rust_agent_action_model_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 ('_convert_initial_actions', '_update_action_indices', 'multi_act'):+ 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