LangChain Agent Teams
One agent with twenty tools gets confused. A team of small agents, each with a narrow job, performs better. A researcher gathers facts, a writer shapes the text, and a reviewer checks quality. Multi-agent systems split a big task among specialists and coordinate their work through a graph.
Newsroom Analogy
A newsroom has reporters, editors, and fact checkers. An editor assigns stories, reporters collect facts, and a checker approves the final piece. Nobody does everything, and the product improves because each person focuses on one skill.
+-------------+
| SUPERVISOR | (the editor)
+------+------+
assigns work |
+---------------+----------------+
v v v
[Researcher] [Writer] [Reviewer]
search tools no tools checks facts
Why Split the Work
- Each agent keeps a short, clear prompt.
- Each agent sees only the tools it needs, which improves tool choice.
- Teams are easier to test, because each agent has one measurable job.
- Cheaper models can handle simple roles while stronger models handle hard roles.
Pattern 1: Supervisor
A supervisor model reads the state and picks the next worker. Workers report back, and the supervisor decides again until the task is done.
from typing import TypedDict, Literal
from langgraph.graph import StateGraph, START, END
class TeamState(TypedDict):
task: str
notes: str
draft: str
next_worker: str
def supervisor(state: TeamState):
if not state.get("notes"):
return {"next_worker": "researcher"}
if not state.get("draft"):
return {"next_worker": "writer"}
return {"next_worker": "done"}
def researcher(state: TeamState):
notes = model.invoke("List 3 key facts about: " + state["task"]).content
return {"notes": notes}
def writer(state: TeamState):
text = model.invoke(
"Write a short paragraph using these facts:\n" + state["notes"]
).content
return {"draft": text}
def pick(state: TeamState):
return END if state["next_worker"] == "done" else state["next_worker"]
builder = StateGraph(TeamState)
builder.add_node("supervisor", supervisor)
builder.add_node("researcher", researcher)
builder.add_node("writer", writer)
builder.add_edge(START, "supervisor")
builder.add_conditional_edges("supervisor", pick)
builder.add_edge("researcher", "supervisor")
builder.add_edge("writer", "supervisor")
team = builder.compile()
result = team.invoke({"task": "benefits of solar energy"})
print(result["draft"])This supervisor uses simple rules. A production supervisor often asks a model to choose the worker with structured output, so the decision adapts to the task.
The Flow in Action
Supervisor → Researcher → Supervisor → Writer → Supervisor → END (no notes) (adds notes) (no draft) (adds draft) (all done)
Pattern 2: Agents as Nodes
A worker can be a full agent with tools, placed inside the graph as a node. The node calls the agent and returns the final message.
from langchain.agents import create_agent
research_agent = create_agent(
model="openai:gpt-4o-mini",
tools=[search_web],
system_prompt="You research facts. Return a short bullet list.",
)
def researcher(state: TeamState):
out = research_agent.invoke(
{"messages": [{"role": "user", "content": state["task"]}]}
)
return {"notes": out["messages"][-1].content}Pattern 3: Agent as a Tool
Wrap a specialist agent as a tool, and a main agent calls it like any other function. The main agent stays simple, while the specialist handles details.
from langchain_core.tools import tool
@tool
def ask_researcher(question: str) -> str:
"""Ask the research specialist a factual question."""
out = research_agent.invoke(
{"messages": [{"role": "user", "content": question}]}
)
return out["messages"][-1].contentPattern 4: Peer Handoffs
Agents pass the conversation to each other without a boss. A sales agent hands a customer to a billing agent when the topic changes. The handoff updates a state key that names the active agent, and routing follows it.
Design Advice
- Start with one agent. Add teammates only when one agent struggles.
- Give every agent a one-sentence job description.
- Pass short summaries between agents instead of full histories.
- Cap total rounds to prevent endless back-and-forth.
- Trace the whole team to see which agent caused a bad result.
Common Mistakes
- Creating five agents for a task a single prompt solves.
- Giving all agents all tools, which removes the benefit of specialization.
- Skipping a stop condition in the supervisor.
Real-World Scenario
A marketing team uses three agents to prepare a weekly newsletter. The researcher collects trends, the writer drafts short sections, and the reviewer checks tone and facts. A supervisor starts the writer only after the researcher finishes, and ends the run after the reviewer approves. Each agent holds a short prompt and only the tools it needs. The editor reads one polished draft instead of managing three separate tools.
Practice Tasks
- Add a reviewer node to the supervisor example that sets an approved flag.
- Change the supervisor so it asks a model to choose the next worker.
- Wrap one specialist agent as a tool and call it from a main agent.
- Add a round counter that stops the team after five supervisor decisions.
Key Points
- Multi-agent systems split work among focused specialists.
- A supervisor routes tasks to workers and decides when to stop.
- Agents can run as graph nodes or as tools of another agent.
- Short messages and step limits keep teams efficient.
- Begin small and grow the team only when needed.
