Memory Summarization
~2 min read
Concept & How It Works
Why Does It Exist?
Summarization is the most practical compression technique — cheap with small models and effective for conversational memory.
Real-World Analogy
Summarization is a journalist's lede — the whole story in two paragraphs so the reader can decide if they need details.
Visual Workflows
What is Memory Summarization?
Example
Scenario
After a 40-message planning session, summarization produces: 'Team chose React, deadline April 1, open question: auth provider (Auth0 vs Clerk).'
Solution
In Agent Memory, apply Memory Summarization to this scenario: After a 40-message planning session, summarization produces: 'Team chose React, deadline April 1, open question: auth provider (Auth0 vs Clerk). 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 Memory Summarization (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 Memory Summarization happens in the code.
1def summarize_history(messages, llm): # define a reusable function2 transcript = "\n".join(f"{m['role']}: {m['content']}" for m in messages)3 prompt = f"Summarize this conversation. Keep facts, decisions, open questions:\n{transcript}"4 return llm.invoke(prompt).content # 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 Memory Summarization as a black box without evaluation
- Ignoring cost and latency in production
- Skipping error handling for memory summarization
Cheat Sheet
Quick recap — the most important points from this module.
Cheat Sheet
quick ref- •Memory Summarization
- •Rolling Summary
- •Cold Storage
- •Context Pruning