Skip to content

.NET: Add FinishReason to AgentResponses#4617

Merged
westey-m merged 2 commits intomicrosoft:mainfrom
westey-m:add-response-finishreason
Mar 11, 2026
Merged

.NET: Add FinishReason to AgentResponses#4617
westey-m merged 2 commits intomicrosoft:mainfrom
westey-m:add-response-finishreason

Conversation

@westey-m
Copy link
Contributor

Motivation and Context

It's currently difficult to determine when a ChatClientAgent completed because of content filtering, so adding FinishReason to AgentRunResponse, and mapping where we have enough data to do so.

#4556

Description

  • Add FinishReason to AgentResponse and AgentResponseUpdate

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 11, 2026 10:43
@markwallace-microsoft markwallace-microsoft added .NET workflows Related to Workflows in agent-framework labels Mar 11, 2026
@github-actions github-actions bot changed the title Add FinishReason to AgentResponses .NET: Add FinishReason to AgentResponses Mar 11, 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

Adds FinishReason to the .NET AgentResponse / AgentResponseUpdate abstractions so callers can detect non-normal completions (e.g., content filtering), and wires that value through key adapters/mergers.

Changes:

  • Added ChatFinishReason? FinishReason to AgentResponse and AgentResponseUpdate, including mapping to/from ChatResponse / ChatResponseUpdate.
  • Propagated finish reason through workflow merging and A2A agent conversions.
  • Updated/added unit tests validating defaults and propagation behavior.

Reviewed changes

Copilot reviewed 12 out of 12 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
dotnet/src/Microsoft.Agents.AI.Abstractions/AgentResponse.cs Adds FinishReason property; maps from ChatResponse; includes in ToAgentResponseUpdates().
dotnet/src/Microsoft.Agents.AI.Abstractions/AgentResponseUpdate.cs Adds FinishReason property; maps from ChatResponseUpdate.
dotnet/src/Microsoft.Agents.AI.Abstractions/AgentResponseExtensions.cs Ensures FinishReason round-trips when converting to ChatResponse/ChatResponseUpdate.
dotnet/src/Microsoft.Agents.AI.Workflows/MessageMerger.cs Carries FinishReason into merged workflow response.
dotnet/src/Microsoft.Agents.AI.A2A/A2AAgent.cs Sets/mapps FinishReason for A2A message/task responses and streaming updates.
dotnet/src/Microsoft.Agents.AI.Hosting.OpenAI/ChatCompletions/AgentResponseExtensions.cs Uses AgentResponse.FinishReason when producing OpenAI-style choices.
dotnet/src/Microsoft.Agents.AI.Hosting.OpenAI/ChatCompletions/AIAgentChatCompletionsProcessor.cs Uses AgentResponseUpdate.FinishReason for streaming chunk finish reason.
dotnet/tests/Microsoft.Agents.AI.Workflows.UnitTests/MessageMergerTests.cs Adds coverage for merged FinishReason behavior.
dotnet/tests/Microsoft.Agents.AI.Abstractions.UnitTests/AgentResponseUpdateTests.cs Verifies default/null and round-tripping for AgentResponseUpdate.FinishReason.
dotnet/tests/Microsoft.Agents.AI.Abstractions.UnitTests/AgentResponseUpdateExtensionsTests.cs Verifies conversion helpers preserve FinishReason.
dotnet/tests/Microsoft.Agents.AI.Abstractions.UnitTests/AgentResponseTests.cs Verifies default/null and round-tripping for AgentResponse.FinishReason + update generation.
dotnet/tests/Microsoft.Agents.AI.A2A.UnitTests/A2AAgentTests.cs Updates assertions to validate FinishReason for A2A runs/streams.

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

Labels

.NET workflows Related to Workflows in agent-framework

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants