Long-Term Memory
~2 min read
Concept & How It Works
Why Does It Exist?
Short-term memory resets. Long-term memory makes agents feel personal and competent over weeks of interaction.
Real-World Analogy
Long-term memory is a CRM record on every customer — the agent 'knows' you even if the current chat just started.
Visual Workflows
What is Long-Term Memory?
Example
Scenario
After three sessions, the agent recalls you use Python 3.12, deploy on AWS, and dislike verbose logging — injected into the system prompt automatically.
Solution
In Agent Memory, apply Long-Term Memory to this scenario: After three sessions, the agent recalls you use Python 3. Identify the inputs, run the technique, validate the output, and note one thing you would monitor in production.
Practice Task
Do this before moving to the next module — reading alone is not enough.
Open the Code Walkthrough below and run it locally. Change one parameter related to Long-Term Memory (e.g. model, temperature, top_k, or tool name), observe the difference in output, and write 2–3 sentences explaining what changed.
Code Walkthrough
Highlighted lines show where Long-Term Memory happens in the code.
1def recall_memories(user_id, query, vector_store, k=5): # define a reusable function2 results = vector_store.similarity_search( # key line for Long-Term Memory3 query,4 k=k,5 filter={"user_id": user_id},6 )7 return "\n".join(r.page_content for r in results) # return the resultCommands to Remember
Commands to Remember
pip install chromadb # vector store for long-term memorypip install redis # fast session / working memorypip install tiktoken # count tokens before injecting memory
Common Mistakes
- Treating Long-Term Memory as a black box without evaluation
- Ignoring cost and latency in production
- Skipping error handling for long term memory
Cheat Sheet
Quick recap — the most important points from this module.
Cheat Sheet
quick ref- •Long-Term Memory
- •Persistent Store
- •Memory Extraction
- •User Profile