fix: strip orphaned think/reasoning tags from user-facing responses#4286
Closed
arasovic wants to merge 1 commit into
Closed
fix: strip orphaned think/reasoning tags from user-facing responses#4286arasovic wants to merge 1 commit into
arasovic wants to merge 1 commit into
Conversation
Some models (e.g. Kimi K2.5 on Alibaba OpenAI-compatible endpoint) emit reasoning text followed by a closing </think> without a matching opening <think> tag. The existing paired-tag regexes in _strip_think_blocks() cannot match these orphaned tags, so </think> leaks into user-facing responses on all platforms. Add a catch-all regex that strips any remaining opening or closing think/thinking/reasoning/REASONING_SCRATCHPAD tags after the existing paired-block removal pass. Closes NousResearch#4285
Contributor
|
Merged via PR #4311. Your commit was cherry-picked onto current main with authorship preserved. Thanks for the fix! |
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
Some models (e.g. Kimi K2.5 on Alibaba's OpenAI-compatible endpoint) emit reasoning as plain text followed by a closing
</think>tag without a matching opening<think>._strip_think_blocks()uses paired-tag regexes (<think>.*?</think>) that require both tags — orphaned</think>passes through unmatched and appears in user-facing responses.Closes #4285
Changes
run_agent.py— Add one catch-all regex to_strip_think_blocks():tests/test_run_agent.py— 4 new tests:some reasoning</think>actual answer→</think>strippedreasoning</thinking>answer→</thinking>stripped<think>orphaned without close→<think>strippedstray</think><think>paired</think> visible→ all tags stripped, visible keptTest plan
python -m pytest tests/test_run_agent.py::TestStripThinkBlocks -q— 8 passed, 0 failed