Repository navigation
feat(ui): prime a new chat's exact prompt before the first message - #5041
Conversation
A new Agent UI chat answered "hello" in ~43 s on Qwen3.6-35B-A3B because the first turn read ~19.3K tokens of system prompt and tool schemas cold. The backend now builds the flagship the way a new chat does and runs its warm_up() at start-up and whenever a new chat is opened, so the first turn reads only its own ~50 tokens. The new-chat view shows "Getting GAIA ready… Ns" meanwhile without blocking the message box; a message sent mid-warm-up waits for it instead of reading the prompt a second time. One warm-up runs at a time, never alongside a chat turn, and a repeat within 30 s is a no-op. The HTTP sidecar's warm-up sent only the agent's own prompt section and no tools, so its prefix never matched a turn (0 of 19.3K tokens reused). It now calls the same warm_up(), and logs a failure as a warning with its cause instead of swallowing it at info level. warm_up() reports prompt and cached token counts. Tests pin the warm-up request's system message and tool schemas byte-for-byte to the first turn's, for the TUI/sidecar agent and for the Agent UI's new-chat build.
|
Verdict: Request changes This PR loads GAIA's instructions into the local model's cache before a new chat's first message, so "hello" answers in seconds rather than ~40 s. The sidecar's warm-up now primes the same prompt a real turn sends. The design is sound and the prefix-equality tests are strong. One bug needs fixing first:
Real-world evidenceN/A: no evidence bundle was produced for this run. The PR description has before/after timings measured against a real Lemonade, but nothing in this run reproduced them. There's no screenshot of the "Getting GAIA ready… Ns" line, and no captured 🔍 Technical details🟡 ImportantBlocking (Check that The busy probe misses non-streaming turns ( 🟢 Minor
Strengths
|
…route The new-chat warm-up only recognised fireworks/amd cloud ids, so a cloud model known only from Lemonade's catalog would have been sent a paid request on every new chat. It now reads the catalog before classifying the model, also checks the model the agent actually picked when the session defers to the agent default, and skips the eval Claude provider. Also documents /api/system/warm-up in the Agent UI SDK reference, which test_route_doc_coverage requires, and narrows the module docstring to say only streamed turns block a warm-up.
|
Holding this until after 0.25.0, unless you want it in the release. It doesn't change what the model sees, so no eval is needed. But it's an 850-line performance feature that runs a model request in the background on every new chat, and the RC is frozen. I pushed one fix: the warm-up could have sent a paid request to a cloud model on every new chat. That only happened when GAIA knew the model was cloud-hosted from Lemonade's model list, not from its name. The bot's main finding is a false alarm. The non-streaming wait already runs in a worker thread, so it doesn't freeze the server. 🔍 Technical detailsPushed
The bot's 🟡 is a false alarm. In Checked and fine: the warm-up sends the same prefix as the real turn. Byte-for-byte tests cover both the UI and the sidecar. A model that isn't downloaded is never loaded. A turn sent mid-warm-up waits for it instead of reading the prompt twice. Local results: |
… absent The CI unit job doesn't install hub packages, so the unguarded gaia_agent_chat import failed the hub-import guard on every platform.
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:
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.
🔍 Technical details
Agent.warm_up(). It sendssystem_promptand_openai_toolsexactly asprocess_querydoes, and now reportsprompt_tokensandcached_tokens. The sidecar and the Agent UI (gaia/ui/warmup.py) both call it. The UI builds the agent with the sameregistry.create_agentkwargs that the streaming chat path uses on a cache miss.PrefixWarmerruns 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 callwait_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.GETandPOST /api/system/warm-up, plus awarm_upfield on/api/system/status. API types were regenerated.GAIA_DYNAMIC_TOOLS=1the first turn picks tools for its query, so a warm-up can't match it exactly. That opt-in path is unchanged.timings.cache_n/prompt_nfrom the response, and the Agent UI's storedinput_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.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.pycd src/gaia/apps/webui && npx vitest run && npx tsc --noEmit -p .gaia chat --uiwith 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.Warm-up (...) doneline, and the message'sinput_tokensof about 50, show the prompt was reused.