Skip to content

.NET: [BREAKING] Trim final FRC to match service storage#4792

Open
westey-m wants to merge 6 commits intomicrosoft:mainfrom
westey-m:trime-final-frc
Open

.NET: [BREAKING] Trim final FRC to match service storage#4792
westey-m wants to merge 6 commits intomicrosoft:mainfrom
westey-m:trime-final-frc

Conversation

@westey-m
Copy link
Contributor

@westey-m westey-m commented Mar 19, 2026

Motivation and Context

#4791

Currently there is a mismatch in behavior between service stored chat history and ChatHistoryProvider stored chat history when function tools are terminated. This brings those behaviors into sync, with an opt out.
Also not notifying AIContextProviders to match chat history storage.

This change is a behavioral break, but only for very limited circumstances, e.g. when using function call termination.

Description

  • Don't store FRC when it is the last content in the response, which means it was generated without a subsequent service call.

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 March 19, 2026 16:30
Copy link
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

Aligns ChatHistoryProvider-backed chat history with service-side storage by trimming trailing FunctionResultContent when tool loops terminate, with an opt-out flag.

Changes:

  • Added ChatClientAgentRunOptions.StoreFinalFunctionResultContent (experimental) to control persistence of trailing FunctionResultContent.
  • Implemented response trimming of trailing tool-only FunctionResultContent before persisting to chat history (and currently also before AI context notification).
  • Added unit tests covering non-streaming/streaming behavior and cloning behavior for the new run option.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 5 comments.

File Description
dotnet/src/Microsoft.Agents.AI/ChatClient/ChatClientAgent.cs Filters trailing tool FunctionResultContent before notifying history/context providers.
dotnet/src/Microsoft.Agents.AI/ChatClient/ChatClientAgentRunOptions.cs Adds the nullable StoreFinalFunctionResultContent run option with detailed remarks.
dotnet/tests/Microsoft.Agents.AI.UnitTests/ChatClient/ChatClientAgentRunOptionsTests.cs Ensures the new run option is cloned correctly.
dotnet/tests/Microsoft.Agents.AI.UnitTests/ChatClient/ChatClientAgent_StoreFinalFunctionResultContentTests.cs Adds coverage for persistence trimming behavior (incl. streaming).

@westey-m westey-m changed the title Trim final FRC to match service storage [BREAKING] Trim final FRC to match service storage Mar 19, 2026
westey-m and others added 3 commits March 19, 2026 17:08
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
…ilterFinalFunctionResultContent to use IList
@TaoChenOSU TaoChenOSU added .NET needs_port_to_python Indicate this item needs to also be done for Python labels Mar 19, 2026
@github-actions github-actions bot changed the title [BREAKING] Trim final FRC to match service storage .NET: [BREAKING] Trim final FRC to match service storage Mar 19, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

needs_port_to_python Indicate this item needs to also be done for Python .NET

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants