@@ -555,7 +555,7 @@ def _convert_google_chunk_to_streaming_chunk(
555555 content = ""
556556 tool_calls : list [ToolCallDelta ] = []
557557 finish_reason = None
558- reasoning_deltas : list [dict [ str , str ] ] = []
558+ reasoning_deltas : list [str ] = []
559559 thought_signature_deltas : list [dict [str , Any ]] = [] # Track thought signatures in streaming
560560
561561 if chunk .candidates :
@@ -606,39 +606,39 @@ def _convert_google_chunk_to_streaming_chunk(
606606
607607 # Handle thought parts for Gemini 2.5 series
608608 elif hasattr (part , "thought" ) and part .thought :
609- thought_delta = {
610- "type" : "reasoning" ,
611- "content" : part .text if part .text else "" ,
612- }
613- reasoning_deltas .append (thought_delta )
609+ reasoning_deltas .append (part .text if part .text else "" )
610+
611+ # Combine reasoning deltas into a single ReasoningContent
612+ reasoning = ReasoningContent (reasoning_text = "" .join (reasoning_deltas )) if reasoning_deltas else None
614613
615614 # start is only used by print_streaming_chunk. We try to make a reasonable assumption here but it should not be
616615 # a problem if we change it in the future.
617616 start = index == 0 or len (tool_calls ) > 0
618617
619- # Create meta with reasoning deltas and thought signatures if available
618+ # Create meta with thought signatures if available
620619 meta : dict [str , Any ] = {
621620 "received_at" : datetime .now (timezone .utc ).isoformat (),
622621 "model" : model ,
623622 "usage" : usage ,
624623 }
625624
626- # Add reasoning deltas to meta if available
627- if reasoning_deltas :
628- meta ["reasoning_deltas" ] = reasoning_deltas
629-
630625 # Add thought signature deltas to meta if available (for multi-turn context)
631626 if thought_signature_deltas :
632627 meta ["thought_signature_deltas" ] = thought_signature_deltas
633628
629+ # StreamingChunk allows only one of content/tool_calls/reasoning to be set.
630+ # Determine the effective content: tool_calls and reasoning take priority.
631+ effective_content = "" if tool_calls or reasoning else content
632+
634633 return StreamingChunk (
635- content = "" if tool_calls else content , # prioritize tool calls over content when both are present
634+ content = effective_content ,
636635 tool_calls = tool_calls ,
637636 component_info = component_info ,
638637 index = index ,
639638 start = start ,
640639 finish_reason = FINISH_REASON_MAPPING .get (finish_reason or "" ),
641640 meta = meta ,
641+ reasoning = reasoning ,
642642 )
643643
644644
@@ -662,13 +662,9 @@ def _aggregate_streaming_chunks_with_reasoning(chunks: list[StreamingChunk]) ->
662662 thoughts_token_count = None
663663
664664 for chunk in chunks :
665- # Extract reasoning deltas
666- if chunk .meta and "reasoning_deltas" in chunk .meta :
667- reasoning_deltas = chunk .meta ["reasoning_deltas" ]
668- if isinstance (reasoning_deltas , list ):
669- for delta in reasoning_deltas :
670- if delta .get ("type" ) == "reasoning" :
671- reasoning_text_parts .append (delta .get ("content" , "" ))
665+ # Extract reasoning from the StreamingChunk.reasoning field
666+ if chunk .reasoning and chunk .reasoning .reasoning_text :
667+ reasoning_text_parts .append (chunk .reasoning .reasoning_text )
672668
673669 # Extract thought signature deltas (for multi-turn context preservation)
674670 if chunk .meta and "thought_signature_deltas" in chunk .meta :
0 commit comments