-
Notifications
You must be signed in to change notification settings - Fork 838
Preserve function content in SummarizingChatReducer
#6908
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
Fixes an issue in SummarizingChatReducer
where function call content was being removed even when not summarized. The PR preserves function call and result content in the returned message list and improves message boundary detection to avoid orphaning assistant responses from their user messages.
Key changes:
- Preserves
FunctionCallContent
andFunctionResultContent
in message lists - Implements backward search within threshold window for user message boundaries
- Updates logic to keep complete function call sequences together
Reviewed Changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
File | Description |
---|---|
src/Libraries/Microsoft.Extensions.AI/ChatReduction/SummarizingChatReducer.cs |
Core implementation changes to preserve function content and improve message boundary detection |
test/Libraries/Microsoft.Extensions.AI.Tests/ChatReduction/SummarizingChatReducerTests.cs |
Updated and added tests to verify function content preservation and threshold behavior |
src/Libraries/Microsoft.Extensions.AI/ChatReduction/SummarizingChatReducer.cs
Show resolved
Hide resolved
// We want to keep complete function call sequences together with their responses | ||
while (indexOfFirstMessageToKeep > 0) | ||
{ | ||
if (!unsummarizedMessages[indexOfFirstMessageToKeep - 1].Contents.Any(c => c is FunctionCallContent or FunctionResultContent)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's also UserInputRequestContent / UserInputResponseContent. Does this need to pay attention to those as well?
// Start at the ideal cut point (keeping exactly targetCount messages) | ||
var indexOfFirstMessageToKeep = unsummarizedMessages.Count - targetCount; | ||
|
||
// Move backward to skip over function call/result content at the boundary |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So is this never getting rid of any FunctionCall/ResultContent? Does that mean in a really long conversation we could end up with lots and lots of these, and eventually still overflow context windows?
Summary
Fixes an issue where
SummarizingChatReducer
always removes function call content, even if it didn't get summarized.Description
This PR makes the following changes to
SummarizingChatReducer
:FunctionCallContent
andFunctionResultContent
now get preserved in the returned message list.targetCount + threshold
messages.Fixes #6890
Microsoft Reviewers: Open in CodeFlow