Course contentsShow
← AI Engineering
Lesson 510 of 1,88613. LLM Orchestration FrameworksFree lesson

Memory: Summary and Window Memory

Managing long conversations with summarization memory and sliding window memory to control context length.

Memory: Summary and Window Memory

You'll learn: How to handle long conversations by either summarizing the history or keeping only the most recent messages to avoid overwhelming your model's context window.

The Challenge of Long Conversations

Remember ConversationBufferMemory from the previous lesson? It stores everything—which works great until your conversation gets so long that you hit token limits or slow down your model. Imagine recording every word you've ever said to someone; at some point, you can't carry all that history around efficiently.

Summarization Memory

Summarization memory periodically compresses older conversation turns into a summary. Instead of keeping 50 message pairs word-for-word, it uses an LLM to create a brief summary of what happened earlier, then keeps only recent messages in full.

Analogy: Like taking meeting notes instead of recording every word—you capture the key points and move on.

In LangChain, ConversationSummaryMemory automatically summarizes older exchanges when the conversation grows, keeping your context lean while preserving essential information.

Sliding Window Memory

Window memory (or ConversationBufferWindowMemory) takes a simpler approach: keep only the last N message pairs. Everything older just falls off the edge.

Analogy: Like a scrolling chat window that only shows the most recent 10 messages—older ones disappear, but you stay focused on the current thread.

This is faster (no summarization step) but loses older context completely. It's perfect for conversations where recent exchanges matter most.

When to Use Which

  • Summary memory: For long sessions where early context matters (customer support, tutoring)
  • Window memory: For reactive tasks where only recent turns are relevant (quick Q&A, transactional bots)

Key Takeaway: When conversations grow too long, use summary memory to compress history intelligently or window memory to keep only recent turns—both prevent context overflow while maintaining usable conversation state.