CompactionProvider 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 AIContextProvider that applies a CompactionStrategy to compact the message list before each agent invocation.
public sealed class CompactionProvider : Microsoft.Agents.AI.AIContextProvider
type CompactionProvider = class
inherit AIContextProvider
Public NotInheritable Class CompactionProvider
Inherits AIContextProvider
- Inheritance
Remarks
This provider performs in-run compaction by organizing messages into atomic groups (preserving tool-call/result pairings) before applying compaction logic. Only included messages are forwarded to the agent's underlying chat client.
The CompactionProvider can be added to an agent's context provider pipeline via AIContextProviders or via UseAIContextProviders on a ChatClientBuilder or AIAgentBuilder.
Constructors
| Name | Description |
|---|---|
| CompactionProvider(CompactionStrategy, String, ILoggerFactory) |
Initializes a new instance of the CompactionProvider class. |
Properties
| Name | Description |
|---|---|
| ProvideInputMessageFilter |
Gets the filter function to apply to input messages before providing context via ProvideAIContextAsync(AIContextProvider+InvokingContext, CancellationToken). (Inherited from AIContextProvider) |
| StateKeys |
Gets the set of keys used to store the provider state in the StateBag. |
| StoreInputRequestMessageFilter |
Gets the filter function to apply to request messages before storing context via StoreAIContextAsync(AIContextProvider+InvokedContext, CancellationToken). (Inherited from AIContextProvider) |
| StoreInputResponseMessageFilter |
Gets the filter function to apply to response messages before storing context via StoreAIContextAsync(AIContextProvider+InvokedContext, CancellationToken). (Inherited from AIContextProvider) |
Methods
| Name | Description |
|---|---|
| CompactAsync(CompactionStrategy, IEnumerable<ChatMessage>, ILogger, CancellationToken) |
Applies compaction strategy to the provided message list and returns the compacted messages. This can be used for ad-hoc compaction outside of the provider pipeline. |
| GetService(Type, Object) |
Asks the AIContextProvider for an object of the specified type |
| GetService<TService>(Object) |
Asks the AIContextProvider for an object of type |
| InvokedAsync(AIContextProvider+InvokedContext, CancellationToken) |
Called at the end of the agent invocation to process the invocation results. (Inherited from AIContextProvider) |
| InvokedCoreAsync(AIContextProvider+InvokedContext, CancellationToken) |
Called at the end of the agent invocation to process the invocation results. (Inherited from AIContextProvider) |
| InvokingAsync(AIContextProvider+InvokingContext, CancellationToken) |
Called at the start of agent invocation to provide additional context. (Inherited from AIContextProvider) |
| InvokingCoreAsync(AIContextProvider+InvokingContext, CancellationToken) |
Called at the start of agent invocation to provide additional context. (Inherited from AIContextProvider) |
| ProvideAIContextAsync(AIContextProvider+InvokingContext, CancellationToken) |
When overridden in a derived class, provides additional AI context to be merged with the input context for the current invocation. (Inherited from AIContextProvider) |
| StoreAIContextAsync(AIContextProvider+InvokedContext, CancellationToken) |
When overridden in a derived class, processes invocation results at the end of the agent invocation. (Inherited from AIContextProvider) |