LangChain & LangGraph for AI Agents
Back to Production Patterns: Multi-Agent, Memory & Observability

Case 4 — Hierarchical Multi-Agent Research System

Three specialized agents coordinated by a supervisor. The classic multi-agent pattern done right.

82 minutesProject submission
🎯 Free Guest Mode: You are learning for free. Sign in to save your completion progress and quiz answers.

Assignment Instructions

Executive Briefing: Build an enterprise competitive intelligence system. A central Supervisor coordinates three specialized worker agents: (1) WebResearcher (gathers news and financial releases), (2) PatentAnalyst (searches patent registries and IP filings), and (3) BriefWriter (synthesizes structured executive intelligence memos). The supervisor dynamically delegates tasks, evaluates worker outputs, and enforces revision limits.


1. Enterprise Scenario & Requirements

Monolithic single-agent prompts degrade in accuracy when loaded with 20+ disparate tools. By decomposing capabilities into a supervisor multi-agent architecture:

  1. Specialized Workers: Author independent worker agents using create_react_agent, each equipped strictly with domain-specific tools and persona prompts.
  2. Supervisor Coordination: Implement the supervisor using langgraph-supervisor (create_supervisor) with explicit delegation instructions.
  3. Automated Handoffs: Leverage dynamic handoff tools (transfer_to_researcher, transfer_to_writer).
  4. Context Window Management: Configure output_mode="last_message" to pass synthesized agent responses rather than flooding the main conversation with dozens of raw tool call tokens.

2. Explicit Deliverables

  1. workers.py: Definitions for research_agent, patent_agent, and writer_agent.
  2. supervisor.py: Compiled hierarchical multi-agent graph with supervisor routing.
  3. test_multi_agent.py: Test suite verifying: (a) task delegation to appropriate worker based on query intent, (b) multi-worker collaboration on complex queries, and (c) token usage comparison between last_message and full_history.
  4. sample_intelligence_memo.md: Executive memo generated by the system on a real technology company.

3. Starter Code & Scaffold

from langgraph_supervisor import create_supervisor
from langgraph.prebuilt import create_react_agent
from langchain_core.tools import tool
from langchain_openai import ChatOpenAI

@tool
def search_press_releases(company: str) -> str:
    '''Search recent corporate press releases and news.'''
    return f"Latest news for {company}: Launched cloud AI platform Q2 2026."

@tool
def search_patent_database(technology: str) -> str:
    '''Search USPTO and international patent filings.'''
    return f"Patent filings for {technology}: 14 new grants in transformer quantization."

model = ChatOpenAI(model="gpt-4o")

# Create specialized worker agents
researcher = create_react_agent(model, [search_press_releases], name="researcher")
patent_analyst = create_react_agent(model, [search_patent_database], name="patent_analyst")

# Create supervisor
workflow = create_supervisor(
    agents=[researcher, patent_analyst],
    model=model,
    prompt=(
        "You are an executive intelligence director. Assign market news queries to the 'researcher' "
        "and patent/IP questions to the 'patent_analyst'. Synthesize worker findings into a final briefing."
    ),
    output_mode="last_message"
)
app = workflow.compile()

4. 100-Point Grading Rubric

CriterionPointsExcellent (25 pts)Acceptable (15 pts)Needs Work (5 pts)
Worker Specialization & Tool Scoping25 ptsWorkers have distinct personas, isolated toolsets, and clean separation of concerns.Workers separated but tools overlap heavily.Single monolithic agent pretending to be multiple roles.
Supervisor Handoff Mechanics25 ptsSupervisor correctly identifies appropriate workers and transfers context seamlessly.Transfers correctly but occasionally loops between workers.Hardcoded static routing instead of LLM delegation.
Context Window Optimization25 ptsUses output_mode='last_message' to suppress raw scratchpads and protect token budgets.Uses full_history causing token usage to balloon.Manually wipes conversation history, losing context.
Synthesis & Memo Quality25 ptsFinal output integrates findings from multiple workers into a coherent, cited executive briefing.Combines text but reads as disconnected paragraphs.Ignores worker outputs and hallucinates summary.
Checking your access…