Skip to main content
To build agent loops, chain tool calls inside one response (multi-step), and conversations that thread tools across many turns (multi-turn).

Multi-step function calling

Multi-step function calling chains sequential function calls within one conversation turn. The model calls a function, you process the result, and the result is fed back to inform the final response. Here’s an example of passing the result of a tool call from one completion into a second follow-up completion:
And here’s the final output from the second call:
JSON
In this run, the model generated three tool call descriptions, your code iterated over them to execute each one, and the results were passed back so the model could produce a final answer.

Multi-turn function calling

Multi-turn function calling maintains context across multiple conversation turns. Functions can be called at any point in the conversation, and previous function results inform future decisions.
In this example, the assistant:
  1. Turn 1: Calls weather functions for three cities and provides temperature information.
  2. Turn 2: Remembers the previous weather data, analyzes which city is best for outdoor activities (San Francisco with 65°F), and automatically calls the restaurant recommendation function for that city.
The model maintains context across turns and makes informed decisions based on previous interactions.