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 final outcome guidance

Magnus Müller5f91da04a44a
diff --git a/RUST_AGENT_INTEGRATION_FEATURES.md b/RUST_AGENT_INTEGRATION_FEATURES.md
index e1eccb2eb..ec5d7a394 100644
--- a/RUST_AGENT_INTEGRATION_FEATURES.md
+++ b/RUST_AGENT_INTEGRATION_FEATURES.md
@@ -846,10 +846,15 @@ Terminal core branch: `magnus/browser-use-rust-main-integration` at terminal mai
- Usage-summary logging runs before telemetry/event finalization, matching the Python Agent's observable run finalization order.
- Proof: `test_rust_agent_run_logs_token_usage_summary`.
+167. Rust Agent final outcome guidance parity
+ - Terminal-backed `Agent.run()` and `Agent.follow_up()` now call Browser Use final outcome guidance logging before run cleanup.
+ - Failed or not-done Rust terminal histories now emit the same user-facing issue/CAPTCHA guidance path that the Python Agent runs after GIF/output handling and before eventbus shutdown.
+ - Proof: `test_rust_agent_run_logs_final_outcome_guidance`.
+
## 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` (138 tests)
+- `uv run pytest -q tests/ci/test_rust_agent.py` (139 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 b765f946d..fc945eb39 100644
--- a/browser_use/rust/service.py
+++ b/browser_use/rust/service.py
@@ -2888,6 +2888,7 @@ class Agent(Generic[Context, AgentStructuredOutput]):
self._record_run_telemetry(max_steps=max_steps, agent_run_error='Rust agent stopped before terminal run.')
self._dispatch_run_update_event()
await self._call_callback(on_step_end, self)
+ self._log_final_outcome_messages()
await self._finalize_run_cleanup()
return self.history
if self.state.paused:
@@ -2905,6 +2906,7 @@ class Agent(Generic[Context, AgentStructuredOutput]):
self._record_run_telemetry(max_steps=max_steps, agent_run_error='Rust agent is paused before terminal run.')
self._dispatch_run_update_event()
await self._call_callback(on_step_end, self)
+ self._log_final_outcome_messages()
await self._finalize_run_cleanup()
return self.history
if self.state.follow_up_task and self.terminal_session_id:
@@ -2942,6 +2944,7 @@ class Agent(Generic[Context, AgentStructuredOutput]):
await self._call_callback(on_step_end, self)
await self._call_done_callback()
await self._generate_gif_if_requested()
+ self._log_final_outcome_messages()
await self._finalize_run_cleanup()
return self.history
@@ -2985,6 +2988,7 @@ class Agent(Generic[Context, AgentStructuredOutput]):
await self._call_new_step_callback()
await self._call_done_callback()
await self._generate_gif_if_requested()
+ self._log_final_outcome_messages()
await self._finalize_run_cleanup()
return self.history
diff --git a/tests/ci/test_rust_agent.py b/tests/ci/test_rust_agent.py
index 403ea26c5..9bb30837a 100644
--- a/tests/ci/test_rust_agent.py
+++ b/tests/ci/test_rust_agent.py
@@ -3052,6 +3052,48 @@ async def test_rust_agent_run_logs_token_usage_summary(monkeypatch):
]
+async def test_rust_agent_run_logs_final_outcome_guidance(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.errors = []
+
+ def info(self, message, *args, **kwargs):
+ self.infos.append(message)
+
+ def error(self, message, *args, **kwargs):
+ self.errors.append(message)
+
+ logger = RecordingLogger()
+ monkeypatch.setattr(Agent, 'logger', property(lambda self: logger))
+
+ class Telemetry:
+ def capture(self, event):
+ pass
+
+ agent = Agent(task='Handle failed terminal run.', llm=type('LLM', (), {'model': 'gpt-test'})())
+ agent.telemetry = Telemetry()
+
+ async def fake_run_process(argv, timeout_seconds=None):
+ return 1, 'Session: 12345678-1234-1234-1234-123456789abc\n', 'terminal failed'
+
+ async def fake_load_events():
+ return []
+
+ agent._run_process = fake_run_process
+ agent._load_events = fake_load_events
+
+ history = await agent.run(max_steps=1)
+
+ assert history.errors() == ['terminal failed']
+ assert 'Did the Agent not work as expected? Let us fix this!' in logger.infos
+ assert ' Please open a short issue here: https://github.com/browser-use/browser-use/issues' in logger.infos
+
+
async def test_rust_agent_run_initializes_browser_use_session_state(monkeypatch):
from browser_use.rust import Agent