Multi-Agent Patterns and Deep Agents
Multi-agent design in LangGraph is mostly context engineering: deciding which agent sees what, who owns control flow, and what crosses each boundary. Know the five documented patterns (subagents, handoffs, skills, router, custom workflow) and their cost profiles, why the docs now prefer a tool-calling supervisor over `langgraph-supervisor`, how swarm-style handoffs use `Command.PARENT` and `active_agent`, and how Deep Agents (`deepagents` 0.7.30) packages subagents, a virtual filesystem with pluggable backends, and context compression on top of `create_agent`.
Key points
- 1
Start with one agent. The docs reach for multi-agent only for context management (too many tools or too much specialised knowledge), distributed development by separate teams, parallel subtasks, or sequential constraints that unlock capabilities step by step.
- 2
Patterns: subagents, where a main agent (supervisor) calls agents as tools and all routing goes through it; handoffs, where a state variable such as
active_agentorcurrent_stepswitches the agent or configuration and agents talk to the user directly; skills, where one agent loads prompts on demand; router, a classification step that dispatches (often in parallel withSend) and synthesises; and custom workflow, a bespokeStateGraphthat mixes deterministic and agentic nodes. - 3
Cost profile from the docs: on a one-shot request subagents take 4 model calls and the others 3, because results flow back through the supervisor. On repeat requests the stateful patterns (handoffs, skills) save 40–50% of calls. On multi-domain fan-out, subagents and router win through parallelism and isolation, while handoffs are sequential and skills accumulate tokens.
- 4
Tool-calling supervisor: wrap each worker
create_agentin a@toolthat invokes it and returnsresult["messages"][-1].content. Subagents are stateless by default. Prompt them to put their results in the final message, or return aCommandwith extra state keys plus a matchingToolMessage. - 5
langgraph-supervisoris no longer actively maintained. Mapcreate_supervisorto acreate_agentwith tool-wrapped workers,output_mode(last_messageby default, orfull_history) to what the wrapper returns, and nested supervisors to tools that call middle-tier agents. For interrupts, compile only the outermost graph with a checkpointer and pass athread_id. - 6
Handoffs between agent subgraphs: a tool returns
Command(goto=agent, graph=Command.PARENT, update={...}). The update must carry theAIMessagewith the tool call and aToolMessagewith the sametool_call_id. Every key in the update must exist in the parent schema, or it is silently dropped. For most handoffs the docs prefer a single agent whose middleware swaps the prompt and tools bycurrent_step. - 7
langgraph-swarm:create_handoff_toolmakestransfer_to_<agent>tools that forward the full history and setactive_agent.create_swarmadds aSTARTrouter that returnsactive_agent(ordefault_active_agent), so with a checkpointer the next turn resumes with the last active agent. - 8
Loop and routing control: give the supervisor or handoff graph a hop or attempt counter in state with an explicit terminal route (clarify, escalate or
END).recursion_limitis only the safety net. Fix misrouting with sharper names and descriptions and a routing eval set built from traces. - 9
Deep Agents:
create_deep_agentreturns a compiled LangGraph graph with filesystem tools (ls,read_file,write_file,edit_file,delete,glob,grep;executeonly on sandbox backends), atasktool with an auto-addedgeneral-purposesubagent, summarisation and tool-call patching. Yourtools=are additive. Since v0.7,write_todosplanning is opt-in throughTodoListMiddleware(). - 10
Deep Agents subagents:
task(description, subagent_type). Isolated mode (the default) starts the subagent with a single human message; it returns one final report as aToolMessage. State keys other thanmessages,todosand similar (for examplefiles) merge back into the parent.mode: "fork"(beta) continues the parent's conversation. Omittedtools,modelandinterrupt_onare inherited,permissionsreplaces the parent's list, andCompiledSubAgentdoes not inheritinterrupt_on. - 11
Backends:
StateBackend(the default) keeps files in thread state and shares them with subagents.FilesystemBackenduses real disk and suits CLIs and CI, not web servers.StoreBackend(namespace=...)gives cross-thread storage scoped by a namespace factory, which is required in 0.7.30.CompositeBackend(default=StateBackend(), routes={"/memories/": StoreBackend(...)})routes by longest prefix. - 12
Context compression in Deep Agents: tool results over 20,000 tokens are offloaded to the backend and replaced by a path plus a 10-line preview. Around 85% of
max_input_tokens, older large tool inputs are truncated, and once nothing more can be offloaded the history is summarised while a text copy of the original messages is kept on the filesystem.
Common traps
Recommending
create_supervisorfor new work: the docs now saylanggraph-supervisoris unmaintained and recommend a tool-calling supervisor built withcreate_agent.Wiring workers to
ENDin a custom supervisor graph: the supervisor never sees their results and cannot decide the next step.A handoff that sends only a
ToolMessage, or no messages: the receiving agent sees a broken tool-call history. Send the AIMessage/ToolMessage pair.Adding a payload key such as
task_descriptionto aCommand.PARENTupdate when the parent schema lacks it: it disappears silently instead of raising.Assuming a Deep Agents subagent sees the whole conversation: isolated mode passes only the
description, so the description must be self-contained.Assuming
write_todosis built in: indeepagents0.7+ you must addTodoListMiddleware()yourself.Setting
interrupt_onat the top level and expecting aCompiledSubAgentto pause: compiled runnables do not inherit it.Scoping
StoreBackendper assistant on a multi-user deployment: every user of that assistant shares the files. Derive the namespace from the authenticated user (and tenant).
Read the source
Further reading
Suggest a resourceNo extra reading for Multi-Agent Patterns and Deep Agents yet. Found a guide, video or cheat sheet that made it click? Share it and help the next learner.
Test yourself on Multi-Agent Patterns and Deep Agents
Ten questions, with the answer and explanation after each one.