@@ -81,8 +81,18 @@ def try_run(self, prompt_stack: PromptStack) -> Message:
8181 usage = response ["usage" ]
8282 output_message = response ["output" ]["message" ]
8383
84+ message_content = output_message .get ("content" , [])
85+
86+ # Move reasoning content to the beginning of the content to have it appear first in output
87+ reasoning_content_index = next (
88+ (i for i , content in enumerate (message_content ) if "reasoningContent" in content ),
89+ None ,
90+ )
91+ if reasoning_content_index is not None :
92+ message_content .insert (0 , message_content .pop (reasoning_content_index ))
93+
8494 return Message (
85- content = [self .__to_prompt_stack_message_content (content ) for content in output_message [ "content" ] ],
95+ content = [self .__to_prompt_stack_message_content (content ) for content in message_content ],
8696 role = Message .ASSISTANT_ROLE ,
8797 usage = Message .Usage (input_tokens = usage ["inputTokens" ], output_tokens = usage ["outputTokens" ]),
8898 )
@@ -222,6 +232,8 @@ def __to_prompt_stack_message_content(self, content: dict) -> BaseMessageContent
222232 ),
223233 ),
224234 )
235+ if "reasoningContent" in content :
236+ return TextMessageContent (TextArtifact (content ["reasoningContent" ]["reasoningText" ]["text" ]))
225237 raise ValueError (f"Unsupported message content type: { content } " )
226238
227239 def __to_prompt_stack_delta_message_content (self , event : dict ) -> BaseDeltaMessageContent :
0 commit comments