DS DevShelfHub Projects · AI tools
Tutorials / LangChain / Reference / Methods / .get_state()
Method CompiledStateGraph

.get_state(): Reference Guide

By DevShelfHub

Get current state of a graph execution.

What is .get_state()?

.get_state() retrieves a point-in-time snapshot of a LangGraph graph execution for a specific thread. It returns a StateSnapshot object whose .values dict mirrors the TypedDict you defined as the graph's state schema — every key in your state (messages, context, tool_results, etc.) is accessible as state.values["key"]. The method is read-only: calling it never advances execution or triggers any node.

The config argument must include a thread_id inside the configurable key. This thread_id is the same value you pass to graph.invoke() or graph.stream() — it is how LangGraph persists and retrieves checkpointed state from the configured checkpointer (MemorySaver, SqliteSaver, PostgresSaver, or a custom backend). Without a matching thread_id, get_state() will return an empty StateSnapshot with no values.

The StateSnapshot also exposes .next (a tuple of node names scheduled to run next), .metadata (run ID, step count, and source), and .created_at (ISO timestamp of when this checkpoint was written). In human-in-the-loop workflows, you call get_state() after an interrupt to inspect what the graph is waiting on before calling update_state() or re-invoking with a resume config. For debugging, pair get_state() with graph.get_state_history() to walk back through all prior checkpoints in the thread.

Use Cases

  • Inspect execution
  • Resume after interrupt
  • Check progress
  • Debug state
  • Conditional logic
  • State inspection

Key Features

  • State retrieval
  • Thread-based
  • Current snapshot
  • Metadata access
  • Resume support
  • Inspection

When NOT to Use

During graph execution—query after complete.

Notes

thread_id is mandatory — no default exists

Calling get_state() without a thread_id in the configurable dict raises a ValueError at runtime. Always structure config as {"configurable": {"thread_id": "your-id"}}. Use a UUID or user-session ID so threads remain isolated across concurrent users.

StateSnapshot.next is empty when execution is complete

After graph.invoke() returns normally, state.next is an empty tuple — there are no more nodes to run. A non-empty .next means the graph is paused at an interrupt_before or interrupt_after point and is waiting for a resume signal via graph.invoke(None, config) or update_state().

get_state() requires a checkpointer — in-memory graphs have no state

If you compiled the graph without a checkpointer (graph = builder.compile()), get_state() returns an empty StateSnapshot every time. Persistence only works when you pass checkpointer=MemorySaver() or a persistent backend at compile time.

State history is available via get_state_history()

For time-travel debugging or rolling back to a prior step, iterate graph.get_state_history(config). Each yielded item is a StateSnapshot at one checkpoint boundary. You can re-invoke from any past snapshot by passing its config to graph.invoke().

Method Signature

python
state = graph.get_state(config)

Parameters

Parameter Type Required Purpose
config dict Yes Config with thread_id

Return Value

Type:

StateSnapshot

Description:

Current state snapshot

Example Output:

StateSnapshot(...)

Code Examples

Inspect current state

python
config = {'configurable': {'thread_id': '1'}}
state = graph.get_state(config)
print(state.values)  # Current values
print(state.next)  # Next nodes

Interrupt-inspect-resume pattern

python
config = {'configurable': {'thread_id': 'thread-42'}}
# After graph.invoke() with interrupt_before
snapshot = graph.get_state(config)
print(snapshot.next)  # Nodes waiting to run
print(snapshot.metadata['step'])  # How many steps ran
# Inject human feedback and resume
graph.update_state(config, {'human_feedback': 'approved'})
result = graph.invoke(None, config)

Walk state history for debugging

python
config = {'configurable': {'thread_id': 'debug-1'}}
for checkpoint in graph.get_state_history(config):
    print(checkpoint.metadata['step'], checkpoint.values)

Common Mistakes

❌ Query state without config/thread_id

✅ graph.get_state(config={'configurable': {'thread_id': 'id'}})

Browse the full LangChain API reference index to explore more classes, methods, and decorators, or start with the LangChain introduction tutorial for end-to-end context on building with .get_state() and the wider framework.

.get_state() FAQ

What does .get_state() do in LangChain?

Get current state of a graph execution. .get_state() retrieves a point-in-time snapshot of a LangGraph graph execution for a specific thread. It returns a StateSnapshot object whose .values dict mirrors the TypedDict you defined as the graph's state schema — every key in your state (messages, context, tool_results, etc.) is accessible as state.values["key"]. The method is read-only: calling it never advances execution or triggers any node. The config argument must include a thread_id inside the configurable key. T…

Which LangChain classes support .get_state()?

.get_state() is available on CompiledStateGraph. Pin your installed LangChain version and verify the method exists in that release before deploying.

When should I use .get_state()?

Use .get_state() when your LangChain chains, agents, or pipelines need the behavior described in this guide.

What does .get_state() return?

.get_state() returns a StateSnapshot. Current state snapshot

Does .get_state() have an async equivalent?

.get_state() does not have a documented async variant. Avoid .get_state() During graph execution—query after complete.

Where can I explore more LangChain API reference pages?

Open the LangChain API reference index on DevShelfHub to browse classes, methods, and decorators, each with runnable examples, parameters, common mistakes, and cross-links.