.NET: Add FinishReason to AgentResponses#4617
Merged
westey-m merged 2 commits intomicrosoft:mainfrom Mar 11, 2026
Merged
Conversation
rogerbarreto
approved these changes
Mar 11, 2026
Contributor
There was a problem hiding this comment.
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? FinishReasontoAgentResponseandAgentResponseUpdate, including mapping to/fromChatResponse/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. |
dotnet/src/Microsoft.Agents.AI.Hosting.OpenAI/ChatCompletions/AgentResponseExtensions.cs
Outdated
Show resolved
Hide resolved
SergeyMenshykh
approved these changes
Mar 11, 2026
This was referenced Mar 13, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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
Contribution Checklist