Orchestration
Who runs next
Orchestration is the runtime that decides which agent runs next, with what context, and when it's done — via fixed graph, router, or adaptive planner. Orchestrators turn patterns into products.
What you will learn
- Distinguish graph, router, and adaptive control flow
- Pass context and results between stages
- Add approval and error nodes to graphs
What is this?
Orchestration defines control flow over agents: deterministic graphs (fixed stage order), routers (choose next stage by classify), or adaptive planners (model decides dynamically). Context passes as state between nodes; error handling and approval gates attach to specific edges. Choose determinism proportional to reliability needs.
Why do you need it?
- Control flow is where reliability is engineered — before model layers.
- Routers formalize 'pick the right specialist' behavior.
- Graphs give teams reviewable, testable pipelines.
- Noding errors, retries and approvals at edges = operational reality.
Mental model
Airport baggage routing
Orchestration
Baggage (task) goes from ticket (input) along a fixed route with scans (nodes), diverting at marks (router), rerouted on system hiccups (error edges), and finally gated at the gate (approval). Nobody improvises the plane-side; the conveyor is the choreographer.
How it works
- Define stages (nodes) and state contract between them.
- Choose edges: fixed, conditional (router), or model-decided.
- Attach retries, timeouts, approval gates per edge.
- Emit trace/state for each node.
- Evaluate end-to-end in evals; tweak edges by failure pattern.
Stages and edges.
In production
- Multi-destination support flows route by classification.
- Data pipelines chain extract→validate→patch→review stages.
- Deployment agents approve, then execute per-env.
Best practices
- Make state flow explicit and typed between nodes.
- Fail edges loudly: retry, degrade, or abort.
- Put approval nodes exactly where consequences live.
- Trace node → node for debugging and evals.
Common mistakes
- Implicit state that stages improvise.
- Router with fuzzy criteria (routes everywhere).
- No error edges — a node failure strands the task.
Common issues
Node inputs staleState contract violated
Enforce typed state; validate at node boundaries.
Orchestration brittle to changeEdges hard-coded everywhere
Define edges in one config/graph the team reads and evals cover.
Debugging tips
- Router misrouting → classify node needs fewer, sharper classes.
- Stuck stage → missing error edge or timeout.
- State divergence → version the state schema between nodes.
Interview checkpoint
Hands-on lab
- Register workers as callable functions
- Dispatch a task to the right worker
- Fail over to a backup worker on error
Orchestrator With Fallback Workers
25 min · intermediate
Quick quiz
A router node's job is to…
Approval gates belong exactly where consequences live.