Repository navigation
fix(agent): bound tool output and recover omitted evidence - #3670
Conversation
|
Verdict: Request changes — small, careful change; two things to settle first. This closes a real gap: a single huge string result (a log, a transcript, a JSON blob a tool returns as text) could previously eat the whole context window. It now becomes a bounded head-and-tail excerpt that states exactly how much was dropped, and short strings are untouched. The mechanism itself checks out — I fuzzed the eliding helper across quotes, backslashes, newlines, NUL bytes and multi-byte characters and it never exceeds its budget, never splits a character, and always reports the omitted count correctly. Two items before merge:
Also worth considering: the excerpt tells the model that content was dropped but not how to get it back. A one-line hint in the envelope would keep the model from guessing at the gap. Real-world evidenceNo automated evidence bundle was produced for this PR ( 🔍 Technical detailsIssues🟡 JSON-string tool results are sliced mid-record ( Tools that return Parsing first keeps the existing invariant test ( 🟡 Agent eval not run — per 🟢 Local import ( 🟢 Docs restate the budgets as literals ( 🟢 No recovery hint in the envelope — the model learns 🟢 Cross-test-module coupling ( Verified, not findings
Strengths
|
Tools that hand back `json.dumps(...)` as a str — code search, index status — were `isinstance(str)`, so an oversized result took the head-and-tail path and the model read half a record at each end. That is the corruption the structured path was built to avoid, one level up: the envelope parses, the payload the model reasons over does not. `_as_structured_payload` parses a str first and routes it to the existing item-dropping path when it turns out to be an object or an array, so every record that survives is whole and the tail marker says how many were left out. A str still comes back as a str — the tool's declared result type is part of its contract with whatever reads it next. A bare JSON scalar stays prose: `"null"` or a quoted word parses, but there are no records in it to drop, and a log that happens to be valid JSON should still read as a log.
|
Fixed the JSON-string slicing. A tool result that parses as an object or array now goes down the whole-item-dropping path regardless of whether it arrived as a I checked the end-to-end behaviour rather than just the branch: a 182KB code-search result now comes back as 43 complete records plus the existing A string still comes back as a string — the tool declared a text result and whatever reads it next is entitled to that. And prose that happens to be a valid JSON scalar ( Not done: the agent eval. @kovtcharov-amd is running those separately, so the box stays unchecked — this does change what every oversized tool result looks like to the model, and your point that it's the merge gate stands. I left the "how to get the dropped content back" hint alone — it's a good idea, but it's new prompt text on the same surface the eval would be measuring, so it's better landed with a measurement than bundled in here. 🔍 Technical detailsNew Two tests added to |
…ng-tool-results # Conflicts: # hub/agents/gaia/python/gaia-agent.yaml # hub/agents/gaia/python/gaia_agent/__init__.py
# Conflicts: # tests/unit/test_file_tools.py
|
Verdict: Approve with suggestions
This is a solid implementation of session-scoped artifact storage for large tool outputs. Replacing silent head-truncation with an explicit head+tail excerpt plus a One 🟡 concern, then a handful of minor nits. 🟡 Browser link enumeration: unbounded memory allocation before truncation
🟢 Nit 1 — 🟢 Nit 2 — section placement in 🟢 Nit 3 — 🔍 Technical detailsBrowser links ( # OLD
for i, link in enumerate(links[:100], 1):
# NEW — allocates len(links) * ~80 chars before retain_excerpt
for i, link in enumerate(links, 1):The allocation is bounded by the page's link density, not by anything GAIA controls. A one-liner cap ( End-of-stream consistency
|
Co-Authored-By: Claude Opus 5 <[email protected]>
|
Verdict: Approve with suggestions This PR adds session-scoped tool output archiving: large results get a head/tail excerpt in the LLM context while the full text is retrievable page-by-page via a new 🟢 The "Recovering large tool outputs" section in 🟢 🔍 Technical detailsDoc placement — Import location — No architectural violations or missing test coverage found. The |
…l count
The guard this PR re-pins has never executed in any CI lane, so the numbers
it protects drifted unchallenged and it is red on main today. Wiring it into
the one lane that installs gaia-agent-chat makes the budget this PR enforces
actually enforceable.
The module opens with importorskip("gaia_agent_chat"); test_unit.yml installs
only ".[api]", so it skipped there, and none of the lanes that do install that
wheel ran the file. test_gaia_agent.yml already installs it and triggers on
src/gaia/** and tests/**.
The doc-profile tool count has been 38 since amd#3670 added read_tool_output to
the bundle; the pin still said 37. With the description budget's re-pinned
token numbers, that was the last failing assertion in the file.
Part of amd#3294.
The doc profile has had 38 tools since #3670 added `read_tool_output` on 2026-09-18, so the pinned 37 is a stale measurement rather than a regression. It registers unconditionally — there is no platform gate and no optional-import gate anywhere in the doc profile's registration path — so the count is the same on every machine. Only the count. The char and token pins stay where they are: #4038 re-pins them on the same lines and earns those numbers by trimming the docstrings they measure, so a value pinned here would be ~18% outside the band the moment it lands. A docstring trim cannot move a count, so both PRs make the identical edit to this line and neither side can lose it.
…ne (amd#4125) The tool-loader budget tests went red on `main` without anything regressing. Four tests failed at once, three of them pointing at CORE bloat that never happened — CORE's share of the registry moved from ~40% to ~43% while the registry itself grew. The cause is that the reduction guards divided a freshly-measured numerator by a constant frozen in June, so any registry-wide edit trips every guard simultaneously and buries the one failure that actually means something. Those guards now take their baseline from the same run, so a real CORE regression fails the CORE test and a schema-wide change fails only the pin test. **This PR does not turn the file green, and that is deliberate.** The tool *count* is re-pinned to 38, because amd#3670 added `read_tool_output` to the doc profile on 2026-09-18 — an unconditional 12th CORE tool, so the old 37 is a stale measurement, not a regression. The char and token pins are left alone: amd#4038 re-pins them on the same lines and earns those numbers by trimming the very docstrings they measure (~17% smaller), so any value pinned here is wrong the moment it lands. One failure therefore survives this PR — `test_token_baseline_when_tiktoken_available` — and it is amd#4038's to fix. The share ceilings hold on both sides: CORE measures 42.8% native today and 41.0% with amd#4038 applied, against a 45% ceiling. **A green check on this PR verifies none of the above.** No CI lane executes this file: `test_unit.yml` collects it but never installs the chat wheel, so the root `conftest.py` leaves `gaia_agent_chat` unimportable and `pytest.importorskip` skips the whole module at collection without printing a line. That is why the pins rotted unnoticed — tracked in amd#4121, not fixed here. Every result below was produced locally. ## Test plan - [x] `pytest tests/unit/test_tool_loader_token_budget.py` on this branch at current `main` → **1 failed, 9 passed** (was 2 failed, 8 passed before the count re-pin); the survivor is the native-token pin amd#4038 owns - [x] Test-merged with amd#4038: clean merge, no conflict; `test_tool_loader_token_budget.py` + `test_tool_description_budget.py` → **19 passed** - [x] Guard still bites: temporarily inflated a CORE docstring by ~370 tokens (inside the absolute band, so only the share guard can see it) → **1 failed, 9 passed**, `CORE native tokens 3104 exceeded 45% of the 6762-token registry measured in this run`. Reverted; not committed. - [x] Guard stays quiet on registry-wide growth: temporarily grew a non-CORE docstring past the band → **2 failed, 8 passed**, both ratio guards silent. Before this change the same edit took down all four. Reverted; not committed. - [x] Count is not platform-conditional: read the doc profile's whole registration path — every gate in `_register_tools()` is profile, config, or constructor-arg; `platform.system()` appears only in prompt text and tool bodies, never around a registration. - [x] `python util/lint.py --all` → exit 0. --------- Co-authored-by: Kalin Ovtcharov <[email protected]>
Large tool results now keep a bounded preview while letting the agent retrieve the exact omitted evidence. Previously plain text could flood a small local context window, and early tool-specific truncation could destroy facts before the agent saw them. This completes #3632 with session-local continuation reads and file paging, while preserving whole records in structured output. Unspecified local devices now use the configured profile; FLM retains the NPU budget.
Closes #3632.
🔍 Technical details
Shell, browser, and Python execution results are retained before their local display caps. The continuation reader is registered only on its owning agent, and deliberately tool-free agents stay tool-free.
read_tool_outputreads up to 8,000 characters per page from a session-owned handle; file readers support bounded character offsets. Archives expire after one hour and have a 64 MiB quota, with explicit errors for exhaustion, expiry, and cross-session access. Handles are process-local: restarting requires rerunning the source tool. This does not implement adaptive allocation of every remaining context token or the broader work in #3378.Test plan
read_tool_outputwith offset 40,000 and limit 16, then returned the exact requested text. The trace confirms real tool execution.