File tree Expand file tree Collapse file tree
integrations/amazon_bedrock
src/haystack_integrations/components/generators/amazon_bedrock/chat Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -585,13 +585,15 @@ def _convert_event_to_streaming_chunk(
585585 reasoning_content = delta ["reasoningContent" ]
586586 if "redactedContent" in reasoning_content :
587587 reasoning_content ["redacted_content" ] = reasoning_content .pop ("redactedContent" )
588+ reasoning_text = reasoning_content .get ("text" , "" )
588589 streaming_chunk = StreamingChunk (
589590 content = "" ,
590591 index = block_idx ,
591- meta = {
592- ** base_meta ,
593- "reasoning_contents" : [{"index" : block_idx , "reasoning_content" : reasoning_content }],
594- },
592+ reasoning = ReasoningContent (
593+ reasoning_text = reasoning_text ,
594+ extra = {"reasoning_contents" : [{"index" : block_idx , "reasoning_content" : reasoning_content }]},
595+ ),
596+ meta = base_meta ,
595597 )
596598
597599 elif "messageStop" in event :
@@ -642,7 +644,10 @@ def _process_reasoning_contents(chunks: list[StreamingChunk]) -> ReasoningConten
642644 reasoning_signature = None
643645 redacted_content = None
644646 for chunk in chunks :
645- reasoning_contents = chunk .meta .get ("reasoning_contents" , [])
647+ if chunk .reasoning and chunk .reasoning .extra :
648+ reasoning_contents = chunk .reasoning .extra .get ("reasoning_contents" , [])
649+ else :
650+ reasoning_contents = []
646651
647652 for reasoning_content in reasoning_contents :
648653 content_block_index = reasoning_content ["index" ]
Original file line number Diff line number Diff line change @@ -1269,6 +1269,12 @@ def test_callback(chunk: StreamingChunk):
12691269 ]
12701270 assert replies == expected_messages
12711271
1272+ # Verify streaming chunks carry reasoning in the reasoning field, not in meta
1273+ reasoning_chunks = [c for c in streaming_chunks if c .reasoning is not None ]
1274+ assert len (reasoning_chunks ) > 0
1275+ for chunk in reasoning_chunks :
1276+ assert "reasoning_contents" not in chunk .meta
1277+
12721278 def test_process_streaming_response_with_one_tool_call_with_redacted_thinking (self , mock_boto3_session ):
12731279 model = "arn:aws:bedrock:us-east-1::inference-profile/us.anthropic.claude-sonnet-3-7-20250219-v1:0"
12741280 type_ = (
You can’t perform that action at this time.
0 commit comments