← chapter

Multi-agent orchestration

Chapter 21 · when one agent hits its ceiling

The hour

Why more than one?

"Write it, critique it, rewrite it, fact-check, stay friendly" — the instructions fight each other.

A writer that only writes + a critic that only critiques beats one agent doing both.

Orchestration is just Python

def collaborate(task):
    draft    = agent(WRITER, task)
    critique = agent(CRITIC, f"DRAFT:\n{draft}")
    final    = agent(WRITER, f"Fix these:\n{critique}")
    return final

Passing outputs between agents is a function call.

Three patterns

Each is control flow over one-job prompts.

Router = an if over a classification

route = agent(ROUTER, message).strip()   # "billing"
answer = agent(SPECIALISTS[route], message)

Scale across domains without one bloated prompt.

The costs and the new failure mode

Pay when quality is worth it. Evaluate the OUTPUT, not your faith in the architecture (week 15).

Put it to work — three apps

Takeaway

Split roles, compose with plain control flow. Pipeline, router, debate. Frameworks add convenience, not magic. Next: the capstone — the whole course in one app.