How langchain-ai/langgraph-swarm-py works
LangGraph Swarm is a Python library for assembling specialized agents into a shared-state graph that can transfer control between agents and resume with the last active agent. The principal workflow is to create handoff tools, supply agents to create_swarm, compile the resulting graph, and invoke it across turns. The graph distinguishes handoff construction and destination discovery from swarm assembly and entry routing. README-documented memory, streaming, and human-in-the-loop capabilities are provided through LangGraph; source excerpts do not show their internal wiring.
Main entry points: swarm.py Swarm builder · handoff.py Handoff tool
Components 13
Swarm assembly
- Swarm builder
langgraph_swarm/swarm.py - Active-agent router
langgraph_swarm/swarm.py
Agent handoffs
- Handoff tool
langgraph_swarm/handoff.py - Destination discovery
langgraph_swarm/handoff.py
Graph runtime
- Compiled swarm
- Conversation state
- LangGraph runtime
- Memory services
- Human review
- Streaming output
Other components
- Application developer
- Configured agents
- Application caller
Connections 16
- Application developer → Handoff tool: creates
README.md - Application developer → Swarm builder: assembles
README.md - Configured agents → Swarm builder: supplies agents
langgraph_swarm/swarm.py - Swarm builder → Destination discovery: discovers destinations
langgraph_swarm/swarm.py - Swarm builder → Active-agent router: adds router
langgraph_swarm/swarm.py - Swarm builder → Compiled swarm: returns graph
langgraph_swarm/swarm.py - Active-agent router → Compiled swarm: routes entry
langgraph_swarm/swarm.py - Handoff tool → Conversation state: updates messages
langgraph_swarm/handoff.py - Handoff tool → Compiled swarm: transfers control
langgraph_swarm/handoff.py - Destination discovery → Swarm builder: provides destinations
langgraph_swarm/swarm.py - Application caller → Compiled swarm: invokes
README.md - Compiled swarm → LangGraph runtime: executes on
- Compiled swarm → Conversation state: shares messages
README.md - LangGraph runtime → Memory services: supports persistence
README.md - LangGraph runtime → Human review: supports review
README.md - LangGraph runtime → Streaming output: supports streaming
README.md