Multi-Agent Systems with LangGraph: Orchestrating Complex AI Pipelines

Introduction
Multi-agent systems represent the next evolution beyond single-prompt LLM calls. Instead of one model handling everything, you decompose complex workflows into specialized agents that coordinate, delegate, and check each other's work. LangGraph is the leading open-source framework for building these systems as stateful graphs.
This guide covers LangGraph's core primitives, practical patterns for agent handoffs, and what it takes to run multi-agent pipelines reliably in production.
Why Multi-Agent Over Single-Agent?
A single agent running in a loop can handle simple tasks, but breaks down when the problem space is wide or when different sub-tasks require different expertise, context windows, or tool sets.
- Specialization: A research agent retrieves and summarizes; a code agent writes and tests; a review agent verifies. Each has focused prompts, tools, and context.
- Parallelism: Independent sub-tasks run concurrently, dramatically cutting end-to-end latency.
- Reliability: Explicit checkpoints and human-in-the-loop nodes prevent runaway pipelines and enable recovery.
- Cost control: Route cheap tasks to smaller models and expensive reasoning to frontier models only when needed.
LangGraph Core Concepts
LangGraph models your workflow as a directed graph where nodes are Python functions (or agents) and edges define control flow. State flows through the graph as a typed dictionary.
State
Every graph has a shared state schema. Nodes read from it, make decisions or LLM calls, and write updates back. TypedDict with Annotated fields and reducers (like add_messages) keeps concurrent updates safe.
from typing import Annotated, TypedDict
from langgraph.graph.message import add_messages
class AgentState(TypedDict):
messages: Annotated[list, add_messages]
next_agent: str
artifacts: list[dict]Nodes
A node is any callable that receives the current state and returns a partial state update. Nodes can invoke LLMs, call tools, run code, query databases, or delegate to sub-graphs.
Edges and Conditional Routing
Static edges always move to the same next node. Conditional edges call a router function that inspects state and returns the name of the next node — this is how you implement supervisor routing, tool dispatch, and loop control.
def route_after_supervisor(state: AgentState) -> str:
last_message = state["messages"][-1]
if last_message.content == "FINISH":
return END
return state["next_agent"]
graph.add_conditional_edges("supervisor", route_after_supervisor)The Supervisor Pattern
The most common multi-agent architecture has a supervisor node that reads the task, selects which worker agent to call next, and decides when the task is complete. Workers are isolated — they only see their portion of state.
The supervisor is typically an LLM call with a structured output that names the next agent. This keeps the routing logic readable and allows the supervisor to explain its decisions.
from langchain_anthropic import ChatAnthropic
from pydantic import BaseModel
class RouterDecision(BaseModel):
next: str # "researcher" | "coder" | "reviewer" | "FINISH"
reasoning: str
supervisor_llm = ChatAnthropic(model="claude-sonnet-4-6").with_structured_output(RouterDecision)
def supervisor_node(state: AgentState):
decision = supervisor_llm.invoke([
{"role": "system", "content": SUPERVISOR_PROMPT},
*state["messages"]
])
return {"next_agent": decision.next}Agent Handoffs and Context Passing
Each worker agent receives the full message history but has its own system prompt tuned for its role. Artifacts (code files, research summaries, test results) accumulate in the shared state so downstream agents can reference them.
Keep handoff context tight. Passing an entire conversation to a specialized agent is expensive and often counterproductive. Use a summary node to compress history before handoffs in long-running workflows.
Human-in-the-Loop
LangGraph's interrupt mechanism pauses graph execution at any node and surfaces the current state to a human reviewer. This is critical for high-stakes workflows: approving a deployment plan, reviewing generated contracts, or validating an AI-written PR.
from langgraph.types import interrupt
def approval_node(state: AgentState):
human_review = interrupt({
"question": "Does this plan look correct?",
"plan": state["artifacts"][-1]
})
if human_review["approved"]:
return {"next_agent": "executor"}
return {"next_agent": "planner", "messages": [{"role": "user", "content": human_review["feedback"]}]}Production Deployment Patterns
Running LangGraph in production requires a persistence layer, a way to resume interrupted graphs, and observability on every node execution.
- Checkpointers: Use
PostgresSaverorRedisSaverto persist graph state between turns. This enables long-running workflows that survive restarts and async human review. - LangGraph Platform: The managed cloud offering handles deployment, scaling, and the UI for human-in-the-loop. Useful for teams that want to skip the ops overhead.
- Streaming: Stream events with
graph.astream_events()so frontends can show incremental progress. Buffer tool call results and emit agent-level milestones to keep UX responsive. - Observability: Instrument every node with LangSmith traces or OpenTelemetry. Track token usage, latency per node, and failure modes across runs.
Cost and Latency Optimization
Multi-agent systems multiply LLM calls, so costs can escalate quickly without discipline. Assign model tiers to agents by task complexity. Use Claude Haiku for classification and routing; reserve Opus or Sonnet for deep reasoning nodes.
Cache deterministic sub-tasks. If a research agent pulls the same documentation page on every run, cache the retrieval result keyed by query hash. Prompt caching on Anthropic's API also reduces cost for long system prompts shared across many calls.
Conclusion
LangGraph gives you the graph primitives, state management, and interrupt mechanism needed to build reliable multi-agent systems. The supervisor pattern covers most use cases, and the platform handles persistence and deployment when you're ready to ship.
Start with two agents — a planner and an executor — wire in a human approval node for safety, and expand from there. Measure latency and cost per node from day one so you know where optimization is worth it.
Want to build multi-agent AI systems?
Mickiesoft engineers specialize in AI agent development, LLM integration, and production-grade agentic workflows.
Talk to Our TeamFrequently Asked Questions
Find answers to common questions about our services, process, and capabilities.