Skip to content

fix(gaia): offer the flagship every tool on every turn, as the Agent UI does - #4554

Merged
kovtcharov-amd merged 12 commits into
amd:mainfrom
kovtcharov:kalin/gaia-all-tools-default
Oct 5, 2026
Merged

kovtcharov-amd merged 12 commits into
amd:mainfrom
kovtcharov:kalin/gaia-all-tools-default

Conversation

@kovtcharov

@kovtcharov kovtcharov commented Oct 1, 2026 •

Copy link
Copy Markdown
Contributor

The TUI's flagship picks about 29 of its ~90 tools for each turn by embedding similarity. The Agent UI keeps that selector as an opt-in Beta that is off by default, so the same agent behaved differently in the two apps. In the TUI it hurt both speed and answers. Scores sit bunched between 0.2 and 0.46, so the loader hits its cap and swaps about 12 tools every turn. The tool list then changes on every call, which breaks the local model's prompt cache, and the tool a question needs is often missing. This PR turns selection off by default; GAIA_DYNAMIC_TOOLS=1 still enables it.

TUI, local Qwen3-30B selector on (today) selector off (this PR)
"What is 17 times 23?" 34.0s, 16.9s to first token 1.0s, 0.4s
"Which region had the highest revenue in docs/sales_data_2025.csv?" fetched an unrelated GitHub page first; 683s read the CSV directly; 121s
"What PPE does the safety handbook PDF require?" never listed docs/, claimed searches it didn't run found, indexed and searched the PDF; correctly said it isn't covered

On the CSV question, today's selector offered web search and image generation but not the data tools: analyze_data_file scored 0.35, ranked 11th, and wasn't admitted.

Draft for a design decision. The selector was on by design, for the cost of re-reading ~10K tokens of tool schemas on a 4B model. With prefix caching, an unchanging tool list is read once per session. Loader tests now enable it explicitly so its behavior stays covered.

Test plan

  • pytest hub/agents/gaia/python/tests: the same 3 failures as main (optional browser extra).
  • TUI A/B on the same questions (table above).
  • pytest hub/agents/gaia/python/tests/test_prompt_prefix_stability.py now builds the flagship with its default tool setting, so a default that brings back per-turn tool selection fails it (checked by flipping the default)
  • gaia eval agent --category gaia_core and a tool-heavy category before merge

@kovtcharov

kovtcharov commented Oct 2, 2026 •

Copy link
Copy Markdown
Contributor Author

Measured on a fresh install, this PR makes the first launch slower but the session faster. Ready takes 83 s instead of 40 s, while four ordinary first-session prompts finish in 72 s instead of 173 s — 155 s total vs 213 s. The dynamic loader re-sends a different tool set almost every turn, so each turn reprocesses the whole ~11K-token prompt; with every tool loaded the prefix stays cached. I recommend merging, and making the one-time warm-up (which the TUI already shows with type-ahead) the place to pay that cost.

🔍 Technical details

Sandboxed install.ps1 + gaia init install, embedded Lemonade v2026.40.0, Gemma-4-E4B on Vulkan (Radeon 8060S), model unloaded and memory DB wiped before each run. Prompts: hi! I'm new here. what can you do? → My favourite fruit is mango. Just acknowledge. → What fruit did I just mention? One word. → What files are in my Documents folder? — all four answered correctly in both runs.

dynamic tools on (main) all 83 tools (this PR)
warm-up prompt 8,647 tokens 17,111 tokens
TUI "Ready" 39.5 s 83.1 s (1m50.8s on a first run)
turns 27.6 / 42.3 / 24.7 / 78.6 s 26.8 / 13.5 / 17.9 / 14.1 s
total 212.7 s 155.4 s

Dynamic run, from lemond.log: the warm-up's 8,647-token prefix was never reused (the first turn sent a 2,014-token prompt with a different tool subset), and the directory-listing turn ran two full re-prefills of 10,698 and 11,047 tokens (63 s of prompt processing). The 83 tool schemas are 48.8K chars (~12K tokens) — trimming them is the remaining lever for the warm-up.

