█
LastWrite
  • > Curriculum
  • > Pricing
  • > For Educators
  • > About
  • > Contact
Log InGet Started

Questions, concerns, bug reports, or suggestions? We read every message, write to us at [email protected].

More ways to reach us →
LastWrite

Structured computer science lessons for aspiring developers and security professionals.

[email protected]

(201) 785-7951

Mon–Fri, 9 AM–5 PM EST

Learn

  • Curriculum
  • Pricing

Company

  • About
  • For Educators & Schools
  • Contact Us

Legal

  • Terms of Service
  • Privacy Policy
© 2026 LastWrite. All rights reserved.
Curriculum/AI Agents/Code-First Agents/Multi-Agent Systems: Orchestration, Supervisor Patterns, and When Not To
60 minAdvanced

Multi-Agent Systems: Orchestration, Supervisor Patterns, and When Not To

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.

Prerequisites:CrewAI: Multi-Agent Teams with Roles and Tasks

Three orchestration patterns that work in production

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.

💡 When a single agent is the right answer (most of the time)

If a task can be done by one model + tool calling, a single agent will be more reliable, cheaper, and easier to debug than a team. Most 'multi-agent' systems in production are actually one agent calling specialised tools. Try a single agent first; reach for a team only when one of the following is true: the task has a natural parallel decomposition, specialised system prompts genuinely beat one generalist, or human-readable handoffs (researcher → reviewer) match the workflow.

Supervisor pattern in LangGraph (the canonical example)

Two specialists, one supervisor that routes between them based on the task state.

python
from langgraph.graph import StateGraph, END
from typing import TypedDict, Literal
class AgentState(TypedDict):
messages: list
next: 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].content
if "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()

Debugging a multi-agent system

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.

Cost and latency are the multi-agent killers

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.

Common mistakes only experienced agent engineers avoid

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.

Quick Check

When should you reach for multi-agent over single-agent?

Pick the strongest justification.

Sign in and purchase access to unlock this lesson.

Sign in to purchase
←Model Context Protocol (MCP): Connect Agents to External Tools
Back to Code-First Agents
Code-First Agent Capstone: Build and Deploy a Production Agent→