Memory & Checkpoints

LangGraph state and checkpointers enable multi-turn memory and human-in-the-loop resume.


State and messages

Default agent state includes a messages list. With a checkpointer, each invoke merges into persisted history.

from langchain.agents import create_agent
from langgraph.checkpoint.memory import InMemorySaver

agent = create_agent(
    "openai:gpt-4.1-mini",
    tools=[],
    checkpointer=InMemorySaver(),
)

Without a checkpointer, each call is isolated.


thread_id

config = {"configurable": {"thread_id": "user-42-session-1"}}

agent.invoke({"messages": [{"role": "user", "content": "Hi"}]}, config=config)
agent.invoke({"messages": [{"role": "user", "content": "Continue."}]}, config=config)

Same thread_id shares history; use distinct ids per user/session.


Checkpointer backends

BackendUse
InMemorySaverDev/test
SqliteSaverSingle-node persistence
Postgres / RedisProduction, multi-instance

Plan for concurrency and retention in production.


Custom state

Extend with state_schema or middleware (user_id, retrieved_docs, etc.):

from typing_extensions import TypedDict, Annotated
from langgraph.graph.message import add_messages

class CustomState(TypedDict):
    messages: Annotated[list, add_messages]
    user_id: str

See official Memory docs for create_agent integration.


Short vs long-term memory

Approach
Short-termmessages + checkpointer
Long-termMiddleware loads profile from DB/vector store into prompt
CompressionSummarization middleware

Memory is a harness concern in 1.0, not one legacy Memory class.


Interrupts & HITL

LangGraph interrupts pause before tools; resume with another invoke. HITL middleware wraps this; checkpoints store the pause point.


Context limits

Use summarization middleware, sliding windows, or external RAG for long histories.


Next steps