Advanced Concepts

Multi-agent orchestration

Router, supervisor–worker, and handoff patterns — when multiple agents beat one mega-prompt.

55 min

Why split agents

One agent with 40 tools and a novel-length system prompt thrashes: wrong tool choice, bloated context, and failures that are hard to isolate. Multi-agent orchestration splits work the way companies staff teams — specialists, clear interfaces, shared state, and a supervisor or router.

This is not “more LLMs = more magic.” It is decomposition + isolation when a single ReAct loop cannot carry the product.

flowchart TD
  User[User] --> Router[Router / supervisor]
  Router --> A[Researcher]
  Router --> B[Coder]
  Router --> C[Reviewer]
  A --> State[(Shared state)]
  B --> State
  C --> State
  State --> User

Prerequisites: agents and ReAct, context engineering, Model Context Protocol.

When multi-agent beats one mega-prompt

Prefer one agent when… Prefer multi-agent when…
Few tools, short workflows Tool sets conflict or are huge
One clear success metric Distinct skills (research vs code vs review)
Latency must stay minimal Parallel subtasks help wall-clock
Debuggability > structure You need failure isolation per role

Ship rule: start single-agent. Split when context budgets or tool confusion show up in traces — not on day one architecture cosplay.

Core patterns

Pattern Structure Use
Router Intent → one specialist Support triage, mode select
Supervisor–worker Boss plans; workers execute Parallel research + synthesize
Pipeline Fixed stages + validators ETL-like doc → draft → QA
Handoff Agent A transfers thread to B Escalation, human-in-the-loop
Swarm / debate Peers critique High-variance ideation (careful)
sequenceDiagram
  participant U as User
  participant R as Router
  participant W1 as Worker A
  participant W2 as Worker B
  participant S as State store
  U->>R: Task
  R->>W1: Subtask + budget
  R->>W2: Subtask + budget
  W1->>S: Write artifacts
  W2->>S: Write artifacts
  R->>S: Read + synthesize
  R-->>U: Final response

Shared state (the real architecture)

Agents should not pass megabytes through prompts. Use an explicit store:

  • Thread state — messages, status, owners
  • Artifacts — docs, diffs, retrieved ids in object storage / DB
  • Locks / versions — avoid two workers clobbering the same file

Poisoned or stale shared state is a top outage class — guided Agentic workflows & multi-agent.

Control plane requirements

Every serious orchestration needs:

  1. Timeouts per agent and per tool
  2. Step / $ budgets for the whole graph
  3. Idempotent writes to shared state
  4. Typed handoff contracts (schema for what A must produce for B)
  5. Trace IDs across agents (OpenTelemetry for LLMs)
  6. Human escalation paths
flowchart LR
  Graph[Agent graph] --> Budgets[Token / step / $ caps]
  Graph --> Authz[Tool allowlists]
  Graph --> Traces[Distributed traces]
  Graph --> Eval[Trajectory evals]

Tools today (2025–2026)

Tooling Role
LangGraph / LangChain Explicit graphs, checkpointing (LangGraph)
MCP Shared tool protocol across agents
Queues / Kafka Long-running or fan-out jobs (Kafka for evented AI)
Temporal / workflows Durable multi-step business processes
Custom gateway Router + policy in your API layer

Framework optional; contracts + state + budgets are not.

Failure modes

Failure Symptom Mitigation
Infinite handoffs Ping-pong agents Max hops + supervisor stop
Context duplication Each agent restuffs RAG Shared retrieval cache
Unclear ownership Two writers, corrupt doc Single-writer roles
Latency pile-up Serial “review” chains Parallelize; skip optional stages
Eval blindness Only final answer scored Score per-node trajectories

Micro-project shape

Implement:

  1. Router classifying {research, code}
  2. Two workers with disjoint tools
  3. Shared state object (goal, notes[], pr_url?)
  4. Hard cap: ≤ 8 model calls

Compare quality and cost to a single agent with the union of tools.

Checklist

  1. Written why multi-agent (measured pain)?
  2. Typed outputs between nodes?
  3. Budgets, timeouts, traces?
  4. Single place for authz on tools?
  5. Trajectory evals, not only final BLEU/vibe?

Guided Agentic workflows & multi-agent agentic workflows; Key Tech LangGraph; MCP for tools; guardrails on every node that can act.

Project checklist0/3 done