@@ -173,7 +173,7 @@ def _format_tool_call_message(tool_call_message: ChatMessage) -> dict[str, Any]:
173173
174174 # tool call messages can contain reasoning content
175175 if reasoning_content := tool_call_message .reasoning :
176- content .extend (_format_reasoning_content (reasoning_content = reasoning_content ))
176+ content .append (_format_reasoning_content (reasoning_content = reasoning_content ))
177177
178178 # Tool call message can contain text
179179 if tool_call_message .text :
@@ -291,22 +291,23 @@ def _repair_tool_result_messages(bedrock_formatted_messages: list[dict[str, Any]
291291 return [msg for _ , msg in repaired_bedrock_formatted_messages ]
292292
293293
294- def _format_reasoning_content (reasoning_content : ReasoningContent ) -> list [ dict [str , Any ] ]:
294+ def _format_reasoning_content (reasoning_content : ReasoningContent ) -> dict [str , Any ]:
295295 """
296296 Format ReasoningContent to match Bedrock's expected structure.
297297
298298 :param reasoning_content: ReasoningContent object containing reasoning contents to format.
299- :returns: List of formatted reasoning content dictionaries for Bedrock.
299+ :returns: Dictionary representing the formatted reasoning content for Bedrock.
300+
300301 """
301- formatted_contents = []
302- for content in reasoning_content . extra . get ( "reasoning_contents" , []):
303- formatted_content = { "reasoningContent " : content [ "reasoning_content" ]}
304- if reasoning_text := formatted_content [ "reasoningContent" ]. pop ( " reasoning_text" , None ):
305- formatted_content [ "reasoningContent" ][ "reasoningText" ] = reasoning_text
306- if redacted_content := formatted_content [ "reasoningContent" ]. pop ( "redacted_content" , None ):
307- formatted_content [ "reasoningContent" ][ "redactedContent" ] = redacted_content
308- formatted_contents . append ( formatted_content )
309- return formatted_contents
302+ formatted_content = {
303+ "reasoningContent" : {
304+ "reasoningText " : {
305+ "text" : reasoning_content . reasoning_text ,
306+ ** ({ "signature" : reasoning_content . extra [ "signature" ]} if reasoning_content . extra . get ( "signature" ) else {}),
307+ }
308+ }
309+ }
310+ return formatted_content
310311
311312
312313def _format_user_message (message : ChatMessage ) -> dict [str , Any ]:
@@ -345,7 +346,7 @@ def _format_textual_assistant_message(message: ChatMessage) -> dict[str, Any]:
345346 bedrock_content_blocks : list [dict [str , Any ]] = []
346347 # Add reasoning content if available as the first content block
347348 if message .reasoning :
348- bedrock_content_blocks .extend (_format_reasoning_content (reasoning_content = message .reasoning ))
349+ bedrock_content_blocks .append (_format_reasoning_content (reasoning_content = message .reasoning ))
349350
350351 for part in content_parts :
351352 if isinstance (part , TextContent ):
0 commit comments