The tool calling flow is a loop: your application executes the function and makes a second request to the model with the tool output, and the model then gives a final response or makes more tool calls. The result must be tied to the call that produced it, by its call id, or the model cannot tell which result belongs to which call. Keep the id with the result.
Prerequisites
- An agent loop that receives tool calls.
- The call id from each tool call.
- Code that appends the tool result to the message list.
Steps
Step 1: Keep the call id
When the model returns a tool call, save its id alongside the function name and arguments. The id is the link between the call and its result.
Step 2: Send the result
After running the function, append a message with the result and the same call id to the conversation, then send the whole conversation back to the model. Include the original request and the tool call itself, so the model sees the full history.
Step 3: Let the model continue
Read the model’s next response: it may give the final answer, or it may make another tool call. Either way, the loop continues with the same history, so the model never loses the earlier results.
Worked example: Maple Corner bakery stock check
The fictional Maple Corner bakery’s agent checks flour stock: the model calls check_stock, the code runs it, and the result goes back to the model.
| Step | Message added | Call id kept |
|---|---|---|
| Model calls check_stock | Tool call: flour, 25 kg bags | call_001 |
| Code runs the check | Result: 12 bags in stock | call_001 |
| Model answers | Final answer: 12 bags, enough for the week | Done |
The stock result, 12 bags, is sent back with the call id call_001, and the model’s final answer uses that number.
Expected result. Every tool result reaches the model with its call id, and the final answer uses the results. UNTESTED: this guide was not run against a live model or API. The worked example below is fictional practice material, and its result is the expected result, not a measured one.
Limits
- For reasoning models, any reasoning items returned with tool calls must also be passed back with the tool outputs.
- A result sent without its call id can be misread when several tools were called.
- This guide does not cover parallel tool calls, where several results return at once.
