All Agent Engineering

Passing State and Restoring Context Between LangGraph Parent and Sub Graphs

Decide state mapping and checkpoint namespaces from schemas and checkpointer settings.

AINavWritten / Updated
On this page

At a glance

When a parent graph uses a subgraph as a node, two questions come first: how state keys correspond, and whether the subgraph's internal data survives between calls. This procedure follows the supplied LangGraph subgraph documentation and covers both separate and shared state schemas, before and after wiring.

Runtime and applicability

Article type
Engineering practice
Verified
Applies to
  • LangGraph Passing State and Restoring Context Between LangGraph Parent and Sub Graphs

Execution locations and responsibilities

  • LangGraph graph runtime and application host Use the workflow below to distinguish responsibilities of the caller, runtime, and external actions.
Engineering workflow order
Engineering workflow order1. List parent and subgraph state keys → 2. Choose the pattern and write the mapping → 3. Decide the persistence mode → 4. Isolate namespaces and check repeated and parallel calls → 5. Compile the parent with a checkpointer and resume → 6. Inspect subgraph state and event paths. Arrows show the order of checks in the guide. Follow each step’s prerequisites, branches and stop conditions; unexecuted steps are not completed work.1. List parent and subgraph state keys2. Choose the pattern and write the mapping3. Decide the persistence mode4. Isolate namespaces and check repeated and parallelcalls5. Compile the parent with a checkpointer and resume6. Inspect subgraph state and event paths

Arrows show the order of checks in the guide. Follow each step’s prerequisites, branches and stop conditions; unexecuted steps are not completed work.

When to use

  • The documentation describes two communication patterns. If the schemas share no keys, or state must be transformed, call the subgraph inside a node: a wrapper function maps parent state to subgraph input and the output back to parent state. If they share keys, pass the compiled subgraph straight to add_node with no wrapper. Check key sharing first, then choose.

When not to use

  • A checkpointer=True subgraph does not support parallel tool calls, and calling the same instance several times in one node also conflicts; if you need several independent calls, use the default per-invocation mode
  • When a subgraph is called inside a tool function or similar indirection, get_state(config, subgraphs=True) does not work, although interrupts still reach the top-level graph
  • A subgraph compiled with checkpointer=False can only be re-run from the start after a crash
  • The documented examples use LangChain's create_agent and middleware; without them you must prevent parallel calls yourself

Prerequisites and input

  • Parent and subgraph state schemas are defined and you can tell which keys share names
  • The parent graph can take a checkpointer, and calls can supply a stable thread_id configuration

Engineering checks

State contract — The documentation describes two communication patterns. If the schemas share no keys, or state must be transformed, call the subgraph inside a node: a wrapper function maps parent state to subgraph input and the output back to parent state. If they share keys, pass the compiled subgraph straight to add_node with no wrapper. Check key sharing first, then choose.

Persistence — The checkpointer argument of compile() sets subgraph persistence. The default None starts fresh per call but inherits the parent's checkpointer within one call, so interrupt() works. True accumulates state across calls on a thread. False disables checkpointing, with no interrupts or durable execution. The documentation says the parent must be compiled with a checkpointer for these features.

Namespaces and observability — In the default per-invocation mode, each call to the same subgraph gets its own checkpoint namespace, so repeated calls do not conflict. The risk is concentrated in checkpointer=True subgraphs: when several of them are called inside a node, namespaces are assigned by call order, so reordering can make a subgraph load the wrong state. Wrapping each subagent in its own StateGraph with a unique node name gives a stable namespace. Calling the same stateful subgraph instance several times in one node writes to one namespace and conflicts. Subgraphs added as nodes are named automatically. For observation, event namespaces combine the node name with a task identifier, and get_state(config, subgraphs=True) shows subgraph state.

1. List parent and subgraph state keys

Where: the code in the graph runtime and application host. Input: both schemas. Action: mark each key as shared or subgraph-private. Completion check: every key has an owner. Stop condition: if any key's ownership is unclear, fix the schema before wiring.

2. Choose the pattern and write the mapping

Where: parent graph construction code. Input: the key list. Action: with no shared keys or when transformation is needed, write a wrapper node with explicit input and output mapping; with shared keys, pass the compiled subgraph to add_node. Completion check: each subgraph output key maps to a parent key or is deliberately dropped. Stop condition: stop if the mapping needs keys from another level; the documented multi-level example keeps each level's keys invisible to the others, so map level by level.

3. Decide the persistence mode

Where: the subgraph's compile() call. Input: whether the subgraph must remember earlier calls. Action: use default None for independent requests, True for multi-turn memory, and False only when interrupts and recovery are not needed. Completion check: the chosen value and its reason are recorded. Stop condition: if False is chosen but the workflow needs interrupts or crash recovery, switch modes.

4. Isolate namespaces and check repeated and parallel calls

Where: the node or tool wrapper that calls subgraphs. Input: each subgraph's persistence mode, the number of subgraphs, call order, how many times the same subgraph is called within one node, and whether the model may call the same tool in parallel. Action: for checkpointer=True subgraphs, wrap each in its own StateGraph with a unique node name; check whether the same checkpointer=True subgraph is called more than once in a single node, serial calls included, and never call it in parallel (limit calls or disable parallel tool calling); the default None mode needs no such isolation because every invocation has its own namespace. Completion check: each checkpointer=True subgraph has a fixed name and is called once per node. Stop condition: if you need several independent calls to the same subgraph, or cannot rule out parallel calls, use the default None mode and re-confirm whether multi-turn memory is still required.

5. Compile the parent with a checkpointer and resume

Where: parent compile and invocation code. Input: a checkpointer and a configuration with thread_id. Action: compile with the checkpointer; after an interrupt, continue with Command(resume=...) using the same configuration. Completion check: the subgraph continues from the pause point rather than restarting. Stop condition: stop if the thread_id differs from the first call, since that creates a new thread.

6. Inspect subgraph state and event paths

Where: debugging and monitoring code. Input: a thread that already has checkpoints. Action: call get_state(config, subgraphs=True) for statically discoverable subgraphs, and use event namespaces to separate parent from subgraph updates. Completion check: you can name the level each update came from. Stop condition: when the subgraph is called inside a tool function, the documentation says its state cannot be viewed this way; use other records instead of assuming visibility.

Task example

This is a hand-made hypothetical walkthrough, not an actual run. Suppose the parent has foo and the subgraph has bar and baz, with no shared keys. You pick the wrapper node, map foo to bar, then write the subgraph's bar back to foo. Following the shape of the documented example, you would expect parent updates to carry an empty namespace and subgraph updates to carry a node name plus task identifier. You must confirm these expectations in your own environment; this text did not verify them.

Completion checks

  • Every parent and subgraph key has an owner, and the mapping lives in a wrapper or in shared key declarations
  • checkpointer matches the need for interrupts and multi-turn memory, and the parent has a checkpointer
  • Each checkpointer=True subgraph has a unique name, is called once per node (serial calls included), and is never called in parallel
  • Resume uses the same thread_id, and the state-inspection method fits where the subgraph is called

Verification scope

This text is based on reading the supplied LangGraph subgraph documentation only. Installation, login, API execution and output were not tested. Model names, version differences and LangSmith links in the source are outside this topic.

Sources

All links are official pages; verification dates are listed per source, and links point to the version checked.

  1. LangGraph · LangGraph documentation: langgraph-subgraphs

Found an error? Tell us →