Skip to content

.NET: Fix Structured Output for agents configured with function middleware#4179

Merged
SergeyMenshykh merged 1 commit intomicrosoft:mainfrom
SergeyMenshykh:fix/function-invocation-preserve-options
Feb 23, 2026
Merged

.NET: Fix Structured Output for agents configured with function middleware#4179
SergeyMenshykh merged 1 commit intomicrosoft:mainfrom
SergeyMenshykh:fix/function-invocation-preserve-options

Conversation

@SergeyMenshykh
Copy link
Member

@SergeyMenshykh SergeyMenshykh commented Feb 23, 2026

Summary

Fixes incomplete property preservation in FunctionInvocationDelegatingAgent.AgentRunOptionsWithFunctionMiddleware() when converting base AgentRunOptions to ChatClientAgentRunOptions.

Changes

  • FunctionInvocationDelegatingAgent.cs — Copy all base AgentRunOptions properties (AllowBackgroundResponses, ContinuationToken, AdditionalProperties) when converting to ChatClientAgentRunOptions.
  • FunctionInvocationDelegatingAgentTests.cs — Added unit test using an AnonymousDelegatingAIAgent spy to verify all original properties are preserved after conversion.

Closes: #4118

Copilot AI review requested due to automatic review settings February 23, 2026 14:06
@SergeyMenshykh SergeyMenshykh changed the title .NET: Fix FunctionInvocationDelegatingAgent to preserve all AgentRunOptions properties .NET: Fix Structured Output for agents configured with function middleware Feb 23, 2026
@SergeyMenshykh SergeyMenshykh self-assigned this Feb 23, 2026
@SergeyMenshykh SergeyMenshykh moved this to In Review in Agent Framework Feb 23, 2026
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

Fixes FunctionInvocationDelegatingAgent.AgentRunOptionsWithFunctionMiddleware() so that when it converts a base AgentRunOptions into ChatClientAgentRunOptions, it preserves all relevant base properties instead of dropping them.

Changes:

  • Copy AllowBackgroundResponses, ContinuationToken, and AdditionalProperties (in addition to ResponseFormat) during AgentRunOptionsChatClientAgentRunOptions conversion.
  • Add a unit test that captures the converted options passed to an inner agent to verify preservation behavior.

Reviewed changes

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

File Description
dotnet/src/Microsoft.Agents.AI/FunctionInvocationDelegatingAgent.cs Updates the conversion logic to carry over base AgentRunOptions properties into ChatClientAgentRunOptions.
dotnet/tests/Microsoft.Agents.AI.UnitTests/FunctionInvocationDelegatingAgentTests.cs Adds a test to validate that options are preserved during the conversion path.

…ptions properties

When converting base AgentRunOptions to ChatClientAgentRunOptions, the middleware
now preserves AllowBackgroundResponses, ContinuationToken, and AdditionalProperties
in addition to ResponseFormat.

Added unit test verifying all properties are preserved during the conversion.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

.NET: [Bug]: RC1's AIAgent.RunAsync<T> does not work with FunctionCallingMiddleware

5 participants