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
Export Rust agent from agent package
Magnus Müllerce864232d4c9
diff --git a/RUST_AGENT_INTEGRATION_FEATURES.md b/RUST_AGENT_INTEGRATION_FEATURES.mdindex 807a60481..b2a18d4d6 100644--- a/RUST_AGENT_INTEGRATION_FEATURES.md+++ b/RUST_AGENT_INTEGRATION_FEATURES.md@@ -75,10 +75,15 @@ Terminal core branch: `magnus/browser-use-rust-integration` at latest pulled mai- A timed-out terminal run is killed and surfaced as a normal history error instead of hanging the Python wrapper indefinitely.- Proof: `test_rust_agent_terminal_process_timeout`.+14. Agent package import path+ - `from browser_use.agent import Agent` now lazily resolves to the same Rust-backed wrapper as `from browser_use import Agent`.+ - The export is lazy to avoid circular imports with `browser_use.agent.views`.+ - Proof: `test_agent_package_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` (21 tests)+- `uv run pytest -q tests/ci/test_rust_agent.py` (22 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`- Managed-headless end-to-end:diff --git a/browser_use/agent/__init__.py b/browser_use/agent/__init__.pynew file mode 100644index 000000000..2bf8af620--- /dev/null+++ b/browser_use/agent/__init__.py@@ -0,0 +1,31 @@+"""Agent package exports."""++from __future__ import annotations++from typing import TYPE_CHECKING++if TYPE_CHECKING:+ from browser_use.rust.service import Agent, RustAgentError++_LAZY_IMPORTS = {+ 'Agent': ('browser_use.rust.service', 'Agent'),+ 'RustAgentError': ('browser_use.rust.service', 'RustAgentError'),+}+++def __getattr__(name: str):+ if name in _LAZY_IMPORTS:+ module_path, attr_name = _LAZY_IMPORTS[name]+ from importlib import import_module++ module = import_module(module_path)+ attr = getattr(module, attr_name)+ globals()[name] = attr+ return attr+ raise AttributeError(f"module '{__name__}' has no attribute '{name}'")+++__all__ = [+ 'Agent',+ 'RustAgentError',+]diff --git a/tests/ci/test_rust_agent.py b/tests/ci/test_rust_agent.pyindex 65db959ea..4457cf760 100644--- a/tests/ci/test_rust_agent.py+++ b/tests/ci/test_rust_agent.py@@ -26,6 +26,13 @@ def test_top_level_agent_uses_rust_wrapper():assert TopLevelAgent is RustAgent+def test_agent_package_export_uses_rust_wrapper():+ from browser_use.agent import Agent as AgentPackageAgent+ from browser_use.rust import Agent as RustAgent++ assert AgentPackageAgent is RustAgent++def test_rust_events_reconstruct_browser_use_history():from browser_use.rust.service import _history_from_events