Parallel Tool Calling
In the Intermediate course, we learned how Claude can pause a conversation, ask your Node.js server to run a tool, and wait for the result.
But what if a user asks: "What is the weather in London, Paris, and Tokyo?"
If Claude has to ask for London, wait for the result, then ask for Paris, wait for the result, and then ask for Tokyo, the user will be waiting 15 seconds for an answer.
To solve this, Anthropic introduced Parallel Tool Calling.
How it Works
When you provide tools to Claude, it is smart enough to realize when it can run multiple tools simultaneously.
If the user asks for the weather in three cities, Claude will return an array containing three tool_use blocks in a single API response!
// The API Response from Claude
[
{
"type": "tool_use",
"id": "toolu_01A",
"name": "get_weather",
"input": { "city": "London" }
},
{
"type": "tool_use",
"id": "toolu_02B",
"name": "get_weather",
"input": { "city": "Paris" }
},
{
"type": "tool_use",
"id": "toolu_03C",
"name": "get_weather",
"input": { "city": "Tokyo" }
}
]
Executing in Parallel
When your Node.js server intercepts this response, you shouldn't process them one by one. You should use Promise.all() to fire off all three external API requests at the exact same time.
// 1. Map over the tool_use blocks to create an array of Promises
const promises = response.content.map(async (block) => {
if (block.type === 'tool_use' && block.name === 'get_weather') {
// Call your local function
const data = await myWeatherFunction(block.input.city);
// Format the result exactly how Claude expects it
return {
type: 'tool_result',
tool_use_id: block.id,
content: JSON.stringify(data)
};
}
});
// 2. Execute all of them simultaneously!
const toolResults = await Promise.all(promises);
Sending the Results Back
Just like in the standard tool loop, you must append Claude's tool_use requests to the chatHistory, and then append your tool_result array.
chatHistory.push({
role: 'user',
content: toolResults // This array now contains all 3 results!
});
When you send this updated history back to Claude, it reads all three results instantly and generates the final answer: "It is raining in London, sunny in Paris, and cloudy in Tokyo."
Parallel tool calling drastically reduces latency in Agentic applications, making them feel snappy and responsive to the end user.