In this video, you followed a passenger’s question about Saturday’s sailings through the tool-calling loop. The model asked for two lookups in one reply, your code ran both and sent the results back by their IDs, and the model’s next reply was the answer.
Key Points
- The history carries everything. The model keeps nothing between calls, so your code keeps the conversation as a history and sends all of it, with the instructions and the tools, on every request.
- One reply can hold several tool calls. The passenger asked about Gull Island or Heron Island, and in this run, the reply held two calls to
findSailings, each with its own ID, the tool’s name, and its arguments. Whether the calls come together varies from run to run, so your run may ask for one per round. - Every call needs a result. Answer only the first of two calls, and the next request fails.
- The reply joins the history first. Your code adds it as an assistant entry that holds the tool calls, so the model sees its own requests on the next call.
- Run each call, and answer it by its ID. For now, each call’s arguments go into your own function unchecked, and checking them comes later in the course. Its result joins the history as a tool entry whose
callIdis the call’s ID, so the model can match the result to its request. ItsisErrorflag isfalsewhen the function worked. - Call again with the whole history. The second request carried 393 input tokens, about twice the first request’s 193, because the calls and their results are part of the input now.
- A finished reply without calls is the answer. A reply that was cut off or refused has no calls either, so your model module will check for those first, as
askForJson()does. Otherwise, your code adds the answer to the history, and the loop stops. Your own run will word the answer differently. - Cap the rounds. A model can keep asking for calls, and every round costs tokens, so the loop stops after a fixed number of rounds, such as five, answer or not. This run needed two. Another run can need more.
The model only asks. Your code runs every call, answers each one by its ID, and calls again until a finished reply has no calls or the cap is reached.
Behind the Scenes: The Raw History
The video’s history used a shape of your own: { role: "assistant", toolCalls } for the model’s requests and { role: "tool", callId, result, isError } for each result. Each provider expects its own shape for the same conversation, and in the next lesson, your model module translates between them. Open the version for your provider to see the history that the second request sent:
This is the input array of the video’s second request, from the real run against OpenAI’s Responses API. The two calls are function_call items, each with a call_id, and each result is a function_call_output item with the same call_id and the function’s result as a string (here, the rows as JSON).
The long strings are cut to ... here. Each call’s arguments also held "date": "2026-12-05", and each result held the full rows, with every sailing’s seatsLeft, vehicleSpacesLeft, and status:
[
{
"role": "user",
"content": "Is there room for my car on Saturday morning's sailing ..."
},
{
"arguments": "{\"from\": \"Linden Harbor\", \"to\": \"Gull Island\", ...}",
"call_id": "call_e67c99dc664f4b93bc21d5cf18ba5c7e",
"id": "fc_05bb74b7b91e6eb0006b0f9bfdad1087d2ba65ba873317cb2f",
"name": "findSailings",
"status": "completed",
"type": "function_call"
},
{
"arguments": "{\"from\": \"Linden Harbor\", \"to\": \"Heron Island\", ...}",
"call_id": "call_146abc2b8fdb47aea4bbee17b59ec21b",
"id": "fc_05bb74b7b91e6eb0006b0f9bfe6fb487d2bbc64b6b9cfc9091",
"name": "findSailings",
"status": "completed",
"type": "function_call"
},
{
"type": "function_call_output",
"call_id": "call_e67c99dc664f4b93bc21d5cf18ba5c7e",
"output": "[{\"id\":\"LF101\",\"departs\":\"08:00\",...},{\"id\":\"LF102\",...}]"
},
{
"type": "function_call_output",
"call_id": "call_146abc2b8fdb47aea4bbee17b59ec21b",
"output": "[{\"id\":\"LF201\",\"departs\":\"09:15\",...}]"
}
]
The calls and the results are separate items in one flat array, matched only by call_id. In another run, a request that answered only the first of the two calls came back with a 400 error: No tool output found for function call call_....
OpenAI has no error flag. A failed call still gets its function_call_output, with the error message in output. It has no tool stop reason either. A reply is asking for tools when its output holds function_call items.
The runs for this video went to OpenAI only, because there was no Anthropic key for them. This is the shape that Anthropic’s documentation on handling tool calls describes, with the same sailings in it. The IDs are placeholders, since Anthropic generates its own, starting with toolu_. The long strings are cut to ..., as in the OpenAI version:
[
{
"role": "user",
"content": "Is there room for my car on Saturday morning's sailing ..."
},
{
"role": "assistant",
"content": [
{
"type": "tool_use",
"id": "toolu_FIRST",
"name": "findSailings",
"input": { "from": "Linden Harbor", "to": "Gull Island", "date": "2026-12-05" }
},
{
"type": "tool_use",
"id": "toolu_SECOND",
"name": "findSailings",
"input": { "from": "Linden Harbor", "to": "Heron Island", "date": "2026-12-05" }
}
]
},
{
"role": "user",
"content": [
{
"type": "tool_result",
"tool_use_id": "toolu_FIRST",
"content": "[{\"id\":\"LF101\",\"departs\":\"08:00\",...},{\"id\":\"LF102\",...}]"
},
{
"type": "tool_result",
"tool_use_id": "toolu_SECOND",
"content": "[{\"id\":\"LF201\",\"departs\":\"09:15\",...}]"
}
]
}
]
The model’s reply is an assistant message whose content holds one tool_use block per call, sometimes after a short text block, and its stop_reason is "tool_use". Your code answers in the next user message, with one tool_result block per call, all of them together and before any text, each with the tool_use_id of the call it answers.
A failed call still gets its tool_result, with is_error: true. According to the same documentation, a request where a tool_use has no matching tool_result in the next user message is rejected with a 400 error.
With either provider, every call in a reply gets exactly one result, matched by its ID, and the next request carries the whole conversation so far.