Skip to content

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

Log Rust post-process results like Browser Use

Magnus Müllerb8bfdf6b367f
diff --git a/RUST_AGENT_INTEGRATION_FEATURES.md b/RUST_AGENT_INTEGRATION_FEATURES.md
index e7400c8b7..1403da99f 100644
--- a/RUST_AGENT_INTEGRATION_FEATURES.md
+++ b/RUST_AGENT_INTEGRATION_FEATURES.md
@@ -976,10 +976,15 @@ Terminal core branch: `magnus/browser-use-rust-main-integration` at terminal mai
- The helper still retries once with the Browser Use clarification message and inserts the same failed `done` action when the retry also returns no usable action.
- Proof: `test_rust_agent_exposes_model_output_helper_methods`.
+193. Rust Agent post-process result logging parity
+ - Rust-backed `_post_process(...)` now emits Browser Use-style consecutive-failure debug markers and color-coded final-result logs.
+ - Attachment logs now use Browser Use's attachment labels while preserving download checks, failure counting, reset behavior, and final-result bookkeeping.
+ - Proof: `test_rust_agent_post_process_logs_browser_use_result_messages`.
+
## 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` (161 tests)
+- `uv run pytest -q tests/ci/test_rust_agent.py` (162 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 c19ac9932..06470db60 100644
--- a/browser_use/rust/service.py
+++ b/browser_use/rust/service.py
@@ -3550,18 +3550,21 @@ class Agent(Generic[Context, AgentStructuredOutput]):
await self._check_and_update_downloads('after executing actions')
if self.state.last_result and len(self.state.last_result) == 1 and self.state.last_result[-1].error:
self.state.consecutive_failures += 1
- self.logger.debug(f'Step {self.state.n_steps}: Consecutive failures: {self.state.consecutive_failures}')
+ self.logger.debug(f'🔄 Step {self.state.n_steps}: Consecutive failures: {self.state.consecutive_failures}')
return
if self.state.consecutive_failures > 0:
self.state.consecutive_failures = 0
- self.logger.debug(f'Step {self.state.n_steps}: Consecutive failures reset to: {self.state.consecutive_failures}')
+ self.logger.debug(f'🔄 Step {self.state.n_steps}: Consecutive failures reset to: {self.state.consecutive_failures}')
if self.state.last_result and self.state.last_result[-1].is_done:
- self.logger.info(f'\nFinal Result:\n{self.state.last_result[-1].extracted_content}\n')
+ success = self.state.last_result[-1].success
+ if success:
+ self.logger.info(f'\n📄 \033[32m Final Result:\033[0m \n{self.state.last_result[-1].extracted_content}\n\n')
+ else:
+ self.logger.info(f'\n📄 \033[31m Final Result:\033[0m \n{self.state.last_result[-1].extracted_content}\n\n')
if self.state.last_result[-1].attachments:
total_attachments = len(self.state.last_result[-1].attachments)
for index, file_path in enumerate(self.state.last_result[-1].attachments):
- label = f'Attachment {index + 1}' if total_attachments > 1 else 'Attachment'
- self.logger.info(f'{label}: {file_path}')
+ self.logger.info(f'👉 Attachment {index + 1 if total_attachments > 1 else ""}: {file_path}')
async def _handle_step_error(self, error: Exception) -> None:
"""Convert a step exception into Browser Use-style state.last_result."""
diff --git a/tests/ci/test_rust_agent.py b/tests/ci/test_rust_agent.py
index 73e1809ea..ce5164d59 100644
--- a/tests/ci/test_rust_agent.py
+++ b/tests/ci/test_rust_agent.py
@@ -4447,6 +4447,55 @@ async def test_rust_agent_done_only_guidance_matches_browser_use(monkeypatch):
assert 'set success in "done" to false! E.g. if not all steps are fully completed.' in messages[-1]
+async def test_rust_agent_post_process_logs_browser_use_result_messages(monkeypatch):
+ from browser_use.agent.views import ActionResult
+ from browser_use.rust import Agent
+
+ class RecordingLogger:
+ def __init__(self):
+ self.debugs = []
+ self.infos = []
+
+ def debug(self, message, *args, **kwargs):
+ self.debugs.append(message)
+
+ def info(self, message, *args, **kwargs):
+ self.infos.append(message)
+
+ logger = RecordingLogger()
+ monkeypatch.setattr(Agent, 'logger', property(lambda self: logger))
+ agent = Agent(task='Post-process log parity.')
+ download_checks = []
+
+ async def fake_check_downloads(label):
+ download_checks.append(label)
+
+ agent._check_and_update_downloads = fake_check_downloads
+
+ agent.state.last_result = [ActionResult(error='failed action')]
+ await agent._post_process()
+ assert agent.state.consecutive_failures == 1
+ assert logger.debugs == [f'🔄 Step {agent.state.n_steps}: Consecutive failures: 1']
+
+ agent.state.last_result = [
+ ActionResult(is_done=True, success=True, extracted_content='final answer', attachments=['file:///tmp/a.txt', 'file:///tmp/b.txt'])
+ ]
+ await agent._post_process()
+ assert agent.state.consecutive_failures == 0
+ assert logger.debugs[-1] == f'🔄 Step {agent.state.n_steps}: Consecutive failures reset to: 0'
+ assert logger.infos[-3:] == [
+ '\n📄 \033[32m Final Result:\033[0m \nfinal answer\n\n',
+ '👉 Attachment 1: file:///tmp/a.txt',
+ '👉 Attachment 2: file:///tmp/b.txt',
+ ]
+
+ logger.infos.clear()
+ agent.state.last_result = [ActionResult(is_done=True, success=False, extracted_content='not done')]
+ await agent._post_process()
+ assert logger.infos == ['\n📄 \033[31m Final Result:\033[0m \nnot done\n\n']
+ assert download_checks == ['after executing actions', 'after executing actions', 'after executing actions']
+
+
def test_rust_agent_initializes_message_manager_and_followup_state():
from browser_use.agent.message_manager.service import MessageManager
from browser_use.rust import Agent