Single-step vs Multi-step
Single-step vs Multi-step
This guide outlines the difference in model behavior for single-step and multi-step tool use. This is a mode that can be toggled in the Chat API by providing tools and setting the force_single_step parameter.
Single Step Tool Use
Single step tool use is enabled by setting force_single_step=True and providing a list of tools through the Chat API. This forces the model to make just one set of tool calls, after which it will provide a final answer. In single-step tool use, the model cannot make a sequence of tool calls and reason over them.
Note that “single step” doesn’t mean “single tool.” In single-step tool use the model can still call multiple tools by calling them in parallel. Whet this happens, the model will output multiple tool calls in the tool_results part of the response.
When Should I Use Single-step Tool Use?
You should operate in single-step mode when you want the model to answer a question after one step. With a query like “Is there a reservation available at Johnny’s Pizza or Alfredo’s Pizza at 9PM,” for example, the model would query the APIs for Johny’s Pizza and Alfredo’s Pizza, in parallel.
Code example
For the sake of this illustration, we’ll assume a developer is building a chatbot to assist with sales-related questions. The chatbot has access to two tools to answer user questions: a daily sales report tool which holds data on sales volumes, and a product catalog which contains information about each product being sold.
Here is a walkthrough of what a relevant single-step tool use workflow would look like.
Step 1
The developer provides the sales database and the products database to the model using the tools parameter.
Observe that, for each tool, the developer describes the tool name, description, and inputs. Each input can have a type and can be marked as required.
Step 2
The model’s response contains the list of appropriate tools to call in order to answer the user’s question, as well as the appropriate inputs for each tool call.
Step 3
Now, the developer will query the appropriate tools and receive a tool result in return.
Step 4
Call the chat endpoint again with the tool results to get the final model answer. Note that this is done through the tool_results parameter, with the other parameters operating as expected.
In this step, the model cites which tool results were used to generate the final model answer! These citations make it easy to check where the model’s generated response claims are coming from.
When Should I Use Multi-step Tool Use?
For more complex queries, such as those that require multiple steps, it’s probably better to operate in multi-step mode. You can do this by setting enable_multistep=True and providing a list of tools through the Chat API. In multi-step mode, the model can reason across steps and select multiple tools to answer a question completely.
To illustrate, imagine you give the Chat API a query like “What was the weather where I was yesterday,” along with a location tool (to return the user’s location given a timestamp) and a weather tool (to return the weather at a given location). Here’s what happens:
- First, the model will make a plan, which consists in first calling the location tool (step 1), and then calling the weather tool (step 2) based on the output of the location tool.
- Then, the model receives the results of these tool calls and the underlying model’s reasoning.
- In a subsequent call, the model will determine that it still doesn’t have all the information required to answer, and select another tool.
- Etc.
In the next section, there’s a code snippet demonstrating how to do this programmatically.
Multi-step Code Examples
Here, we’ll walk through a couple of different ways of using multi-step tool use in order to answer questions about the weather.
In the response below, the model selects a tool and returns a message containing its reasoning.
In this next request, we’ll send the model the tool result and the reasoning message through the chat_history parameter to get the next tool step. If you’re going to use this approach, make sure to include the reasoning message, as it helps the model select the right tool.
And here’s the response. As you can see, the model outputs another reasoning step and another tool call request. Again, make sure to include the model reasoning step in the next request via the chat_history.
In this final request, the tool results for get_weather are passed to the model along with the text containing the model’s reasoning text, so that the final text can be generated.
And in the final response, the model completes a sequence of tool calls and outputs the final message.
Best practices
Use single step when you want to force the model to answer the user query using a single tool. Otherwise, the model may take more steps than necessary to provide an answer.