fix(gemini): fix reasoning_content showing duplicate content in streaming responses #17266
+83
−19
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.
Title
fix(gemini): use thought:true instead of thoughtSignature to detect thinking blocks
Relevant issues
Fixes the issue reported in #16854 (comment)
Pre-Submission checklist
tests/litellm/directorymake test-unitType
🐛 Bug Fix
Changes
The previous implementation of
_extract_thinking_blocks_from_partsincorrectly used"thoughtSignature" in partas the criterion to detect thinking blocks.Per Google's docs:
thought: trueindicates that a part contains reasoning/thinking contentthoughtSignatureis just a token for multi-turn context preservation (docs)A part can have
thoughtSignaturewithoutthought: true(e.g., function calls), which causedfunctionCalldata to leak intoreasoning_contentwhen using Gemini 2.5 Pro with streaming + tools.Before:
content: "Hello! How can I help you today?"
reasoning_content: { text: "Hello! How can I help you today?" } // duplicated!
After:
content: "Hello! How can I help you today?"
reasoning_content: None // correct - only shows reasoning when thought: true
Changes:
_extract_thinking_blocks_from_parts checkspart.get("thought") is True`json.dumps(part)