Learn / Frameworks / LangChain / Multi-Agent Patterns

LangChain · Lesson 13 of 15

Multi-Agent Patterns

Supervisor, handoff and router patterns — and when one agent is enough.

  • Advanced
  • 16 min read
  • 3 objectives

Before this lessonLesson 12: LangGraph Basics

What you will learn

  • Route to a specialist
  • Handoff state
  • Bound the loop

Your Progress

0 of 15 lessons 0%

  • Lessons0 / 15
  • Completed0
  • Est. time left~ 4 hours

Create a free account to keep your progress on every device.

Several agents in a loop look impressive and fail in surprising ways. Start with one agent and tools. Split only when you have specialists with different prompts, tools or models.

A router

from typing import Literal

class Route(BaseModel):
    expert: Literal["billing", "tech", "smalltalk"]

router = model.with_structured_output(Route)

def handle(question: str) -> str:
    choice = router.invoke(question).expert
    return experts[choice].invoke(question)

Supervisor vs handoff

  • Supervisor: one node decides which worker to call, sees every result, and stops the loop.
  • Handoff: a worker transfers the whole state to another worker (support → billing). Easy to lose the original question.

Bounds

Cap steps, cap tokens, and never let a worker call the supervisor forever. Log which expert ran; that is how you debug a wrong answer.

Up next · Lesson 14LangSmith Tracing and EvalsTrace every run, build a dataset and score answers with evaluators.