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 execution start

Magnus Müller3688f70eda8c
diff --git a/RUST_AGENT_INTEGRATION_FEATURES.md b/RUST_AGENT_INTEGRATION_FEATURES.md
index 2735be224..a97477d95 100644
--- a/RUST_AGENT_INTEGRATION_FEATURES.md
+++ b/RUST_AGENT_INTEGRATION_FEATURES.md
@@ -886,10 +886,15 @@ Terminal core branch: `magnus/browser-use-rust-main-integration` at terminal mai
- The first run logs session and task event dispatches; later runs on the same Browser Use session log only the task dispatch, matching the one-session/many-tasks lifecycle.
- Proof: `test_rust_agent_run_logs_browser_use_lifecycle_dispatch`.
+175. Rust Agent main-loop start debug logging parity
+ - Terminal-backed `Agent.run()` now logs Browser Use's main execution-loop start line immediately before launching the Rust terminal core.
+ - The log includes the resolved max-step budget, preserving the observable run-start debug metadata expected by Browser Use callers.
+ - Proof: `test_rust_agent_run_logs_main_execution_start`.
+
## 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` (146 tests)
+- `uv run pytest -q tests/ci/test_rust_agent.py` (147 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 b0921ce24..5b71e641b 100644
--- a/browser_use/rust/service.py
+++ b/browser_use/rust/service.py
@@ -2661,6 +2661,10 @@ class Agent(Generic[Context, AgentStructuredOutput]):
f'Starting a browser-use agent with version {self.version}, with provider={provider} and model={model}'
)
+ def _log_main_execution_start(self, max_steps: int) -> None:
+ """Log Browser Use's main execution-loop start for terminal-backed runs."""
+ self.logger.debug(f'Starting main execution loop with max {max_steps} steps...')
+
def _log_step_context(self, browser_state_summary: BrowserStateSummary) -> None:
"""Log current step and page context."""
url = getattr(browser_state_summary, 'url', '') if browser_state_summary else ''
@@ -2989,6 +2993,7 @@ class Agent(Generic[Context, AgentStructuredOutput]):
self.state.follow_up_task = False
return await self._follow_up_terminal(self.task, max_steps=max_steps, resolved_max_steps=max_steps)
+ self._log_main_execution_start(max_steps)
returncode, stdout_text, stderr_text = await self._run_process(self._run_argv(max_steps), timeout_seconds=self.settings.step_timeout)
finished = time.time()
self.last_stdout = stdout_text
diff --git a/tests/ci/test_rust_agent.py b/tests/ci/test_rust_agent.py
index 9aa6d4446..c494bdb9e 100644
--- a/tests/ci/test_rust_agent.py
+++ b/tests/ci/test_rust_agent.py
@@ -3167,6 +3167,46 @@ async def test_rust_agent_run_logs_browser_use_setup_metadata(monkeypatch):
assert logger.errors == []
+async def test_rust_agent_run_logs_main_execution_start(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 main execution start.', llm=type('LLM', (), {'model': 'gpt-test'})())
+
+ async def fake_run_process(argv, timeout_seconds=None):
+ assert 'Starting main execution loop with max 6 steps...' 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 execution start'}}]
+
+ agent._run_process = fake_run_process
+ agent._load_events = fake_load_events
+
+ history = await agent.run(max_steps=6)
+
+ assert history.final_result() == 'logged execution start'
+ assert logger.errors == []
+
+
async def test_rust_agent_run_registers_browser_use_signal_handler(monkeypatch):
import asyncio