Module 8 of 10
Module 8Coordination Patterns

Multi-Agent Patterns: Supervisor & Swarm

Scale beyond single agents: Master architectural coordination topologies including Centralized Supervisors, Hierarchical Subgraphs, and Decentralized Agent Handoffs.

1. Multi-Agent Coordination Topologies

When multiple autonomous agents collaborate, how should control and context flow between them? Three primary architectural topologies have emerged:

1. Centralized Supervisor

A master router agent inspects user input and decides which specialized worker node (Coder, Researcher, Tester) executes next. Workers always report back to the supervisor.

2. Dynamic Handoff (Swarm)

Decentralized routing. Agents transfer execution directly to peer agents via tool calls (e.g., transfer_to_support()). There is no central orchestrator bottleneck.

3. Hierarchical Teams

Supervisors orchestrating sub-teams. E.g., an Executive Supervisor delegates to a Software Team Supervisor and a Marketing Team Supervisor, each managing their own subgraphs.

2. Implementing a Supervisor Architecture in LangGraph

The Supervisor pattern is the most robust and deterministic pattern for enterprise workflows. The supervisor outputs a structured decision: next_agent: Literal["Researcher", "Coder", "FINISH"].

from typing import TypedDict, Annotated, Literal
from langchain_core.messages import BaseMessage, HumanMessage
from langgraph.graph import StateGraph, END
from langgraph.graph.message import add_messages

class TeamState(TypedDict):
    messages: Annotated[list[BaseMessage], add_messages]
    next: str

# 1. Define Specialized Worker Nodes
def research_node(state: TeamState):
    print("--> Worker [Researcher] executing web search...")
    return {"messages": ["Researcher: Retrieved latest benchmark data for vLLM inference throughput."]}

def code_node(state: TeamState):
    print("--> Worker [Coder] writing benchmark script...")
    return {"messages": ["Coder: Generated Python benchmark harness using locust and httpx."]}

# 2. Define the Central Supervisor Node
def supervisor_node(state: TeamState):
    # Evaluates conversation and routes to next worker or finishes
    messages = state["messages"]
    last_message = messages[-1].content if messages else ""
    
    if "benchmark data" in last_message:
        return {"next": "Coder"}
    elif "benchmark harness" in last_message:
        return {"next": "FINISH"}
    else:
        return {"next": "Researcher"}

# 3. Assemble the Multi-Agent StateGraph
workflow = StateGraph(TeamState)

workflow.add_node("Supervisor", supervisor_node)
workflow.add_node("Researcher", research_node)
workflow.add_node("Coder", code_node)

# Set Entry Point
workflow.set_entry_point("Supervisor")

# Conditional routing from Supervisor to workers
workflow.add_conditional_edges(
    "Supervisor",
    lambda state: state["next"],
    {
        "Researcher": "Researcher",
        "Coder": "Coder",
        "FINISH": END
    }
)

# Workers always report back to Supervisor!
workflow.add_edge("Researcher", "Supervisor")
workflow.add_edge("Coder", "Supervisor")

app = workflow.compile()

# Execute team
final_state = app.invoke({"messages": [HumanMessage(content="Benchmark vLLM throughput.")]})
print("\nTeam Finished Execution! Total Messages:", len(final_state["messages"]))

3. The Handoff Pattern (OpenAI Swarm Style)

In customer support or concierge chatbots, a user might start with general FAQ questions, switch to billing, and then ask for technical debugging.

How Handoffs Operate

Instead of a central supervisor deciding every step, the active agent itself calls a handoff tool:transfer_to_billing_agent(context). The execution harness detects this special tool return, swaps the active agent persona to the Billing Agent, and continues the conversation seamlessly without forcing the user to re-explain their problem.

Next Chapter

Guardrails & Code Sandboxing

Continue to the next advanced agentic AI engineering module.

Continue Learning →

Explore Related Tools

Hand-picked utilities and calculators related to this tool.

Related Tools