Skip to content

Commit 7e362be

Browse files
committed
Pass tool results back to the model
1 parent f2099c4 commit 7e362be

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

llm/responses.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff 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(

0 commit comments

Comments
 (0)