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 event bus naming
Magnus Müller26ab1d008481
diff --git a/RUST_AGENT_INTEGRATION_FEATURES.md b/RUST_AGENT_INTEGRATION_FEATURES.mdindex e4b45da73..6bd9cf899 100644--- a/RUST_AGENT_INTEGRATION_FEATURES.md+++ b/RUST_AGENT_INTEGRATION_FEATURES.md@@ -556,10 +556,15 @@ Terminal core branch: `magnus/browser-use-rust-integration` at terminal main `ee- The redirected `browser_use.agent.service.Agent` import also supports the same two-argument generic subscription, while one-argument subscriptions raise the same too-few-arguments error shape as Browser Use.- Proof: `test_rust_agent_generic_subscription_matches_browser_use`.+110. Rust Agent event bus naming parity+ - The Rust-backed Agent now mirrors Browser Use's public event bus naming convention with an `Agent_` prefix and public task-id suffix.+ - Hyphenated task-id suffixes are sanitized into valid identifiers, and follow-up task event buses keep the same base prefix with a unique suffix.+ - Proof: `test_rust_agent_eventbus_name_matches_browser_use_suffix_prefix`.+## 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` (83 tests)+- `uv run pytest -q tests/ci/test_rust_agent.py` (84 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 4dbfab597..dfbd71bf7 100644--- a/browser_use/rust/service.py+++ b/browser_use/rust/service.py@@ -980,14 +980,12 @@ def _register_llm_for_usage(token_cost_service: TokenCost, llm: Any | None) -> Nreturn-def _eventbus_name(agent_id: str, prefix: str = 'RustAgent') -> str:- suffix = re.sub(r'\W', '_', str(agent_id)[-8:])- if suffix and suffix[0].isdigit():- suffix = 'a' + suffix+def _eventbus_name(agent_id: str, prefix: str = 'Agent') -> str:+ suffix = re.sub(r'\W', '_', str(agent_id)[-4:])return f'{prefix}_{suffix or "agent"}'-def _unique_eventbus_name(agent_id: str, prefix: str = 'RustAgent') -> str:+def _unique_eventbus_name(agent_id: str, prefix: str = 'Agent') -> str:unique_suffix = re.sub(r'\W', '_', uuid7str()[-8:])return f'{_eventbus_name(agent_id, prefix)}_{unique_suffix}'diff --git a/tests/ci/test_rust_agent.py b/tests/ci/test_rust_agent.pyindex 7f2e786ee..bdce78e28 100644--- a/tests/ci/test_rust_agent.py+++ b/tests/ci/test_rust_agent.py@@ -1025,14 +1025,21 @@ def test_rust_agent_state_id_defaults_like_browser_use():async def ainvoke(self, messages, output_format=None, **kwargs):return type('Result', (), {'usage': None})()- task_id = 'explicit_task_id'llm = LLM()- browser_use_agent = BrowserUseAgent(task='Inspect state.', llm=llm, task_id=task_id, directly_open_url=False)- rust_agent = RustAgent(task='Inspect state.', llm=llm, task_id=task_id, directly_open_url=False)+ browser_use_task_id = 'browser_use_state'+ rust_task_id = 'rust_state_id'+ browser_use_agent = BrowserUseAgent(+ task='Inspect state.',+ llm=llm,+ task_id=browser_use_task_id,+ directly_open_url=False,+ )+ rust_agent = RustAgent(task='Inspect state.', llm=llm, task_id=rust_task_id, directly_open_url=False)- assert browser_use_agent.task_id == rust_agent.task_id == task_id- assert browser_use_agent.state.agent_id != task_id- assert rust_agent.state.agent_id != task_id+ assert browser_use_agent.task_id == browser_use_task_id+ assert rust_agent.task_id == rust_task_id+ assert browser_use_agent.state.agent_id != browser_use_task_id+ assert rust_agent.state.agent_id != rust_task_idassert rust_agent.state.n_steps == browser_use_agent.state.n_steps == 1injected_state = AgentState(agent_id='restored-state-id')@@ -1042,6 +1049,32 @@ def test_rust_agent_state_id_defaults_like_browser_use():assert restored_agent.state.agent_id == 'restored-state-id'+def test_rust_agent_eventbus_name_matches_browser_use_suffix_prefix():+ from browser_use.agent.service import _PythonAgent as BrowserUseAgent+ from browser_use.rust import Agent as RustAgent++ class LLM:+ model = 'gpt-test'+ provider = 'test'++ async def ainvoke(self, messages, output_format=None, **kwargs):+ return type('Result', (), {'usage': None})()++ browser_use_agent = BrowserUseAgent(task='Inspect event bus.', llm=LLM(), task_id='browseruseabcd', directly_open_url=False)+ rust_agent = RustAgent(task='Inspect event bus.', llm=LLM(), task_id='rustagentwxyz', directly_open_url=False)++ assert browser_use_agent.eventbus.name == 'Agent_abcd'+ assert rust_agent.eventbus.name == 'Agent_wxyz'++ rust_agent_with_hyphen = RustAgent(task='Inspect event bus.', llm=LLM(), task_id='task-1', directly_open_url=False)+ initial_name = rust_agent_with_hyphen.eventbus.name+ rust_agent_with_hyphen.add_new_task('Follow up.')++ assert initial_name == 'Agent_sk_1'+ assert rust_agent_with_hyphen.eventbus.name.startswith(f'{initial_name}_')+ assert rust_agent_with_hyphen.eventbus.name.isidentifier()++def test_rust_agent_initializes_tools_and_action_models():from browser_use.rust import Agentfrom browser_use.tools.service import Tools