Skip to content

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

Log Rust agent setup metadata

Magnus Müllerbbf2285f732f
diff --git a/RUST_AGENT_INTEGRATION_FEATURES.md b/RUST_AGENT_INTEGRATION_FEATURES.md
index 06f48ddc0..94596954f 100644
--- a/RUST_AGENT_INTEGRATION_FEATURES.md
+++ b/RUST_AGENT_INTEGRATION_FEATURES.md
@@ -876,10 +876,15 @@ Terminal core branch: `magnus/browser-use-rust-main-integration` at terminal mai
- The startup log preserves the Browser Use provider/model/version line that callers and support logs expect at the beginning of a run.
- Proof: `test_rust_agent_run_logs_first_step_startup`.
+173. Rust Agent setup debug logging parity
+ - Terminal-backed `Agent.run()` now logs Browser Use-style setup metadata after run metadata and before Rust terminal execution.
+ - The setup log exposes the public agent session suffix, task suffix, browser session suffix, and whether the run is launching locally or connecting through CDP.
+ - Proof: `test_rust_agent_run_logs_browser_use_setup_metadata`.
+
## 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` (144 tests)
+- `uv run pytest -q tests/ci/test_rust_agent.py` (145 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.py
index 008028ffa..37348819f 100644
--- a/browser_use/rust/service.py
+++ b/browser_use/rust/service.py
@@ -2641,6 +2641,16 @@ class Agent(Generic[Context, AgentStructuredOutput]):
f'Newer version available: {latest_version} (current: {self.version}). Upgrade with: uv add browser-use@{latest_version}'
)
+ def _log_agent_setup(self) -> None:
+ """Log Browser Use run setup metadata for the Rust-backed wrapper."""
+ browser_session_id = getattr(self.browser_session, 'id', None) if self.browser_session else None
+ browser_session_suffix = str(browser_session_id)[-4:] if browser_session_id else 'None'
+ cdp_url = getattr(self.browser_session, 'cdp_url', None) if self.browser_session else None
+ connection_mode = '(connecting via CDP)' if cdp_url else '(launching local browser)'
+ self.logger.debug(
+ f'Agent setup: Agent Session ID {self.session_id[-4:]}, Task ID {self.task_id[-4:]}, Browser Session ID {browser_session_suffix} {connection_mode}'
+ )
+
def _log_first_step_startup(self) -> None:
"""Log the first-step startup line used by Browser Use callers."""
if len(self.history.history) != 0:
@@ -2932,6 +2942,7 @@ class Agent(Generic[Context, AgentStructuredOutput]):
on_step_end: AgentHookFunc | None,
) -> AgentHistoryList[AgentStructuredOutput]:
await self._log_agent_run()
+ self._log_agent_setup()
await self._call_callback(on_step_start, self)
self._initialize_run_lifecycle_state()
self._log_first_step_startup()
diff --git a/tests/ci/test_rust_agent.py b/tests/ci/test_rust_agent.py
index 1d7364264..5e953a852 100644
--- a/tests/ci/test_rust_agent.py
+++ b/tests/ci/test_rust_agent.py
@@ -3123,6 +3123,50 @@ async def test_rust_agent_run_logs_first_step_startup(monkeypatch):
assert logger.errors == []
+async def test_rust_agent_run_logs_browser_use_setup_metadata(monkeypatch):
+ from browser_use.rust import Agent
+
+ monkeypatch.setenv('BROWSER_USE_TERMINAL_BINARY', '/tmp/browser-use-terminal')
+
+ class RecordingLogger:
+ def __init__(self):
+ self.infos = []
+ self.debugs = []
+ self.errors = []
+
+ def info(self, message, *args, **kwargs):
+ self.infos.append(message)
+
+ def debug(self, message, *args, **kwargs):
+ self.debugs.append(message)
+
+ def error(self, message, *args, **kwargs):
+ self.errors.append(message)
+
+ logger = RecordingLogger()
+ monkeypatch.setattr(Agent, 'logger', property(lambda self: logger))
+ agent = Agent(task='Log setup metadata.', llm=type('LLM', (), {'model': 'gpt-test'})())
+
+ async def fake_run_process(argv, timeout_seconds=None):
+ expected = (
+ f'Agent setup: Agent Session ID {agent.session_id[-4:]}, Task ID {agent.task_id[-4:]}, '
+ f'Browser Session ID {agent.browser_session.id[-4:]} (launching local browser)'
+ )
+ assert expected in logger.debugs
+ return 0, 'Session: 12345678-1234-1234-1234-123456789abc\n', ''
+
+ async def fake_load_events():
+ return [{'event_type': 'session.done', 'payload': {'result': 'logged setup'}}]
+
+ agent._run_process = fake_run_process
+ agent._load_events = fake_load_events
+
+ history = await agent.run(max_steps=1)
+
+ assert history.final_result() == 'logged setup'
+ assert logger.errors == []
+
+
async def test_rust_agent_run_registers_browser_use_signal_handler(monkeypatch):
import asyncio