Open-source Python library for AI browser agents, plus Browser Use Cloud: stealth browsers and a hosted agent API.
Python ai-agentsai-toolsbrowser-agentbrowser-automationbrowser-usecdpcloud-browsercomputer-useheadless-browserllmmcpplaywrightpythonremote-browserstealth-browserweb-automationweb-scraping
Surface Rust terminal tool failures
Magnus Müller536f146a631a
diff --git a/RUST_AGENT_INTEGRATION_FEATURES.md b/RUST_AGENT_INTEGRATION_FEATURES.mdindex 214d42f69..7b2ea4ecb 100644--- a/RUST_AGENT_INTEGRATION_FEATURES.md+++ b/RUST_AGENT_INTEGRATION_FEATURES.md@@ -644,10 +644,15 @@ Terminal core branch: `magnus/browser-use-rust-main-integration` at terminal mai- The reducer mirrors terminal current-main retry semantics by clearing stale streamed text after `model.turn.request`, `model.turn.retry`, and `model.turn.error`, and de-duplicates prefix-style deltas before exposing `history.model_outputs()` and `history.model_thoughts()`.- Proof: `test_rust_history_reconstructs_terminal_streamed_model_thoughts`.+127. Rust terminal tool-failure error reconstruction+ - Terminal `tool.failed` events now surface their concrete tool name and error message in Rust-backed Browser Use histories when no final `session.done` result is available.+ - This keeps `history.errors()` and final action errors actionable instead of falling back to the generic "Rust terminal session did not produce a final result" message after the terminal core already recorded the failure.+ - Proof: `test_rust_history_surfaces_terminal_tool_failure_message`.+## 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` (98 tests)+- `uv run pytest -q tests/ci/test_rust_agent.py` (99 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.pyindex b5551b0f0..7ec330150 100644--- a/browser_use/rust/service.py+++ b/browser_use/rust/service.py@@ -788,9 +788,40 @@ def _failure_from_events(events: list[dict[str, Any]]) -> str | None:error = payload.get('error') or payload.get('message')if isinstance(error, str) and error:return error+ if event_type in ('agent.failed', 'agent.cancelled'):+ payload = _event_payload(event)+ inner_payload = payload.get('payload')+ if not isinstance(inner_payload, dict):+ inner_payload = payload+ error = inner_payload.get('error') or inner_payload.get('reason')+ if isinstance(error, str) and error.strip():+ return error.strip()+ return None+++def _recoverable_failure_from_events(events: list[dict[str, Any]]) -> str | None:+ for event in reversed(events):+ event_type = _event_type(event)+ payload = _event_payload(event)+ if event_type == 'tool.failed':+ error = _tool_failure_message(payload)+ if error:+ return error+ if event_type in ('model.turn.error', 'model.turn.context_overflow'):+ error = payload.get('error') or payload.get('message') or payload.get('reason')+ if isinstance(error, str) and error.strip():+ return error.strip()return None+def _tool_failure_message(payload: dict[str, Any]) -> str | None:+ error = payload.get('error')+ if not isinstance(error, str) or not error.strip():+ return None+ name = payload.get('name')+ return f'{name} failed: {error.strip()}' if isinstance(name, str) and name else error.strip()++def _safe_tool_action_name(value: Any) -> str | None:if not isinstance(value, str):return None@@ -953,10 +984,10 @@ def _action_results_from_tool_calls(for tool_call in tool_calls:event_type, payload = tool_results.get(str(tool_call.get('tool_call_id')), ('', {}))text = _tool_result_text(payload)- error = payload.get('error') if event_type == 'tool.failed' else None+ error = _tool_failure_message(payload) if event_type == 'tool.failed' else Noneaction_results.append(ActionResult(- error=str(error).strip() if isinstance(error, str) and error.strip() else None,+ error=error,extracted_content=text if event_type == 'tool.output' else None,long_term_memory=text if event_type == 'tool.output' else None,)@@ -1148,6 +1179,8 @@ def _history_from_events() -> AgentHistoryList[AgentStructuredOutput]:final_result = _structured_result_text(_result_from_events(events), output_model_schema)failure = process_error or _failure_from_events(events)+ if final_result is None and failure is None:+ failure = _recoverable_failure_from_events(events)if final_result is None and failure is None:failure = 'Rust terminal session did not produce a final result.'is_done = final_result is not None and failure is Nonediff --git a/tests/ci/test_rust_agent.py b/tests/ci/test_rust_agent.pyindex 81b057716..c588db5c0 100644--- a/tests/ci/test_rust_agent.py+++ b/tests/ci/test_rust_agent.py@@ -2746,6 +2746,42 @@ def test_rust_history_surfaces_terminal_stream_error_message():assert history.errors() == ['provider error']+def test_rust_history_surfaces_terminal_tool_failure_message():+ from browser_use.rust.service import _history_from_events++ history = _history_from_events(+ [+ {'event_type': 'model.turn.request', 'payload': {'model': 'gpt-test'}},+ {+ 'type': 'tool.started',+ 'payload': {+ 'name': 'browser_script',+ 'tool_call_id': 'call-browser',+ 'arguments': {'code': "goto_url('https://example.invalid')"},+ },+ },+ {+ 'type': 'tool.failed',+ 'payload': {+ 'name': 'browser_script',+ 'tool_call_id': 'call-browser',+ 'error': 'RuntimeError: navigation failed',+ },+ },+ ],+ model='gpt-test',+ started=1.0,+ finished=2.0,+ output_model_schema=None,+ process_error=None,+ )++ assert history.final_result() is None+ assert history.is_done() is False+ assert history.errors() == ['browser_script failed: RuntimeError: navigation failed']+ assert history.action_results()[-1].error == 'browser_script failed: RuntimeError: navigation failed'++def test_real_v8_smoke_selects_case_by_index_and_task_id(tmp_path):module = _load_real_v8_smoke_module()dataset = tmp_path / 'real_v8.json'