Skip to content

.NET: Add FinishReason to AgentResponses - #4617

Merged
westey (westey-m) merged 2 commits into
microsoft:mainfrom
westey-m:add-response-finishreason
Mar 11, 2026
Merged

.NET: Add FinishReason to AgentResponses#4617
westey (westey-m) merged 2 commits into
microsoft:mainfrom
westey-m:add-response-finishreason

Conversation

@westey-m

Copy link
Copy Markdown
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.

CopilotAI review requested due to automatic review settings March 11, 2026 10:43
@markwallace-microsoftMark Wallace (markwallace-microsoft) added .NET Usage: [Issues, PRs], Target: .Net workflows Usage: [Issues, PRs], Target: Workflows labels Mar 11, 2026
@github-actionsgithub-actionsBot changed the title Add FinishReason to AgentResponses.NET: Add FinishReason to AgentResponsesMar 11, 2026

CopilotAI left a comment

Copy link
Copy Markdown
Contributor

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
FileDescription
dotnet/src/Microsoft.Agents.AI.Abstractions/AgentResponse.csAdds FinishReason property; maps from ChatResponse; includes in ToAgentResponseUpdates().
dotnet/src/Microsoft.Agents.AI.Abstractions/AgentResponseUpdate.csAdds FinishReason property; maps from ChatResponseUpdate.
dotnet/src/Microsoft.Agents.AI.Abstractions/AgentResponseExtensions.csEnsures FinishReason round-trips when converting to ChatResponse/ChatResponseUpdate.
dotnet/src/Microsoft.Agents.AI.Workflows/MessageMerger.csCarries FinishReason into merged workflow response.
dotnet/src/Microsoft.Agents.AI.A2A/A2AAgent.csSets/mapps FinishReason for A2A message/task responses and streaming updates.
dotnet/src/Microsoft.Agents.AI.Hosting.OpenAI/ChatCompletions/AgentResponseExtensions.csUses AgentResponse.FinishReason when producing OpenAI-style choices.
dotnet/src/Microsoft.Agents.AI.Hosting.OpenAI/ChatCompletions/AIAgentChatCompletionsProcessor.csUses AgentResponseUpdate.FinishReason for streaming chunk finish reason.
dotnet/tests/Microsoft.Agents.AI.Workflows.UnitTests/MessageMergerTests.csAdds coverage for merged FinishReason behavior.
dotnet/tests/Microsoft.Agents.AI.Abstractions.UnitTests/AgentResponseUpdateTests.csVerifies default/null and round-tripping for AgentResponseUpdate.FinishReason.
dotnet/tests/Microsoft.Agents.AI.Abstractions.UnitTests/AgentResponseUpdateExtensionsTests.csVerifies conversion helpers preserve FinishReason.
dotnet/tests/Microsoft.Agents.AI.Abstractions.UnitTests/AgentResponseTests.csVerifies default/null and round-tripping for AgentResponse.FinishReason + update generation.
dotnet/tests/Microsoft.Agents.AI.A2A.UnitTests/A2AAgentTests.csUpdates assertions to validate FinishReason for A2A runs/streams.

Comment threaddotnet/src/Microsoft.Agents.AI.Workflows/MessageMerger.cs Outdated
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

.NETUsage: [Issues, PRs], Target: .NetworkflowsUsage: [Issues, PRs], Target: Workflows

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants

@westey-m@rogerbarreto@SergeyMenshykh@markwallace-microsoft