LangGraph 1 cheatsheet
LangGraph 1: Memory and persistence
7 common LangGraph 1 tasks.
Add short-term memory
Compile with a checkpointer to save state after every step. Use InMemorySaver for experiments only.
from langgraph.checkpoint.memory import InMemorySaver
graph = builder.compile(checkpointer=InMemorySaver())
Continue a conversation on a thread
Calls that share a thread_id share state.
config = {"configurable": {"thread_id": "user-1"}}
graph.invoke(inputs, config)
Browse state history
Iterate over past checkpoints of a thread, newest first. Useful for debugging and time travel.
for snapshot in graph.get_state_history(config):
print(snapshot.values)
Persist to SQLite
Install the SQLite checkpointer. It keeps state across restarts for local use.
pip install -U langgraph-checkpoint-sqlite
Persist to PostgreSQL
Use PostgreSQL for production. Install the package, then create the tables once with setup().
pip install -U langgraph-checkpoint-postgres
from langgraph.checkpoint.postgres import PostgresSaver
with PostgresSaver.from_conn_string(DB_URI) as checkpointer:
checkpointer.setup()
Add long-term memory
A store keeps data across threads, such as facts about a user.
from langgraph.store.memory import InMemoryStore
graph = builder.compile(checkpointer=InMemorySaver(), store=InMemoryStore())