Skip to content

Fix empty response from reasoning/thinking models - #102

Open
tkdlabs wants to merge 1 commit into
darrenburns:mainfrom
tkdlabs:fix/thinking-models-empty-response
Open

Fix empty response from reasoning/thinking models#102
tkdlabs wants to merge 1 commit into
darrenburns:mainfrom
tkdlabs:fix/thinking-models-empty-response

Conversation

@tkdlabs

@tkdlabs tkdlabs commented Jun 22, 2026

Copy link
Copy Markdown

Problem

When using a reasoning ("thinking") model — e.g. many models served via Ollama — the agent message box renders completely empty and no response is shown.

Cause

Such models stream their reasoning as delta.reasoning_content, during which delta.content is None. The streaming loop in chat.py treats any non-string content chunk as the end of the stream and breaks immediately on the very first chunk, so the entire response is discarded before the model's actual answer arrives:

if isinstance(chunk_content, str):
    ... append ...
else:
    break   # fires on the first reasoning chunk

Fix

Skip non-string content chunks with continue instead of break. The async iterator still terminates naturally at end-of-stream, and the model's answer (which follows the reasoning) renders as normal. One-line change + explanatory comment.

Verified against several thinking models on a local Ollama server (gemma/qwen/glm families): empty boxes before, correctly streamed answers after.

When streaming from a reasoning model (e.g. a "thinking" model served via
Ollama), the thinking tokens arrive as `delta.reasoning_content` while
`delta.content` is `None`. The streaming loop treated any non-string
content chunk as the end of the stream and `break`ed immediately, so the
entire response was discarded and the agent message box rendered empty.

Skip non-string content chunks with `continue` instead of breaking. The
async iterator terminates naturally at the end of the stream, and the
model's actual answer (which follows the reasoning) is rendered as before.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant