Skip to main content
Memory in LangGraph enables agents to remember information across interactions, creating more contextual and personalized experiences.

Types of Memory

LangGraph supports two types of memory:
  • Short-term memory: Conversation state within a single thread (via checkpointers)
  • Long-term memory: Persistent storage across threads and sessions (via stores)

Short-Term Memory

Short-term memory is automatically handled through checkpointers and message state.

Message History

Use MessagesState or add_messages for conversation history:
The add_messages reducer maintains conversation history:

Trimming History

Manage message history length:

Semantic Trimming

Keep important messages:

Long-Term Memory

Long-term memory persists information across conversations using stores.

Store Interface

Stores provide key-value storage with namespaces:

Storing User Preferences

Memory Store Pattern

Create a dedicated memory system:

Vector Store Integration

For semantic search over memories:

Memory Architectures

Summary Memory

Summarize old messages to save context:

Entity Memory

Track entities across conversations:

Knowledge Graph Memory

Build relationships between entities:

Memory Management

Forgetting

Implement memory decay:

Memory Consolidation

Merge similar memories:

Best Practices

  • Separate thread and cross-thread memory: Use checkpointers for thread state, stores for cross-thread data
  • Index your stores: Add indexes on frequently queried fields
  • Implement memory limits: Prevent unbounded growth
  • Use semantic search: Vector stores enable better context retrieval
  • Privacy considerations: Implement user data deletion
  • Test memory behavior: Verify memories persist and load correctly
  • Monitor memory size: Track storage usage per user

Next Steps

  • Add Interrupts to review memories before saving
  • Learn about Deployment for production memory systems
  • Explore Debugging to trace memory operations