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 task helper parity
Magnus Müller9a61a39fa380
diff --git a/RUST_AGENT_INTEGRATION_FEATURES.md b/RUST_AGENT_INTEGRATION_FEATURES.mdindex f38056492..1629c5d22 100644--- a/RUST_AGENT_INTEGRATION_FEATURES.md+++ b/RUST_AGENT_INTEGRATION_FEATURES.md@@ -471,10 +471,15 @@ Terminal core branch: `magnus/browser-use-rust-integration` at terminal main `ee- The helper evaluates external stop callbacks, sets stopped state for should-stop callbacks, and raises `InterruptedError` for stopped or paused agents.- Proof: `test_rust_agent_check_stop_or_pause_matches_browser_use_lifecycle`.+93. Rust Agent task helper method parity+ - The Rust-backed `Agent` now exposes Browser Use's `_enhance_task_with_schema(...)` and `_extract_start_url(...)` helper methods.+ - The helpers preserve Browser Use-style schema text formatting and direct-start URL filtering for domains, email addresses, ambiguous tasks, and document URLs.+ - Proof: `test_rust_agent_exposes_task_helper_methods`.+## 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` (66 tests)+- `uv run pytest -q tests/ci/test_rust_agent.py` (67 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 aeafe647b..c04a78b0c 100644--- a/browser_use/rust/service.py+++ b/browser_use/rust/service.py@@ -1364,6 +1364,21 @@ class Agent(Generic[AgentStructuredOutput]):def message_manager(self) -> MessageManager:return self._message_manager+ def _enhance_task_with_schema(self, task: str, output_model_schema: type[AgentStructuredOutput] | None) -> str:+ """Enhance task description with Browser Use-style output schema information."""+ if output_model_schema is None:+ return task+ try:+ schema_json = json.dumps(output_model_schema.model_json_schema(), indent=2)+ return f'{task}\nExpected output format: {output_model_schema.__name__}\n{schema_json}'+ except Exception as exc:+ self.logger.debug(f'Could not parse output schema: {exc}')+ return task++ def _extract_start_url(self, task: str) -> str | None:+ """Extract Browser Use-style direct startup URL from a task string."""+ return _extract_start_url(task)+def _setup_action_models(self, page_url: str | None = None) -> None:"""Expose Browser Use-style action model classes from the configured tools."""registry = getattr(self.tools, 'registry', None)diff --git a/tests/ci/test_rust_agent.py b/tests/ci/test_rust_agent.pyindex 7fd2a3baa..bc4f5d9c4 100644--- a/tests/ci/test_rust_agent.py+++ b/tests/ci/test_rust_agent.py@@ -719,6 +719,24 @@ def test_rust_agent_mirrors_direct_url_startup():assert "First navigate to 'https://example.com'" in agent.task+def test_rust_agent_exposes_task_helper_methods():+ from browser_use.rust import Agent++ class Answer(BaseModel):+ answer: str++ agent = Agent(task='Open example.com and report the title.')++ enhanced = agent._enhance_task_with_schema('Return the answer.', Answer)++ assert agent._enhance_task_with_schema('Return the answer.', None) == 'Return the answer.'+ assert 'Expected output format: Answer' in enhanced+ assert '"answer"' in enhanced+ assert agent._extract_start_url('Open example.com and report the title.') == 'https://example.com'+ assert agent._extract_start_url('Email [email protected] only.') is None+ assert agent._extract_start_url('Open https://example.com/report.pdf and summarize it.') is None++def test_rust_agent_preserves_ordered_initial_actions_context():from browser_use.rust import Agent