@@ -799,6 +799,38 @@ def convert_to_responses_payload(payload: dict) -> dict:
799799 system_content = '\n ' .join (p .get ('text' , '' ) for p in content if p .get ('type' ) == 'text' )
800800 continue
801801
802+ # Handle assistant messages with tool_calls (from convert_output_to_messages)
803+ if role == 'assistant' and msg .get ('tool_calls' ):
804+ # Add text content as message if present
805+ if content :
806+ text = content if isinstance (content , str ) else '\n ' .join (
807+ p .get ('text' , '' ) for p in content if p .get ('type' ) == 'text'
808+ )
809+ if text .strip ():
810+ input_items .append ({
811+ 'type' : 'message' , 'role' : 'assistant' ,
812+ 'content' : [{'type' : 'output_text' , 'text' : text }],
813+ })
814+ # Convert each tool_call to a function_call input item
815+ for tool_call in msg ['tool_calls' ]:
816+ func = tool_call .get ('function' , {})
817+ input_items .append ({
818+ 'type' : 'function_call' ,
819+ 'call_id' : tool_call .get ('id' , '' ),
820+ 'name' : func .get ('name' , '' ),
821+ 'arguments' : func .get ('arguments' , '{}' ),
822+ })
823+ continue
824+
825+ # Handle tool result messages
826+ if role == 'tool' :
827+ input_items .append ({
828+ 'type' : 'function_call_output' ,
829+ 'call_id' : msg .get ('tool_call_id' , '' ),
830+ 'output' : msg .get ('content' , '' ),
831+ })
832+ continue
833+
802834 # Convert content format
803835 text_type = 'output_text' if role == 'assistant' else 'input_text'
804836
0 commit comments