Skip to content

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

Log Rust step errors like Browser Use

Magnus Müller7e8ad7657321
diff --git a/RUST_AGENT_INTEGRATION_FEATURES.md b/RUST_AGENT_INTEGRATION_FEATURES.md
index 1403da99f..b412c013e 100644
--- a/RUST_AGENT_INTEGRATION_FEATURES.md
+++ b/RUST_AGENT_INTEGRATION_FEATURES.md
@@ -981,10 +981,15 @@ Terminal core branch: `magnus/browser-use-rust-main-integration` at terminal mai
- 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`.
+194. Rust Agent step-error logging parity
+ - Rust-backed `_handle_step_error(...)` now emits Browser Use's `❌ Result failed ...` prefix for normal step failures while preserving consecutive-failure counting and `state.last_result`.
+ - Parse/tool-call failures now use Browser Use's model-specific module logger path, and interrupted steps continue to log without mutating `state.last_result`.
+ - Proof: `test_rust_agent_handle_step_error_logs_browser_use_failure_prefix`.
+
## 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` (162 tests)
+- `uv run pytest -q tests/ci/test_rust_agent.py` (163 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`
@@ -1062,6 +1067,7 @@ Terminal core branch: `magnus/browser-use-rust-main-integration` at terminal mai
- Source `/home/exedev/.evaluation_tool_env`, set `BROWSER_USE_TERMINAL_BINARY=/home/exedev/Developer/terminal/target/debug/browser-use-terminal`, set `BROWSER_USE_RUST_BROWSER_MODE=managed-headless`, and run two `uv run python - <<'PY' ...` Agent scripts in parallel.
- Follow-up/callback script output: `{"smoke": "python_api_followup_callbacks", "first": "Example Domain", "second": "example.com", "callback_kinds": ["step", "done", "step", "done"], "conversation_files": 2}`.
- Initial-actions/files/structured-output script output: `{"smoke": "python_api_initial_files_structured", "answer": {"title": "Example Domain", "host": "example.com", "marker": "file-marker-ok"}, "history_urls": ["", "", "", "https://example.com", "https://example.com"], "available_files": ["/tmp/.../input-note.txt"]}`.
+ - 2026-06-03 rerun after step-error parity: both scripts passed concurrently through the Python `Agent` import with `provider=rust-terminal`; follow-up/callback output was `Example Domain` then `example.com`, and initial-actions/files/structured-output produced `{"title":"Example Domain","host":"example.com","marker":"file-marker-ok"}`.
- Multi-feature Python API cloud end-to-end:
- Source `/home/exedev/.evaluation_tool_env`, unset browser-mode overrides, and construct `Agent(..., browser_profile=BrowserProfile(use_cloud=True), register_new_step_callback=..., register_done_callback=..., save_conversation_path=..., step_timeout=300)`.
- Output: first run `Example Domain`; follow-up `example.com`; callback sequence `step, done, step, done`; two conversation JSON snapshots written; terminal session id present.
diff --git a/browser_use/rust/service.py b/browser_use/rust/service.py
index 06470db60..a4b663ef7 100644
--- a/browser_use/rust/service.py
+++ b/browser_use/rust/service.py
@@ -68,6 +68,7 @@ AgentNewStepCallback = (
| Callable[[BrowserStateSummary, AgentOutput, int], Awaitable[None]]
)
AgentDoneCallback = Callable[[AgentHistoryList], Awaitable[None]] | Callable[[AgentHistoryList], None]
+logger = logging.getLogger(__name__)
class RustAgentError(RuntimeError):
@@ -3573,10 +3574,13 @@ class Agent(Generic[Context, AgentStructuredOutput]):
return
include_trace = self.logger.isEnabledFor(logging.DEBUG)
error_msg = AgentError.format_error(error, include_trace=include_trace)
+ prefix = f'❌ Result failed {self.state.consecutive_failures + 1}/{self.settings.max_failures + int(self.settings.final_response_after_failure)} times:\n '
self.state.consecutive_failures += 1
- self.logger.error(
- f'Result failed {self.state.consecutive_failures}/{self.settings.max_failures + int(self.settings.final_response_after_failure)} times:\n {error_msg}'
- )
+ if 'Could not parse response' in error_msg or 'tool_use_failed' in error_msg:
+ logger.error(f'Model: {getattr(self.llm, "model", None)} failed')
+ logger.error(f'{prefix}{error_msg}')
+ else:
+ self.logger.error(f'{prefix}{error_msg}')
self.state.last_result = [ActionResult(error=error_msg)]
async def _finalize(self, browser_state_summary: BrowserStateSummary | None) -> None:
diff --git a/tests/ci/test_rust_agent.py b/tests/ci/test_rust_agent.py
index ce5164d59..25b7ade66 100644
--- a/tests/ci/test_rust_agent.py
+++ b/tests/ci/test_rust_agent.py
@@ -4496,6 +4496,63 @@ async def test_rust_agent_post_process_logs_browser_use_result_messages(monkeypa
assert download_checks == ['after executing actions', 'after executing actions', 'after executing actions']
+async def test_rust_agent_handle_step_error_logs_browser_use_failure_prefix(monkeypatch):
+ import browser_use.rust.service as rust_service
+ from browser_use.rust import Agent
+
+ class RecordingLogger:
+ def __init__(self):
+ self.errors = []
+
+ def error(self, message, *args, **kwargs):
+ self.errors.append(message)
+
+ def debug(self, message, *args, **kwargs):
+ pass
+
+ def info(self, message, *args, **kwargs):
+ pass
+
+ def warning(self, message, *args, **kwargs):
+ pass
+
+ def isEnabledFor(self, level):
+ return False
+
+ class LLM:
+ model = 'gpt-test'
+
+ agent_logger = RecordingLogger()
+ module_logger = RecordingLogger()
+ monkeypatch.setattr(Agent, 'logger', property(lambda self: agent_logger))
+ monkeypatch.setattr(rust_service, 'logger', module_logger)
+
+ agent = Agent(task='Handle normal step error.', llm=LLM())
+ await agent._handle_step_error(ValueError('bad step'))
+ assert agent.state.consecutive_failures == 1
+ assert agent.state.last_result is not None
+ assert agent.state.last_result[-1].error == 'bad step'
+ assert agent_logger.errors == ['❌ Result failed 1/4 times:\n bad step']
+
+ agent_logger.errors.clear()
+ agent.state.last_result = None
+ await agent._handle_step_error(InterruptedError('paused'))
+ assert agent_logger.errors == ['The agent was interrupted mid-step - paused']
+ assert agent.state.last_result is None
+
+ parse_agent = Agent(task='Handle parse step error.', llm=LLM())
+ agent_logger.errors.clear()
+ module_logger.errors.clear()
+ await parse_agent._handle_step_error(ValueError('Could not parse response: missing action'))
+ assert parse_agent.state.consecutive_failures == 1
+ assert parse_agent.state.last_result[-1].error == 'Could not parse response: missing action'
+ assert agent_logger.errors == []
+ assert module_logger.errors == [
+ 'Model: gpt-test failed',
+ '❌ Result failed 1/4 times:\n Could not parse response: missing action',
+ ]
+
+
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