Skip to content
derpx06.dev
WritingExplainersNotesAbout
works on my machineit's always DNSship itLGTMTODO: sleepoff by oneread the docsgit push --force-with-lease404: sleep not foundhave you tried turning it off and on againrubber duck says: explain itpremature optimisationworks on my machineit's always DNSship itLGTMTODO: sleepoff by oneread the docsgit push --force-with-lease404: sleep not foundhave you tried turning it off and on againrubber duck says: explain itpremature optimisation

Learning in public.

A student's notebook on system design, distributed systems and databases. Shared as I learn.

ReadWritingExplainersNotesAbout
ElsewhereGitHubLinkedInHugging FaceLeetCode
Say hellomanaskhairnar1511@gmail.com
derpx06
NORMALmain© 2026 Derpx06Pune, Indiatop ↑
Learn/LangChain Mastery/Part 7 · 6. Memory & State Management
Lesson 49 of 68

ConversationSummaryMemory

Compressing the past. Recall vs Resolution.

Derpx0610 Jan · 1 min read
LangChain Mastery
Why Memory Breaks SystemsConversationBuffer & Window MemoryConversationSummaryMemoryEntity MemorySession IsolationPersistence Layers (Redis / DB)
Contents
1. The Compression Strategy2. How It Works3. The Trade-offsA. Lossy CompressionB. Latency & Cost4. Summary
0% read · 1 min leftBack to top ↑
Course outline & contents0%
LangChain Mastery
Why Memory Breaks SystemsConversationBuffer & Window MemoryConversationSummaryMemoryEntity MemorySession IsolationPersistence Layers (Redis / DB)
Contents
1. The Compression Strategy2. How It Works3. The Trade-offsA. Lossy CompressionB. Latency & Cost4. Summary

1. The Compression Strategy

If you can't keep every word, maybe you can keep the gist. ConversationSummaryMemory uses an LLM to rewrite the history as it grows.

Turn 1:

  • History: "User: My name is Bob. I like coding."
  • Summary: "User's name is Bob. He likes coding."

Turn 2:

  • History: "+ User: What is my favorite hobby?"
  • New Summary: "User (Bob) asked about his hobby (coding)."

2. How It Works

It maintains a running summary. Every time a new message comes in, it triggers an internal LLM call: LLM(Old Summary + New Message) -> New Summary This new summary is then injected into the System Prompt of the next turn.

summary_memory.py
from langchain.memory import ConversationSummaryMemory

memory = ConversationSummaryMemory(llm=llm)
# The prompt will receive: "Current Summary: Bob is a coder..."

3. The Trade-offs

A. Lossy Compression

Every time you summarize, you lose detail.

  • Original: "I am allergic to peanuts."
  • Summary: "User has dietary restrictions."
  • Result: AI offers almond butter (which might be cross-contaminated).

B. Latency & Cost

You are doubling your LLM calls. 1 call to summarize. 1 call to answer. This gets expensive fast.

4. Summary

Summary memory extends the effective window indefinitely, but at the cost of resolution. Use it when "Global Context" matters more than "Exact Phrasing."

Key Intuition: "It's like a blurry JPEG of the conversation."

Track your progressSign in and your progress follows you across devices.
Sign in to track progress Next lesson
← Previous lessonConversationBuffer & Window MemoryNext lesson →Entity Memory