# Multi-agent supervisor: researcher, analyst, writer and reviewer

Large tasks go better when specialists each do one thing. A supervisor reads the shared state and decides who works next. Watch the hand-offs, the shared state and the review loop.

<div data-sim="supervisor"><p>Interactive simulation. It needs JavaScript; the text below explains what it shows.</p></div>

## What you are looking at

The diagram shows which agent is working; the log lists every hand-off; the shared state is what all agents read and write. The researcher uses the real knowledge-base search, the analyst real tools; routing follows rules standing in for the supervisor model.

## Things to try

- Run the first example with the unsupported-claim switch on and off.
- Ask about complaint themes to bring in the analyst.
- Write your own task about the shop.

## How it works in real systems

LangGraph supports supervisor and hierarchical teams; the OpenAI Agents SDK uses hand-offs; CrewAI and AutoGen package similar patterns. Keep the number of agents small: every hand-off costs tokens and adds a place to fail.

The tools in this simulation compute real results; the choice of which tool to call is made by rules that stand in for the language model, so you can try your own input without an API key.

## Code lab

The same idea in real code, step by step. Copy each block into a notebook or a file and run it in order.

<div class="cl-start"></div>

### Step 1 · Specialists as small agents

```python
# pip install langgraph langchain-openai
from langchain_openai import ChatOpenAI
from langgraph.prebuilt import create_react_agent
from langchain_core.tools import tool
llm = ChatOpenAI(model="gpt-4o-mini", temperature=0)
@tool
def search_kb(query: str) -> str:
    """Search the shop's policies."""
    return "Damaged items qualify for a full refund or replacement; refunds are issued within five business days."
researcher = create_react_agent(llm, [search_kb], prompt="Find facts. Return them as bullet points with sources.")
writer = create_react_agent(llm, [], prompt="Write a short, friendly answer using only the facts given.")
reviewer = create_react_agent(llm, [], prompt="Check every sentence against the facts. Reply APPROVED or list the unsupported sentences.")
```

### Step 2 · A supervisor that routes

```python
from typing import TypedDict, Literal
from langgraph.graph import StateGraph, START, END
class Team(TypedDict):
    task: str; facts: str; draft: str; review: str; rounds: int
def run_agent(a, text): return a.invoke({"messages": [("user", text)]})["messages"][-1].content
def research(s): return {"facts": run_agent(researcher, s["task"])}
def write(s):   # the reviewer's notes go into the prompt, then the review is cleared so the new draft is reviewed again
    return {"draft": run_agent(writer, f"Task: {s['task']}\nFacts: {s['facts']}\nReviewer notes: {s['review']}"), "review": "", "rounds": s["rounds"] + 1}
def review(s): return {"review": run_agent(reviewer, f"Facts: {s['facts']}\nAnswer: {s['draft']}")}
def supervisor(s) -> Literal["research", "write", "review", "__end__"]:
    if not s["facts"]: return "research"
    if not s["draft"]: return "write"
    if not s["review"]: return "review"
    return END if s["review"].startswith("APPROVED") or s["rounds"] >= 3 else "write"
g = StateGraph(Team)
for n, f in [("research", research), ("write", write), ("review", review)]: g.add_node(n, f)
g.add_conditional_edges(START, supervisor)
for n in ("research", "write", "review"): g.add_conditional_edges(n, supervisor)
app = g.compile()
print(app.invoke({"task": "Refund for a damaged tent, how long?", "facts": "", "draft": "", "review": "", "rounds": 0})["draft"])
```

Here the supervisor is plain Python; it can also be an LLM that picks the next worker.

<div class="cl-end"></div>

## More simulations

[← ReAct tool calling](/ai-simulations/react-tool-calling) · [All AI Simulations](/ai-simulations) · [Guardrails →](/ai-simulations/guardrails)
