File tree Expand file tree Collapse file tree 1 file changed +31
-0
lines changed
Expand file tree Collapse file tree 1 file changed +31
-0
lines changed Original file line number Diff line number Diff line change @@ -450,6 +450,37 @@ def _build_request_body(
450450 "content" : [{"type" : "output_text" , "text" : response_text }],
451451 }
452452 )
453+ # Add tool calls from assistant's response
454+ tool_calls = resp .tool_calls ()
455+ if tool_calls :
456+ for tool_call in tool_calls :
457+ input_items .append (
458+ {
459+ "type" : "function_call" ,
460+ "call_id" : tool_call .tool_call_id ,
461+ "name" : tool_call .name ,
462+ "arguments" : json .dumps (tool_call .arguments ),
463+ }
464+ )
465+ # Add tool results for this response's tool calls
466+ for tool_result in prev_response .prompt .tool_results :
467+ input_items .append (
468+ {
469+ "type" : "function_call_output" ,
470+ "call_id" : tool_result .tool_call_id ,
471+ "output" : tool_result .output ,
472+ }
473+ )
474+
475+ # Add tool results from current prompt (for chain continuation)
476+ for tool_result in prompt .tool_results :
477+ input_items .append (
478+ {
479+ "type" : "function_call_output" ,
480+ "call_id" : tool_result .tool_call_id ,
481+ "output" : tool_result .output ,
482+ }
483+ )
453484
454485 if prompt .prompt :
455486 input_items .append (
You can’t perform that action at this time.
0 commit comments