Claude API Multi-Agent Orchestration Framework Guide
What a multi-agent orchestration framework actually does
A multi-agent orchestration framework coordinates several Claude API calls — each playing a distinct role — into a single workflow that solves a task no single prompt handles well. Instead of one giant prompt doing research, writing, and fact-checking at once, you split it into specialized agents (a planner, a researcher, a writer, a critic) and route messages between them with explicit control logic.
If you're searching for this, you're probably past the "one prompt, one response" stage and hitting real problems: context windows filling up with irrelevant history, one bad step poisoning the whole output, or a task that genuinely needs different system prompts and tools at different stages. This guide covers the core architecture patterns, where state should live, how to handle tool calls across agents, and how to avoid the failure modes that make multi-agent systems slower and less reliable than a well-structured single call.
Core architecture patterns
There are three patterns that cover almost every real use case.
1. Orchestrator-worker (hub and spoke) One "orchestrator" agent decides what needs to happen next and dispatches work to specialized worker agents, then merges their outputs. This is the most predictable pattern because control flow lives in your code, not in model reasoning.
async function orchestrate(task) {
const plan = await callAgent("planner", task);
const results = await Promise.all(
plan.subtasks.map(st => callAgent("worker", st))
);
return callAgent("synthesizer", { task, results });
}
2. Sequential pipeline Agents run in a fixed order, each consuming the previous agent's output. Good for workflows like research → draft → edit → fact-check, where the stages are always the same and don't branch.
3. Debate/critic loop Two agents (a "generator" and a "critic") iterate on the same artifact until the critic approves it or a max-round limit is hit. Useful for code generation, legal/compliance text, or anything where self-review catches real errors.
Most production systems combine these: an orchestrator that runs a sequential pipeline for the happy path, with a critic loop inserted at the one step that's error-prone.
Designing agent roles and system prompts
Each agent should have a narrow, single-purpose system prompt. Resist the urge to make one agent "smart" and give it a 2,000-word system prompt covering every case — that's just a monolithic prompt with extra latency. A well-scoped agent looks like this:
You are a fact-checking agent. You receive a claim and a source document.
Respond only with JSON: {"verdict": "supported"|"unsupported"|"unclear", "evidence": "<quote>"}.
Do not add commentary outside the JSON.
Narrow roles give you two things: predictable output format (easier to parse programmatically) and smaller context per call, which keeps latency and cost down.
Routing and shared state
The hardest part of orchestration isn't calling the model multiple times — it's deciding what context each agent sees. Two mistakes to avoid:
- Passing full conversation history to every agent. This bloats context and leaks irrelevant details (the writer agent doesn't need the planner's internal reasoning). Pass only the structured output each agent needs.
- Storing state only in message history. Instead, maintain an explicit state object in your application (task status, intermediate results, retry counts) and construct each agent's prompt from that object, not from replaying the whole chat.
const state = {
task: "...",
research: null,
draft: null,
critique: null,
round: 0,
};
async function runPipeline(state) {
state.research = await callAgent("researcher", state.task);
state.draft = await callAgent("writer", state.research);
while (state.round < 3) {
state.critique = await callAgent("critic", state.draft);
if (state.critique.approved) break;
state.draft = await callAgent("writer", { state.draft, state.critique });
state.round++;
}
return state.draft;
}
This keeps your orchestration logic in plain code, which is debuggable and testable, instead of hidden inside model reasoning you can't unit test.
Tool use across agents
When agents need tools (search, calculators, internal APIs), decide per-agent which tools are exposed — don't give every agent every tool. A critic agent reviewing text has no business calling a database write tool. Scope tool access tightly, and log every tool call with the agent name attached so you can trace which agent triggered which side effect. See /docs/tools for the tool-calling request/response shape.
Handling failures without cascading errors
Multi-agent systems fail in a specific way: one agent's bad output becomes the next agent's bad input, and the error compounds. Guard against this with:
- Schema validation on every agent output — if the critic agent is supposed to return JSON with a boolean
approvedfield and it doesn't, retry that call before passing anything downstream. - Hard round limits on any loop (debate, critique, retry) so a disagreement between agents can't spin forever.
- Circuit breakers per agent — if a worker agent fails validation three times in a row, stop the pipeline and return a partial result rather than burning tokens on a doomed run.
Running this on SubToAPI
If you're building this on top of your Claude access through SubToAPI, each agent in your framework can just be a separate call to https://api.subtoapi.app/v1/messages with its own system prompt, model parameters, and tool list — no architectural changes needed since it's the standard Claude Messages API shape. This matters at scale because SubToAPI gives every application (or every agent type, if you want finer-grained tracking) its own sub_live_... key, so you can see usage broken down per agent in one dashboard instead of guessing which part of the pipeline is burning tokens. Streaming works per-call too, so a long-running writer agent can stream its draft to your UI while the orchestrator waits on the result — see /docs/streaming for the implementation. Start with /docs/quickstart to get your first key, and check /docs/messages for the full request reference. Plans start at €9/month with a free trial at /signup; see /pricing for team and scale tiers if you're running this across a product team.
questions
Do I need a dedicated orchestration library (LangGraph, CrewAI, etc.) to build this? No — the patterns above (orchestrator-worker, pipeline, critic loop) are straightforward to implement in plain code with explicit state objects. Libraries add value once you have many branching workflows to maintain, but a small number of agents is often clearer without a framework layer in between.
How many agents is too many? There's no fixed number, but each additional agent adds latency and failure surface. A good rule: if two agents could be merged into one prompt without hurting output quality or format reliability, merge them. Split only when roles genuinely need different system prompts, tools, or context.
How do I debug a multi-agent pipeline when the final output is wrong? Log every agent's input and output with an agent name and run ID attached, not just the final result. Most bugs trace back to one agent receiving the wrong slice of state — explicit logging at each hop makes that visible immediately instead of forcing you to re-run the whole pipeline to reproduce it.