Skip to content

fix(agent): fixes from NPU eval runs of Gemma-4-E4B - #6496

Merged
kovtcharov-amd merged 6 commits into
amd:mainfrom
kovtcharov:kalin/npu-eval-fixes
Nov 3, 2026
Merged

kovtcharov-amd merged 6 commits into
amd:mainfrom
kovtcharov:kalin/npu-eval-fixes

Conversation

@kovtcharov

@kovtcharov kovtcharov commented Nov 3, 2026 •

Copy link
Copy Markdown
Contributor

Running Gemma-4-E4B on the Ryzen AI NPU through the agent evals turned up bugs that ended turns badly. Asked to total eight short regional reports, the agent summed only five, because search returned at most five chunks even when the whole index was smaller than that. A model reply with zero tokens ended the turn on "I received an empty response, please try again". This happens on about 1 in 250 NPU calls after a long prompt. Told to "Index ", the model asked "Should I index it?". It also treated an instruction planted in a PDF as a possibly valid override, and gave in when pushed on a correct fact. Each case now recovers: a small index comes back whole, an empty reply or a needless permission question costs one bounded re-prompt, and the prompt names injection and fact-holding rules.

Follows #6341, which made the FastFlowLM models reachable.

  • Prompt changes reach every model, not just the NPU. Duplicate rules were merged to pay for the new ones. The full profile is 11,925 chars on Linux, under its 12K budget (11,844 before). The GPU eval on the next RC covers gaia_core, gaia_rag and tool_selection.
  • Results on the NPU (Gemma-4-E4B FLM, 128K window): document Q&A went from 14/19 to 17/19 and core from 10/15 to 11/15 before the last round of fixes. The rerun on this branch is still going; results will be added here.

Test plan

  • python -m pytest tests/unit hub/agents/gaia/python/tests — passes, except three tests that need Playwright, which isn't installed on the test machine
  • Prompt goldens recaptured against an empty GAIA_CONFIG_FILE (no local default model)
  • gaia_rag and gaia_core evals on the NPU on this branch's final commit
  • GPU eval on the next RC: gaia_core, gaia_rag, tool_selection

NPU evals of gemma4-it-e4b-FLM failed on real bugs as well as model
slips; these fixes took tool_selection, gaia_core and gaia_rag from
27/41 to 32/41.

- RAG cited the wrong page when a chunk ran across a page break:
  every chunk's 'page' was where it started. Chunks now split at
  '[Page N]' markers, so each entry's page is true for all its text.
- The eval MCP clipped assistant replies at 2000 chars, so a judge
  failed answers whose figures came later. Replies are no longer
  clipped.
