After this lesson, you will be able to: Reason about agent orchestration, supervisor patterns, and the honest question of when a single agent beats a team.
Multi-agent systems are oversold and under-engineered. This lesson covers the orchestration patterns that actually work, when teams beat single agents, and how to debug a system of agents arguing with each other.
Supervisor: one 'lead' agent decides which specialist to call next. Specialists return; lead routes again. LangGraph's `Supervisor` pattern is the canonical implementation. Pipeline: agents form a deterministic chain (researcher → writer → editor). Each output is the next input. Simple, debuggable, often enough. Swarm / handoff: any agent can hand off to any other agent via shared state. OpenAI's Agents SDK uses this. More flexible, much harder to reason about.
Two specialists, one supervisor that routes between them based on the task state.
from langgraph.graph import StateGraph, ENDfrom typing import TypedDict, Literalclass AgentState(TypedDict):messages: listnext: Literal["researcher", "writer", "FINISH"]def supervisor(state: AgentState):# An LLM decides which specialist to call next, or FINISH.# In real code this calls Claude with a structured-output prompt.last = state["messages"][-1].contentif "research" in last.lower():return {"next": "researcher"}if "draft" in last.lower():return {"next": "writer"}return {"next": "FINISH"}def researcher(state: AgentState):# Specialist with its own system prompt, tools, and Claude call.return {"messages": state["messages"] + [...]}def writer(state: AgentState):return {"messages": state["messages"] + [...]}graph = StateGraph(AgentState)graph.add_node("supervisor", supervisor)graph.add_node("researcher", researcher)graph.add_node("writer", writer)graph.set_entry_point("supervisor")graph.add_conditional_edges("supervisor", lambda s: s["next"],{"researcher": "researcher", "writer": "writer", "FINISH": END},)graph.add_edge("researcher", "supervisor")graph.add_edge("writer", "supervisor")app = graph.compile()
Trace every handoff. LangSmith, LangFuse, or your own structured logs let you see who called whom and why. Watch for infinite handoffs ('researcher calls writer calls researcher calls writer...'). Cap the total turns at the graph level. Watch for cost explosion: each agent call is a full LLM round-trip. A 5-agent system with 10 handoffs is 50 model calls. Watch for state mutation conflicts: if two agents write to the same state field, the last one wins silently. Use immutable state where possible.
A single Sonnet call costs $0.01-$0.05. A 5-handoff supervisor system costs $0.05-$0.25 and takes 5-15s. Production multi-agent systems use cheap fast models (Haiku, gpt-4o-mini) for routing and supervision; reserve expensive frontier models for specialist work. Always benchmark cost-per-task vs the single-agent baseline; 'multi-agent' is rarely worth 5x the price unless quality measurably improves.
Building multi-agent because it sounds impressive. Most demos are one-agent-in-disguise. Skipping a turn cap. Without one, you'll burn through your API budget the first time an agent loops. Treating each agent as a black box. Trace every prompt and every output; a system of black boxes is impossible to debug. Mixing frameworks (CrewAI + LangGraph + custom). Pick one orchestration layer per project. Skipping evals. A multi-agent system needs evals at the team output level, not per-agent.
Pick the strongest justification.
Sign in and purchase access to unlock this lesson.