Learn/LangChain Mastery/Part 7 · 6. Memory & State Management
Lesson 49 of 68
SyllabusLangChain Mastery · Part 7

ConversationSummaryMemory

Compressing the past. Recall vs Resolution.

Course outline & contents
LangChain Mastery
Why Memory Breaks SystemsConversationBuffer & Window MemoryConversationSummaryMemoryEntity MemorySession IsolationPersistence Layers (Redis / DB)

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)."

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..."

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).

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

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