Skip to content

Conversation

MackinnonBuck
Copy link
Member

@MackinnonBuck MackinnonBuck commented Oct 9, 2025

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:

  1. FunctionCallContent and FunctionResultContent now get preserved in the returned message list.
  2. To avoid orphaning assistant responses from their user messages, the reducer searches backward within the threshold window for a user message boundary, keeping up to targetCount + threshold messages.

Fixes #6890

Microsoft Reviewers: Open in CodeFlow

@MackinnonBuck MackinnonBuck requested a review from a team as a code owner October 9, 2025 23:26
@MackinnonBuck MackinnonBuck requested review from Copilot and removed request for a team October 9, 2025 23:26
@github-actions github-actions bot added the area-ai Microsoft.Extensions.AI libraries label Oct 9, 2025
Copy link
Contributor

@Copilot 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

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 and FunctionResultContent 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

// 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))
Copy link
Member

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
Copy link
Member

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area-ai Microsoft.Extensions.AI libraries

Projects

None yet

Development

Successfully merging this pull request may close these issues.

SummarizingChatReducer removes all FunctionCallContents and FunctionResultContents

2 participants