Fix empty response from reasoning/thinking models - #102
Open
tkdlabs wants to merge 1 commit into
Open
Conversation
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>
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.
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 whichdelta.contentisNone. The streaming loop inchat.pytreats any non-string content chunk as the end of the stream andbreaks immediately on the very first chunk, so the entire response is discarded before the model's actual answer arrives:Fix
Skip non-string content chunks with
continueinstead ofbreak. 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.