Repository navigation
fix(gaia): offer the flagship every tool on every turn, as the Agent UI does - #4554
Conversation
|
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 detailsSandboxed
Dynamic run, from |
|
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.
Real-world evidenceN/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
🟡 LLM-affecting change with no eval run ( 🟢 Unrelated black reformatting ( Strengths
|
…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.
769832b to
805bb09
Compare
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.
…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
…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]>
…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.
…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]>
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=1still enables it.docs/, claimed searches it didn't runOn the CSV question, today's selector offered web search and image generation but not the data tools:
analyze_data_filescored 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).pytest hub/agents/gaia/python/tests/test_prompt_prefix_stability.pynow 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_coreand a tool-heavy category before merge