Skip to content

.NET: Clarify compaction provider and chat reducer choices - #7678

Draft
Ravi Kiran Pagidi (ravikiranpagidi) wants to merge 1 commit into
microsoft:mainfrom
ravikiranpagidi:agent/docs-compaction-vs-reducer
Draft

.NET: Clarify compaction provider and chat reducer choices#7678
Ravi Kiran Pagidi (ravikiranpagidi) wants to merge 1 commit into
microsoft:mainfrom
ravikiranpagidi:agent/docs-compaction-vs-reducer

Conversation

@ravikiranpagidi

Copy link
Copy Markdown

Motivation & Context

CompactionProvider and Microsoft.Extensions.AI's IChatReducer can both reduce the messages supplied to a model, but they run at different lifecycle points and have different persistence behavior. The existing compaction sample did not give users a clear way to choose between them or explain the two adapters, which led to confusion about whether they should be composed together.

This documentation makes that decision explicit and addresses #4608 without changing runtime behavior or public API.

Description & Review Guide

  • What are the major changes? Add a decision table comparing builder-level and agent-level CompactionProvider registration with IChatReducer on InMemoryChatHistoryProvider; document reducer trigger events; show each supported adapter direction; and update the sample index so the guidance is discoverable.
  • What is the impact of these changes? Users can choose request-only compaction when they need to preserve complete history, or persistent history reduction when they need to bound stored session state. The adapter examples also clarify that wrapping a strategy into a reducer and immediately back into a strategy is redundant.
  • What do you want reviewers to focus on? Please verify the lifecycle and persistence descriptions, especially the distinction between chat-client-builder and agent-level context providers.

Related Issue

Fixes #4608

Contribution Checklist

  • The code builds clean without any errors or warnings
  • All unit tests pass, and I have added new tests where possible
  • The PR follows the Contribution Guidelines
  • This PR is linked to an issue and there is no other open PR for this issue (see Related Issue above).
  • This is not a breaking change. If it is a breaking change, add the breaking change label (or add "[BREAKING]" to the title prefix, before or after a language prefix such as .NET:) — workflows keep the label and title prefix in sync automatically.

Copilot AI balanced review requested due to automatic review settings August 15, 2026 14:31
@agent-framework-automation agent-framework-automation Bot added documentation Usage: [Issues, PRs], Target: documentation in the code base and learn docs .NET Usage: [Issues, PRs], Target: .Net labels Aug 15, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Note

Copilot was unable to run its full agentic suite in this review.

Updates the Step 18 compaction pipeline documentation to clarify where to apply compaction vs. reduction, and refreshes the sample index entry to match the expanded guidance.

Changes:

  • Expanded Step 18 README with a comparison of CompactionProvider vs IChatReducer, including adapter examples and guidance.
  • Updated the Agents sample index description for the compaction pipeline step to reflect the new guidance.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
dotnet/samples/02-agents/Agents/README.md Updates the Step 18 row description to mention provider vs reducer integration.
dotnet/samples/02-agents/Agents/Agent_Step18_CompactionPipeline/README.md Adds detailed guidance, a comparison table, and adapter examples for compaction vs reduction.

💡 Add a code-review agent skill for context-aware, tailored reviews. Learn more in the docs.

Comment on lines +21 to +25
| Choose | When you need | Effect on stored history | Function-calling loop |
|---|---|---|---|
| `CompactionProvider` on `ChatClientBuilder.UseAIContextProviders(...)` | Request-context management that preserves the original conversation | The compacted view is forwarded to the inner chat client; the source history remains unchanged | Runs for each inner chat-client call, including calls made while tools are being invoked |
| `CompactionProvider` in `ChatClientAgentOptions.AIContextProviders` | Agent-specific compaction without decorating a shared chat client | Runs before chat history is stored, so generated replacement messages can become part of the persisted history | Runs at the agent boundary, not for each call inside the tool loop |
| `IChatReducer` in `InMemoryChatHistoryProviderOptions.ChatReducer` | Storage management where the reduced list should replace the session's in-memory history | Permanently replaces the provider's stored message list with the reducer output | Runs at the configured history-provider event, not for each call inside the tool loop |
Comment on lines +46 to +50
InMemoryChatHistoryProvider historyProvider = new(new()
{
ChatReducer = strategy.AsChatReducer(),
ReducerTriggerEvent = InMemoryChatHistoryProviderOptions.ChatReducerTriggerEvent.BeforeMessagesRetrieval
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Usage: [Issues, PRs], Target: documentation in the code base and learn docs .NET Usage: [Issues, PRs], Target: .Net

Projects

None yet

Development

Successfully merging this pull request may close these issues.

.NET Compaction - Distinguish compaction from MEAI concepts

2 participants