Give the model a tool, let it decide to call that tool, run the tool yourself, and feed the result back so the model can produce a final answer. This is the full round trip that turns a text generator into something that can act.
A model on its own can only produce text. Tool use is what lets it affect the world: it emits a structured request to call a function, your code runs the function, and you return the result for the model to use. The loop is always the same shape, and getting it right once is the foundation for every agent and tool-using app.
get_weather) with a JSON Schema for its arguments.tool message.The model calls the tool, you supply the data, and the model turns it into a natural answer.
The loop has four moves: offer the tool, receive a structured call, execute it locally, and return the result tagged with its tool_call_id so the model knows which call it answers. The model never runs your code; it only asks, and your code decides what actually happens. That separation is what makes tool use safe to reason about, and extending it to many tools or several rounds is how you build an agent.
A model can request several tools in a single turn. A question like "what is the weather and the time in Paris?" should produce two tool calls at once, and your code must run all of them and return one result per call before asking for the final answer. Handling the list, not just the first call, is what makes tool use work for compound requests.
get_weather, get_time).message.tool_calls, run each, and append one tool result per call (matched by tool_call_id).The model requests both tools at once; you run both and it combines the results into one answer.
The key difference from a single call is the loop over message.tool_calls: the model decides how many tools to invoke, and each result must be appended with its own tool_call_id so the model can match answers to requests. Returning one tool message per call, then asking again, lets the model fuse the separate results into a single response. Skipping any call or mismatching an id breaks the turn, which is why compound tool use is about handling the full list correctly.