14 min read
Lesson 4 of 6
Memory, State & Conversation Management
From the course LangChain & AI Orchestration Frameworks
LLMs are stateless — they don't remember previous interactions. Memory systems give your AI applications the ability to maintain context across conversations and sessions.
Types of Memory
- Buffer memory: Store the full conversation history. Simple but hits context window limits quickly.
- Window memory: Keep only the last N messages. Trades recall for bounded context usage.
- Summary memory: An LLM periodically summarizes the conversation, compressing old messages. Good balance of recall and efficiency.
- Entity memory: Extract and track entities (people, places, facts) mentioned in conversation. Structured and queryable.
- Vector store memory: Embed and store all messages, retrieve relevant ones via similarity search. Scales to unlimited history.
LangGraph State Management
LangGraph uses explicit state schemas:
from typing import Annotated, TypedDict
from langgraph.graph import add_messages
class AgentState(TypedDict):
messages: Annotated[list, add_messages]
user_preferences: dict
current_task: str | None
completed_steps: list[str]
State is passed between nodes and persisted across sessions using checkpointers:
from langgraph.checkpoint.memory import MemorySaver
checkpointer = MemorySaver()
app = graph.compile(checkpointer=checkpointer)
# Resume conversation with thread_id
config = {"configurable": {"thread_id": "user-123"}}
result = app.invoke({"messages": [new_message]}, config)
Long-Term Memory Patterns
For applications that need to remember users across weeks or months:
- User profile store: Persist learned preferences, facts, and interaction history in a database
- Episodic memory: Store summaries of past conversations, retrievable by topic
- Semantic memory: Maintain a knowledge graph of entities and relationships
Practical Tips
- Start with simple buffer memory and add complexity only when needed
- Always set a maximum context budget and handle overflow gracefully
- Test memory retrieval with realistic conversation lengths (50+ turns)
- Consider privacy — users should be able to view and delete their stored memory
Key Takeaways
- •Choose memory type based on conversation length: buffer for short, summary for medium, vector for long
- •LangGraph checkpointers persist state across sessions with thread-based resumption
- •Long-term memory requires explicit storage — user profiles, episodic summaries, or knowledge graphs
- •Always implement memory limits and provide users control over their stored data
0 of 6 lessons marked complete
Progress is kept in this browser only.