ChatReducerCompactionStrategy Class

Definition

A compaction strategy that delegates to an IChatReducer to reduce the conversation's included messages.

public sealed class ChatReducerCompactionStrategy : Microsoft.Agents.AI.Compaction.CompactionStrategy
type ChatReducerCompactionStrategy = class
    inherit CompactionStrategy
Public NotInheritable Class ChatReducerCompactionStrategy
Inherits CompactionStrategy
Inheritance
ChatReducerCompactionStrategy

Remarks

This strategy bridges the IChatReducer abstraction from Microsoft.Extensions.AI into the compaction pipeline. It collects the currently included messages from the CompactionMessageIndex, passes them to the reducer, and rebuilds the index from the reduced message list when the reducer produces fewer messages.

The CompactionTrigger controls when reduction is attempted. Use CompactionTriggers for common trigger conditions such as token or message thresholds.

Use this strategy when you have an existing IChatReducer implementation (such as MessageCountingChatReducer) and want to apply it as part of a CompactionStrategy pipeline or as an in-run compaction strategy.

Constructors

Name Description
ChatReducerCompactionStrategy(IChatReducer, CompactionTrigger)

Initializes a new instance of the ChatReducerCompactionStrategy class.

Properties

Name Description
ChatReducer

Gets the chat reducer used to reduce messages.

Target

Gets the target predicate that controls when compaction stops. Strategies re-evaluate this after each incremental exclusion and stop when it returns true.

(Inherited from CompactionStrategy)
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.

Applies to