Multiple Tool Execution
Independent educational resource, not an official Anthropic course. Facts about the API, prices and limits were checked against Anthropic's documentation on 15 November 2026 and the code was run against a local mock of the API, not the live service. Check the linked official pages before relying on a number, and test with your own key.
Ask a shop assistant "compare the weather in Paris and London" and Claude may answer with two tool calls in one go. Ask it where an order is and when it will arrive, and it may call one tool, read the result, then call a second. Both patterns are common, and both have rules. Getting them wrong doesn't usually crash anything. It just quietly makes your assistant slower or less capable. This lesson covers what to expect and how to run the calls well.
What you'll learn
- The difference between parallel calls (one turn) and chained calls (several turns).
- How to return results for several calls correctly.
- When to run calls concurrently and when to run them one at a time.
- How to handle a failure in the middle of a batch.
Before you start
Parallel and chained
Parallel: in one response, Claude returns several tool_use blocks because the calls are independent. Weather in two cities, three file reads, an order lookup and a stock check. By default, Claude 4 and later models make parallel calls when a request benefits from them.
Chained: the second call depends on the first call's result, so it can only happen on the next turn. Look up the order, then track the parcel using the tracking number from the order. Your loop from lesson 4.2 already handles chains, because it keeps going while stop_reason is tool_use. This lesson is mostly about the parallel case.
The result rules for parallel calls
Anthropic's documentation is clear on this:
- Return one
tool_result for each tool_use, matched by tool_use_id.
- Put all of them in a single user message, before any text.
- If you decide not to run a call (for instance an earlier call failed and the later one depended on it), still return a
tool_result for it with is_error: true and a short reason such as "Not executed: the preceding write_file call failed."
The first two matter for another reason too. The docs warn that putting each result in its own user message is the most common mistake, and that it "teaches" Claude to stop making parallel calls. The model learns from the history it sees. A conversation where results come back one at a time looks like a conversation where one call at a time is the norm.
Wrong: assistant [tool_use_1, tool_use_2]
user [tool_result_1]
user [tool_result_2] <- separate messages
Right: assistant [tool_use_1, tool_use_2]
user [tool_result_1, tool_result_2]
Concurrent or sequential?
The API doesn't prescribe an order for running calls. It's your decision, and the right choice depends on what the tools do:
- Independent, read-only calls (lookups, searches, status checks) are safe to run at the same time. Three calls of 400 ms each take about 400 ms, not 1.2 seconds.
- Calls with side effects, shared state or ordering requirements (writes, deletes, anything that changes something the next call reads) should run one at a time, in the order Claude listed them, and usually stop at the first failure.
That suggests a rule you can encode instead of deciding each time: tag each tool with a risk level when you register it (read, write or destructive, as the executor from lesson 4.4 allows), and let a batch runner apply the rule.
A batch runner
This function runs read-only calls together, runs everything else in order, skips later writes after a failure, and always returns one result per call, in the original order:
from concurrent.futures import ThreadPoolExecutor
from typing import Any
from executor import ToolRegistry
def make_execute_many(registry: ToolRegistry, ctx: Any = None, max_workers: int = 4):
"""Run one assistant turn's tool calls the way the tools deserve.
* Read-only calls are independent, so they run at the same time.
* Anything that writes or deletes runs one after another, in the order Claude listed them,
and stops at the first failure.
* Every call still gets a result, in the original order. A call we chose not to run is reported as an error.
"""
def execute_many(calls: list[tuple[str, dict]]) -> list[tuple[str, bool]]:
results: list[tuple[str, bool] | None] = [None] * len(calls)
reads, others = [], []
for index, (name, _) in enumerate(calls):
tool = registry.tools.get(name)
(reads if tool is not None and tool.risk == "read" else others).append(index)
if reads:
with ThreadPoolExecutor(max_workers=max_workers) as pool:
futures = {i: pool.submit(registry.execute, calls[i][0], calls[i][1], ctx) for i in reads}
for i, future in futures.items():
results[i] = future.result()
failed: str | None = None
for i in others:
name, tool_input = calls[i]
if failed:
results[i] = (f"Not executed: the preceding {failed} call failed.", True)
continue
results[i] = registry.execute(name, tool_input, ctx)
if results[i][1]:
failed = name
return results # type: ignore[return-value]
return execute_many
Plug it into the loop from lesson 4.2 through the optional execute_many argument, and the loop takes care of putting all the results into a single message.
These cases were tested. Two reads of 0.4 seconds each plus a third finished in under 0.9 seconds in total, with results in the original order (that's concurrency working). One failing read didn't lose the other results. Two writes after a failing write were never run, and the skipped one came back as "Not executed: the preceding write_fail call failed." A mixed batch with an unknown tool name gave a normal result for the known calls and an error for the unknown one.
One caution about threads: tool functions that run concurrently must be safe to call from several threads at once. Database connections, caches and counters need care. (We made the call budget from lesson 4.8 thread-safe for this reason.) In PHP, true parallelism inside a single web request is harder; either run the calls one after another, which is often fast enough, or use something like Http::pool() for several HTTP calls at once.
Encouraging or preventing parallel calls
- To encourage: Anthropic suggests a line in the system prompt such as "For maximum efficiency, whenever you need to perform multiple independent operations, invoke all relevant tools simultaneously rather than sequentially." In a user message, "check the weather in Paris and London simultaneously" works too.
- To prevent: set
disable_parallel_tool_use: true inside the tool_choice object, not at the top level. With tool_choice: {"type": "auto", "disable_parallel_tool_use": true}, Claude makes at most one tool call per response. Do this if your tools aren't safe to run alongside one another and you'd rather have simple behaviour than speed.
Chained calls and the iteration cap
Chains are where loops run long. A plan of "find the order, then the parcel, then the delivery estimate" is three iterations. Choose a cap that fits your longest sensible chain and no more, and write tools that return what the next step needs (the order lookup returns the tracking number, so Claude doesn't have to guess it).
Real-world use case (illustrative scenario)
This scenario is an invented example to show how the ideas fit together. It is not a case study and its details are not measured results.
A customer writes: "What's the status of A100 and A101, and what's in my cart?" Claude issues three read-only calls at once. The batch runner executes them concurrently, so the turn takes as long as the slowest lookup instead of the sum. If the customer instead says "cancel A101 and refund it", those are two write-level calls and the runner executes them one at a time, so the refund can't run if the cancellation failed. The first case is fast because of concurrency, and the second is safe because of ordering.
Mistakes to avoid
- Returning results in separate user messages.
- Running writes in parallel because it's faster.
- Skipping a call without returning a
tool_result for it.
- Assuming results come back in the order the calls finished. Always map by
tool_use_id and keep the original order.
- Sharing a non-thread-safe resource between concurrently running tools.
Security notes
Parallel calls multiply whatever mistake a model can make. Per-conversation call budgets (lesson 4.8) and an iteration cap matter more when several calls can fire at once, and approval for risky actions has to happen before anything runs, not after the batch has gone out.
Cost and speed
Parallel calls reduce the number of model round trips: three independent lookups cost one extra request, not three. The tool results still add to input tokens on the next request, so keep each one small. Concurrency reduces waiting time but not tokens.
Key takeaways
- Parallel calls come in one response; chained calls span several turns.
- Return every result in one user message, matched by id, and answer skipped calls with an error result.
- Run read-only calls concurrently and side-effecting calls one at a time, stopping at the first failure.
- Use
disable_parallel_tool_use inside tool_choice when simplicity matters more than speed.
Lesson recap: parallel versus chained, concurrent versus sequential, and one reply for all results.
Quick quiz
- How many user messages should carry the results of three parallel tool calls?
- What do you do with a call you decided not to run?
- Which calls are safe to run concurrently?
- Where does
disable_parallel_tool_use go in the request?
- Why match results by
tool_use_id instead of by completion order?
Answers and explanations
- One. All three
tool_result blocks go in a single user message.
- Still return a
tool_result for it, with is_error: true and a short explanation.
- Independent, read-only calls that don't share mutable state.
- Inside the
tool_choice object, for example {"type": "auto", "disable_parallel_tool_use": true}.
- Calls finish in any order. The id is what pairs each answer with its question.
Official references and further reading
Related tutorials