Split thinking output into reasoning_content#2
Merged
Conversation
Thinking models (Qwen3.x) emit their reasoning inline, which previously landed in the response `content`. Separate it into an OpenAI-style `reasoning_content` field on both the message and streaming deltas. - ReasoningSplitter: streaming-safe <think>/</think> classifier, with partial-marker handling across chunk boundaries - --reasoning mode: auto (split on literal <think>), prefilled (output starts mid-thought, for Qwen3.5/3.6), or off - reasoning_content on the non-streaming message and on stream deltas - 8 splitter tests covering both modes, token-by-token streaming, and split markers Verified on Qwen3.6-35B-A3B with --reasoning prefilled: clean content, separated reasoning, streaming and tool calls intact.
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.
What
Thinking models (Qwen3.x) emit their chain-of-thought inline. Until now that text landed in the response
content, so opencode and other clients showed the reasoning as part of the answer. This separates it into an OpenAI-stylereasoning_contentfield.ReasoningSplitter— a streaming-safe classifier that splits model output into reasoning vs answer on<think>/</think>markers, holding back partial markers that straddle a chunk boundary.--reasoningflag —auto(default; splits on a literal<think>),prefilled(output begins mid-thought because the chat template prefilled<think>— for Qwen3.5 / Qwen3.6), oroff.reasoning_contentadded to the non-streaming message and to streaming deltas.ReasoningSplittertests: both modes, token-by-token streaming, markers split across chunks, incomplete trailing markers.Why
contentshould be the model's actual answer. Mixing reasoning into it is noisy for chat UIs and confuses agentic clients.Verified
On
Qwen3.6-35B-A3B-8bitwith--reasoning prefilled:contentis the clean answer ("42"),reasoning_contentholds the thinking; streaming emits incrementalreasoning_contentthencontentdeltas; tool calls unaffected. 28 tests pass.Note
When reasoning precedes the answer,
contentkeeps the leading whitespace that followed</think>(e.g."\n\n42"). Trimming that is a small follow-up.