@kovtcharov
kovtcharov marked this pull request as ready for review October 2, 2026 06:29
@github-actions

github-actions Bot commented Oct 2, 2026

Copy link
Copy Markdown
Contributor

Verdict: Request changes

Turning per-turn tool selection off by default is well argued: the before/after table shows the selector broke the prompt cache and kept the right tool out of reach. Two things need fixing before merge.

  • The published tool count is probably wrong now. The load_tools helper only exists while selection is on, so the default agent registers one tool fewer than the 96 the hub manifest advertises. The test that checks that number should start failing. Decide whether the published count describes the default agent, then update the manifest, registration, capability matrix and test so they agree.
  • The agent eval hasn't run. Changing which tools the model sees on every call is exactly the kind of change the repo requires a gaia eval agent run for. The test plan already lists it as unchecked; run a tool-heavy category before merging.

Real-world evidence

N/A here: no evidence bundle was produced for this run, and real inference is deferred to the strix-halo lane. The PR description reports a TUI A/B on local Qwen3-30B (34.0s → 1.0s on simple arithmetic; the CSV question went straight to the file instead of web tools first). That supports the direction of the change, but this verdict rests on static review. I couldn't run the tests either, because the runner has no Python environment.

🔍 Technical details

🟡 The default registry drops load_tools, so tools_count: 96 drifts (hub/agents/gaia/python/gaia_agent/agent.py:213)
load_tools is registered only if self.tool_loader is not None (hub/agents/chat/python/gaia_agent_chat/agent.py:1582). tool_surfaces in tests/test_gaia_agent.py:57 builds GaiaAgentConfig(silent_mode=True), which now has no loader, so test_manifest_tools_count_matches_real_registry should see 95 against 96. This wasn't run here. If it's one of the "same 3 failures as main", say so in the PR.
It's also a real disagreement, not just a test to edit. reconcile_tools_count in packaging/capability_matrix.py derives its count from the AST of FULL_CORE_TOOLS, and that set contains load_tools, so it will keep saying 96. TOOLS_COUNT_DEFINITION, and the CAPABILITY_MATRIX.md text generated from it, still say "default construction … including the load_tools escape hatch" and "a single turn only shows the model a subset". Pick one:

  • Exclude load_tools from the published count when the loader is off, and update the manifest, __init__.py, the AST derivation and the definition text together.
  • Or pin tool_surfaces to dynamic_tools=True, and say in the definition that the count includes the opt-in loader's helper.

🟡 LLM-affecting change with no eval run (agent.py:213)
The default tool payload changes from about 29 tools to all of them on every call. CLAUDE.md's eval rule covers "Tool registration … or the JSON tool schema sent to Lemonade". Run gaia eval agent on a tool-heavy category, such as the tool-selection, data or files categories. No baseline is committed yet, so report the scores you measured rather than claiming "no regression". The run should also check how the full schema fits on NPU at 32K ctx, since the selector existed to save about 10K tokens of schema per call.

🟢 Unrelated black reformatting (tests/test_server_query.py, tests/test_skill_learning_reachability.py, tests/test_stdio_wire_contract.py)
These hunks only re-wrap lines and don't touch selection. Consider dropping them to keep the diff in scope, or noting why they're here (main may have been unformatted).

Strengths

  • The change brings the TUI and the Agent UI to the same default, and keeps GAIA_DYNAMIC_TOOLS=1 as the opt-in.
  • Loader tests now set dynamic_tools=True explicitly instead of losing coverage, and the assertion messages were updated to match.
  • The new code comment and CHANGELOG entry give the reason with concrete numbers.

…UI does

