Skip to main content
Conversation summarization helps manage long conversation histories by condensing older messages while preserving important context. This is essential for maintaining context in extended conversations without exceeding token limits or performance constraints.

Overview

The SDK provides two types of summarizers:
  1. LLM Summarizer: Uses an LLM to intelligently summarize conversation history while preserving important context
  2. Sliding Window Summarizer: Keeps only the most recent N conversation runs and discards older messages
Summarizers are integrated with conversation managers and automatically trigger when certain conditions are met (e.g., token threshold for LLM summarizer, or when the number of runs exceeds the window size for sliding window).

LLM Summarizer

The LLM summarizer uses an LLM to create intelligent summaries of conversation history. It triggers when the total token count exceeds a specified threshold, keeping recent messages intact and summarizing older ones.

Configuration

Parameters

  • LLM: The LLM provider to use for summarization (can be different from the agent’s LLM)
  • Instruction: System prompt that defines how the summarizer should summarize conversations
  • TokenThreshold: The token count threshold at which summarization triggers
  • KeepRecentCount: Number of recent conversation runs to keep unsummarized (default: 5)
  • Parameters: Optional LLM parameters (temperature, etc.) for the summarization call

How It Works

  1. When messages are loaded, the summarizer checks if the total token count exceeds the threshold
  2. If the threshold is exceeded and there are enough messages, it groups messages by run ID
  3. It keeps the most recent KeepRecentCount runs intact
  4. Older runs are summarized into a single system message using the LLM
  5. The summary replaces the old messages, preserving context while reducing token usage

Sliding Window Summarizer

The sliding window summarizer keeps only the most recent N conversation runs and discards older ones. This is a simple, cost-effective approach that doesn’t require an LLM.

Configuration

Parameters

  • KeepCount: The number of recent conversation runs to retain. Older runs are discarded.

How It Works

  1. Messages are grouped by their run ID
  2. If the number of runs exceeds KeepCount, only the most recent KeepCount runs are kept
  3. Older runs are discarded without creating a summary
  4. This approach is simple and cost-effective but loses older context completely

Using Summarizers with Conversation Managers

To use a summarizer, pass it to the conversation manager using history.WithSummarizer():

Complete Example: LLM Summarizer

Here’s a complete example using an LLM summarizer:

Complete Example: Sliding Window Summarizer

Here’s a complete example using a sliding window summarizer: