AI Dev 25 | Harrison Chase: Long Term Memory with LangGraph
Key Moments
AI agents can use semantic, episodic, and procedural memory, managed via LangGraph, for personalized interactions.
Key Insights
AI agents can be endowed with long-term memory by categorizing it into semantic (facts), episodic (experiences), and procedural (skills) types.
LangGraph provides a framework for building agent and multi-agent systems, enabling the implementation of complex memory functionalities.
Memory can be updated in real-time ('hot path') or asynchronously ('background'), each with trade-offs in latency and transparency.
Procedural memory directly maps to agent instructions and system prompts; its optimization is akin to prompt engineering.
Episodic memory, often implemented using few-shot examples, is effective for classification tasks like email triage.
Semantic memory, analogous to RAG, stores factual information about users or the environment, retrievable via semantic search.
THE IMPORTANCE OF MEMORY IN AI AGENTS
AI agents, to be truly effective personal assistants, need to emulate human-like memory. Unlike static LLM interactions that require repetitive context provision, agents with memory can recall past interactions, learn user preferences, and adapt over time. This is crucial for moving agents from being merely 80% useful to achieving 95-97% effectiveness, enabling personalization and a more natural, less redundant user experience.
TYPES OF MEMORY MAPPED TO HUMAN COGNITION
The presentation categorizes AI memory into three types, drawing parallels with human memory. Semantic memory stores factual information, similar to facts learned in school. Episodic memory captures specific past experiences and events, like remembering a particular conversation. Procedural memory encompasses skills and behaviors, akin to learning how to ride a bike. These categories provide a conceptual framework for designing and implementing memory systems in AI agents.
IMPLEMENTING MEMORY TYPES IN AGENTS WITH LANGGRAPH
These memory types are mapped to agent functionalities. Semantic memory is represented by facts about the user, retrievable through techniques like semantic search. Episodic memory can be implemented using few-shot prompting with past agent actions as examples. Procedural memory aligns with system prompts and instructions that guide the agent's behavior and tone. LangGraph, an orchestration framework, is used to build these complex agent systems.
MEMORY UPDATE STRATEGIES: HOT PATH VS. BACKGROUND
Two primary strategies exist for updating memory: 'hot path' and 'background'. Hot path updates occur before the agent responds, allowing for immediate use of new information but potentially increasing latency and complexity for the agent. Background updates happen asynchronously after the interaction, avoiding latency issues and separating memory management but with less immediate user visibility. Both approaches have distinct advantages and are utilized in agent development.
SEMANTIC MEMORY: FACTS AND USER INFORMATION
Semantic memory stores factual data, such as user preferences or specific details about past interactions. Implemented using tools like `manage_memory` and `search_memory` from the LangMe package, it leverages an in-memory store initially, with production-ready options like PostgreSQL and Redis available. This memory is namespaced, allowing for user-specific or organization-specific storage, and is crucial for an agent to recall facts pertinent to its tasks.
EPISODIC MEMORY: PAST INTERACTIONS AND EXPERIENCES
Episodic memory, particularly useful for classification tasks like email triage, is implemented using few-shot examples. These examples, representing past interactions and their desired outcomes, are stored in a memory store and retrieved via semantic search. For instance, an agent can learn to classify emails as 'respond,' 'ignore,' or 'notify' based on curated historical examples, allowing it to generalize and handle new, similar situations effectively.
PROCEDURAL MEMORY: INSTRUCTIONS AND BEHAVIORS
Procedural memory directly translates to the agent's instructions and system prompts. This type of memory is crucial for defining the agent's core behaviors, tone, and specific task guidelines. By storing these instructions in a persistent store and fetching them at runtime, they can be dynamically updated based on user feedback or performance analysis. This approach blurs the line between memory and prompt optimization, allowing agents to adapt their fundamental operating procedures.
THE ROLE OF USER INTERFACE AND FEEDBACK LOOPS
A user-friendly interface is critical for gathering feedback, which in turn fuels memory updates and prompt optimization. Whether it's a simple 'ignore' button on an email, an option to edit generated content, or direct natural language instructions, user interaction provides invaluable data. This feedback loop allows agents to learn, adapt, and refine their responses, moving towards more sophisticated and personalized assistance, and it is essential for correcting potential hallucinations or suboptimal behaviors.
PERSISTENCE AND NAMESPACING FOR MEMORY MANAGEMENT
Memory persistence is managed through a 'store' that acts as a namespace key-value store supporting semantic search. This allows memories to be scoped to specific users, organizations, or agents. For enterprise settings, robust authentication mechanisms are layered on top of these namespaces to ensure data privacy and prevent proliferation of information between different agents or users, safeguarding sensitive data.
OBSERVABILITY AND DEBUGGING WITH LANGSMITH
Tools like LangSmith are essential for observing and debugging agent behavior, especially when memory is involved. They provide detailed traces of agent execution, including LLM calls, tool usage, and memory interactions. This transparency is vital for understanding why an agent behaves a certain way, identifying potential issues like hallucinations, and iterating on prompt design and memory management strategies. Bulk exports to data warehouses further aid in system-level observability.
ADVANCED CONSIDERATIONS: PRIORITIES AND MULTIMODALITY
While not explicitly covered in basic implementations, advanced memory systems can incorporate priority mechanisms, combining semantic similarity, importance scores, and timestamps to resolve conflicting memories. The system's current store primarily handles key-value lookups for multimodal data; semantic search over multimodal content is an area for future development. The underlying principles of memory management, however, remain applicable across different data types and complexity levels.
Mentioned in This Episode
●Software & Apps
●Companies
●Organizations
●Books
Common Questions
Langchain is a set of developer tools designed to make it easy to build applications on top of Large Language Models (LLMs). Langraph is an orchestration framework within Langchain specifically for building highly customizable agent and multi-agent systems, often serving as a follow-up to Langchain for more advanced agent development.
Topics
Mentioned in this video
A database system mentioned as a production-ready persistence layer for long-term memory storage in Langraph.
A debugger for observing agent trajectories and internal LLM traces, used in debugging and understanding agent behavior.
A natural language inference model mentioned as a possible tool to check for conflicting memories in a background process.
A paper from Stanford on simulating agents, which spent significant time on memory systems, including importance scores and temporal aspects for memory retrieval.
A system where observability data from Langsmith can be published for system-level monitoring.
More from DeepLearningAI
View all 65 summaries
1 minThe #1 Skill Employers Want in 2026
1 minThe truth about tech layoffs and AI..
2 minBuild and Train an LLM with JAX
1 minWhat should you learn next? #AI #deeplearning
Found this useful? Build your knowledge library
Get AI-powered summaries of any YouTube video, podcast, or article in seconds. Save them to your personal pods and access them anytime.
Try Summify free