LangGraph provides first-class support for persistent memory across graph executions. This guide covers how to integrate agent-memory-kit patterns with LangGraph's built-in persistence layer.
LangGraph uses a Checkpointer interface for persistence. Memory is stored between graph runs, enabling stateful agents, conversation history, and cross-session recall.
from langgraph.checkpoint.memory import MemorySaver
from langgraph.graph import StateGraph
# In-memory checkpointer
checkpointer = MemorySaver()
# Build graph with persistence
graph = StateGraph(MyState)
graph.set_checkpointer(checkpointer)from agent_memory_kit.patterns import SlidingWindowMemory
class SlidingWindowCheckpointer:
def __init__(self, max_messages=20):
self.memory = SlidingWindowMemory(max_messages=max_messages)
def get(self, config):
return self.memory.get_context()
def put(self, config, checkpoint):
self.memory.add(checkpoint)Use LangGraph's interrupt/resume to trigger summarization when context exceeds a threshold:
def should_summarize(state):
return len(state["messages"]) > 10
def summarize_messages(state):
summary = llm.invoke(f"Summarize: {state['messages']}")
state["summary"] = summary
state["messages"] = state["messages"][-2:] # keep last 2
return statepip install langgraph-checkpoint-postgresfrom langgraph.checkpoint.postgres import PostgresSaver
conn_string = "postgresql://user:pass@localhost:5432/memory"
checkpointer = PostgresSaver.from_conn_string(conn_string)- Use
graph.update_state()to inject memory into running graphs - Combine with
cache-aware-designstrategy for token optimization - Episodic memory works naturally with LangGraph's thread-level persistence