Parallel tool calls on Claude 3.7 Sonnet
Claude 3.7 Sonnet may be less likely to make make parallel tool calls in a response, even when you have not set disable_parallel_tool_use. To work around this, we recommend introducing a "batch tool" that can act as a meta-tool to wrap invocations to other tools simultaneously. We find that if this tool is present, the model will use it to simultaneously call multiple tools in parallel for you.
Let's take a look at the problem, and examine this workaround in more detail.
Performing a query with multiple tool calls
Recall that the default behavior is for Claude to be allowed parallel tool calls. Combined with the default tool_choice of auto, this means that Claude can call any of the specified tools, or call more than one of them in a single assistant turn.
Let's set Claude up with a get_weather and get_time tool.
Next, let's provide Claude with these tools and perform a query.
I'll check the current weather and time in San Francisco for you.
Tool: get_weather({'location': 'San Francisco, CA'})Notice how claude returned with a single tool call for the weather, even though we asked for both?
Let's see what happens if we call the weather tool and proceed.
Tool: get_time({'location': 'San Francisco, CA'})Notice now that Claude made a second tool call to get the time. While this technically happened immediately, this is potentially wasteful because it required "back and forth" – first Claude asked for the weather, then we had to process it, and then Claude asked for the time, and now we have to process that.
Claude will still do the right thing with the results, but it may be beneficial to encourage Claude to use both in one call, so we can process it simultaneously.
Introducing a batch tool
Let's introduce a batch_tool, so that Claude can have an opportunity to use it to combine multiple tool calls into one.
Now let's try to provide Claude with the existing weather and time tool, along with this new batch tool, and see what happens when we make a query requiring the weather and time.
I can help you check both the weather and the time in San Francisco. Let me get that information for you right away.
Tool: batch_tool({'invocations': [{'name': 'get_weather', 'arguments': '{"location": "San Francisco, CA"}'}, {'name': 'get_time', 'arguments': '{"location": "San Francisco, CA"}'}]})Notice how this time, Claude used the batch tool to query both the time and weather in one go. This allows us to process them simultaneously, potentially improving overall latency to the result.
Here's the information you requested: Weather in San Francisco, CA: 72 degrees and sunny Time in San Francisco, CA: 12:32 PM Is there anything else you'd like to know about San Francisco?
