Encouraging parallel tool calls with a batch tool
By default, Claude can call several tools in a single assistant turn (parallel tool use is on unless you set disable_parallel_tool_use), and current models usually do so on their own when a request clearly needs more than one tool. A model may still choose to call tools one at a time on some prompts, which costs an extra round trip per call. One way to make batching explicit is a "batch tool": a meta-tool whose only job is to wrap several invocations of your other tools, which your code then unpacks and executes together.
This notebook first shows the plain multi-tool case and a loop that answers every tool_use block in a turn, then adds the batch tool so you can compare. Treat the batch tool as an optional pattern: if the model already returns all the calls you need in one turn (as it does in the recorded run below), you don't need it.
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.
Tool: get_weather({'location': 'San Francisco, CA'})
Tool: get_time({'location': 'San Francisco, CA'})In the recorded run Claude asked for both tools in the same turn, which is the common case on current models. On other prompts or models you may get a single call here and the second one only after you return the first result, costing an extra round trip.
Either way, the right client pattern is the same: answer every tool_use block in the turn with a matching tool_result, all in one user message, then continue.
In San Francisco, CA it's 12:32 PM. The weather is sunny and 72°F.
With both results returned together, Claude answers in a single follow-up. If your run produced the calls one at a time instead, you paid for an extra request/response cycle: that sequential "back and forth" is what the batch tool below is designed to discourage.
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.
Tool: get_weather({'location': 'San Francisco, CA'})
Tool: get_time({'location': 'San Francisco, CA'})With the batch tool available, Claude can either wrap the calls in a single batch_tool invocation or, as in the recorded run, simply call get_weather and get_time in parallel directly. Both give you every call in one turn. The helper below handles either shape, unpacking batch_tool invocations when they appear.
In San Francisco, CA, it's 12:32 PM, and the weather is sunny and 72°F.
