Skip to content

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

Compact large Rust terminal history outputs

Magnus Müller71a4ddbca107
diff --git a/RUST_AGENT_INTEGRATION_FEATURES.md b/RUST_AGENT_INTEGRATION_FEATURES.md
index 820d0456f..5b6f291e6 100644
--- a/RUST_AGENT_INTEGRATION_FEATURES.md
+++ b/RUST_AGENT_INTEGRATION_FEATURES.md
@@ -1291,6 +1291,19 @@ Terminal core branch: `magnus/browser-use-rust-main-integration` at terminal mai
- This targets repeated 2026-06-04 gates where Google-heavy tasks accumulated many `f*.txt` artifacts in the downloads directory, polluting eval artifacts and wasting background fetch work.
- Proof: `uv run pytest -q tests/ci/test_downloads_watchdog.py`, `uv run python -m py_compile browser_use/browser/watchdogs/downloads_watchdog.py tests/ci/test_downloads_watchdog.py`, and `git diff --check -- browser_use/browser/watchdogs/downloads_watchdog.py tests/ci/test_downloads_watchdog.py`.
+252. Rust Agent eval Agent SDK judge bounded parallelism
+ - Eval Agent SDK judging now uses a configurable semaphore, `AGENT_SDK_JUDGE_CONCURRENCY`, defaulting to 16 concurrent judge calls instead of a process-wide single-call lock.
+ - This preserves bounded local resource use while preventing completed parallel agent tasks from queueing behind one slow or timed-out judge subprocess.
+ - This targets repeated 2026-06-04 five-task gates where tool-enabled Agent SDK judge attempts commonly hit the timeout fallback and serialized judging consumed the remaining eval cap.
+ - Proof: eval `.venv/bin/python -m pytest -q tests/test_service_cli.py -k 'agent_sdk_judge'`, eval `.venv/bin/python -m pytest -q tests/test_service_cli.py`, and eval `.venv/bin/python -m py_compile eval/judges/agent_sdk_judge.py tests/test_service_cli.py`.
+
+253. Rust Agent terminal history payload compaction parity
+ - Reconstructed Rust terminal textual tool results now keep small outputs unchanged but compact large outputs over 1000 characters in `long_term_memory`.
+ - Large outputs remain available as `extracted_content` with `include_extracted_content_only_once=True`, while long-term memory stores only a short note with the tool name and character count.
+ - This reduces Python history, judge prompt, and eval payload bloat from large browser-script/page-text outputs without changing the final answer or hiding the one-step full tool output from Browser Use history.
+ - This targets repeated real_v8 gates where completed tasks carried hundreds of thousands to millions of prompt-token-equivalent text through reconstructed terminal histories and judge/eval payloads.
+ - Proof: `uv run pytest -q tests/ci/test_rust_agent.py -k 'rust_history_compacts_large_terminal_tool_memory or rust_history_attaches_terminal_tool_images_to_actions or rust_history_reconstructs_terminal_tool_call_actions'`, `uv run python -m py_compile browser_use/rust/service.py tests/ci/test_rust_agent.py`, and `git diff --check -- browser_use/rust/service.py tests/ci/test_rust_agent.py`.
+
## 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 browser_use/llm/models.py tests/ci/test_rust_agent.py tests/ci/models/test_llm_model_factory.py examples/rust_agent/basic.py examples/rust_agent/real_v8_smoke.py`
@@ -1300,6 +1313,7 @@ Terminal core branch: `magnus/browser-use-rust-main-integration` at terminal mai
- `uv run pytest -q tests/ci/test_rust_agent.py -k 'mirrors_direct_url_startup or exposes_task_helper_methods'`
- `uv run python -m py_compile browser_use/browser/watchdogs/downloads_watchdog.py tests/ci/test_downloads_watchdog.py`
- `uv run pytest -q tests/ci/test_downloads_watchdog.py`
+- `uv run pytest -q tests/ci/test_rust_agent.py -k 'rust_history_compacts_large_terminal_tool_memory or rust_history_attaches_terminal_tool_images_to_actions or rust_history_reconstructs_terminal_tool_call_actions'`
- `.venv/bin/python -m pytest -q tests/test_service_cli.py` on evaluations-internal branch `main`
- `.venv/bin/python -m pytest -q tests/test_service_cli.py -k 'browser_script_wait or max_steps or cloud_create or agent_sdk_judge_retries'` on evaluations-internal branch `main`
- `.venv/bin/python -m pytest -q tests/test_service_cli.py -k 'agent_sdk_judge'` on evaluations-internal branch `main`
@@ -1502,6 +1516,12 @@ Terminal core branch: `magnus/browser-use-rust-main-integration` at terminal mai
## Not Verified Yet
+- 2026-06-04 no-vision five-task real_v8 Agent SDK gate:
+ - Run `kh76x89db29h53xtbskrtmk1fd881f7b` used `BU_RUNTIME=brust`, `--browser browser-use-cloud`, `BROWSER_USE_CLOUD_PROXY_COUNTRY_CODE=us`, `BU_BROWSER_SCRIPT_INITIAL_WAIT_MS=7000`, `--use-vision false`, the eval default `AGENT_SDK_JUDGE_TIMEOUT_SECONDS=45`, `--judge-type agent_sdk`, `--model claude-sonnet-4-6`, `--eval-model claude-sonnet-4-6`, `--parallel-runs 5`, and `--max-steps 100` for real_v8 tasks 6-10.
+ - Saved results before the 10-minute stop: task 9 score `0.85` in 226.16s agent time/318.30s total pipeline, task 8 score `1.0` in 298.69s/388.56s, task 10 score `1.0` in 390.37s/521.15s, and task 6 score `1.0` in 425.37s/544.40s.
+ - Task 7 was still in the agent stage when the cap fired; its remaining Browser Use cloud session was manually stopped and no eval or terminal subprocesses remained.
+ - The run still used the old serialized Agent SDK judge code because it launched before feature 252 was patched and pushed. Four saved tasks were enough to confirm repeated tool-enabled judge timeouts followed by successful no-tools Agent SDK fallback scores, but not enough to justify scaling.
+ - This gate does not justify scaling to 50: saved-task mean score was `0.9625`, but missing-task-as-zero mean score was `0.77` with only 4/5 tasks saved within the iteration budget.
- 2026-06-04 post-download-filter five-task real_v8 Agent SDK gate:
- Run `kh76d5r82p69gshaa3vr0ph0bn8809h8` used `BU_RUNTIME=brust`, `--browser browser-use-cloud`, `BROWSER_USE_CLOUD_PROXY_COUNTRY_CODE=us`, `BU_BROWSER_SCRIPT_INITIAL_WAIT_MS=7000`, the eval default `AGENT_SDK_JUDGE_TIMEOUT_SECONDS=45`, `--judge-type agent_sdk`, `--model claude-sonnet-4-6`, `--eval-model claude-sonnet-4-6`, `--parallel-runs 5`, and `--max-steps 100` for real_v8 tasks 6-10.
- The network auto-download filter was verified live: the same Google-heavy slice no longer logged `Detected downloadable content` or `Tracked download: f*.txt` for Google async/autocomplete responses, while tasks still entered normal browser execution.
diff --git a/browser_use/rust/service.py b/browser_use/rust/service.py
index 592db0de6..c7d46db5e 100644
--- a/browser_use/rust/service.py
+++ b/browser_use/rust/service.py
@@ -1301,6 +1301,7 @@ _TEXTUAL_TOOL_RESULT_EVENTS = (
'tool.finished',
'model.response.input_item',
)
+_MAX_TERMINAL_LONG_TERM_TEXT_LENGTH = 1000
def _is_redundant_paired_output_delta(
@@ -1774,6 +1775,16 @@ def _synthetic_tool_result_text(name: str) -> str:
return f'{name} completed'
+def _terminal_tool_memory(name: str, text: str) -> tuple[str, bool]:
+ if len(text) < _MAX_TERMINAL_LONG_TERM_TEXT_LENGTH:
+ return text, False
+ tool_name = name or 'tool'
+ return (
+ f'{tool_name} returned {len(text):,} characters. Full output was included once in <read_state> for that step.',
+ True,
+ )
+
+
def _append_streaming_text_delta(current: str, incoming: str) -> str:
if not incoming:
return current
@@ -1945,12 +1956,18 @@ def _action_results_from_tool_calls(
error = _exec_command_end_failure_message(payload)
else:
error = None
+ long_term_memory = None
+ include_extracted_content_only_once = False
+ if event_type in _TEXTUAL_TOOL_RESULT_EVENTS and text:
+ name = str(payload.get('name') or tool_call.get('name') or 'tool')
+ long_term_memory, include_extracted_content_only_once = _terminal_tool_memory(name, text)
action_results.append(
ActionResult(
error=error,
attachments=list(tool_attachments) if tool_attachments else None,
extracted_content=text if event_type in _TEXTUAL_TOOL_RESULT_EVENTS else None,
- long_term_memory=text if event_type in _TEXTUAL_TOOL_RESULT_EVENTS else None,
+ long_term_memory=long_term_memory,
+ include_extracted_content_only_once=include_extracted_content_only_once,
)
)
diff --git a/tests/ci/test_rust_agent.py b/tests/ci/test_rust_agent.py
index aa55fa58b..22a960260 100644
--- a/tests/ci/test_rust_agent.py
+++ b/tests/ci/test_rust_agent.py
@@ -452,6 +452,47 @@ def test_rust_history_attaches_terminal_tool_images_to_actions(tmp_path):
assert history.screenshot_paths() == [str(screenshot_path)]
+def test_rust_history_compacts_large_terminal_tool_memory():
+ from browser_use.rust.service import _history_from_events
+
+ large_output = 'large browser output\n' + ('row,value\n' * 200)
+
+ history = _history_from_events(
+ [
+ {
+ 'type': 'tool.started',
+ 'payload': {
+ 'name': 'browser_script',
+ 'tool_call_id': 'call-browser',
+ 'arguments': {'code': 'print(document.body.innerText)'},
+ },
+ },
+ {
+ 'type': 'tool.output',
+ 'payload': {
+ 'name': 'browser_script',
+ 'tool_call_id': 'call-browser',
+ 'text': large_output,
+ },
+ },
+ {'event_type': 'session.done', 'payload': {'result': 'final answer'}},
+ ],
+ model='gpt-test',
+ started=1.0,
+ finished=2.0,
+ output_model_schema=None,
+ process_error=None,
+ )
+
+ result = history.action_results()[0]
+
+ assert result.extracted_content == large_output.strip()
+ assert result.include_extracted_content_only_once is True
+ assert result.long_term_memory is not None
+ assert 'browser_script returned' in result.long_term_memory
+ assert large_output.strip() not in result.long_term_memory
+
+
def test_rust_history_reconstructs_terminal_tool_call_actions():
from browser_use.rust.service import _history_from_events