.NET: Preserve opening user message in history during compaction tool-call loops - #8461
Open
banned2054 wants to merge 1 commit into
Open
banned2054 wants to merge 1 commit into
banned2054 wants to merge 1 commit into
Conversation
Contributor
There was a problem hiding this comment.
🟢 Approval recommended
The focused fix correctly isolates message metadata and includes comprehensive regression coverage for both execution paths.
Pull request overview
Fixes #8441 by isolating compaction state from caller-owned messages, preserving the opening user message during tool-call loops.
Changes:
- Clone messages and property dictionaries before compaction indexing.
- Add mutation and sync/streaming tool-loop regression tests.
File summaries
| File | Description |
|---|---|
dotnet/src/Microsoft.Agents.AI/Compaction/CompactionProvider.cs |
Prevents source-attribution mutations from leaking to input messages. |
dotnet/tests/Microsoft.Agents.AI.UnitTests/Compaction/CompactionProviderTests.cs |
Tests input-message isolation. |
dotnet/tests/Microsoft.Agents.AI.UnitTests/ChatClient/ChatClientAgent_ChatHistoryManagementTests.cs |
Tests complete history persistence for synchronous and streaming tool loops. |
Review details
- Files reviewed: 3/3 changed files
- Comments generated: 0
- Review effort level: Balanced
💡 Add a code-review agent skill for context-aware, tailored reviews. Learn more in the docs.
Author
|
@microsoft-github-policy-service agree |
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 & Context
When a CompactionProvider runs inside a function-calling loop, the opening user message can be omitted from InMemoryChatHistoryProvider even when the compaction threshold is never reached. On the second model call, the provider marks previously indexed messages as ChatHistory. Because those messages share instances with the original request, the history provider then filters out the opening user message when persisting the run.
This change preserves the opening request alongside the tool call, tool result, and final response.
Description & Review Guide
Related Issue
Fixes #8441
Contribution Checklist