Repository navigation
feat(agent): index large tool results by their structure - #4379
Conversation
Every tool result is re-sent on every later step, and on a real 144K-line repository accumulated results were 83% of the conversation. An over-budget result now reaches the model as the parts that fit plus an index of the rest, split where the document splits: functions and methods, headings, JSON records, a search's files, test sections, diff hunks, paragraphs. Each index entry is an exact offset/length that read_tool_output returns verbatim, so nothing is lost and no new tool is needed. check_result and the other result fields stay in view. A remote model reached through Lemonade gets its own budget (8,000/6,000 chars) sized by re-send cost; 46% of the benchmark's result bytes sat above 8,000. Local NPU/GPU budgets are unchanged. Replaying 12 benchmark transcripts offline, tool-result characters re-sent fall 29.7% (23.9% if every condensed result is read back once). The message backstop now caps at the threshold the gate passes, not the smaller target, so results between the two are no longer cut unarchived; a read_tool_output page is never condensed again.
…n view Index entries could be longer than the 8,000-char page read_tool_output allowed, so the model was told to make a call that failed: a 1 MB Python file had every entry over the limit, and a 50,000-char stdout line was one. A read now takes any length, returns at most one page, and reports `remaining` with `next_offset` to continue, so every entry reads back exactly. When one line too long to split is most of a result, the result keeps its head and tail in view with the middle indexed, instead of showing only the first line. Search matches with no file group under "(no file)" instead of crashing, and a text `context` is one line, not one per character. On NPU, a non-string tool result between 20,000 and 30,000 chars now reaches the model whole, where the message backstop used to cut it to 20,000 without archiving it; that path wants an NPU eval before merge.
Verdict: Request changesThis replaces the old head-and-tail excerpt for oversized tool results with a structural index — a large file, search or test run now reaches the model as the parts that fit plus an exact A long test run loses its final summary line. The docs added in this PR promise that for shell and test output "failing sections and the final summary are shown first", but past roughly 100 KB of pytest output the closing The eval this change requires hasn't run yet. The project rule is that a change to a tool docstring needs an agent eval before merge, and this PR edits the Real-world evidenceN/A — no evidence bundle was produced in this lane, so the verdict rests on static review plus the results the PR description reports itself: unit tests (1546 passed) and the offline transcript replay (29.4% fewer re-sent characters, 23.6% with one read-back per condensed result). I reproduced the summary-line finding above directly against the new module with the cloud budget, outside the test suite. The two live items in the test plan — the TheRock benchmark and the NPU check — are the real-hardware evidence that is still missing. 🔍 Technical details🟡 Important1. The trailing "lead" chunk is crowded out of
Reproduction, driving where the final line is Two possible fixes, both local to
2. Eval evidence for the tool-docstring change is still pending
🟢 Minor3. An overshoot in the condenser aborts the user's turn (
4. In Strengths
|
On a live GLM run the model ignored the index and paged through whole archived outputs 8,000 chars at a time, re-sending every file on top of its condensed copy, because the reader advertised offset/limit with 8,000 as the page size. Index entries are now numbered, read_tool_output(artifact, entry=n) returns exactly that part, and every condensed result carries a `fetch` line saying so. The docstring leads with the entry, lets limit default to the entry's length, and says paging through a whole output is almost never needed. offset/limit still work; an entry number outside the index is an error that names the valid range.
The 8,000-char cloud threshold made files of 20-30K chars, which the model needs whole to edit, arrive indexed; it then read them back one entry per round trip, so steps rose and tokens did not fall (GLM, 4 tasks: 8.39M vs 8.29M; DeepSeek's worst task: 77 vs 72 steps, 20 entry reads). A remote model reached through Lemonade again gets truncation_budget(None), as before. The index, numbered entry reads, the fetch field, paging and the message-backstop change stay: the index now applies only to results over the device threshold, where it keeps every omitted byte reachable.
…aller did Three defects in the chunk index, two of them visible to the model. Past ~20 KB of pytest output the closing "N failed, M passed in Xs" line fell out of what the model sees and survived only as an index entry it had to go fetch — the one line that says whether the run passed. Two things pushed it out: the "test session starts" banner was always offered room ahead of every priority part, and over 256 parts the trailing summary was fused into a multi-KB neighbour that no longer fit. The trailing lead now bids first and sits out the pre-merge; reproduced and fixed at all three budgets. On Windows the search index named a POSIX path with backslashes, because ntpath.relpath answers in backslashes whatever it was given — so the index entry disagreed with the body text right above it. This was the Windows-smoke CI failure on this branch. read_tool_output's docstring is its schema description, and main's new 400-char budget check counted all 662 of it. The per-argument detail moves into the parameter schema, where it is budgeted separately and where the prompt-text renderer never looked anyway. Also: a terse label with a line-range prefix no longer runs over SHORT_LABEL_CHARS.
|
Pushed fixes for both of the bot's findings plus the two nits, and merged main in. One gate is still open, so I have not merged. A long test run was still losing its summary line, at every budget. The bot found this at the cloud budget that was in force when it reviewed; after the budget revert it still reproduced — on NPU, GPU and Claude alike — because the bid order was the real cause, not the budget. The Windows CI failure was real and is fixed. The index was naming a POSIX path with backslashes, because Main's new tool-description budget would have failed this PR. It landed while this was open and caps a tool description at 400 characters; Still open: the eval. Your test plan's NPU item is unchecked, and this PR edits the One thing that is not yours: the two remaining red checks are both main's. Code Quality fails identically on main's own pushes, and the Windows lane now fails on an installer test from #4348 — filed as #4388. 🔍 Technical detailsCommit 1. Trailing lead crowded out of
|
| copies | chars | NPU before → after | GPU before → after | Claude before → after |
|---|---|---|---|---|
| 30 | 49,969 | ✗ → ✓ | ✗ → ✓ | ✓ → ✓ |
| 60 | 99,860 | ✗ → ✓ | ✗ → ✓ | ✓ → ✓ |
| 120 | 200,261 | ✗ → ✓ | ✗ → ✓ | ✗ → ✓ |
| 300 | 505,181 | ✗ → ✓ | ✗ → ✓ | ✗ → ✓ |
| 600 | 1,013,382 | ✗ → ✓ | ✗ → ✓ | ✗ → ✓ |
Pinned by test_a_long_run_keeps_its_closing_summary_in_view, parametrized over pytest_log() * [3, 20, 60, 200]. The [20] and [60] cases fail on the pre-fix source; the bot was right that pytest_log() and * 3 alone sit in the passing range.
On the bot's note about split_oversized assigning lead=chunk.lead and k == 1: not reachable for this path. chunk_output runs _refine_large_sections, then re-marks chunks[-1] as lead, so the flag always lands on the part holding the actual last lines. Left alone.
2. Windows path separators (chunk_index.py render_search)
def relative(path: str) -> str:
# Keep the separator the caller's path used: ntpath.relpath answers in
# backslashes even for a POSIX path, so the index would name a file
# differently from the body text right above it.
name = os.path.relpath(path, root)
return name.replace("\\", "/") if "\\" not in path else nameNative Windows paths are untouched — only a path with no backslash in it gets normalized, which is exactly the case where inventing one is wrong. test_search_labels_keep_the_separator_the_paths_used pins it platform-independently (no label may contain a separator the input did not).
3. Tool-description budget
util/check_tool_descriptions.py (new on main, wired into util/lint.py --all as check 11 of 15) reported read_tool_output: description is 662 chars (budget 400). @tool and the hand-built registry entry both send __doc__ whole, Args block included. Now: description 248 chars, parameter descriptions 310 across four args, all under the 160-per-arg cap. _format_tools_for_prompt only ever consumed the first non-blank line, so the prompt-text path is unchanged.
test_the_reader_advertises_entry_first_and_no_fixed_page_size updated — it asserted doc.index("entry") < doc.index("offset") and an exact param dict, neither of which survives moving the detail into the schema. It now pins the param order (entry before offset), the entry spec, and both budgets.
4. Nits
_tilenow re-clips after prepending theLx-yprefix, soshorthonoursSHORT_LABEL_CHARS.condense_result's docstring says the over-target raise is deliberate, per the bot's suggestion. Left as a raise: house rule, and the test pins it.docs/sdk/core/agent-system.mdxupdated — it described the old bid order.
Test results
pytest tests/unit/agents/ tests/unit/test_tool_description_budget.py— 1604 passed, 55 skippedpytest tests/unit/(the Windows smoke lane's command, on Windows) — 5277 passed, only Windows unit lane is red on main: GAIA_HOME test asserts a drive-less path #4388's installer test failingpython util/lint.py --black --isort --fix— clean;util/check_tool_descriptions.py—[OK] All 83 flagship tool schemas within 400/160 charspython util/check_doc_links.py --internal-only— passed
The two red checks are main's
Run Code Quality Checks fails on src/gaia/ui/server.py (W0404 ×2, C0412) and src/gaia/ui/utils.py (W1309) — files this PR does not touch. Byte-identical failure on main's own pushes, e.g. run 36220628174 for #4323.
Unit Tests (Windows smoke) now fails only on test_uninstall_command.py::TestGaiaHomeEnvVar::test_env_var_overrides_home — WindowsPath('C:/srv/gaia-alt') != WindowsPath('/srv/gaia-alt'), from #4348 at 04:48Z. Both src/gaia/installer/ and tests/unit/installer/ are byte-identical to main on this branch. Filed as #4388; deliberately not fixed here to keep this PR's scope clean.
|
Re-verified after merging current main in: the summary-line fix, the Windows path fix, and the trimmed 🔍 Technical details
|
…-results # Conflicts: # src/gaia/agents/base/agent.py
400 was tight enough that a carefully-tuned, eval-validated docstring (read_tool_output, #4379) tripped the CI gate at 469 chars. Raising the ceiling avoids forcing a rewrite of text that was tuned against real model behavior — the two named allowances (run_shell_command, remember_skill_lesson) still exist for cases that need to go further.
When a tool result is too large for the model, GAIA used to keep its first and last few thousand characters and drop the middle, so the agent often went back for what it could not see. Now an over-budget result arrives as the parts that fit plus a numbered index of everything left out, split where the document splits: functions and methods, headings, JSON records, a search's files, failing test sections, diff hunks.
read_tool_output(artifact, entry=n)returns one part verbatim, so nothing is lost and the model can see exactly what it is missing. The split is deterministic, with no summarising model in the tool path. Budgets are unchanged: the index applies only above the existing device threshold.Measured on the TheRock benchmark (4 real ROCm build-system bugs, GLM-5.3 Flash and DeepSeek V4.1 Flash), the judged quality of fixes rose on the two tasks where the old cut had hidden the relevant code (3.00 → 4.00 and 3.75), and stayed level elsewhere. Tokens and cost did not fall: a tighter cloud budget was tried and reverted, because the model walks an index of a file it needs whole, one part per round trip. This PR is the "nothing lost" mechanism, not a cost saving.
Test plan
pytest tests/unit/agents— 1578 passed, 50 skipped on main, including ~90 chunk-index tests: every chunker tiles its text exactly, every index entry reads back verbatim by number, inputs of 100 KB, 1 MB and a single 50K-char line page correctly, a property test over 30 seeds of mixed text,check_resultkept verbatim, local NPU/GPU and remote budgets pinned, aread_tool_outputpage is never re-condensedpython util/bench_chunk_index_sim.py 'runs.*/*/*/_transcript.json'(needs local transcripts)