Repository navigation
feat(tui): get the model ready before the chat opens - #4488
Merged
Merged
Conversation
On a local model the flagship's first answer sat behind ~20 s of silence: the agent process only started on the first message, then loaded the model, embedded every tool description, tidied memory and read ~10K tokens of system prompt while the user watched a spinner with no reason given. - The TUI now shows a "Getting GAIA ready" stage after the readiness gate, naming each step as the agent reports it, then opens the chat. Anything typed meanwhile queues and is sent the moment it is ready; Esc shows the chat without stopping the work (a cancel on this transport kills the agent). - New stdio sentinel `warm_up`: memory upkeep, tool embeddings (without touching the loader's turn state), and one priming request with the real system prompt and core tools and a one-token budget, so llama.cpp keeps the prefix. It renders skills through the per-turn filter, so the primed prompt is byte-identical to the first turn's. Remote models answer `warm_up_skipped`. - Measured on Gemma-4-E4B: first-answer TTFT 19.9 s -> 5.8-7.1 s; the first turn now prefills ~1.7K new tokens instead of ~10K.
kovtcharov-amd
force-pushed
the
kalin/warmup-stage
branch
from
September 29, 2026 18:16
cda44d0 to
f3efca6
Compare
4 tasks
kovtcharov
added a commit
to kovtcharov/gaia
that referenced
this pull request
Sep 29, 2026
…amd#4497) Before: a model picked in the TUI (Fireworks → DeepSeek V4.1 Flash, say) was forgotten on quit. The next launch ran local Gemma with no notice, and the header didn't name the model. After: the last provider + model the agent confirmed is saved in `~/.gaia/config.json` and restored on launch, and the header names the model from the moment the chat opens, local included. If a restore doesn't take (key gone, model not listed, agent down, or you stop it), GAIA says so in one line and opens the provider picker. It never quietly runs another model. This is the third piece after amd#4469 (provider registration kept) and amd#4485 (key kept): the *selection*. Closes amd#4490 ## Test plan - [ ] `cd tui && go vet ./... && go test ./...` - [ ] `python -m pytest hub/agents/gaia/python/tests/test_stdio.py tests/unit/test_cli_config.py` - [ ] Fresh `GAIA_HOME` + `GAIA_CONFIG_DIR`: launch `gaia-tui`. The header names the local model before any message. `/provider` → Fireworks → `deepseek-v4p1-flash`, chat once, quit, relaunch. Expect "Restored your last model." `/model` should say `Currently running: fireworks.deepseek-v4p1-flash`, and the gate should skip the local chat load. - [ ] Set `last_model` to a bogus `fireworks.*` id or an undownloaded local id and relaunch. Expect one `Couldn't restore your last model, …` line, the picker opens, and the saved value is untouched. <details> <summary>🔍 Technical details</summary> - **Storage:** `last_provider` / `last_model` are declared on `GaiaConfig`, because `save()` writes declared fields only and a Python `gaia config set` would otherwise drop them. Go writes them with the same read-modify-write as `full_access` (the shared helper is `writeConfigKeys`). A value is saved only when the agent's `/model` ping matches the requested id and the turn ends in a `final`. - **Restore:** one `/model <id>` turn sent as the chat opens, before amd#4488's warm-up. The warm-up then runs on the restored model, and is skipped if the restore fails. Anything typed before it, and a `--query`, waits behind it. Every non-confirmed ending sets `startup.unresolved`, which `ChatModel.Update` turns into the line + picker: an agent refusal, a crash before the model ping, a transport error, a cancel, or a double-Esc abort. - **Which choices become the launch model:** a saved cloud model does, so the gate skips the local chat load. Local and Claude choices are switched to after launch, so a deleted model or missing `ANTHROPIC_API_KEY` reaches the one-line path instead of halting at the gate. Explicit `--model` / `--use-claude` win for that launch. - **Scope:** the remembered choice lives in a shared box in `root` and is only ever applied to the flagship. `/agents` switches to other agents never receive it, and switching back restores the latest confirmed choice. A gate pick is cleared from `m.model` once the flagship has launched on it. - **Header before the first ping:** shows the chat model the readiness gate loaded (new `Report.ChatModel`), display-only, so the agent's first ping replaces it without tripping the revert warning. - **Agent:** `/model` on a cloud id Lemonade doesn't list now asks `readiness.probe_model_present`, which replays the key amd#4485 keeps (Fireworks or AMD), then re-lists. So a restore survives a Lemonade restart. - **Live drive** (Windows Terminal, control API, isolated `GAIA_HOME`/config/memory/daemon, `PYTHONPATH` pinned to this checkout, existing embedded Lemonade that already held a Fireworks key): ``` fresh launch: GAIA │ agent gaia │ Gemma-4-E4B-it-GGUF (no config.json yet) after pick: {"last_model": "fireworks.deepseek-v4p1-flash", "last_provider": "fireworks"} relaunch gate: Starting GAIA — chat runs on fireworks.deepseek-v4p1-flash (in the cloud)… relaunch: GAIA │ agent gaia │ Fireworks AI · deepseek-v4p1-flash (remote) Restored your last model. /model: Currently running: fireworks.deepseek-v4p1-flash. bogus cloud id: Couldn't restore your last model, Fireworks AI · not-a-real-model: Fireworks AI does not list it — the key may be missing or the provider is not connected. Pick a model to continue, now or later with /provider. missing local: Couldn't restore your last model, Qwen3-0.6B-GGUF: it is not downloaded. Pick a model to continue, now or later with /provider. ``` - **Pre-existing failures, not from this PR:** three `hub/agents/gaia` browser-tool registry tests fail without `playwright` installed, and pylint flags `os.getuid` / `signal.SIGKILL` on Windows. Both reproduce on `main`. - **Agent eval:** not run. No prompt, tool schema or error classification changed; the agent change only adds a re-list in the `/model` handler. </details>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
On a local model, the flagship's first answer sat behind ~20 s of silence: the agent process only started on the first message, then loaded the model, embedded every tool, tidied memory and read ~10K tokens of instructions while the user watched a spinner with no reason given. Now that work happens in a "Getting GAIA ready" stage between the readiness gate and the chat, with each step named. Measured on Gemma-4-E4B, the first answer's time-to-first-token dropped from 19.9 s to 5.8–7.1 s.
warm_up_skipped): nothing loads locally, and a priming call would only cost money.No eval run: the system prompt, tool schemas and docstrings are unchanged. The warm-up adds one request before the first turn and moves the existing memory upkeep ahead of it.
Test plan
cd tui && go test ./internal/ui/... ./internal/client/: frame tests for the stage, type-ahead queuing, Esc not cancelling, and only the flagship warming uppython -m pytest tests/unit/test_warm_up.py hub/agents/gaia/python/tests/test_stdio_wire_contract.pygaia tuion a local model: the stage lists its steps, then "[✓] Ready — … (Ns)"; the first question starts answering within a few seconds🔍 Technical details
New stdio sentinel
\u0000gaia:warm_up\u0000ingaia_agent.stdio, pinned in the shared wire fixture. It emitsstatusper step, thenfinalwarmed_up/warm_up_skipped, orerrornaming that chat still works.Agent.warm_up()does three things:ToolLoader.warm(), which builds the embeddings and returns CORE in registry order without touching turn statemax_tokens=1usingsystem_promptand_openai_toolsMemoryMixin.warm_upruns the deferred reconcile/consolidate first, so the first query doesn't.Root cause of the first measured miss (TTFT unchanged at 19.9 s): the primed prompt rendered
==== LOADED SKILLS ====and the turn==== LOADED SKILLS (active this turn) ====, so everything from char 18,798 on, tools included, was re-read. Checked that llama.cpp in Lemonade does reuse a prefix across requests (14,197 of 14,212 tokens cached for a different question) and that appending tools keeps it (14,640 cached).TUI: the warm-up is an ordinary turn on the sentinel, so the agent's startup model-state event still sets the model chip. The stage replaces the transcript while
warming. The status bar reads "getting ready".client.WarmUpperlimits it to the flagship's canonical stdio transport.Live drive (flagship over stdio, Gemma-4-E4B at 64K, isolated TUI home/memory/config):
then
[✓] Ready — … (24.7s), answer391,ttft 7.121,input_tokens 1693.