Skip to content

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

Route agent service import to Rust agent

Magnus Müller04d239946a13
diff --git a/RUST_AGENT_INTEGRATION_FEATURES.md b/RUST_AGENT_INTEGRATION_FEATURES.md
index 23c313fff..b63de39d8 100644
--- a/RUST_AGENT_INTEGRATION_FEATURES.md
+++ b/RUST_AGENT_INTEGRATION_FEATURES.md
@@ -521,10 +521,15 @@ Terminal core branch: `magnus/browser-use-rust-integration` at terminal main `ee
- 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`.
+103. Rust Agent service import parity
+ - `from browser_use.agent.service import Agent` now resolves to the Rust-backed Agent wrapper, matching the top-level `browser_use.Agent` and package-level `browser_use.agent.Agent` exports.
+ - The original Python Agent class remains available privately as `_PythonAgent` for parity audits while common direct service imports run through the Rust core.
+ - Proof: `test_agent_service_export_uses_rust_wrapper`.
+
## 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` (76 tests)
+- `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` (77 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/agent/service.py b/browser_use/agent/service.py
index a65bb3b2d..e65c08a32 100644
--- a/browser_use/agent/service.py
+++ b/browser_use/agent/service.py
@@ -2309,3 +2309,8 @@ class Agent(Generic[Context, AgentStructuredOutput]):
import asyncio
return asyncio.run(self.run(max_steps=max_steps, on_step_start=on_step_start, on_step_end=on_step_end))
+
+
+_PythonAgent = Agent
+
+from browser_use.rust.service import Agent as Agent
diff --git a/tests/ci/test_rust_agent.py b/tests/ci/test_rust_agent.py
index f0362cf1e..4b18375c5 100644
--- a/tests/ci/test_rust_agent.py
+++ b/tests/ci/test_rust_agent.py
@@ -34,8 +34,15 @@ def test_agent_package_export_uses_rust_wrapper():
assert AgentPackageAgent is RustAgent
+def test_agent_service_export_uses_rust_wrapper():
+ from browser_use.agent.service import Agent as ServiceAgent
+ from browser_use.rust import Agent as RustAgent
+
+ assert ServiceAgent is RustAgent
+
+
def test_rust_agent_constructor_signature_matches_browser_use_order(tmp_path):
- from browser_use.agent.service import Agent as BrowserUseAgent
+ from browser_use.agent.service import _PythonAgent as BrowserUseAgent
from browser_use.rust import Agent as RustAgent
browser_use_params = list(inspect.signature(BrowserUseAgent.__init__).parameters)
@@ -899,7 +906,7 @@ def test_rust_agent_initializes_tools_and_action_models():
def test_rust_agent_setup_action_models_signature_matches_browser_use():
- from browser_use.agent.service import Agent as BrowserUseAgent
+ from browser_use.agent.service import _PythonAgent as BrowserUseAgent
from browser_use.rust import Agent as RustAgent
browser_use_signature = inspect.signature(BrowserUseAgent._setup_action_models)