A sample LangGraph agent demonstrating the supervisor pattern with custom handoff tools and message forwarding.
This sample agent showcases:
- Supervisor Pattern: Central coordination between specialized sub-agents
- Custom Handoff Tools: Seamless agent-to-agent communication
- Message Forwarding: Efficient information flow between agents
- Specialized Sub-agents: Math expert and research expert agents
┌─────────────────┐
│ Supervisor │
│ Agent │
└─────────┬───────┘
│
┌─────┴─────┐
│ │
┌───▼───┐ ┌───▼───┐
│ Math │ │Research│
│Expert │ │Expert │
└───────┘ └───────┘
- Math Expert: Handles mathematical calculations using
addandmultiplytools - Research Expert: Performs web searches and research tasks
# Start development server
make dev sample-agent
# Start without opening browser
make dev sample-agent -- --no-browser
# With custom host/port
make dev sample-agent -- --host 0.0.0.0 --port 3000# Run unit tests
make unit sample-agent
# Run integration tests
make integration sample-agent
# Run all tests
make test_apps# Lint code
make lint_apps
# Format code
make format_appsCopy .env.example to .env and set:
# OpenRouter API Key
OPENROUTER_API_KEY=your_key_here
# LangSmith (optional)
LANGCHAIN_TRACING_V2=true
LANGCHAIN_PROJECT=your_project_name
LANGCHAIN_API_KEY=your_langsmith_keyThe agent uses:
- Model: Anthropic Claude Sonnet 4 via OpenRouter
- Dependencies: Shared libs (
shared,common) - Graph Entry Point:
src/sample_agent/graph.py:make_graph
apps/sample-agent/
├── README.md # This file
├── pyproject.toml # Package configuration
├── langgraph.json # LangGraph configuration
├── .env # Environment variables
├── .env.example # Environment template
├── src/sample_agent/ # Main package
│ ├── __init__.py
│ ├── graph.py # Main graph definition
│ ├── state.py # Agent state schema
│ ├── prompts.py # Agent prompts
│ ├── context.py # Context utilities
│ ├── subagents/ # Sub-agent definitions
│ │ ├── math.py # Math expert agent
│ │ └── research.py # Research expert agent
│ └── tools/ # Tool definitions
│ ├── basic.py # Basic tools (add, multiply, web_search)
│ └── handoff.py # Custom handoff tools
└── tests/ # Test suite
├── conftest.py # Test configuration
├── unit/ # Unit tests
└── integration/ # Integration tests
from sample_agent.graph import make_graph
# Create the graph
graph = make_graph()
# Use the agent
result = await graph.ainvoke({
"messages": [{"role": "user", "content": "Calculate 15 * 24"}]
})# Import components
from sample_agent.state import AgentState
from sample_agent.subagents import create_math_agent, create_research_agent
from sample_agent.tools.handoff import create_custom_handoff_tool- Add new sub-agents in
src/sample_agent/subagents/ - Add new tools in
src/sample_agent/tools/ - Update prompts in
src/sample_agent/prompts.py - Modify the graph in
src/sample_agent/graph.py
When running the dev server:
- API: http://127.0.0.1:2024
- Studio UI: https://smith.langchain.com/studio/?baseUrl=http://127.0.0.1:2024
- API Docs: http://127.0.0.1:2024/docs
langgraph-supervisor>=0.0.28- Supervisor pattern implementationlanggraph-up-devkits- Development utilities (workspace dependency)- Shared libraries from
libs/sharedandlibs/common
MIT