Long-Term Memory for Agents
You'll learn to
- -Distinguish working memory from long-term semantic and episodic memory
- -Design a memory retrieval strategy for an agent
- -Implement importance-weighted memory retrieval from scratch
An assistant that learns a user's preferences on Monday and asks the same questions again on Wednesday feels broken in a specific way: not incapable, just forgetful in a way a competent human assistant never would be. ConversationMemory from Tier 7 solves this within a single session. It does nothing for what happens between sessions, days or weeks apart. That gap is what long-term agent memory closes.
Three Kinds of Memory, Not One
- -Short-term (working) memory is the current session: roughly the last twenty turns, exactly the ConversationMemory component already covered.
- -Long-term semantic memory holds durable facts about the user: "is vegan," "prefers window seats," the kind of statement that stays true and relevant indefinitely.
- -Long-term episodic memory holds specific past experiences: "had a bad experience at Restaurant X," a concrete event rather than a standing fact, still worth recalling when it becomes relevant again.
Not Every Memory Deserves Equal Weight
"User is vegan" matters for every single future food recommendation. "User had pasta yesterday" matters for approximately one day and then becomes noise. Treating every stored fact as equally important, and simply retrieving whatever is most recent (an LRU-style cache), misses this entirely. A genuinely useful memory system scores importance at storage time and lets that score, not just recency, shape what gets retrieved later.
Notice that a 40-turns-ago memory (vegan) and a 60-turns-ago memory (shellfish allergy) both outrank a 1-turn-ago memory (pasta yesterday) and a 20-turns-ago memory (window seats) for this specific query. High importance genuinely beats high recency here, exactly the point: a real production system would use actual semantic similarity from the embedding chapter instead of raw word overlap, but the weighting principle, importance times relevance, not recency alone, is the same either way.
Consolidation: Compressing What Accumulates
Left unchecked, stored memories grow without bound. Memory consolidation periodically summarizes and compresses older, lower-importance memories into more compact form, the same summarization instinct behind ConversationMemory's context-overflow handling in Tier 7, now applied across sessions instead of within one. The pipeline at every turn is consistent: retrieve relevant long-term memories, use them in the prompt, extract any new facts worth remembering from this turn, and store them with an importance score for next time.
Interview Signal is part of Pro
See a real weak answer next to a real strong one for this exact topic.
Quiz is part of Pro
Test what you just read with a short quiz, and bank the XP.
Build the Planner and Memory Keeper levels in the GenAI Lab.