SummarizationCompactionStrategy Class
Definition
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
A compaction strategy that uses an LLM to summarize older portions of the conversation, replacing them with a single summary message that preserves key facts and context.
public sealed class SummarizationCompactionStrategy : Microsoft.Agents.AI.Compaction.CompactionStrategy
type SummarizationCompactionStrategy = class
inherit CompactionStrategy
Public NotInheritable Class SummarizationCompactionStrategy
Inherits CompactionStrategy
- Inheritance
Remarks
This strategy protects system messages and the most recent MinimumPreservedGroups non-system groups. All older groups are collected and sent to the IChatClient for summarization. The resulting summary replaces those messages as a single assistant message with Summary.
MinimumPreservedGroups is a hard floor: even if the Target has not been reached, compaction will not touch the last MinimumPreservedGroups non-system groups.
The CompactionTrigger predicate controls when compaction proceeds. Use CompactionTriggers for common trigger conditions such as token thresholds.
Constructors
| Name | Description |
|---|---|
| SummarizationCompactionStrategy(IChatClient, CompactionTrigger, Int32, String, CompactionTrigger) |
Initializes a new instance of the SummarizationCompactionStrategy class. |
Fields
| Name | Description |
|---|---|
| DefaultMinimumPreserved |
The default minimum number of most-recent non-system groups to preserve. |
| DefaultSummarizationPrompt |
The default summarization prompt used when none is provided. |
Properties
| Name | Description |
|---|---|
| ChatClient |
Gets the chat client used for generating summaries. |
| MinimumPreservedGroups |
Gets the minimum number of most-recent non-system groups that are always preserved. This is a hard floor that compaction cannot exceed, regardless of the target condition. |
| SummarizationPrompt |
Gets the prompt used when requesting summaries from the chat client. |
| Target |
Gets the target predicate that controls when compaction stops.
Strategies re-evaluate this after each incremental exclusion and stop when it returns |
| Trigger |
Gets the trigger predicate that controls when compaction proceeds. (Inherited from CompactionStrategy) |
Methods
| Name | Description |
|---|---|
| CompactAsync(CompactionMessageIndex, ILogger, CancellationToken) |
Evaluates the Trigger and, when it fires, delegates to CompactCoreAsync(CompactionMessageIndex, ILogger, CancellationToken) and reports compaction metrics. (Inherited from CompactionStrategy) |
| CompactCoreAsync(CompactionMessageIndex, ILogger, CancellationToken) |
Applies the strategy-specific compaction logic to the specified message index. (Inherited from CompactionStrategy) |
Extension Methods
| Name | Description |
|---|---|
| AsChatReducer(CompactionStrategy) |
Returns an IChatReducer that applies this CompactionStrategy to reduce a list of messages. |