fix: strip <think> tokens from reasoning model output#617
Open
benjamin7007 wants to merge 1 commit into
Open
Conversation
Models with thinking/reasoning capabilities (DeepSeek-R1, MiniMax-M2.7, QwQ, etc.) include <think>...</think> blocks in their response content. These internal reasoning tokens leak into agent output and downstream node inputs, corrupting the workflow. Add _strip_thinking_tokens() classmethod to OpenAIProvider that filters <think>...</think> blocks via regex. Applied in both: - _deserialize_chat_response() (Message content) - _append_chat_response_output() (timeline content) The fix is zero-cost for models without thinking tokens (fast path checks for '<think>' substring before regex). Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.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
Models with thinking/reasoning capabilities (DeepSeek-R1, MiniMax-M2.7, QwQ, Qwen3, etc.) include
<think>...</think>blocks in their response content when used via OpenAI-compatible API endpoints. These internal reasoning tokens leak into:<think>tags in the outputRoot Cause
OpenAIProvider._deserialize_chat_response()and_append_chat_response_output()pass rawcontentfrom model responses without filtering reasoning tokens.Fix
Add
_strip_thinking_tokens()classmethod toOpenAIProvider:<think>.*?</think>\s*withre.DOTALLto strip thinking blocks<think>substring not found (zero-cost for non-thinking models)_deserialize_chat_responseand_append_chat_response_output)Testing
Verified with MiniMax-M2.7 (thinking model) in a Writer→Reviewer workflow:
<think>blocks leaked into Reviewer input and final outputNotes
MessageBlock) and would need separate handling if Gemini models add thinking tokens