Compressing the past. Recall vs Resolution.
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:
Turn 2:
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.
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.
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."