Skip to content

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

Reconstruct Rust terminal structured tool outputs

Magnus Müller55681764532f
diff --git a/RUST_AGENT_INTEGRATION_FEATURES.md b/RUST_AGENT_INTEGRATION_FEATURES.md
index b2acfe21e..d21bebd48 100644
--- a/RUST_AGENT_INTEGRATION_FEATURES.md
+++ b/RUST_AGENT_INTEGRATION_FEATURES.md
@@ -724,10 +724,15 @@ Terminal core branch: `magnus/browser-use-rust-main-integration` at terminal mai
- This preserves current-main Python worker outputs that truncate large text in `text` while carrying the full artifact under `text_artifact`, including the synthesized final `done.files_to_display`.
- Proof: `test_rust_history_reconstructs_terminal_text_artifact_attachments`.
+143. Rust terminal structured tool-output reconstruction
+ - Terminal tool outputs now fall back to structured `summary`, `data`, and `outputs` payloads when no textual `text`, `output`, `result`, or text content is present.
+ - This preserves current-main browser/Python tool results that return structured payloads instead of transcripts, so Browser Use `action_history()` and `ActionResult` surfaces do not show `None` for successful actions.
+ - Proof: `test_rust_history_reconstructs_terminal_structured_tool_output_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` (114 tests)
+- `uv run pytest -q tests/ci/test_rust_agent.py` (115 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.py
index 5d4f4b814..e4772bd41 100644
--- a/browser_use/rust/service.py
+++ b/browser_use/rust/service.py
@@ -1180,6 +1180,14 @@ def _tool_output_text(value: Any) -> str | None:
return None
+def _structured_tool_output_text(value: Any) -> str | None:
+ if isinstance(value, str) and value.strip():
+ return value.strip()
+ if isinstance(value, (dict, list)) and value:
+ return json.dumps(value, ensure_ascii=False, default=str)
+ return None
+
+
def _tool_result_text(payload: dict[str, Any]) -> str | None:
for key in ('text', 'output', 'result'):
text = _tool_output_text(payload.get(key))
@@ -1189,6 +1197,10 @@ def _tool_result_text(payload: dict[str, Any]) -> str | None:
text = _tool_output_text(content)
if text:
return text
+ for key in ('summary', 'data', 'outputs'):
+ text = _structured_tool_output_text(payload.get(key))
+ if text:
+ return text
return None
diff --git a/tests/ci/test_rust_agent.py b/tests/ci/test_rust_agent.py
index 8aa5a1ca9..80e868083 100644
--- a/tests/ci/test_rust_agent.py
+++ b/tests/ci/test_rust_agent.py
@@ -632,6 +632,59 @@ def test_rust_history_reconstructs_terminal_unkeyed_tool_results():
assert history.final_result() == 'final answer'
+def test_rust_history_reconstructs_terminal_structured_tool_output_results():
+ 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': "return page.summary()"},
+ },
+ },
+ {
+ 'type': 'tool.output',
+ 'payload': {
+ 'name': 'browser_script',
+ 'tool_call_id': 'call-browser',
+ 'ok': True,
+ 'text': '',
+ 'summary': {
+ 'kind': 'page',
+ 'title': 'Example Domain',
+ 'url': 'https://example.com',
+ },
+ 'data': {'ignored_when_summary_exists': True},
+ 'outputs': [{'label': 'page', 'value': {'url': 'https://example.com'}}],
+ },
+ },
+ {'event_type': 'session.done', 'payload': {'result': 'Example Domain'}},
+ ],
+ model='gpt-test',
+ started=1.0,
+ finished=2.0,
+ output_model_schema=None,
+ process_error=None,
+ )
+
+ first_result = history.action_results()[0]
+ structured_result = json.loads(first_result.extracted_content or '{}')
+
+ assert history.action_names() == ['browser_script', 'done']
+ assert structured_result == {
+ 'kind': 'page',
+ 'title': 'Example Domain',
+ 'url': 'https://example.com',
+ }
+ assert first_result.long_term_memory == first_result.extracted_content
+ assert json.loads(history.action_history()[0][0]['result'])['url'] == 'https://example.com'
+ 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