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 first-step startup

Magnus Müller10d76210e5d7
diff --git a/RUST_AGENT_INTEGRATION_FEATURES.md b/RUST_AGENT_INTEGRATION_FEATURES.md
index 909586cc2..06f48ddc0 100644
--- a/RUST_AGENT_INTEGRATION_FEATURES.md
+++ b/RUST_AGENT_INTEGRATION_FEATURES.md
@@ -871,10 +871,15 @@ Terminal core branch: `magnus/browser-use-rust-main-integration` at terminal mai
- Failed follow-ups log usage summaries, record telemetry with the follow-up error text, dispatch the final task update, log final guidance, unregister signal handlers, close browser resources, and then re-raise the original exception.
- Proof: `test_rust_agent_follow_up_finalizes_after_terminal_exception`.
+172. Rust Agent first-step startup logging parity
+ - Terminal-backed `Agent.run()` now invokes Browser Use's first-step startup logging before Rust terminal execution when history is empty.
+ - 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`.
+
## 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` (143 tests)
+- `uv run pytest -q tests/ci/test_rust_agent.py` (144 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 0daf8cce2..008028ffa 100644
--- a/browser_use/rust/service.py
+++ b/browser_use/rust/service.py
@@ -2934,6 +2934,7 @@ class Agent(Generic[Context, AgentStructuredOutput]):
await self._log_agent_run()
await self._call_callback(on_step_start, self)
self._initialize_run_lifecycle_state()
+ self._log_first_step_startup()
started = time.time()
if await self._should_stop_before_run():
finished = time.time()
diff --git a/tests/ci/test_rust_agent.py b/tests/ci/test_rust_agent.py
index c24128439..1d7364264 100644
--- a/tests/ci/test_rust_agent.py
+++ b/tests/ci/test_rust_agent.py
@@ -3076,6 +3076,53 @@ async def test_rust_agent_run_logs_browser_use_run_metadata(monkeypatch):
assert logger.errors == []
+async def test_rust_agent_run_logs_first_step_startup(monkeypatch):
+ from browser_use.rust import Agent
+
+ monkeypatch.setenv('BROWSER_USE_TERMINAL_BINARY', '/tmp/browser-use-terminal')
+
+ class LLM:
+ model = 'gpt-startup'
+ provider = 'startup-provider'
+
+ 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 startup metadata.', llm=LLM())
+
+ async def fake_run_process(argv, timeout_seconds=None):
+ assert (
+ f'Starting a browser-use agent with version {agent.version}, '
+ 'with provider=startup-provider and model=gpt-startup'
+ ) in logger.infos
+ return 0, 'Session: 12345678-1234-1234-1234-123456789abc\n', ''
+
+ async def fake_load_events():
+ return [{'event_type': 'session.done', 'payload': {'result': 'logged startup'}}]
+
+ agent._run_process = fake_run_process
+ agent._load_events = fake_load_events
+
+ history = await agent.run(max_steps=1)
+
+ assert history.final_result() == 'logged startup'
+ assert logger.errors == []
+
+
async def test_rust_agent_run_registers_browser_use_signal_handler(monkeypatch):
import asyncio