Skip to main content

How to Handle Several Tool Calls in One Claude Reply

· 7 min read
Jagdish Kumawat
Founder @ Dewiride

Ask Claude something that needs two lookups, and it doesn't have to ask for them one at a time: one reply can hold several tool calls. Your code then runs them all and sends every result back together. This guide asks about two days' opening hours at once, with real output from anthropic 2.14.0.

Syntax​

Syntax
calls = [block for block in response.content if block.type == "tool_use"]
results = [
{"type": "tool_result", "tool_use_id": call.id, "content": <result of the call>}
for call in calls
]
messages.append({"role": "assistant", "content": response.content})
messages.append({"role": "user", "content": results})
PartWhat it means
callsEvery tool_use block in Claude's reply, in order
resultsOne tool_result per call, each with its call's id
{"role": "user", "content": results}One user message that carries all the results

Anthropic's parallel tool use page: "By default, Claude may call multiple tools in a single response." And: "Whichever strategy you use, return one tool_result for each tool_use block, all together in the next user message."

What It Costs​

The Claude API is paid: Claude Opus 5.5 costs $4 per million input tokens and $20 per million output tokens. Two calls in one reply need one round trip instead of two. The run below made two requests, 1,035 input and 175 output tokens in all, about $0.008.

Prerequisites​

  • A Claude API key, in a .env file as ANTHROPIC_API_KEY=....
  • The Anthropic Python SDK in a uv project. This guide uses anthropic 2.14.0, added with uv add anthropic, on Python 3.15.2.

Step 1: Write the Tool​

Create parallel_tools.py with the café's opening hours and the function that looks one day up:

parallel_tools.py
import anthropic

client = anthropic.Anthropic()

OPENING_HOURS = {
"Monday": "closed",
"Tuesday": "7:30 to 18:00",
"Wednesday": "7:30 to 18:00",
"Thursday": "7:30 to 18:00",
"Friday": "7:30 to 18:00",
"Saturday": "8:00 to 16:00",
"Sunday": "9:00 to 14:00",
}


def get_opening_hours(day: str) -> str:
return OPENING_HOURS.get(day.capitalize(), "no opening hours for that day")

The tool takes one day. A question about two days needs two calls.

Step 2: Ask About Two Days​

Add the tool's definition and a question that covers two days:

parallel_tools.py
tools = [
{
"name": "get_opening_hours",
"description": (
"Get the café's opening hours for one day of the week. "
"Use it whenever someone asks when the café is open."
),
"input_schema": {
"type": "object",
"properties": {
"day": {"type": "string", "description": "A day of the week, such as Monday."},
},
"required": ["day"],
},
}
]
messages = [{"role": "user", "content": "When is the café open on Saturday and Sunday?"}]

Step 3: Run Every Call and Send the Results Together​

Add the loop. It collects all the calls in a reply, runs each one, and sends every result back in one message:

parallel_tools.py
response = client.messages.create(
model="claude-opus-5-5", max_tokens=1024, tools=tools, messages=messages
)
while response.stop_reason == "tool_use":
calls = [block for block in response.content if block.type == "tool_use"]
print(f"Claude asked for {len(calls)} tool calls in one reply")
messages.append({"role": "assistant", "content": response.content})
results = []
for call in calls:
hours = get_opening_hours(**call.input)
print(f" {call.name}({call.input}) returned {hours!r}")
results.append({"type": "tool_result", "tool_use_id": call.id, "content": hours})
messages.append({"role": "user", "content": results})
response = client.messages.create(
model="claude-opus-5-5", max_tokens=1024, tools=tools, messages=messages
)

print("Claude:", response.content[-1].text)
  • calls keeps only the tool_use blocks of the reply, however many there are.
  • for call in calls runs them one after another. The API doesn't set an order: you could also run them at the same time.
  • Every result goes into the one results list, and that list becomes one user message.

The complete script:

parallel_tools.py
import anthropic

client = anthropic.Anthropic()

