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 logger names
Magnus Müller1c653746b129
diff --git a/RUST_AGENT_INTEGRATION_FEATURES.md b/RUST_AGENT_INTEGRATION_FEATURES.mdindex 24616d47f..65a4cdda6 100644--- a/RUST_AGENT_INTEGRATION_FEATURES.md+++ b/RUST_AGENT_INTEGRATION_FEATURES.md@@ -1076,10 +1076,15 @@ Terminal core branch: `magnus/browser-use-rust-main-integration` at terminal mai- This preserves the public evaluation, memory, and next-goal log lines that callers see when using Python Agent helper methods against the Rust-backed interface.- Proof: `test_rust_agent_get_model_output_logs_response_like_browser_use`.+213. Rust Agent logger-name parity+ - Rust-backed `agent.logger` now uses Browser Use's task/browser/target-scoped logger name format instead of a Rust-specific logger namespace.+ - This preserves caller-visible log filtering and diagnostics that depend on `agent.logger.name`.+ - Proof: `test_rust_agent_logger_name_matches_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` (181 tests)+- `uv run pytest -q tests/ci/test_rust_agent.py` (182 tests)- `cargo build -q -p browser-use-cli` on terminal branch `magnus/browser-use-rust-main-integration`- `cargo test -q -p browser-use-cli run_codex_session_command_accepts_task_id_and_model -- --nocapture`- `CARGO_INCREMENTAL=0 cargo test -q -p browser-use-agent selected_remote_cdp_mode_allows_remote_cdp_connect -- --nocapture`diff --git a/browser_use/rust/service.py b/browser_use/rust/service.pyindex d9a22feb0..5ebb6b5f3 100644--- a/browser_use/rust/service.py+++ b/browser_use/rust/service.py@@ -3230,9 +3230,7 @@ class Agent(Generic[Context, AgentStructuredOutput]):focus_target_id = getattr(agent_focus, 'target_id', None)if isinstance(focus_target_id, str) and focus_target_id:target_id = focus_target_id[-2:]- return logging.getLogger(- f'browser_use.rust.Agent {self.task_id[-4:]} -> BrowserSession {str(browser_session_id)[-4:]} Target {target_id}'- )+ return logging.getLogger(f'browser_use.Agent🅰 {self.task_id[-4:]} ⇢ 🅑 {str(browser_session_id)[-4:]} 🅣 {target_id}')@propertydef browser_profile(self) -> Any:diff --git a/tests/ci/test_rust_agent.py b/tests/ci/test_rust_agent.pyindex 3e3a48072..8fa33aa33 100644--- a/tests/ci/test_rust_agent.py+++ b/tests/ci/test_rust_agent.py@@ -3162,7 +3162,7 @@ def test_rust_agent_initializes_runtime_metadata_and_observability():assert agent.versionassert agent.source == 'ci'- assert agent.logger.name.endswith('1234 Target --')+ assert agent.logger.name.endswith('1234 ⇢ 🅑 1234 🅣 --')assert agent.eventbus is not Noneassert callable(agent.telemetry.capture)assert callable(agent.telemetry.flush)@@ -3172,6 +3172,59 @@ def test_rust_agent_initializes_runtime_metadata_and_observability():assert agent.DoneAgentOutput is not None+async def test_rust_agent_logger_name_matches_browser_use(monkeypatch):+ import browser_use.rust.service as rust_service+ from browser_use.agent.service import _PythonAgent as BrowserUseAgent+ from browser_use.browser import BrowserProfile, BrowserSession+ from browser_use.rust import Agent as RustAgent++ class TestEventBus:+ def __init__(self, name):+ self.name = name++ def stop(self, *args, **kwargs):+ return None++ monkeypatch.setattr(rust_service, 'EventBus', TestEventBus)++ class LLM:+ model = 'gpt-test'+ provider = 'test'++ async def ainvoke(self, messages, output_format=None, **kwargs):+ return type('Result', (), {'usage': None})()++ async def stop_eventbus(eventbus):+ try:+ result = eventbus.stop(timeout=0.1, clear=True)+ except TypeError:+ result = eventbus.stop(timeout=0.1)+ if inspect.isawaitable(result):+ await result++ browser_use_agent = BrowserUseAgent(+ task='Inspect logger name.',+ llm=LLM(),+ browser_session=BrowserSession(browser_profile=BrowserProfile(), id='browser-abcd'),+ task_id='task-1234',+ directly_open_url=False,+ )+ browser_use_logger_name = browser_use_agent.logger.name+ await stop_eventbus(browser_use_agent.eventbus)++ rust_agent = RustAgent(+ task='Inspect logger name.',+ llm=LLM(),+ browser_session=BrowserSession(browser_profile=BrowserProfile(), id='browser-abcd'),+ task_id='task-1234',+ directly_open_url=False,+ )++ assert rust_agent.logger.name == browser_use_logger_name+ assert rust_agent.logger.name == 'browser_use.Agent🅰 1234 ⇢ 🅑 abcd 🅣 --'+ await stop_eventbus(rust_agent.eventbus)++async def test_rust_agent_exposes_logging_helper_methods(monkeypatch):import time