Skip to content
Tutorials Center
My learning

Topics

Lesson 27 of 32 ยท LangGraph Workflows

Multi-Agent Systems and Supervisors

Split work across specialist agents: the supervisor pattern, agents as tools, handoffs and subgraphs in LangGraph. Includes a runnable supervisor stand-in in Python.

One agent with twenty tools gets confused: descriptions overlap, prompts grow long and mistakes multiply. A common remedy is to split the job among specialist agents, each with a short prompt and a few tools, and add a coordinator that decides who works next. This is a multi-agent system. It is not always better (it costs more model calls and adds complexity), but when responsibilities are clearly different, it makes each part easier to write, test and improve.

LangGraph is not available on this site, so real code is read-only. The runnable examples use plain-Python stand-ins with a scripted routing "model".

When to use more than one agent

Use a single agent until you see a problem. Then consider splitting when:

  • the toolset is large and the model picks the wrong tool;
  • parts of the task need very different prompts or even different models (a cheap model for classification, a strong one for writing);
  • you want independent testing and ownership per specialist;
  • some steps can run in parallel.

Do not split just because it sounds advanced. Every handoff adds latency and a place for context to get lost.

Pattern 1: supervisor

A supervisor looks at the request and the progress so far and routes to a worker, until it decides the work is finished.

flowchart TD
    U["User request"] --> S["Supervisor"]
    S -->|"research"| R["Researcher agent"]
    S -->|"write"| W["Writer agent"]
    R --> S
    W --> S
    S -->|"done"| E["Final answer"]

Workers report back to the supervisor, which chooses the next step.

In LangGraph this is a graph: the supervisor node has a conditional edge to each worker, and each worker has an edge back to the supervisor. LangChain also publishes a helper package for it, langgraph-supervisor.

Python
# Real LangGraph (read-only; check the package docs for your version)
from langgraph_supervisor import create_supervisor
from langchain.agents import create_agent

researcher = create_agent(model, tools=[search_web], name="researcher",
                          system_prompt="Find facts. Do not write prose.")
writer = create_agent(model, tools=[], name="writer",
                      system_prompt="Turn notes into a clear paragraph.")

workflow = create_supervisor(
    [researcher, writer],
    model=model,
    prompt="Route research questions to the researcher, then ask the writer to draft the answer.",
)
app = workflow.compile()
result = app.invoke({"messages": [{"role": "user", "content": "Explain how tides work."}]})

A supervisor stand-in

The supervisor below is a function with rules, standing in for an LLM that reads the state and picks the next worker. The workers are ordinary functions.

Python Stand-in: supervisor routing between workers

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

Pattern 2: agents as tools

A simpler variant: wrap each specialist as a tool of one main agent. The main agent calls ask_researcher("...") like any tool; inside, a whole sub-agent runs and returns text. Control stays with the main agent, so the flow is easy to follow, and each sub-agent keeps its own prompt and tools.

Python
# Real LangChain (read-only)
from langchain.tools import tool

@tool
def ask_researcher(question: str) -> str:
    """Ask the research specialist to find facts about a topic."""
    result = researcher.invoke({"messages": [{"role": "user", "content": question}]})
    return result["messages"][-1].content

main_agent = create_agent(model, tools=[ask_researcher], system_prompt="Answer using the researcher.")
Python Stand-in: a sub-agent wrapped as a tool

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

Pattern 3: handoffs

In a handoff (also called a swarm), agents pass control to each other directly. A support agent says "this is a billing question" and hands the conversation to the billing agent, which continues talking to the user. There is no central supervisor. In LangGraph a node returns a Command(goto="billing_agent", update={...}) to move control and update the state at once. Handoffs feel natural in conversations; supervisors are easier to reason about for pipelines.

Pattern Who controls the flow Good for
Supervisor Central coordinator Pipelines, parallel work
Agents as tools The main agent Simple delegation
Handoff Whoever is active Conversations with changing specialists

Subgraphs and shared state

Each specialist can be its own compiled graph, used as a node of a parent graph. Parent and child may share state keys (for example messages) or map between different schemas. Subgraphs keep a large system modular: you can run, test and draw each part separately.

Python
# Real LangGraph (read-only)
parent = StateGraph(MessagesState)
parent.add_node("research_team", research_graph)     # a compiled graph used as a node
parent.add_node("writing_team", writing_graph)

Pitfalls

  • Context loss: pass the information the next agent needs, not just "continue".
  • Ping-pong: two agents handing back and forth. Add step limits and a clear finish condition.
  • Cost: every agent call is a model call; measure before you multiply them.
  • Evaluation: test each specialist alone and the whole flow (evaluating LLM apps).

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. What does a supervisor agent do?

    It routes between specialist workers and decides when to finish.
  2. 2. What is an agent-as-tool?

    The main agent delegates by calling a tool whose body runs another agent.
  3. 3. When should you NOT split into several agents?

    Extra agents add cost and complexity; split only when a problem appears.
  4. 4. In a handoff pattern, how does control move?

    Handoffs let agents transfer control to each other, for example with Command(goto=...).

Summary

  • Split into specialists only when one agent struggles with tools, prompts or scale.
  • Supervisor, agents-as-tools and handoffs are the three main patterns.
  • Subgraphs let each specialist be a separate, testable graph.
  • Bound loops, pass context deliberately and watch cost.

Next: Evaluating LLM Applications