ChatStrategyExtensions.AsChatReducer(CompactionStrategy) Method

Definition

Returns an IChatReducer that applies this CompactionStrategy to reduce a list of messages.

public static Microsoft.Extensions.AI.IChatReducer AsChatReducer(this Microsoft.Agents.AI.Compaction.CompactionStrategy strategy);
static member AsChatReducer : Microsoft.Agents.AI.Compaction.CompactionStrategy -> Microsoft.Extensions.AI.IChatReducer
<Extension()>
Public Function AsChatReducer (strategy As CompactionStrategy) As IChatReducer

Parameters

strategy
CompactionStrategy

The compaction strategy to wrap as an IChatReducer.

Returns

An IChatReducer that, on each call to ReduceAsync(IEnumerable<ChatMessage>, CancellationToken), builds a CompactionMessageIndex from the supplied messages and applies the strategy's compaction logic, returning the resulting included messages.

Remarks

This allows any CompactionStrategy to be used wherever an IChatReducer is expected, bridging the compaction pipeline into systems bound to the Microsoft.Extensions.AIIChatReducer contract.

Applies to