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 subagent completion results
Magnus Müllerc7536f309665
diff --git a/RUST_AGENT_INTEGRATION_FEATURES.md b/RUST_AGENT_INTEGRATION_FEATURES.mdindex f33e55bd7..5e77babfb 100644--- a/RUST_AGENT_INTEGRATION_FEATURES.md+++ b/RUST_AGENT_INTEGRATION_FEATURES.md@@ -784,10 +784,15 @@ Terminal core branch: `magnus/browser-use-rust-main-integration` at terminal mai- This preserves current-main browser cloud shutdown, browser cleanup, browser bridge, command write, compaction, and final-answer-not-ready failures on `history.errors()` and the final `ActionResult.error` instead of falling back to a generic missing-result error.- Proof: `test_rust_history_surfaces_terminal_operational_failure_events`.+155. Rust terminal subagent-completion result reconstruction+ - Terminal `agent.completed` events now fall back to their nested `payload.result` as the Browser Use final result when no `session.done` result is present.+ - This matches terminal protocol result reconstruction for parent/subagent completion histories while preserving `session.done` precedence when both results exist.+ - Proof: `test_rust_history_reconstructs_terminal_agent_completed_result`.+## 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` (126 tests)+- `uv run pytest -q tests/ci/test_rust_agent.py` (127 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 2a7c88aa2..1ed360cf7 100644--- a/browser_use/rust/service.py+++ b/browser_use/rust/service.py@@ -845,6 +845,15 @@ def _result_from_events(events: list[dict[str, Any]]) -> str | None:result_file = _result_file_pointer(payload)if result_file:return f'Saved result file.\n\nFile:\n{result_file}'+ for event in reversed(events):+ if _event_type(event) != 'agent.completed':+ continue+ payload = _event_payload(event).get('payload')+ if not isinstance(payload, dict):+ continue+ result = payload.get('result')+ if isinstance(result, str) and result.strip():+ return result.strip()return Nonediff --git a/tests/ci/test_rust_agent.py b/tests/ci/test_rust_agent.pyindex d34f1d220..83138c0e5 100644--- a/tests/ci/test_rust_agent.py+++ b/tests/ci/test_rust_agent.py@@ -1602,6 +1602,53 @@ def test_rust_history_extracts_fenced_structured_output():assert history.structured_output.answer == 'ok'+def test_rust_history_reconstructs_terminal_agent_completed_result():+ from browser_use.rust.service import _history_from_events++ history = _history_from_events(+ [+ {+ 'event_type': 'agent.completed',+ 'payload': {+ 'child_session_id': 'child-1',+ 'status': 'done',+ 'payload': {'result': 'child answer\n'},+ },+ }+ ],+ model='gpt-test',+ started=1.0,+ finished=2.0,+ output_model_schema=None,+ process_error=None,+ )++ session_done_history = _history_from_events(+ [+ {+ 'event_type': 'agent.completed',+ 'payload': {+ 'child_session_id': 'child-1',+ 'status': 'done',+ 'payload': {'result': 'child answer'},+ },+ },+ {'event_type': 'session.done', 'payload': {'result': 'parent answer'}},+ ],+ model='gpt-test',+ started=1.0,+ finished=2.0,+ output_model_schema=None,+ process_error=None,+ )++ assert history.final_result() == 'child answer'+ assert history.is_done() is True+ assert history.action_names() == ['done']+ assert history.last_action() == {'done': {'text': 'child answer', 'success': True}}+ assert session_done_history.final_result() == 'parent answer'++def test_rust_history_exposes_result_file_attachments():from browser_use.rust.service import _history_from_events