The TUI's flagship sidecar defaulted to per-turn semantic tool selection while the Agent UI keeps it an opt-in Beta. At its cap the loader evicted and admitted about a dozen tools each turn, so the tool list changed every call: the local model re-prefilled it (ttft 16.9s vs 0.4s) and the needed tool was often absent.
@kovtcharov
kovtcharov force-pushed the kalin/gaia-all-tools-default branch from 769832b to 805bb09 Compare October 2, 2026 08:09
With per-turn tool selection off by default, the load_tools escape hatch no
longer registers, so the registry holds 95 tools and the manifest's 96
failed the drift test. The manifest, registration, capability matrix and
docs now say 95, and the guide says every tool is offered on every turn,
with GAIA_DYNAMIC_TOOLS=1 bringing selection and load_tools back.
@github-actions github-actions Bot added documentation Documentation changes sidecar Agent sidecar contract / harness labels Oct 2, 2026
Kalin Ovtcharov and others added 7 commits October 2, 2026 20:59
…hange

Three hub test files were re-wrapped by black without any change related to tool selection. They are restored to main's text so the diff only carries the default flip.
# Conflicts:
#	hub/agents/gaia/npm/CHANGELOG.md
# Conflicts:
#	hub/agents/gaia/npm/CHANGELOG.md
# Conflicts:
#	hub/agents/gaia/npm/CHANGELOG.md
kovtcharov added a commit to kovtcharov/gaia that referenced this pull request Oct 5, 2026
…md#4698)

On a local model, a turn could stall for minutes while the server
re-read the whole conversation from the first token: 34,100 tokens (155
s) and 39,531 tokens (240 s) in the v0.25 RC TUI session on Gemma-4-E4B.
llama.cpp reuses only the prefix two requests share. On Gemma 4 and
Qwen3.6, any change to the system prompt or tool list throws away
everything after it. GAIA still rewrote the system prompt mid-session
for things that change every turn. This PR moves that content into the
turn, so each request extends the one before it.

**Stacked on amd#4571. Merge that first.** It fixes the cause behind both
RC stalls: indexing a document rewrote the system prompt, and the next
step re-read everything. This branch includes its commits until then.
Even with amd#4571, three causes still rewrite the prompt:

- **Learned procedures** recalled for the current goal were written into
the system prompt, so it was rebuilt every time the match changed. They
now ride in the turn's `[GAIA Memory Context]`, next to recalled
memories.
- **The "stable" memory section** was re-read from the store on every
recompose. A fact extracted after the last turn, an auto-stored tool
error, or a confidence bump therefore changed the prompt. That includes
the rebuild `index_document` still triggers under amd#4571, so amd#4571 alone
breaks again once memory extraction runs. The section is now rendered
once per session, which is what the memory docs already promised. A
`forget` or `update_memory` of an item it shows still takes effect
immediately.
- **The skill filter** recomposed the prompt whenever the always-on
`gaia-voice` skill flipped in the selection, even though its body
renders either way. Each needless recompose is what carried the memory
drift in.

Per-turn tool selection, the remaining cause, is amd#4554 (already in the
RC). The new test pins `dynamic_tools=False`.

## Test plan
- [x] `pytest
hub/agents/gaia/python/tests/test_prompt_prefix_stability.py`: builds
the real flagship with the model call captured and runs four turns
through the stdio history path. The turns cover a tool call,
`index_document`, a recalled procedure, a fact stored between turns, and
the RAG guard's re-ask. Each of the 7 requests extends the one before.
**Fails on main and on amd#4571 alone** at the first new turn.
- [x] `pytest tests/unit/test_memory_mixin.py` (331 passed, including
new frozen-section tests: mid-session writes stay out, forgetting a
shown memory removes it at once, forgetting an unshown one costs no
recompose).
- [x] `pytest tests/unit/test_agent_lazy_skill_prompt.py
tests/unit/test_indexed_docs_per_turn.py tests/test_chat_agent.py` plus
the other skill, memory and prompt-composition suites all pass.
- [x] `pytest hub/agents/gaia/python/tests`: 604 passed. The 3 failures
also fail on main (optional browser extra not installed).
- [ ] **`gaia eval agent`** on `gaia_memory`, `memory`, `gaia_rag`,
`context_retention`, on this branch and on main, same machine. This
changes prompt assembly, so CLAUDE.md requires it.
- [ ] Re-run the RC TUI walkthrough and check `lemond.log`. No step
after an `index_document` should start from `progress = 0.0x`, and new
turns should re-read only the new turn.

