.NET: Add context window size compaction strategy for harness#5304
Merged
westey-m merged 3 commits intomicrosoft:feature-harnessfrom Apr 16, 2026
Merged
.NET: Add context window size compaction strategy for harness#5304westey-m merged 3 commits intomicrosoft:feature-harnessfrom
westey-m merged 3 commits intomicrosoft:feature-harnessfrom
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
Adds an opinionated “context window size”-driven compaction strategy to the .NET Agent Framework and wires it into the Harness research sample to keep long-running sessions within token budgets.
Changes:
- Introduces
ContextWindowCompactionStrategy, which derives tool-eviction and truncation triggers from(maxContextWindowTokens - maxOutputTokens). - Adds unit tests covering constructor validation and basic compaction behavior.
- Updates the Harness Step01 Research sample to use the new compaction strategy and display token usage breakdown during streaming.
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/ContextWindowCompactionStrategy.cs | New strategy wrapping a compaction pipeline with thresholds computed from context window and output limits. |
| dotnet/tests/Microsoft.Agents.AI.UnitTests/Compaction/ContextWindowCompactionStrategyTests.cs | New unit tests for constructor validation and compacting behavior. |
| dotnet/samples/02-agents/Harness/Harness_Step01_Research/Program.cs | Uses the new strategy in the Harness sample; switches to Foundry endpoint env var and configures local history reduction. |
| dotnet/samples/02-agents/Harness/Harness_Step01_Research/Harness_Step01_Research.csproj | Adds a project reference needed for OpenAI Responses extensions used by the sample. |
| dotnet/samples/02-agents/Harness/Harness_Shared_Console/HarnessConsole.cs | Enhances streaming console output to show token usage/reasoning and adds optional context-window parameters. |
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
lokitoth
approved these changes
Apr 16, 2026
rogerbarreto
approved these changes
Apr 16, 2026
peibekwe
approved these changes
Apr 16, 2026
westey-m
commented
Apr 16, 2026
Contributor
Author
westey-m
left a comment
There was a problem hiding this comment.
Replying to open review comments with fixes applied — see individual thread replies below.
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.
Motivation and Context
Adding an opinionated compaction strategy that is easy to use based on context window size.
Description
Contribution Checklist