OPENING_HOURS = {
"Monday": "closed",
"Tuesday": "7:30 to 18:00",
"Wednesday": "7:30 to 18:00",
"Thursday": "7:30 to 18:00",
"Friday": "7:30 to 18:00",
"Saturday": "8:00 to 16:00",
"Sunday": "9:00 to 14:00",
}


def get_opening_hours(day: str) -> str:
return OPENING_HOURS.get(day.capitalize(), "no opening hours for that day")


tools = [
{
"name": "get_opening_hours",
"description": (
"Get the café's opening hours for one day of the week. "
"Use it whenever someone asks when the café is open."
),
"input_schema": {
"type": "object",
"properties": {
"day": {"type": "string", "description": "A day of the week, such as Monday."},
},
"required": ["day"],
},
}
]
messages = [{"role": "user", "content": "When is the café open on Saturday and Sunday?"}]

response = client.messages.create(
model="claude-opus-5-5", max_tokens=1024, tools=tools, messages=messages
)
while response.stop_reason == "tool_use":
calls = [block for block in response.content if block.type == "tool_use"]
print(f"Claude asked for {len(calls)} tool calls in one reply")
messages.append({"role": "assistant", "content": response.content})
results = []
for call in calls:
hours = get_opening_hours(**call.input)
print(f" {call.name}({call.input}) returned {hours!r}")
results.append({"type": "tool_result", "tool_use_id": call.id, "content": hours})
messages.append({"role": "user", "content": results})
response = client.messages.create(
model="claude-opus-5-5", max_tokens=1024, tools=tools, messages=messages
)

print("Claude:", response.content[-1].text)

The complete parallel_tools.py script in a macOS-style code window: the opening hours tool, the question about Saturday and Sunday, and a loop that collects every tool_use block of a reply, runs each one and sends all the tool_result blocks back in one user message.

Step 4: Run It​

Terminal
uv run --env-file .env parallel_tools.py
Output
Claude asked for 2 tool calls in one reply
get_opening_hours({'day': 'Saturday'}) returned '8:00 to 16:00'
get_opening_hours({'day': 'Sunday'}) returned '9:00 to 14:00'
Claude: The café's weekend hours are:

- **Saturday:** 8:00 to 16:00
- **Sunday:** 9:00 to 14:00

The output in a terminal: Claude asked for 2 tool calls in one reply, Saturday's and Sunday's opening hours, and answers with both days' hours.

Claude's first reply held two tool_use blocks, one per day. The loop ran both and sent both results back in one message, so Claude answered in the next reply: one round trip for two lookups.

Common Mistakes​

MistakeWhat happensDo this instead
Running only the first call, response.content[0]400: `tool_use` ids were found without `tool_result` blocks immediately after, naming the call that got no resultRun every tool_use block in the reply
One user message per resultThe API accepts it, but Anthropic's docs say it "teaches" Claude to avoid parallel callsSend all the results in one user message

Troubleshooting​

SymptomLikely causeFix
`tool_use` ids were found without `tool_result` blocks immediately afterA call in the reply got no resultAnswer every call, each with its own tool_use_id
Claude calls one tool per reply when it could call twoThe conversation sent earlier results in separate messagesSend each reply's results together, as this script does

FAQ​

Do I have to run the calls in order?​

No. Anthropic's documentation says the API "doesn't prescribe an execution order": you can run them one after another, as here, or at the same time. Each result is matched to its call by tool_use_id, not by position.

Can I make Claude call only one tool per reply?​

Yes. Anthropic's documentation describes disable_parallel_tool_use inside tool_choice: with {"type": "auto", "disable_parallel_tool_use": True}, Claude calls at most one tool in each response.

What if one of the calls fails?​

Send its result with "is_error": True, alongside the others, as How to Tell Claude a Tool Failed with is_error shows. Every call still needs a result.

Conclusion​

Asked about Saturday and Sunday, Claude put two get_opening_hours calls in one reply. Running both and sending both tool_result blocks in one user message got the answer in a single round trip.

Additional Resources​