- Two prompt rules contradicted each other (no documents → answer from
  knowledge, vs. smart discovery for the user's own files), and folder
  indexing asked before acting. Both now say what to do.
- New rules: hold a checked fact under pressure, don't accept "as I
  said" that never happened, ignore fake system notices, treat
  instructions inside documents as prompt injection, prefer the newer
  of conflicting documents.
- An empty-index query result now tells the model to index a folder
  the user named instead of asking.

Prompt snapshots re-captured with the characterization harness.
FastFlowLM ends a long prefill with zero tokens about once in 250 calls
(4 of 1,099 in the NPU eval runs), and the turn ended on "I received an
empty response". An empty reply now spends the same bounded re-prompt as
a narrated next step, so the user gets an answer instead of "try again".
A question over eight one-paragraph reports saw only five of them, so
"total across all eight" was summed over five. When every candidate
chunk fits in the text the five-chunk cap would spend anyway, the search
now returns all of them, ranked chunks first.

The model also asked "Should I index it?" after the user said "Index
<folder>". That reply now spends the bounded re-prompt and the agent is
told to index.

The prompt rules added for the NPU eval fixes put the full profile over
its 12K-char budget on Linux; merging duplicate rules brings it back to
11,926 (11,844 before those fixes).
The NPU rerun still failed the eight-report rollup: the user said "Index
<folder>" in turn 1, and the model offered "Tell me to index it and I'll
process them" there, then asked "Shall I proceed with indexing?" in turns
2 and 3. The guard read only the current message and missed both
phrasings. It now counts an "index" anywhere in the session's user
messages and matches those offers.

The keyword-search test now ignores the unmatched chunks a small index
returns.
@github-actions github-actions Bot added mcp MCP integration changes tests Test changes agents labels Nov 3, 2026
@kovtcharov
kovtcharov marked this pull request as ready for review November 3, 2026 06:42
@kovtcharov-amd kovtcharov-amd added this to the v0.25.4 milestone Nov 3, 2026
@github-actions

github-actions Bot commented Nov 3, 2026

Copy link
Copy Markdown
Contributor

Verdict: Request changes (one small fix)

The PR fixes real NPU eval failures: a small index now comes back whole so rollups see every report, an empty model reply or a needless "should I index it?" gets one bounded re-prompt, citations use the right page, and the prompt gains rules on injection and on holding a correct fact. The approach is sound and well tested. One guard is too eager.

  • The "you were already told to index" nudge can override a user who said no. It fires if any earlier message in the session contains the word "index", including "don't index ~/private". If the model then asks "Should I index it?", the agent is told the user already asked for it and goes ahead. Limit the check to an actual request to index, or at least skip messages that refuse it.
  • The NPU and GPU eval reruns are still open in the test plan. This changes the flagship prompt for every model, so those results should be on the PR before merge.

Real-world evidence

N/A: no evidence bundle was produced for this run. The verdict rests on static review alone. Agent behaviour and the Agent UI MCP transcript change were not exercised here, and the touched unit tests could not run on this runner (pytest isn't installed). The PR's own eval items are still unchecked.

🔍 Technical details

🟡 Important

Index-permission guard matches refusals and unrelated uses of "index" (src/gaia/agents/base/agent.py:5673-5681)
_user_asked_to_index runs \bindex\b over every user turn in conversation_history. "Don't index my tax folder" or "what's the index of this array?" both count. From then on, any "Should I index…?" in the session is re-prompted with "The user already told you to index it", which pushes the model to index a path the user declined. The re-prompt cap limits how often it fires, but each firing goes against what the user said. A narrower check that still covers every test in the PR:

    _INDEX_REQUEST = re.compile(
        r"^(?!.*\b(?:don'?t|do not|never|not)\b.*\bindex).*\bindex\b",
        re.IGNORECASE | re.DOTALL,
    )

    def _user_asked_to_index(self, user_input: str) -> bool:
        """True when this turn or an earlier one asked to index, not to avoid it."""
        said = [getattr(self, "_original_user_input", None) or user_input]
        said += [
            str(m.get("content", ""))
            for m in self.conversation_history
            if isinstance(m, dict) and m.get("role") == "user"
        ]
        return any(self._INDEX_REQUEST.search(text) for text in said)

Add a test for "Don't index ~/private" followed by "Should I index it?" that asserts no re-prompt.

🟢 Minor

  • The message and the count disagree (rag_tools.py:939, and the same in query_specific_file). num_chunks is now len(formatted_chunks) after the page split, but message still says Found {len(top_chunks)}. Use one count for both.
  • The whole-index budget ignores keyword-context snippets (rag_tools.py:842). ranked can hold keyword snippets that aren't in rag.chunks, so the snippet and its full chunk can both be returned. The total can also go slightly over the limit * _CHUNK_CHARS budget. This is bounded and harmless in practice, but worth a one-line note or a dedup by containment.
  • get_messages now returns assistant replies with no length limit (agent_ui_mcp.py:408). That's fine for the judge. Any other MCP client now gets very long replies too. If that's intended, a line in the tool description would make it visible.

Strengths

  • top_or_whole_index and split_entries_at_pages are small pure functions with focused tests, including the over-budget cut and the in-page labels that must not split.
  • The empty-reply recovery shares the existing re-prompt budget, and test_empty_reply_reprompts_are_bounded pins that it still ends loudly.
  • Merging duplicate prompt rules to pay for the new ones keeps the full profile under its 12K budget, and the goldens were recaptured to match.

The "user already told you to index it" nudge fired on anything mentioning
"index" anywhere in the session, so it overrode a user who said "do not
index my private folder" and pushed past the agent's own questions about
which folder to index or whether a 40,000-file index was worth 20 minutes.

- Only this turn's message counts, and only an un-negated imperative to
  index a path or folder/file ("index ~/reports", "re-index the docs
  folder"); "index.html", "S&P 500 index" and "refractive index" never do.
- Only a bare yes/no permission question is nudged; a choice ("which",
  "or"), a cost/scale warning, or a closing remark is left for the user.
- Retrieval messages now count the chunks actually returned after the
  page split, matching num_chunks and the instruction.
- get_messages clips assistant replies again by default; full_replies=True
  returns them whole, and the eval judge asks for that.
@github-actions github-actions Bot added documentation Documentation changes eval Evaluation framework changes performance Performance-critical changes labels Nov 3, 2026
A vendor-onboarding DOCX with an embedded "[Assistant directive]" got
Gemma-4-E4B to claim it had saved a skill file, and on a rerun to try
writing one, when the user asked whether it had changed any files. The
injection rule named documents but never forbade the tool calls a
directive asks for, and "challenged, recheck once" read the user's
"just checking" question as a cue to act.

The injection rule now calls such text data and bars its tool calls
(writes to ~/.gaia, skills or config above all) and dictated replies. A
new rule makes the agent answer "what did you do?" from the tool calls
it made, with no new ones. Recheck-on-challenge is scoped to answers.
@kovtcharov-amd
kovtcharov-amd added this pull request to the merge queue Nov 3, 2026
Merged via the queue into amd:main with commit b37c0d8 Nov 3, 2026
109 of 111 checks passed
@kovtcharov-amd
kovtcharov-amd deleted the kalin/npu-eval-fixes branch November 3, 2026 12:46
kovtcharov-amd added a commit to kovtcharov/gaia that referenced this pull request Nov 3, 2026
Resolves the conflicts with amd#6496 and amd#6287's question-language note, and
bounds the re-search so a fact that really is absent still gets its answer.

- The "search once more" note moves out of the citation instructions into a
  wrapper on query_documents and query_specific_file. Only the turn's first
  search that returns chunks carries it, so the second search can no longer
  ask for a third. Empty and failed searches are left alone and don't spend it.
- Rule 2 of the RAG prompt is cut to fit the full profile's 13,000-char
  budget after amd#6496 (12,979 on Windows, up 10 from main).
- Prompt goldens recaptured: the profilespec rows and the non-Claude golden
  differ from main only in rule 2.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents documentation Documentation changes eval Evaluation framework changes mcp MCP integration changes performance Performance-critical changes tests Test changes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants