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
Reconstruct Rust terminal finished tool results
Magnus Müllerbf77753c2778
diff --git a/RUST_AGENT_INTEGRATION_FEATURES.md b/RUST_AGENT_INTEGRATION_FEATURES.mdindex 8ef322a42..b4306d361 100644--- a/RUST_AGENT_INTEGRATION_FEATURES.md+++ b/RUST_AGENT_INTEGRATION_FEATURES.md@@ -684,10 +684,15 @@ Terminal core branch: `magnus/browser-use-rust-main-integration` at terminal mai- This preserves tool result text for provider-shaped replay/import logs that store tool outputs as response input items instead of `tool.output` events.- Proof: `test_rust_history_reconstructs_terminal_response_input_item_tool_results`.+135. Rust terminal finished-tool result reconstruction+ - Terminal `tool.finished` events now reconstruct Browser Use `ActionResult` entries when no richer tool output event was recorded for the same call id.+ - The fallback text mirrors terminal current-main synthetic tool-result semantics while preserving concrete `tool.output`, failure, abort, and provider input-item results when those are present.+ - Proof: `test_rust_history_reconstructs_terminal_tool_finished_results`.+## 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` (106 tests)+- `uv run pytest -q tests/ci/test_rust_agent.py` (107 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 1f1761a11..ffce975a8 100644--- a/browser_use/rust/service.py+++ b/browser_use/rust/service.py@@ -974,14 +974,18 @@ def _tool_results_by_call_id(events: list[dict[str, Any]]) -> dict[str, tuple[stresults: dict[str, tuple[str, dict[str, Any]]] = {}for event in events:event_type = _event_type(event)- if event_type not in ('tool.output', 'tool.failed', 'tool.aborted', 'model.response.input_item'):+ if event_type not in ('tool.output', 'tool.failed', 'tool.aborted', 'tool.finished', 'model.response.input_item'):continuepayload = _event_payload(event)if event_type == 'model.response.input_item':payload = _response_input_item_tool_payload(payload)call_id = payload.get('tool_call_id') or payload.get('call_id')if call_id:- results[str(call_id)] = (event_type, payload)+ key = str(call_id)+ previous = results.get(key)+ if event_type == 'tool.finished' and previous is not None and previous[0] != 'tool.finished':+ continue+ results[key] = (event_type, payload)return results@@ -1034,6 +1038,14 @@ def _tool_result_text(payload: dict[str, Any]) -> str | None:return None+def _synthetic_tool_result_text(name: str) -> str:+ if name == 'update_plan':+ return 'Plan updated'+ if name == 'done':+ return 'done'+ return f'{name} completed'++def _append_streaming_text_delta(current: str, incoming: str) -> str:if not incoming:return current@@ -1136,6 +1148,9 @@ 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)+ if event_type == 'tool.finished' and not text:+ name = payload.get('name') or tool_call.get('name') or 'tool'+ text = _synthetic_tool_result_text(str(name))if event_type == 'tool.failed':error = _tool_failure_message(payload)elif event_type == 'tool.aborted':@@ -1145,8 +1160,8 @@ def _action_results_from_tool_calls(action_results.append(ActionResult(error=error,- extracted_content=text if event_type in ('tool.output', 'model.response.input_item') else None,- long_term_memory=text if event_type in ('tool.output', 'model.response.input_item') else None,+ extracted_content=text if event_type in ('tool.output', 'tool.finished', 'model.response.input_item') else None,+ long_term_memory=text if event_type in ('tool.output', 'tool.finished', 'model.response.input_item') else None,))diff --git a/tests/ci/test_rust_agent.py b/tests/ci/test_rust_agent.pyindex f7128d949..db1db5974 100644--- a/tests/ci/test_rust_agent.py+++ b/tests/ci/test_rust_agent.py@@ -514,6 +514,69 @@ def test_rust_history_reconstructs_terminal_response_input_item_tool_results():assert history.final_result() == 'Example Domain'+def test_rust_history_reconstructs_terminal_tool_finished_results():+ from browser_use.rust.service import _history_from_events++ history = _history_from_events(+ [+ {+ 'type': 'tool.started',+ 'payload': {+ 'name': 'read_file',+ 'tool_call_id': 'call-read',+ 'arguments': {'path': 'README.md'},+ },+ },+ {+ 'type': 'tool.finished',+ 'payload': {+ 'name': 'read_file',+ 'tool_call_id': 'call-read',+ },+ },+ {+ 'type': 'tool.started',+ 'payload': {+ 'name': 'browser_script',+ 'tool_call_id': 'call-browser',+ 'arguments': {'code': "goto_url('https://example.com')"},+ },+ },+ {+ 'type': 'tool.output',+ 'payload': {+ 'name': 'browser_script',+ 'tool_call_id': 'call-browser',+ 'text': 'Opened Example Domain',+ },+ },+ {+ 'type': 'tool.finished',+ 'payload': {+ 'name': 'browser_script',+ 'tool_call_id': 'call-browser',+ },+ },+ {'event_type': 'session.done', 'payload': {'result': 'Example Domain'}},+ ],+ model='gpt-test',+ started=1.0,+ finished=2.0,+ output_model_schema=None,+ process_error=None,+ )++ results = history.action_results()++ assert history.action_names() == ['read_file', 'browser_script', 'done']+ assert results[0].extracted_content == 'read_file completed'+ assert results[0].long_term_memory == 'read_file completed'+ assert results[1].extracted_content == 'Opened Example Domain'+ assert history.action_history()[0][0]['result'] == 'read_file completed'+ assert history.action_history()[0][1]['result'] == 'Opened Example Domain'+ assert history.final_result() == 'Example Domain'++def test_rust_history_synthesizes_done_action_from_terminal_completion():from browser_use.rust.service import _history_from_events