.NET Compaction - Introduce preconfigured CompactionStrategy pattern#4665
Open
.NET Compaction - Introduce preconfigured CompactionStrategy pattern#4665
CompactionStrategy pattern#4665Conversation
…eate() factory Co-authored-by: crickman <66376200+crickman@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Add preconfigured CompactionStrategy pattern
.NET Compaction - Introduce preconfigured Mar 12, 2026
CompactionStrategy pattern
Contributor
There was a problem hiding this comment.
Pull request overview
This PR introduces a preconfigured compaction “menu” for the .NET Agent Framework, adding a CompactionStrategy.Create(approach, size, chatClient?) factory that maps high-level options to a tuned PipelineCompactionStrategy.
Changes:
- Added
CompactionApproachandCompactionSizeenums to represent the two configuration axes. - Implemented
CompactionStrategy.Create(...)factory to generate Gentle/Balanced/Aggressive pipelines with staged triggers. - Added unit tests validating pipeline composition, argument validation, and (partially) size behavior.
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 8 comments.
Show a summary per file
| File | Description |
|---|---|
| dotnet/src/Microsoft.Agents.AI/Compaction/CompactionStrategy.cs | Marks CompactionStrategy as partial to allow adding the factory in a separate file. |
| dotnet/src/Microsoft.Agents.AI/Compaction/CompactionStrategy.Factory.cs | Adds CompactionStrategy.Create(...) and internal size→threshold mappings for pipeline construction. |
| dotnet/src/Microsoft.Agents.AI/Compaction/CompactionApproach.cs | Adds the CompactionApproach enum describing pipeline composition choices. |
| dotnet/src/Microsoft.Agents.AI/Compaction/CompactionSize.cs | Adds the CompactionSize enum describing context-size profiles. |
| dotnet/tests/Microsoft.Agents.AI.UnitTests/Compaction/CompactionStrategyCreateTests.cs | Adds unit tests for the new factory method and size differentiation behavior. |
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
westey-m
approved these changes
Mar 19, 2026
peibekwe
reviewed
Mar 27, 2026
peibekwe
approved these changes
Mar 27, 2026
…://github.com/microsoft/agent-framework into copilot/add-preconfigured-compaction-strategy
peibekwe
approved these changes
Mar 27, 2026
github-merge-queue Bot
pushed a commit
that referenced
this pull request
Mar 28, 2026
#4665) * Initial plan * Add CompactionApproach/CompactionSize enums and CompactionStrategy.Create() factory Co-authored-by: crickman <66376200+crickman@users.noreply.github.com> * Cleanup * Potential fix for pull request finding Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com> * Potential fix for pull request finding Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com> * Comments * Updated * Add "count" term --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: crickman <66376200+crickman@users.noreply.github.com> Co-authored-by: Chris Rickman <crickman@microsoft.com> Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Developers shouldn't need to understand internal strategy parameters to get a well-tuned compaction pipeline. This adds a
CompactionStrategy.Create(approach, size, chatClient?)factory that maps two intuitive axes to a pre-configuredPipelineCompactionStrategy.New types
CompactionApproach— controls pipeline composition:Gentle: tool-result collapsing + LLM summarizationBalanced: tool-result collapsing + LLM summarization + truncation backstopAggressive: tool-result collapsing + LLM summarization + sliding window + truncationCompactionSize— scales all trigger thresholds to match model context capacity:Compact≈ 8 K tokens,Moderate≈ 32 K tokens,Generous≈ 64 K tokensFactory logic
Within each pipeline, early stages trigger at a fraction of the size limit (⅔ for
Balanced, ½ forAggressive) so incremental compaction fires before reaching the emergency truncation backstop.Usage
chatClientis required (and validated) only whenapproachisBalancedorAggressive.Contribution Checklist
Original prompt
CompactionStrategypattern #4603💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.