<details>
<summary>🔍 Technical details</summary>

**How each cause was found.** A scratch harness captured every outgoing
`messages` + `tools` payload from the real `GaiaAgent`. It rendered each
payload the way the chat template lays it out (system, tools, then
turns) and reported the first diverging byte between consecutive
requests:

| cause | first diverging content |
|---|---|
| indexed docs (amd#4571) | `**CURRENTLY INDEXED DOCUMENTS:**\nNo documents
are currently indexed.` → `You have 1 document(s) already indexed…`, at
the step after `index_document` |
| recalled procedures | `==== LOADED SKILLS (active this turn) ====` →
`=== RECALLED PROCEDURES (learned from past successful runs) ===`, on
every turn whose match changed |
| memory drift | `No memories stored yet.` → `Known facts:\n - Sam works
on the safety team (confidence: 0.50…)`, then `0.50` → `0.52` the turn
after |
| no-op skill recompose | `_refresh_active_skill_filter` going `[]` →
`['gaia-voice']` → `[]`, recomposing on each flip (the trigger for the
drift above) |
| dynamic tools (amd#4554) | tools payload: `-[clear_code_index,
get_index_status, …] +[bookmark, find_files, …]` on every new turn |

**Why ordering didn't help.** `VOLATILE_PROMPT_FRAGMENTS` puts changing
fragments last in the system text. The template renders the tool
declarations after the system text, though, so a change there still
invalidates ~10K tokens of tools plus all history. And Gemma 4
(sliding-window) and Qwen3.6 (hybrid) can resume only from a llama.cpp
checkpoint, which sits near the end of an earlier prompt, never at that
boundary. In the RC log that shows up as 0% reuse.

**Not changed here, for follow-up:**
- Qwen3.6 thinking: the chat template drops `reasoning_content` from
messages before the last user turn, so each new turn re-reads the
previous turn's tool steps. The RC log shows 4–7K tokens per turn.
Fixing it needs `preserve_thinking` plus re-sending reasoning, which is
a design call. Gemma isn't run with thinking on, so it isn't affected.
- `extract_document_items` / `save_extracted_items` join the tool list
only on "extract every X" turns.
- User-loaded skill bodies still toggle in the system prompt (the amd#2848
size trade-off).
- The project map's index-status line still changes, but only when
something else recomposes.

Also: three pre-existing `except …: pass` handlers in the touched files
now log instead of swallowing.
</details>

---------

Co-authored-by: Kalin Ovtcharov <[email protected]>
Kalin Ovtcharov and others added 2 commits October 4, 2026 18:41
…etting

A default that turned per-turn tool selection back on would send a new
tool list every turn and re-read the whole conversation. The stability
test pinned dynamic_tools=False, so it could not catch that; it now
builds the flagship with its defaults.
@kovtcharov-amd
kovtcharov-amd added this pull request to the merge queue Oct 5, 2026
Merged via the queue into amd:main with commit 4c3a9a4 Oct 5, 2026
@kovtcharov-amd
kovtcharov-amd deleted the kalin/gaia-all-tools-default branch October 5, 2026 04:34
grtninja pushed a commit to grtninja/gaia that referenced this pull request Oct 13, 2026
…md#5041)

A new Agent UI chat took about 43 s to answer "hello" on
Qwen3.6-35B-A3B, with only "Reading your request" on screen, because its
first turn read ~19.3K tokens of system prompt and tool schemas from
scratch. Now the backend reads that exact prompt into Lemonade's cache
at start-up and whenever a new chat is opened. While that happens the
new-chat view shows "Getting GAIA ready… 12s", and you can still type
and send. The sidecar's existing warm-up primed a prompt that never
matched a real turn, so its first question reused 0 tokens. It now
primes the same prompt as the other paths.

Measured on the local Lemonade with the model reloaded before each run,
so the prompt cache starts empty:

| Path | First "hello" before | After | Prompt tokens read on the first
turn (before → after) |
|---|---|---|---|
| Agent UI, fresh chat (end to end over HTTP) | 42.8 s | 21.3 s | 19,296
→ 50 |
| Agent UI new-chat build, in-process | 44.2 s | 5.3 s | 19,295 → 50 |
| HTTP sidecar | 34.0 s (old warm-up) | 5.4 s | 19,295 → 50 |
| TUI stdio (already primed, unchanged) | 28.2 s (no warm-up) | 5.8 s |
19,295 → 50 |

The served UI still has a gap: its first token arrives about 15 s later
than the in-process run, even though both read only 50 tokens. A second
new chat on a warm cache answers in 6 s. The likely cause is llama.cpp
restoring its checkpoint for Qwen3.6's hybrid layers. This PR doesn't
fix it.

<details>
<summary>🔍 Technical details</summary>

- The shared primitive is `Agent.warm_up()`. It sends `system_prompt`
and `_openai_tools` exactly as `process_query` does, and now reports
`prompt_tokens` and `cached_tokens`. The sidecar and the Agent UI
(`gaia/ui/warmup.py`) both call it. The UI builds the agent with the
same `registry.create_agent` kwargs that the streaming chat path uses on
a cache miss.
- Every new chat renders the same prefix whatever its session id (no
attached docs). A unit test checks this byte for byte.
- `PrefixWarmer` runs one warm-up at a time. It skips while any SSE chat
turn is active and ignores a repeat within 30 s after success. Chat
turns call `wait_for_warm_up()` before building their agent. That stops
them reading the prompt twice and keeps them from racing the warm-up's
tool registration.
- It skips cloud models and models that aren't downloaded. The start-up
warm-up runs only after the "Loading AI model" boot job succeeds, and it
isn't a visible job, so it never blocks the composer.
- New endpoints are `GET` and `POST /api/system/warm-up`, plus a
`warm_up` field on `/api/system/status`. API types were regenerated.
- The TUI's warm-up already matched the first turn while dynamic tools
are off (the default since amd#4554). The new test pins that. With
`GAIA_DYNAMIC_TOOLS=1` the first turn picks tools for its query, so a
warm-up can't match it exactly. That opt-in path is unchanged.
- No prompt content, tool sets, or tool order changed, so no eval
categories need to re-run.
- How it was measured: before each run the model was unloaded and
reloaded, which clears llama.cpp's RAM prompt cache. Cached tokens are
llama.cpp's own `timings.cache_n` / `prompt_n` from the response, and
the Agent UI's stored `input_tokens`. The Lemonade is shared, and wall
times varied by up to 2× when other clients were active. The numbers
above come from quiet runs.
</details>

## Test plan
- [ ] `python -m pytest tests/unit/test_ui_warmup.py
hub/agents/gaia/python/tests/test_prompt_prefix_stability.py
hub/agents/gaia/python/tests/test_warmup_no_download.py
tests/unit/test_warm_up.py`
- [ ] `cd src/gaia/apps/webui && npx vitest run && npx tsc --noEmit -p
.`
- [ ] Start `gaia chat --ui` with a local model and open a new chat.
"Getting GAIA ready… Ns" shows under the message box and clears when
done, and the message box stays usable throughout.
- [ ] Send "hello" right after it clears. The backend log's `Warm-up
(...) done` line, and the message's `input_tokens` of about 50, show the
prompt was reused.

---------

Co-authored-by: Kalin Ovtcharov <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Documentation changes sidecar Agent sidecar contract / harness

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants