gemini_streaming_reasoning_separationTier 1 · 70% confidence
ai-agents-gemini-streaming-rea-when-using-gemini-2-5-models-with-reasoning-effort-f7809222
agent: ai_agents
When does this happen?
IF When using Gemini 2.5 models with reasoning_effort in stream mode, reasoning/thought chunks are mixed with the main content, producing incorrect final output.
How others solved it
THEN Modify LiteLLM's chunk_parser (in vertex_and_google_ai_studio_gemini.py) to detect thought chunks (e.g., via a flag from Gemini's includeThoughts) and place their text into a separate reasoning_content field in the delta, rather than appending to content. Reference PR #11075 for a partial fix that removes thinking from content; a better approach is to put it in a dedicated field, similar to how Claude uses delta.thinking_blocks or OpenAI uses reasoning_content.
In ModelResponseIterator.chunk_parser, check if a chunk part is a thought (e.g., by inspecting part's structure) and set delta['reasoning_content'] instead of delta['content']. Example: if part.get('thought'): delta['reasoning_content'] = part['text']; else: delta['content'] = part['text']. Ensure other parts like content continue to work.Related patterns
github
ai-agents-github-support-for-reasoning-in-openrouter-and-deepseek-p-48add6f0
Tier 1 · 40%
githubai-agents-github-server-capabilities-not-affecting-the-stream-of-ca-ca806d9e
Tier 1 · 40%
githubai-agents-github-patrick-von-platen-cd4d7ceb
Tier 1 · 40%
model_loadingai-agents-model-loading-loading-a-gemma-3-checkpoint-with-automodelforcaus-cc5b7a71
Tier 1 · 70%
githubai-agents-github-runtimeerror-cuda-error-cublas-status-not-initiali-9b601119
Tier 1 · 40%
githubai-agents-github-bug-frequent-ide-disconnections-disrupting-workflo-e9f35aca
Tier 1 · 40%
Have you seen this in your site?
Connect AgentMinds to match against your tech stack automatically.