Multi-Agent Collaboration in Practice: LangGraph Orchestration Patterns
A single Agent can confidently go off course on complex tasks. This article explains three multi-Agent orchestration patterns (supervisor, hierarchical, and handoff), implements a "supervisor + specialists" system with LangGraph's state graph, and covers the state, loop, and human-intervention engineering needed for production.
Key Points
- Topic Focus: AI、AI Agent
- Suitable for: indie hackers, full-stack engineers, AI application developers
- Core value: quickly understand background, practical paths, common pitfalls, and engineering advice
When a task becomes complex enough that "one Agent must analyze requirements, write code, and perform a review," a single Agent starts to struggle: tool output floods the context, prompts for different subtasks interfere with one another, and one wrong turn derails the entire workflow.
The solution is multi-Agent collaboration: split the larger task among a group of specialized Agents and coordinate them through an orchestration layer. This article uses LangGraph, currently the most widely adopted Agent orchestration framework, to explain how to build such a system.
1. Three Orchestration Patterns
There are essentially three ways to organize multiple Agents:
1. Supervisor (supervisor pattern): the most common approach. A "supervisor Agent" decomposes tasks, delegates work, and aggregates results, while several "specialist Agents" each complete one part. The supervisor decides who should act next, and each specialist reports back when finished.
┌──────────────────┐
┌─────────▶│ Supervisor Agent │◀─────────┐
│ └────────┬─────────┘ │
│ │ │
┌─────┴────────┐ ┌───────┴──────┐ ┌─────────┴─────┐
│ Specialist A │ │ Specialist B │ │ Specialist C │
│ (Retrieval) │ │ (Coding) │ │ (Testing) │
└──────────────┘ └──────────────┘ └───────────────┘
2. Hierarchical (hierarchical pattern): a recursive version of the supervisor pattern. The supervisor delegates subtasks to subordinate supervisors, decomposing the work layer by layer. It is suitable for especially large tasks, such as enterprise workflow automation.
3. Handoff (handoff pattern): there is no central supervisor, and Agents hand work directly to one another. When one Agent reaches the boundary of its responsibility, it transfers the conversation and state to the next Agent. OpenAI's Swarm and many customer-service systems use this pattern. It is lightweight, but you must guard against Agents endlessly passing responsibility around.
Beginners should default to Supervisor. It is controllable, observable, and easy to combine with human intervention, covering 80% of use cases.
2. LangGraph's Core Idea: Model the Workflow as a State Graph
LangGraph has a clean mental model: your entire multi-Agent system is a stateful directed graph.
- State: shared data that flows between all nodes, such as message history, the current subtask, and intermediate results.
- Node: each node is an Agent or function that receives state and returns state updates.
- Edge: a connection between nodes. It may be fixed or a "conditional edge" whose destination is determined by a node's output.
A supervisor system looks like this:
START → supervisor → ┬─→ researcher → supervisor
├─→ coder → supervisor
└─→ tester → supervisor
↓
(finish) END
The supervisor is the source of conditional edges. Each time it runs, it uses the current state to decide whether to call the researcher, coder, or tester next, or to finish.
3. In Practice: One Supervisor and Three Specialists
import { StateGraph, MessagesAnnotation, END, START } from "@langchain/langgraph";
// Define the graph with message history as shared state
const graph = new StateGraph(MessagesAnnotation)
// Supervisor: decide the next step
.addNode("supervisor", supervisorAgent)
// Three specialists
.addNode("researcher", researcherAgent)
.addNode("coder", coderAgent)
.addNode("tester", testerAgent)
// Supervisor → conditional routing
.addConditionalEdges("supervisor", routeFromSupervisor, {
researcher: "researcher",
coder: "coder",
tester: "tester",
done: END,
})
// Each specialist returns to the supervisor when finished
.addEdge("researcher", "supervisor")
.addEdge("coder", "supervisor")
.addEdge("tester", "supervisor")
.addEdge(START, "supervisor");
const app = graph.compile();
// Supervisor routing function: read state and choose the next specialist or finish
function routeFromSupervisor(state) {
if (state.next === "FINISH") return "done";
return state.next; // "researcher" | "coder" | "tester"
}
The supervisor Agent's prompt looks roughly like this:
You are the project supervisor. Based on the current task progress, decide who should handle the next step:
- researcher: research information or read documentation
- coder: write or modify code
- tester: write tests or perform verification
- FINISH: the task is complete
Output exactly one choice.
Run it with app.invoke({ messages: [{ role: "user", content: "Add a rate-limited health-check endpoint to an Express app and verify it" }] }), and you will see a supervisor → coder → tester → supervisor → FINISH trajectory.
4. Engineering Considerations
1. State needs a schema. Use TypedDict/Annotation to define the fields in the state explicitly. After a week, nobody can understand schemaless state, making debugging a disaster.
2. Bound the loops. Multi-Agent systems are especially prone to infinite loops, such as A delegating to B and B delegating back to A. Add a "maximum rounds" field to the supervisor's state and force END when the limit is exceeded. An unbounded multi-Agent system is a time bomb that burns money.
3. Human intervention (human-in-the-loop). LangGraph supports interrupts: pause at critical nodes, such as before the coder executes code, and wait for human confirmation before continuing. Any production system that performs real operations needs this gate.
4. Streaming + trace. Multi-Agent execution paths are long, so users need to see "which specialist is active now." Use streaming to send each node's start and finish events to the frontend, and use LangSmith or a custom trace system to record the graph's complete execution path. That trace is how you diagnose failures.
5. Do not share too much context between specialists. Each specialist should see only the minimum state needed for its work. Do not send the complete global message history to every Agent. Narrower context improves focus and uses fewer tokens.
5. When Not to Use Multiple Agents
Multi-Agent systems are not a silver bullet. Their coordination cost and latency are both higher than those of a single Agent. If one Agent with a good toolset and a clear prompt can handle the task, do not use multiple Agents.
The criterion is whether the task can be divided naturally into "relatively independent subtasks suited to different roles." It is worth splitting only when the answer is yes and each subtask has distinct tool or knowledge requirements. Forcing apart a task that does not divide cleanly will only produce a pile of Agents fighting one another.
Summary
Multi-Agent collaboration turns a complex task from "one all-purpose expert carrying everything" into "one supervisor coordinating a group of specialists," improving both scalability and control. LangGraph captures the model through a unified "state graph": nodes are Agents, edges are control flow, and state is shared memory.
Remember three production red lines: schema-defined state, bounded loops, and traced execution. Meet all three, and your multi-Agent system moves from a demo into production. Miss them, and even the most elaborate orchestration pattern is built on air.
Related
Related Content
Article
What Is Vibe Coding? Will It Change How Programmers Work?
Technical trends, engineering practices, and an indie developer perspective on Vibe Coding, AI, and independent development.
Article
From Copilot to Codex: AI Coding Tools Enter the Agent Era
Technical trends, engineering practices, and indie-developer perspectives around AI, AI Agents, and Vibe Coding.
Article
Why Does MCP Matter? Understanding the AI Tool Protocol
Technical trends, engineering practices, and an independent developer perspective on MCP and AI Agents.
Article
Core Architecture of AI Agents: Planning, Memory, Tools, and Execution
Technical trends, engineering practices, and independent developer perspectives around AI Agents and large language models.