@@ -380,13 +380,13 @@ async def invoke_async(self, prompt: Union[str, list[ContentBlock]], **kwargs: A
380380
381381 return cast (AgentResult , event ["result" ])
382382
383- def structured_output (self , output_model : Type [T ], prompt : Optional [str ] = None ) -> T :
383+ def structured_output (self , output_model : Type [T ], prompt : Optional [Union [ str , list [ ContentBlock ]] ] = None ) -> T :
384384 """This method allows you to get structured output from the agent.
385385
386386 If you pass in a prompt, it will be added to the conversation history and the agent will respond to it.
387387 If you don't pass in a prompt, it will use only the conversation history to respond.
388388
389- For smaller models, you may want to use the optional prompt string to add additional instructions to explicitly
389+ For smaller models, you may want to use the optional prompt to add additional instructions to explicitly
390390 instruct the model to output the structured data.
391391
392392 Args:
@@ -405,13 +405,15 @@ def execute() -> T:
405405 future = executor .submit (execute )
406406 return future .result ()
407407
408- async def structured_output_async (self , output_model : Type [T ], prompt : Optional [str ] = None ) -> T :
408+ async def structured_output_async (
409+ self , output_model : Type [T ], prompt : Optional [Union [str , list [ContentBlock ]]] = None
410+ ) -> T :
409411 """This method allows you to get structured output from the agent.
410412
411413 If you pass in a prompt, it will be added to the conversation history and the agent will respond to it.
412414 If you don't pass in a prompt, it will use only the conversation history to respond.
413415
414- For smaller models, you may want to use the optional prompt string to add additional instructions to explicitly
416+ For smaller models, you may want to use the optional prompt to add additional instructions to explicitly
415417 instruct the model to output the structured data.
416418
417419 Args:
@@ -430,7 +432,8 @@ async def structured_output_async(self, output_model: Type[T], prompt: Optional[
430432
431433 # add the prompt as the last message
432434 if prompt :
433- self ._append_message ({"role" : "user" , "content" : [{"text" : prompt }]})
435+ content : list [ContentBlock ] = [{"text" : prompt }] if isinstance (prompt , str ) else prompt
436+ self ._append_message ({"role" : "user" , "content" : content })
434437
435438 events = self .model .structured_output (output_model , self .messages )
436439 async for event in events :
0 commit comments