Claude API Multi-Tool Orchestration Example
Multi-tool orchestration means giving Claude access to more than one tool in a single conversation and letting it decide which tools to call, in what order, and how to combine their results before answering. This is different from single-tool setups where you bind one function to one specific task. The pattern shows up constantly in real applications: a support bot that needs to look up an order, check inventory, and then draft a refund; a research assistant that searches the web, queries a database, and runs a calculation; a DevOps assistant that reads logs, checks a status API, and files a ticket.
Below is a concrete, runnable example showing how to define multiple tools, handle the back-and-forth tool-use loop, and deal with the two orchestration patterns you'll actually hit: sequential tool calls (output of one feeds into the next) and parallel tool calls (Claude requests several tools at once because it has already decided it needs all of them).
The scenario
Assume an internal assistant for an e-commerce team with three tools:
get_order_status— looks up an order by IDcheck_inventory— checks stock for a SKUissue_refund— processes a refund for an order
A single user message like "Order #4521 arrived damaged, refund it if the item is still unavailable to replace" requires Claude to call the first tool, use its output to decide whether to call the second, and then conditionally call the third. That's orchestration — not just tool use.
Defining multiple tools
[
{
"name": "get_order_status",
"description": "Fetch order details and current status by order ID.",
"input_schema": {
"type": "object",
"properties": {
"order_id": { "type": "string" }
},
"required": ["order_id"]
}
},
{
"name": "check_inventory",
"description": "Check stock level for a SKU.",
"input_schema": {
"type": "object",
"properties": {
"sku": { "type": "string" }
},
"required": ["sku"]
}
},
{
"name": "issue_refund",
"description": "Issue a refund for an order.",
"input_schema": {
"type": "object",
"properties": {
"order_id": { "type": "string" },
"amount": { "type": "number" }
},
"required": ["order_id", "amount"]
}
}
]
Each tool is self-contained. Claude decides the sequence based on the descriptions and the conversation — you don't hardcode "call tool A then tool B" anywhere.
The orchestration loop
The core pattern for any multi-tool setup is the same loop, repeated until Claude stops requesting tools:
- Send the message history + tool definitions.
- If the response contains
tool_useblocks, execute each one against your real backend. - Append the
tool_useand matchingtool_resultblocks to the message history. - Send the updated history back to Claude.
- Repeat until the response has no more
tool_useblocks — that's your final answer.
async function runOrchestration(messages, tools, callTool) {
while (true) {
const res = await fetch("https://api.subtoapi.app/v1/messages", {
method: "POST",
headers: {
"Authorization": `Bearer ${process.env.SUBTOAPI_KEY}`,
"Content-Type": "application/json"
},
body: JSON.stringify({
model: "claude-sonnet-4",
max_tokens: 1024,
messages,
tools
})
});
const data = await res.json();
const toolUses = data.content.filter(b => b.type === "tool_use");
if (toolUses.length === 0) {
return data.content; // final answer
}
messages.push({ role: "assistant", content: data.content });
// Execute tool calls — in parallel if there are multiple
const results = await Promise.all(
toolUses.map(async (tu) => ({
type: "tool_result",
tool_use_id: tu.id,
content: JSON.stringify(await callTool(tu.name, tu.input))
}))
);
messages.push({ role: "user", content: results });
}
}
This loop handles both orchestration patterns without special-casing them:
- Sequential: Claude returns one
tool_useblock, you resolve it, send the result, Claude decides the next step based on that result (e.g., checks inventory only after seeing the order is "damaged"). - Parallel: Claude returns multiple
tool_useblocks in the same response when it already has enough context to know it needs several independent lookups (e.g., checking inventory for three different SKUs at once).Promise.alllets you resolve them concurrently instead of round-tripping one at a time.
Routing tool calls to real functions
In production, callTool is a dispatcher to your actual backend logic:
async function callTool(name, input) {
switch (name) {
case "get_order_status":
return await db.orders.findById(input.order_id);
case "check_inventory":
return await inventory.getStock(input.sku);
case "issue_refund":
return await payments.refund(input.order_id, input.amount);
default:
return { error: `Unknown tool: ${name}` };
}
}
Always return a well-formed result even on failure — a JSON error object, not a thrown exception — so Claude can see what went wrong and adjust its next step instead of the whole request failing.
Practical issues in multi-tool orchestration
- Order isn't guaranteed. Claude might call
check_inventorybeforeget_order_statusif the description makes that seem reasonable. Write tool descriptions that make dependencies explicit if order matters ("requires an order ID from get_order_status"). - Loop limits matter. Cap iterations (e.g., 6–8 loop turns) to avoid runaway orchestration on ambiguous prompts.
- Side-effecting tools need guardrails. For something like
issue_refund, consider requiring explicit confirmation in the prompt or a human-approval step before execution, since a model misjudgment has real consequences. - Token cost adds up. Every loop turn resends the growing message history. Long multi-tool chains can get expensive fast — trim or summarize older turns once a task resolves.
If you're building this against a direct Anthropic subscription, you're often limited by seat-based access rather than a clean API key. SubToAPI turns that access into a standard HTTPS endpoint with sub_live_... API keys, so the orchestration loop above works unchanged whether you're prototyping solo or running it across a team. See the tool use docs and messages reference for request/response details, or start with the quickstart.
FAQs
Can Claude call multiple tools in one response? Yes. If Claude determines it needs several independent pieces of information at once, it returns multiple tool_use blocks in a single response, which you can execute concurrently.
How do I force a specific tool execution order? You can't force it directly, but you can make dependencies explicit in tool descriptions and system prompts, or split the task into sequential API calls where you only expose the next tool after the prior result is known.
What happens if a tool call fails during orchestration? Return a structured error as the tool_result content instead of throwing — Claude will see the error and can retry, choose a different tool, or explain the failure to the user.