Multi-agent orchestration patterns

RoadmapsAI Engineering

Scenario

Agent A (the supervisor) decides a document is useless and hands the job over to Agent B (the researcher). Agent B immediately re-downloads and reads the exact same useless document.

Why did Agent B repeat the work? Didn't it know what Agent A just did?

Mental model

Multi-agent is not a chatroom; it's a corporate org chart.

Agents don't just 'talk' to each other like humans on Slack. They hand over strict, structured data files. The supervisor looks at the inbox, decides who should do the work, and hands them the file. The worker only knows what is explicitly written in that file.

Deep dive

If you have a complex task, one AI model with 50 tools will get confused. Instead, we use **multi-agent orchestration**. The most common structure is the **Supervisor Pattern**: a central router that delegates work to specialized workers (like a Coder Agent and a Researcher Agent).

Supervisors route tasks to specialized sub-agents instead of using one massive model.

A multi-agent system is heavily structured. It is *not* just two LLMs chatting in plain text. They use programmatic handoffs, sharing a strict state object (like the Pydantic models we learned about).

Agents communicate through structured state objects, not freeform text chats.

Here is the golden rule of handoffs: **Context does not transfer automatically.** When the supervisor hands off to a sub-agent, the sub-agent only sees what is explicitly written in the shared state. If the supervisor thought 'this document is bad' but didn't write it in the state, the sub-agent has no idea.

A sub-agent only knows what is explicitly passed to it in the state schema.

Prediction: If a developer pipes the raw text output of Agent A directly into the user prompt of Agent B, Agent B loses all the structured tool schemas and historical state. This breaks the multi-agent graph entirely.

Never pass raw strings between agents; always pass structured state.

Code examples

The Supervisor Pattern

def supervisor_node(state: AgentState):
    # The supervisor decides who goes next
    next_worker = call_llm_router(state.messages)
    
    if next_worker == "need_research":
        return {"next_node": "researcher_agent"}
    elif next_worker == "need_code":
        return {"next_node": "coder_agent"}
    else:
        return {"next_node": "END"}

This is a deterministic routing node. The AI makes the decision, but the code explicitly enforces the handoff by returning the name of the next node in the graph.

Common mistakes

Glossary

supervisor node
A central agent or script that looks at the overall goal and routes the work to a specific sub-agent.
handoff
The exact moment control and data (state) are passed from one agent to another.

Recall questions

Questions & answers

Design a system where an AI writes code and another AI reviews it. How do you ensure the reviewer knows which specific lines the coder changed?

Implement a shared state schema (e.g., using Pydantic) that explicitly includes a `diff_lines` field. When the coder finishes, it writes the diff to this field before handing off to the reviewer.

Approach: Demonstrate that context only survives a handoff if it is explicitly modeled in the state schema.

What is the primary operational difference between an autonomous agent and a router in a multi-agent system?

A router acts deterministically, simply choosing which path or sub-agent to invoke next based on a single condition, whereas an autonomous agent uses a recursive ReAct loop to continually select tools until it determines the task is complete.

Approach: Distinguish between deterministic branching and probabilistic recursive loops.

Continue learning

Previous: State machines for agents

Next: When multi-agent underperforms

Return to AI Engineering Roadmap