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
Prefer Rust done tool final text
Magnus Müllerd58418f4886e
diff --git a/browser_use/rust/service.py b/browser_use/rust/service.pyindex 491b81190..ff72661e4 100644--- a/browser_use/rust/service.py+++ b/browser_use/rust/service.py@@ -959,7 +959,35 @@ def _artifact_attachment_pointer(value: Any) -> str | None:return None+def _done_tool_result_from_events(events: list[dict[str, Any]]) -> str | None:+ for event in reversed(events):+ event_type = _event_type(event)+ if event_type not in ('tool.started', 'tool.output', 'tool.finished'):+ continue+ payload = _event_payload(event)+ if payload.get('name') != 'done':+ continue+ arguments = payload.get('arguments')+ if isinstance(arguments, dict):+ for key in ('text', 'result', 'answer'):+ value = arguments.get(key)+ if isinstance(value, str) and value.strip():+ return value.strip()+ text = _tool_result_text(payload)+ if not text:+ continue+ text = text.strip()+ if text.lower().startswith('done:'):+ text = text[5:].strip()+ if text:+ return text+ return None++def _result_from_events(events: list[dict[str, Any]]) -> str | None:+ done_result = _done_tool_result_from_events(events)+ if done_result:+ return done_resultfor event in reversed(events):if _event_type(event) != 'session.done':continuediff --git a/tests/ci/test_rust_agent.py b/tests/ci/test_rust_agent.pyindex 85ef2fc60..67132ce1c 100644--- a/tests/ci/test_rust_agent.py+++ b/tests/ci/test_rust_agent.py@@ -1144,6 +1144,44 @@ def test_rust_history_reconstructs_terminal_model_turn_steps():assert history.is_done() is True+def test_rust_history_prefers_done_tool_text_over_session_summary():+ from browser_use.rust.service import _history_from_events++ history = _history_from_events(+ [+ {'type': 'model.turn.request', 'ts_ms': 1_000, 'payload': {'model': 'claude-sonnet-4-0', 'attempt': 0}},+ {+ 'type': 'tool.started',+ 'ts_ms': 1_010,+ 'payload': {+ 'name': 'done',+ 'tool_call_id': 'call-done',+ 'arguments': {'text': 'Paramjit Uppal, Founder', 'success': True},+ },+ },+ {+ 'type': 'tool.output',+ 'ts_ms': 1_020,+ 'payload': {'name': 'done', 'tool_call_id': 'call-done', 'text': 'done:Paramjit Uppal, Founder'},+ },+ {+ 'type': 'session.done',+ 'ts_ms': 1_030,+ 'payload': {'result': 'I found the founder and will now provide the requested final format.'},+ },+ ],+ model='claude-sonnet-4-0',+ started=1.0,+ finished=2.0,+ output_model_schema=None,+ process_error=None,+ )++ assert history.final_result() == 'Paramjit Uppal, Founder'+ assert history.action_results()[-1].extracted_content == 'Paramjit Uppal, Founder'+ assert history.is_successful() is True++def test_rust_history_applies_terminal_session_rollback():from browser_use.rust.service import _history_from_events