Repository navigation
fix(agent): keep the answer a model sends alongside its last tool call - #4745
Conversation
A model that answered and cleaned up in the same reply (answer text plus a
drop_table call) ended the turn on a short wrap-up, and only that wrap-up
became the final answer: the user saw "Scratch table cleaned up." instead of
the result. Answer text sent alongside the turn's last tool calls now leads
the final answer when the closing reply is a shorter wrap-up. Reasoning and
next-step narration ("Let me read the file first.") are never promoted, and a
later tool call clears it. The completion checks see the combined text.
The scratchpad workflow prompt now places drop_table before the answer.
|
Verdict: Request changes This fixes a real bug: when a model wrote its answer and called a cleanup tool in the same reply, the user saw only the wrap-up line. The fix is narrow and well tested. Two things need attention before merge:
Real-world evidenceN/A: no evidence bundle was produced for this run, and the change is agent-loop behaviour that needs real inference (strix-halo eval lane). This verdict rests on static review alone. I couldn't run the new tests here either, because the runner lacks the project's dependencies. 🔍 Technical detailsIssues 🟡 Narration filter only drops trailing first-person intent, so other progress text gets promoted (
Paired with a short closing answer like
🟡 LLM-affecting change merged without the eval run (PR test plan) 🟢 Strengths
|
…md#4726) If you asked a chat about a document it hadn't been given, the answer never came. Indexing the file was refused without asking you. Reading it did ask, but the tool gave up after 180 s while your answer was still pending, so clicking "Allow once" afterwards did nothing. Even an approved file stayed blocked for document search. Now indexing asks the same question reading does, one approval covers reading, indexing and querying for the rest of the chat, and waiting on your answer no longer counts against the tool's time limit. Live on DeepSeek V4.1 Flash, the original question ("which source tag do bootstrap-discovered items get…", 47-page PDF) gets one prompt and a cited answer. Before the fix it ran 43 steps and never answered. <details> <summary>🔍 Technical details</summary> - `RAGToolsMixin._index_access_error` uses the agent's `PathValidator.validate_read` (prompting) instead of `_is_path_allowed(prompt_user=False)`. - `RAGSDK(config, path_validator=...)`: ChatAgent passes its own validator, so grants reach `_safe_open`. Before, text files failed outright, and PDFs lost their content-keyed cache and were re-extracted on every index. - `_call_tool_bounded` excludes time spent on a prompt raised inside the tool body, tracked through a contextvar clock in `_confirm_path_access`. The prompt keeps its own 10-minute bound and cancellation. - On an Agent UI cache hit, documents attached since the agent was built are added to its validator. - Model-visible text: `access_denied_message` gains "Do not copy, move or convert it to another location to get around this." amd#4460 records only confirmation denials and shell policy refusals, so it doesn't cover a tool's own access-denied result. - Agent UI eval runs set `GAIA_AUTO_APPROVE_TOOLS=1`. With that set, path prompts are refused by design and never reach the scripted user, so out-of-scope writes in `gaia_files` (e.g. `files_edit_file`) dead-end. That's an eval-harness gap and isn't changed here. </details> ## Test plan - [x] `pytest tests/unit/test_path_access_grant.py`: 8 pass; 5 fail with the src diff reversed - [x] `tests/unit` plus the chat and gaia hub suites: 25 failures, all identical with the src diff reversed; the rest are environment-only - [x] `python util/lint.py --black --isort` - [x] Live Agent UI backend, DeepSeek V4.1 Flash, `GAIA_AGENT_TOOL_TIMEOUT=20`, prompt answered after 30 s: one prompt, correct cited answer - [ ] `gaia eval agent --category gaia_rag` and `--category gaia_files` (tool results the model sees changed; run serially) --------- Co-authored-by: Kalin Ovtcharov <[email protected]>
"Use your shell tool to run pwd" made the flagship guess the directory
instead of running the command (`gaia_shell/shell_pwd_basic` fails 2/2
on main). The shell was never offered. About 90 tools matched the
message semantically, the 29-tool cap decided, and `run_shell_command`
lost its slot to file browsers. Now a tool the user names, or a request
only the shell can answer (pwd, working directory, "run git status", "in
the terminal"), goes into the tool set ahead of semantic ranking.
This brings back a narrow keyword signal, which the tool-loader plan had
removed on purpose. It only adds tools and only fires on explicit asks;
the plan doc now says why.
## Test plan
- [x] `pytest tests/unit/test_chat_tool_requests.py
tests/unit/test_tool_loader_selection.py
hub/agents/gaia/python/tests/test_full_tool_bundles.py` passes. The
flagship test fails with the classifier disabled.
`test_core_and_bundles_cover_the_flagship_registry_exactly` and
`test_optional_tools_are_present_on_a_full_install` fail locally only
because Playwright isn't installed; they fail on main too.
- [x] `python util/lint.py --black --isort --flake8` is clean
- [x] With the real embedder, "Use your shell tool to run pwd…" now
selects `run_shell_command` and `get_shell_state` (before: neither,
`run_shell_command` skipped at the cap)
- [ ] `eval_flagship.yml`: `gaia_shell/shell_pwd_basic` passes, and no
category regresses against
`tests/fixtures/eval_baselines/gaia-flagship/` (especially
`tool_selection` and `gaia_shell`)
<details>
<summary>🔍 Technical details</summary>
- New `REQUESTED` tier in `ToolLoader.select(requested_tools=...)`. It
is admitted after CORE and ahead of SKILL. It reuses the SKILL admission
loop (now `_admit_exact`), so it follows the same cap, LRU eviction and
per-turn protection. Its log key `requested` is emitted only when
non-empty.
- The classifier is `gaia_agent_chat.tool_requests.requested_tools`. It
matches an underscored registry name written out, or a
shell/working-directory phrase. "Terminal" and "bash" count only when
they name the place something runs ("in the terminal"), so "the airport
terminal" doesn't fire.
- Real-embedder scores for the turn-1 message: `get_shell_state` 0.69,
`run_shell_command` 0.40, threshold 0.20, cap 29.
</details>
---------
Co-authored-by: Kalin Ovtcharov <[email protected]>
Progress text sent beside a lookup ("The search returned three files.
Reading the largest one now.") was put in front of a shorter real answer.
Text beside read/search/query/run calls is now always progress; only text
beside closing actions like drop_table or remember can be the answer.
|
Fixed the progress-chatter leak. Text sent beside a lookup (reading, searching, querying, running something) is now always treated as progress, because the reply after a lookup is the answer. Only text sent beside a closing action, like dropping a scratch table or saving to memory, can be promoted. Your example ("The search returned three files. Reading the largest one now." then "Timeout is 30s.") is now a test, and it fails without the change. The 🔍 Technical details
|
…md#4866) **Branch:** `feat/verify-edits-before-the-answer-is-sealed` **Base:** `e0fd6717f609a5be7ca8676a6be2c869fd4fe4b2` (`e0fd6717f`) **Commits:** | SHA | Subject | |---|---| | `bdfc3402885aedfb8fc3488a3aaa85da3ae2c3ab` | feat(agent): read this turn's edits back before the answer is sealed | | `836b57016695d59db4362ade466d60eb032d376f` | fix(agent): read back only text-file edits, not every path a tool reports | ## Relationship to amd#4719 and amd#4745 amd#4719 ("keep the read-back check out of the user's answer") touches a *model-facing prompt string* inside the completion check, and only fires when there is an artifact gap — the model claimed a save the evidence ledger cannot corroborate. It tells the model not to narrate that read-back in its reply. This change is a different mechanism answering a different question: an in-process, read-only check the **loop** runs over the files the turn actually wrote, whenever it wrote any. It does not touch amd#4719's prompt string, does not re-instruct the model to read anything, and does not reintroduce the narration amd#4719 removed — its findings only enter the conversation when something is wrong. The two compose; neither is redundant. amd#4745 ("keep the answer a model sends alongside its last tool call") requires the promoted answer to be in place before the seam's checks run. It is: the promotion happens earlier in `_process_query_impl` than this check, so the read-back still runs against exactly what the user will see. ## The problem A tool result saying `"status": "success"` is not the same as a file that is still on disk, still has content, and still parses. Today the only thing that closes that gap is the model choosing to check — and whether it does is a property of the **model**, not of the loop. Given the same tools and the same prompt, some models read their work back every time and some never do. That means the behaviour disappears the moment the model changes, which is not a property anyone can build on. ## The change The loop is better placed to do it. It already records which files this turn wrote, so just before the answer is sealed it opens each of them and asks three questions the tool result cannot answer: - is it still there, - does it still have content, - and, for Python and JSON, does it still parse. If anything comes back wrong, the findings go into the context and the turn gets **two steps to fix them**. ### The free steps are the load-bearing part Those two steps are granted on top of `max_steps`, not taken out of it. Verifying currently costs steps from the same budget as working, so a model under budget pressure is right to skip it — and the pressure peaks at the end of a turn, which is exactly where the edits are. Making the repair free removes the incentive to look away. Charging for it would make this feature self-defeating. ## Design notes **Where "which files did this turn write" comes from.** The completion-evidence ledger, which every write tool feeds. `_turn_file_edits` looks like the obvious source and is not: it is appended only for a tool result carrying `operation == "edit_file"`, and nothing in `file_io_tools` sets that field, so reading it would make the check silently do nothing for every shipped file tool. There is a test driving the real tools through the real loop specifically to pin that. **Deliberately narrow.** Read-only, in-process, no shell, no subprocess, no repository walk. It cannot be slow in proportion to the repository and cannot touch anything the turn had not already touched, so it is safe to run every time. A file type it cannot parse is checked for existence and content and otherwise left alone, rather than having a syntax guessed at for it. **Bounded.** Two rounds per turn, after which the turn is looping and the findings go into the answer instead of driving another repair. **`GAIA_AGENT_VERIFY_EDITS=0`** turns it off. ## What this is not This does not tell you whether a change is *correct* — nothing that needs no configuration could. It tells you the change is not **obviously broken**, which is the failure the loop can see by itself. Judging correctness needs the repository's own tests, which is a different and much larger piece of work. ## Two existing tests opt out Both register write tools that report success without touching the disk, so the read-back correctly finds the file they named missing and spends a repair step saying so. One pins the loop's exact model-call count; the other scripts a fixed list of replies that the extra call exhausts. Neither is about writing files, so the honest fix is to turn the check off for them and say why in the fixture, not to weaken the check. ## Fix: only text-file edits are read back The first version of this branch took its file list straight from the completion-evidence ledger. That ledger records more than edits: it also holds the outputs of tools that *generate* files (`generate_image`, `text_to_speech`, `take_screenshot`, ...) and paths an executor reported. So a turn that generated an image had the image path read back as if the model had edited it, found a "problem", and spent a repair round asking the model to fix a file it never edited. `tests/unit/agents/test_image_outcome_guard.py` caught it: two of its tests failed with an unexpected extra model call. The second commit fixes the cause rather than the tests (which are unchanged): - the ledger marks an entry `edited` when its last writer was one of the file-editing tools in `WRITE_TOOLS`, and only those are read back. Any later change by something else replaces the entry, so a file a script rewrote or deleted on purpose after its edit is not reported as broken; - binary files are skipped, by extension or by a NUL byte in the content; - reads go through the agent's read boundary without prompting, so a path the model could not read is not read here either; - a file over 2 MiB is checked for presence only. New regression tests cover a generated image (unit, and through the real loop with the check on), a read-only tool, an executor output, a file deleted on purpose, binary content and a path outside the read boundary; five of them fail without the fix. ## Risk The findings enter the conversation and can add turns, so this changes model behaviour and wants an eval run before merge. ## Test plan - [x] `pytest tests/unit/test_post_edit_verification.py tests/unit/agents/test_cut_off_reply_guard.py tests/unit/agents/test_parse_error_recovery.py tests/unit/agents/test_completion_evidence.py tests/unit/agents/test_read_file_line_ranges.py tests/unit/agents/test_image_outcome_guard.py tests/unit/eval/test_flagship_tasks.py::test_an_adversarial_task_rejects_the_shortcut` on this branch alone — 251 passed, 2 skipped (`test_post_edit_verification.py` is 36 tests: a missing file, an emptied file, broken Python and broken JSON, the free repair steps not counting against `max_steps`, the two-round ceiling, an unparseable file type being left alone, the env knob, and the over-reach cases above) - [x] `tests/unit/agents/test_image_outcome_guard.py` — 8 passed, unmodified - [x] Full `tests/unit` — see below - [x] `python util/lint.py --black --isort` - [ ] **Eval (LLM-affecting):** compare against the same run with `GAIA_AGENT_VERIFY_EDITS=0` ### Full unit suite `tests/unit`, Windows, `--timeout=300`, run on unmodified `main` (`e0fd6717f`) and on a disposable build with all four open branches stacked (line endings in file tools, step-budget notices, post-edit read-back, model-endpoint retry): | | Passed | Failed | Skipped | |---|---|---|---| | `main` `e0fd6717f` | 19,373 | 5 | 410 | | stacked build | 19,602 | 5 | 410 | The same five tests fail on both, and none of them is touched by this branch: three installer TUI-detection tests, `test_file_access_scope.py::test_no_allowlist_still_defaults_to_cwd`, and `test_lemonade_asr.py::TestRealServer::test_real_transcription_round_trip`, which needs a live server. No test fails on the stacked build that passes on `main`. ### Stacking with other open branches Applies cleanly to `main` on its own. It conflicts textually with the step-budget notices branch (`feat/tell-the-model-how-much-step-budget-is-left`), whichever lands second: both add an env-knob function after `_TOOL_USER_WAIT` and per-turn state in `__init__` and at the top of `_process_query_impl` in `src/gaia/agents/base/agent.py`. The resolution is to keep both sides — two separate functions and both sets of fields. 🤖 Generated with [Claude Code](https://claude.com/claude-code) --------- Co-authored-by: Claude Opus 5.5 (1M context) <[email protected]> Co-authored-by: v <v@x>
When a model wrote its answer and called a cleanup tool in the same reply, the user only saw the wrap-up that came after it. In the
data_followup_compoundeval, DeepSeek V4.1 Flash answered with the revenue table and dropped the scratch table in one step, then closed with "Scratch table cleaned up." That one line was the whole reply. Now the answer comes first and the wrap-up follows it. Planning lines sent with a tool call ("Let me read the file first.") and model reasoning still never reach the answer.task_sourcewatch_detects_change(whose final answer was just "Logged.") very likely hit the same bug. The source-watch skill tells the model to report what's new first and only thenrememberit, so the report goes out with the memory call and is followed by a one-word wrap-up.🔍 Technical details
drop_tablebefore the final answer instead of ending with "drop_table when done".Test plan
pytest tests/unit/agents/test_answer_beside_tool_calls.py: the 4-message reproduction fails on main and passes here. It covers streaming and non-streaming, narration that must not be promoted, de-duplication, a later tool call, and reasoning.pytest tests/unit/agents/: 2326 passedorigin/main.python util/lint.py --black --isortgaia eval agent --category gaia_datagaia eval agent --category gaia_skills_tasks