Class SummarizingChatReducer
- Namespace
- Oscova.Agents.Reducers
- Assembly
- Oscova.Agents.dll
Compacts conversation history by stripping older tool chatter and summarizing older turns.
public class SummarizingChatReducer : IChatReducerInheritance
Implements
-
IChatReducer
Inherited Members
Remarks
Custom reducer kept instead of Microsoft.Extensions.AI's experimental SummarizingChatReducer: that reducer triggers on message count only; this one budgets by tokens derived from the model's context window, exposes the pre-compaction flush hook, and renders a user-editable Scriban summarization prompt.
Constructors
- SummarizingChatReducer(IChatClient, int, double)
-
Compacts conversation history by stripping older tool chatter and summarizing older turns.
Fields
- DefaultMaxTokenCount
-
Historical default history budget used when the provider context window is unknown.
- DefaultSummarizationPrompt
-
Default Scriban prompt used to ask the model for a compact conversation summary.
- MinimumHistoryBudget
-
Lowest derived history budget allowed for small-context models.
Properties
- MaxTokenCount
-
Gets the token budget this reducer compacts toward.
- OnBeforeCompaction
-
Async callback invoked before compaction begins. Awaited before any history is stripped or summarized. Use this to flush important context (e.g., to daily logs) before the chat history is compacted.
- OnCompactionCompleted
-
Invoked when compaction completes (or fails).
- OnCompactionStarted
-
Invoked when compaction begins.
- SummarizationPrompt
-
Gets or sets the Scriban prompt template used for summarization.
Methods
- CompactAsync(IEnumerable<ChatMessage>, CancellationToken)
-
Compacts older conversation history even when the automatic threshold has not been reached.
- DeriveHistoryBudget(int, int?)
-
Derives the history token budget from a model's context window, reserving room for model output and for prompt content the reducer never sees (instructions, tools, memory). Unknown window sizes keep the historical default.
- ReduceAsync(IEnumerable<ChatMessage>, CancellationToken)
-
Reduces the size of a list of chat messages.