feat(provider): add preserveReasoningInContent config option to fix Qwen preserve_thinking interoperability#25357
Open
jgrcic wants to merge 2 commits intoanomalyco:devfrom
Open
feat(provider): add preserveReasoningInContent config option to fix Qwen preserve_thinking interoperability#25357jgrcic wants to merge 2 commits intoanomalyco:devfrom
jgrcic wants to merge 2 commits intoanomalyco:devfrom
Conversation
…thinking compatibility
…ve isQwen auto-detection
Contributor
|
Thanks for updating your PR! It now meets our contributing guidelines. 👍 |
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.
Issue for this PR
Closes # (No existing issue)
Type of change
What does this PR do?
This adds a
preserveReasoningInContentconfig flag to solve an interoperability issue with thepreserve_thinkingfeature on Qwen models (specifically tested withQwen3.6-35B-A3B-FP8running on vLLM).Currently, OpenCode automatically extracts historical reasoning into a separate
reasoning_contentproperty. However, for Qwen to successfully access its previous reasoning turns in vLLM, the historical reasoning must be embedded directly within the assistant'scontentstring, wrapped in explicit<thinking>...</thinking>tags. When OpenCode strips these out, the model loses its chain of thought in subsequent prompts.To fix this:
preserveReasoningInContentto theModelschema insrc/config/provider.ts.src/provider/transform.tsso that when this flag is enabled, it correctly transforms the reasoning history into<thinking>tags within the content body and unsetsreasoning_content.How did you verify your code works?
I tested this locally against my own vLLM instance running
Qwen3.6-35B-A3B-FP8.I prompted the model to mentally generate two random numbers, but only output one. In the next turn, I asked it for the second number.
Without this flag, the model fails to recall the second number because the reasoning is stripped. With the flag enabled in my
opencode.json, I verified viamitmproxythat the payload correctly contains the<thinking>tags, and the model successfully recalled the second number.Screenshots / recordings
No UI changes.
Checklist