Skip to content

feat(tui): get the model ready before the chat opens - #4488

Merged
kovtcharov-amd merged 1 commit into
amd:mainfrom
kovtcharov:kalin/warmup-stage
Sep 29, 2026
Merged

kovtcharov-amd merged 1 commit into
amd:mainfrom
kovtcharov:kalin/warmup-stage

Conversation

@kovtcharov

Copy link
Copy Markdown
Contributor

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.

  • Type-ahead works. A message typed during the stage queues and is sent the moment GAIA is ready. Esc shows the chat without stopping the warm-up, because a cancel on this transport kills the agent.
  • The cache hit is real, not hoped for. The priming request's system prompt is byte-identical to the first turn's, and its tools are an exact prefix of the turn's. Lemonade reads ~1.7K new tokens on the first turn instead of ~10K.
  • Remote models skip it (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 up
  • python -m pytest tests/unit/test_warm_up.py hub/agents/gaia/python/tests/test_stdio_wire_contract.py
  • gaia tui on a local model: the stage lists its steps, then "[✓] Ready — … (Ns)"; the first question starts answering within a few seconds
  • Type a question during the stage: it shows "⏎ queued · … sent when GAIA is ready" and is answered right after
  • With a Fireworks model selected, the stage ends as soon as the agent starts
🔍 Technical details
  • New stdio sentinel \u0000gaia:warm_up\u0000 in gaia_agent.stdio, pinned in the shared wire fixture. It emits status per step, then final warmed_up / warm_up_skipped, or error naming that chat still works.

  • Agent.warm_up() does three things:

    • applies the per-turn skill filter
    • calls ToolLoader.warm(), which builds the embeddings and returns CORE in registry order without touching turn state
    • sends one request with max_tokens=1 using system_prompt and _openai_tools

    MemoryMixin.warm_up runs 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.WarmUpper limits it to the flagship's canonical stdio transport.

Live drive (flagship over stdio, Gemma-4-E4B at 64K, isolated TUI home/memory/config):

  Getting GAIA ready
  ✓ Starting the agent
  ✓ Tidying memory
  ✓ Indexing tools
  ⣟  Loading Gemma-4-E4B-it-GGUF and reading its instructions  0:06
⏎ queued · What is 17 times 23? Answer with just the number.  sent when GAIA is ready
  ● agent gaia getting ready                         type ahead · Esc show chat · Ctrl+C quit

then [✓] Ready — … (24.7s), answer 391, ttft 7.121, input_tokens 1693.

@github-actions github-actions Bot added documentation Documentation changes tests Test changes agents tui Go terminal UI (gaia-tui) labels Sep 29, 2026
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
kovtcharov-amd added this pull request to the merge queue Sep 29, 2026
Merged via the queue into amd:main with commit 016191e Sep 29, 2026
50 of 52 checks passed
@kovtcharov-amd
kovtcharov-amd deleted the kalin/warmup-stage branch September 29, 2026 18:17
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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents documentation Documentation changes tests Test changes tui Go terminal UI (gaia-tui)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants