Skip to content

fix(llm): keep a cloud model's reasoning out of gaia llm output - #6068

Merged
kovtcharov-amd merged 2 commits into
amd:mainfrom
kovtcharov:kalin/llm-hide-think
Oct 29, 2026
Merged

kovtcharov-amd merged 2 commits into
amd:mainfrom
kovtcharov:kalin/llm-hide-think

Conversation

@kovtcharov

Copy link
Copy Markdown
Contributor

gaia llm with a cloud thinking model (for example the Fireworks models GAIA recommends) printed the model's whole reasoning as a raw <think>…</think> block in front of the answer. Now it prints only the answer. The agent and the Agent UI already strip these tags; gaia llm was the one consumer that didn't. Found while release-testing v0.25.2.

Test plan

  • pytest tests/unit/test_llm_app_thinking.py tests/unit/test_llm.py: pass, including 3 new tests (streamed, glued-to-answer, non-streamed)
  • Live: gaia llm --model fireworks.deepseek-v4p1-flash "Reply with exactly: PONG" prints 🤖 gaia: PONG (v0.25.2 printed <think>The user wants…</think>PONG)
  • CI green

`gaia llm --model fireworks.<model> "..."` printed the model's whole reasoning as a
raw <think>...</think> block before the answer. The Lemonade provider wraps cloud
reasoning in those tags for its consumers to separate; the agent and Agent UI strip
them, `gaia llm` printed them. It now prints and returns only the answer.
@github-actions github-actions Bot added the tests Test changes label Oct 29, 2026
@github-actions

Copy link
Copy Markdown
Contributor

Verdict: Approve with suggestions

gaia llm used to print a cloud thinking model's whole <think>…</think> reasoning ahead of the answer. Now it prints only the answer, which brings it in line with the agent and the Agent UI. The fix is small and has tests for the streamed, glued-to-answer and non-streamed cases. It's safe to merge.

One edge is worth closing. Cloud models can't have thinking switched off, and gaia llm defaults to a 512-token cap. A model that spends that whole budget reasoning used to show its truncated reasoning. Now it prints a blank 🤖 gaia: line with no explanation. A one-line hint telling the user to raise --max-tokens would make that failure visible.

Real-world evidence

N/A: no evidence bundle was produced for this run. The PR description reports a live run, gaia llm --model fireworks.deepseek-v4p1-flash "Reply with exactly: PONG" printing 🤖 gaia: PONG where v0.25.2 printed <think>The user wants…</think>PONG, but this review didn't reproduce it. The verdict rests on reading the diff alone. I couldn't run the tests here because the runner has no dev dependencies installed.

🔍 Technical details

🟡 A reasoning-only response now prints nothing (src/gaia/apps/llm/app.py:137)
no_thinking_kwargs() returns {} for cloud models, so their reasoning counts against max_tokens=512. If the model stops while still in <think> (the provider closes the tag at end of stream), _without_reasoning yields nothing, and both branches print an empty answer and return "". Before this PR the user at least saw why. Suggested fix: after the stream loop (and after the non-stream join), when the answer is empty but the raw output had a <think> block, print a hint such as "[model used its token budget reasoning — raise --max-tokens]" on stderr. This follows the repo's fail-loudly rule. A test feeding ["<think>", "plan…", "</think>"] would cover it.

🟢 Streamed and non-streamed answers are trimmed differently (app.py:137 vs :144)
The non-streamed path calls .strip(), but the streamed path doesn't. When a model emits </think>\n\nAnswer inside content, the streamed output starts with blank lines and main() returns "\n\nAnswer". Dropping leading whitespace from the first yielded chunk after a close tag would make the two paths match.

🟢 Tags split across chunks aren't handled
This is fine for the provider's own tags: <think> is yielded as a whole chunk and </think> always ends a chunk (providers/lemonade.py:975, 1042). Raw tags a model streams inside content ("<thi", "nk>") would leak through. Optional: a short docstring note that this assumes provider-emitted tags.

Strengths

  • The state machine is short and correct for several tag pairs in one chunk, and the glued-to-answer test exercises exactly that.
  • Filtering None chunks in the generator expression keeps the old guard and drops the nested if.
  • The tests go through main() with capsys, so they check what the user actually sees, not just the helper.

A cloud thinking model that spent the whole --max-tokens budget reasoning left gaia llm printing a blank answer with no explanation. It now exits with an error naming --max-tokens, and the streamed answer is trimmed like the non-streamed one.
@kovtcharov-amd

Copy link
Copy Markdown
Collaborator

The review's main finding is fixed. If a thinking model uses up its whole token budget on reasoning, `gaia llm` now exits with an error that tells you to raise `--max-tokens`, instead of printing a blank answer. Streamed answers also drop the blank lines left after the reasoning, the same way non-streamed answers already did.

The Windows unit-test failure comes from a connectors timing test this PR doesn't touch. It's tracked in #6071.

🔍 Technical details
  • An empty reply with no reasoning still returns "", so the error only fires when reasoning was actually removed.
  • Added tests for both paths: a closed think block, one that never closes, whitespace-only text after the reasoning, an empty reply with no reasoning, whitespace inside the answer, and lookalike tags (<thinking>, a stray </think>). Without the fix, 7 of them fail.
  • The split-tag nit is still open. The provider sends the tags as whole chunks, and the docstring now says so.

@kovtcharov-amd
kovtcharov-amd added this pull request to the merge queue Oct 29, 2026
Merged via the queue into amd:main with commit 11c3623 Oct 29, 2026
22 checks passed
@kovtcharov-amd
kovtcharov-amd deleted the kalin/llm-hide-think branch October 29, 2026 19:10
grtninja pushed a commit to grtninja/gaia that referenced this pull request Nov 1, 2026
…#6073)

The connectors test that checks the slot lock and file lock share one
wait budget failed at random on loaded Windows runners, which blocked
unrelated PRs like amd#6068. It timed the whole call against a 1.4 s
ceiling, and a busy runner can blow past that with nothing wrong. It now
checks the budget the file-lock wait actually gets, so runner load can't
fail it, and it still fails if the two waits stop sharing a budget.

Closes amd#6071

## Test plan

- [x] `python -m pytest tests/unit/connectors/ -q` passes (956 passed)
- [x] `python util/lint.py --all` passes
- [x] Mutation check: passing no `timeout` to the file-lock wait in
`get_or_refresh` makes the test fail
- [ ] Windows unit-test job passes on this PR

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

- The test wraps `_refresh_lock.held` to record the `timeout` it
receives. The peer holds the slot for 0.6 s on a 1.0 s budget, so a
shared budget passes at most ~0.4 s. The assertion allows up to 0.45 s
for clock granularity. An unshared wait passes `None` or 1.0 and fails.
- No source change. `tokens.get_or_refresh` already shares the deadline.
The flake came from the wall-clock assertion, not from the code under
test.
- `tests/unit/` with `-x` stopped here on an unrelated collection error:
`responses` isn't installed in this runner. The whole connectors suite
was run instead.
</details>

Co-authored-by: claude[bot] <41898282+claude[bot]@users.noreply.github.com>
Co-authored-by: Kalin Ovtcharov <[email protected]>
kovtcharov-amd pushed a commit to kovtcharov/gaia that referenced this pull request Nov 14, 2026
…amd#8141)

## Summary

`gaia prompt` with a thinking model now prints only the answer, instead
of the model's whole `<think>...</think>` reasoning followed by the
answer. A failed reply now exits 1 instead of 0.

## Why

Scripts that read `gaia prompt`'s stdout got the reasoning glued to the
answer. Every other surface already strips it, and `gaia llm` got the
same fix in amd#6068; `gaia prompt` printed the raw stream. It now goes
through the same filter as `gaia llm`, so the two commands print the
same thing. If the model spends the whole token budget reasoning, `gaia
prompt` now says to raise `--max-tokens`, as `gaia llm` does, instead of
printing a blank line. That error, like a failed model call, used to
exit 0, so a script could not tell it from an answer; it now exits 1.

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

- Reuses `_ReasoningFilter` and `_reasoning_only_error` from
`gaia/apps/llm/app.py` rather than the chunk-splitting state machine
sketched in the triage comment: the Lemonade provider emits `<think>`
and `</think>` whole, which is what the `gaia llm` filter already relies
on.
- Leading blank lines after the reasoning are trimmed, matching `gaia
llm`.
</details>

## Linked issue

Closes amd#8032

## Changes

- `gaia prompt` filters the streamed reply through the `gaia llm`
reasoning filter before printing it.
- `gaia prompt` exits 1 after a failed reply (model call error, or a
reply that is all reasoning), as the review suggested.

## Test plan

- [x] `python -m pytest tests/unit/cli/test_prompt_reasoning.py`: 3 of
the 4 new tests fail on main with the `<think>` block on stdout and pass
with the fix (the fourth checks a reply without reasoning prints
unchanged)
- [x] `test_prompt_model_call_error_exits_non_zero` and the
all-reasoning test fail without the exit-code commit (exit 0) and pass
with it
- [x] `python -m pytest tests/unit/cli
tests/unit/test_llm_app_thinking.py
tests/unit/test_provider_error_surface_advice.py
tests/unit/test_ctx_overflow_device_profile_2884.py` on the final
branch: 698 passed, 1 skipped
- [x] `python -m pytest tests/unit/ -n 8` on the first commit: 42095
passed, 9 failed. The same 8 fail on main on this machine (2 in
`test_verification_scope.py`, 4 in the eval bench tests, 2 in
`test_schedule_missed_runs.py`); the ninth, in `test_log_viewer.py`,
passes when run on its own
- [x] `python util/lint.py --all`: passes apart from two pylint errors
in `utils/awake_clock.py` and `utils/terminal.py`, which come from the
local pylint version (the Lint workflow passes on the same base commit)

## Evidence

- [ ] **Agent exposed in the Agent UI**: N/A, CLI-only change
- [ ] **MCP tools / servers**: N/A
- [x] **CLI**: `gaia prompt "Reply with exactly: hello-rc24-once"
--model fireworks.deepseek-v4p1-flash`, run against a local
OpenAI-compatible server that streams `reasoning_content` and then
`content` the way Fireworks does, so the real Lemonade provider path
wraps the reasoning in `<think>` tags

Before (main):
```
<think>The user wants me to reply with exactly "hello-rc24-once". This is simple.
I should comply exactly.</think>hello-rc24-once
```

After (exit 0):
```
hello-rc24-once
```

After, when the stream ends while still reasoning (exit 1; was 0):
```
❌ Error: The model spent its whole 512-token budget reasoning and returned no answer. Re-run with a larger --max-tokens (for example --max-tokens 4096).
```
- [ ] **HTTP API / REST**: N/A

## Checklist

- [x] I have linked a GitHub issue above (`Closes #N` / `Fixes #N` /
`Refs #N`).
- [x] I have described **why** this change is being made, not just what
changed.
- [x] I have run linting and tests locally (`python util/lint.py --all`,
`pytest tests/unit/`).
- [x] I have attached **real-world evidence matched to the surface I
changed** (see Evidence above), or marked each surface N/A.
- [ ] I have updated documentation if user-visible behavior changed.
N/A: no doc describes `gaia prompt` printing reasoning.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

tests Test changes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants