Hi!
I'm wondering what the difference is between defining a compaction strategy like this:
var compactionStrategy = new ContextWindowCompactionStrategy(
maxContextWindowTokens: 4000,
maxOutputTokens: 800);
var agent = chatClient
.AsAIAgent(new ChatClientAgentOptions
{
ChatOptions = new()
{
Instructions = "You are a helpful assistant.",
},
AIContextProviders = [new CompactionProvider(compactionStrategy)]
});
and instead of using it as a ChatReducer:
var agent = chatClient
.AsAIAgent(new ChatClientAgentOptions
{
ChatOptions = new()
{
Instructions = "You are a helpful assistant.",
},
ChatHistoryProvider = new InMemoryChatHistoryProvider(new()
{
ChatReducer = compactionStrategy.AsChatReducer()
})
});
I'm asking because I read the documentation at https://learn.microsoft.com/en-us/agent-framework/agents/conversations/compaction?#registering-through-chatclientagentoptions, but it doesn't mention using the compaction strategy as a ChatReducer.
More generally, what is the recommended way to register a compaction strategy? For example, in Agent Harness I noticed that the strategy is registered both as a ChatReducer and via UseAIContextProviders(...) on the ChatClientBuilder:
|
ChatReducer = compactionStrategy.AsChatReducer(), |
|
chatClientBuilder = chatClientBuilder.UseAIContextProviders(compactionProvider); |
Should one of these approaches be preferred, or do they serve different purposes?
Hi!
I'm wondering what the difference is between defining a compaction strategy like this:
and instead of using it as a
ChatReducer:I'm asking because I read the documentation at https://learn.microsoft.com/en-us/agent-framework/agents/conversations/compaction?#registering-through-chatclientagentoptions, but it doesn't mention using the compaction strategy as a ChatReducer.
More generally, what is the recommended way to register a compaction strategy? For example, in Agent Harness I noticed that the strategy is registered both as a
ChatReducerand viaUseAIContextProviders(...)on theChatClientBuilder:agent-framework/dotnet/src/Microsoft.Agents.AI.Harness/HarnessAgent.cs
Line 195 in 7b6d257
agent-framework/dotnet/src/Microsoft.Agents.AI.Harness/HarnessAgent.cs
Line 241 in 7b6d257
Should one of these approaches be preferred, or do they serve different purposes?