Skip to content

.NET: Add context window size compaction strategy for harness#5304

Merged
westey-m merged 3 commits intomicrosoft:feature-harnessfrom
westey-m:harness-compaction
Apr 16, 2026
Merged

.NET: Add context window size compaction strategy for harness#5304
westey-m merged 3 commits intomicrosoft:feature-harnessfrom
westey-m:harness-compaction

Conversation

@westey-m
Copy link
Copy Markdown
Contributor

Motivation and Context

Adding an opinionated compaction strategy that is easy to use based on context window size.

Description

  • Add context window size compaction strategy for harness

Contribution Checklist

  • The code builds clean without any errors or warnings
  • The PR follows the Contribution Guidelines
  • All unit tests pass, and I have added new tests where possible
  • Is this a breaking change? If yes, add "[BREAKING]" prefix to the title of the PR.

Copilot AI review requested due to automatic review settings April 16, 2026 11:13
@moonbox3 moonbox3 added the .NET label Apr 16, 2026
@github-actions github-actions bot changed the title Add context window size compaction strategy for harness .NET: Add context window size compaction strategy for harness Apr 16, 2026
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

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.

Comment thread dotnet/samples/02-agents/Harness/Harness_Step01_Research/Program.cs
Comment thread dotnet/src/Microsoft.Agents.AI/Compaction/ContextWindowCompactionStrategy.cs Outdated
Comment thread dotnet/samples/02-agents/Harness/Harness_Shared_Console/HarnessConsole.cs Outdated
Comment thread dotnet/src/Microsoft.Agents.AI/Compaction/ContextWindowCompactionStrategy.cs Outdated
Comment thread dotnet/samples/02-agents/Harness/Harness_Step01_Research/Program.cs Outdated
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Copy link
Copy Markdown
Contributor Author

@westey-m westey-m left a comment

Choose a reason for hiding this comment

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

Replying to open review comments with fixes applied — see individual thread replies below.

@moonbox3 moonbox3 added the documentation Improvements or additions to documentation label Apr 16, 2026
@westey-m westey-m merged commit d0ac1d8 into microsoft:feature-harness Apr 16, 2026
13 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Improvements or additions to documentation .NET

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants