Skip to content

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

Expose Rust result file attachments

Magnus Müllerfa80226f1ba6
diff --git a/RUST_AGENT_INTEGRATION_FEATURES.md b/RUST_AGENT_INTEGRATION_FEATURES.md
index 90b81e2ea..eb988d411 100644
--- a/RUST_AGENT_INTEGRATION_FEATURES.md
+++ b/RUST_AGENT_INTEGRATION_FEATURES.md
@@ -110,10 +110,15 @@ Terminal core branch: `magnus/browser-use-rust-integration` at latest pulled mai
- Global and domain-scoped placeholder names are exposed, but raw secret values are not added to the task text.
- Proof: `test_rust_agent_adds_sensitive_data_placeholders_without_values`.
+21. Result file attachment bridge
+ - Terminal `session.done` result files are now exposed as Browser Use `ActionResult.attachments`.
+ - Nested `result_file` payloads from the Rust core and flat legacy result-file fields are both supported.
+ - Proof: `test_rust_history_exposes_result_file_attachments`.
+
## Current Verification
- `python3 -m py_compile 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` (30 tests)
+- `uv run pytest -q tests/ci/test_rust_agent.py` (31 tests)
- `cargo build -q -p browser-use-cli`
- `CARGO_INCREMENTAL=0 cargo test -q -p browser-use-agent selected_remote_cdp_mode_allows_remote_cdp_connect -- --nocapture`
- Managed-headless end-to-end:
diff --git a/browser_use/rust/service.py b/browser_use/rust/service.py
index 71b24b72f..c0f28864b 100644
--- a/browser_use/rust/service.py
+++ b/browser_use/rust/service.py
@@ -325,6 +325,22 @@ def _event_payload(event: dict[str, Any]) -> dict[str, Any]:
return payload if isinstance(payload, dict) else {}
+def _result_file_pointer(payload: dict[str, Any]) -> str | None:
+ result_file = payload.get('result_file')
+ if isinstance(result_file, dict):
+ for key in ('url', 'path'):
+ value = result_file.get(key)
+ if isinstance(value, str) and value:
+ return value
+ if isinstance(result_file, str) and result_file:
+ return result_file
+ for key in ('result_file_url', 'result_file_path', 'result_file'):
+ value = payload.get(key)
+ if isinstance(value, str) and value:
+ return value
+ return None
+
+
def _result_from_events(events: list[dict[str, Any]]) -> str | None:
for event in reversed(events):
if _event_type(event) != 'session.done':
@@ -333,12 +349,23 @@ def _result_from_events(events: list[dict[str, Any]]) -> str | None:
result = payload.get('result')
if isinstance(result, str) and result.strip():
return result.strip()
- result_file = payload.get('result_file_url') or payload.get('result_file_path') or payload.get('result_file')
- if isinstance(result_file, str) and result_file:
+ result_file = _result_file_pointer(payload)
+ if result_file:
return f'Saved result file.\n\nFile:\n{result_file}'
return None
+def _attachments_from_events(events: list[dict[str, Any]]) -> list[str] | None:
+ attachments: list[str] = []
+ for event in events:
+ if _event_type(event) != 'session.done':
+ continue
+ result_file = _result_file_pointer(_event_payload(event))
+ if result_file and result_file not in attachments:
+ attachments.append(result_file)
+ return attachments or None
+
+
def _failure_from_events(events: list[dict[str, Any]]) -> str | None:
for event in reversed(events):
if _event_type(event) == 'session.failed':
@@ -437,6 +464,7 @@ def _history_from_events(
is_done=is_done,
success=True if is_done else None,
error=failure,
+ attachments=_attachments_from_events(events),
extracted_content=final_result,
)
history = AgentHistory(
diff --git a/tests/ci/test_rust_agent.py b/tests/ci/test_rust_agent.py
index ae24759ac..3877279a7 100644
--- a/tests/ci/test_rust_agent.py
+++ b/tests/ci/test_rust_agent.py
@@ -89,6 +89,32 @@ def test_rust_history_supports_structured_output():
assert history.structured_output.answer == 'ok'
+def test_rust_history_exposes_result_file_attachments():
+ from browser_use.rust.service import _history_from_events
+
+ history = _history_from_events(
+ [
+ {
+ 'event_type': 'session.done',
+ 'payload': {
+ 'result': 'Saved structured report.',
+ 'result_file': {'url': 'file:///tmp/report.json', 'path': '/tmp/report.json', 'bytes': 123},
+ },
+ }
+ ],
+ model='gpt-test',
+ started=1.0,
+ finished=2.0,
+ output_model_schema=None,
+ process_error=None,
+ )
+
+ results = history.action_results()
+
+ assert history.final_result() == 'Saved structured report.'
+ assert results[0].attachments == ['file:///tmp/report.json']
+
+
def test_rust_agent_translates_browser_use_args_to_terminal(monkeypatch):
from browser_use.rust import Agent