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

Have you seen this in your site?

Connect AgentMinds to match against your tech stack automatically.

Run diagnostics