.NET: Delete AgentResponse.{Try}Deserialize<T> methods#3518
Merged
SergeyMenshykh merged 7 commits intomicrosoft:feature-sofrom Jan 30, 2026
Merged
.NET: Delete AgentResponse.{Try}Deserialize<T> methods#3518SergeyMenshykh merged 7 commits intomicrosoft:feature-sofrom
SergeyMenshykh merged 7 commits intomicrosoft:feature-sofrom
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR removes the Deserialize<T> and TryDeserialize<T> methods from the AgentResponse class as part of the structured output (SO) improvement strategy. The change aligns with a new design where structured output is either:
- Configured via
ResponseFormatand consumed as text JSON from non-genericAgentResponse - Provided as a type parameter in generic
RunAsync<T>methods and consumed fromAgentResponse<T>
The removed deserialization methods were intended for scenarios where text JSON output is sufficient, making instance deserialization unnecessary in those cases.
Changes:
- Removed
Deserialize<T>andTryDeserialize<T>methods and related helper code fromAgentResponse.cs - Updated all test cases to use
JsonSerializer.Deserializedirectly instead of removed methods - Updated sample code across 6 files to replace method calls with direct
JsonSerializer.Deserializecalls or localTryDeserializehelper methods
Reviewed changes
Copilot reviewed 8 out of 8 changed files in this pull request and generated 11 comments.
Show a summary per file
| File | Description |
|---|---|
| dotnet/src/Microsoft.Agents.AI.Abstractions/AgentResponse.cs | Removed deserialization methods, helper methods, enums, and unused imports |
| dotnet/tests/Microsoft.Agents.AI.Abstractions.UnitTests/AgentResponseTests.cs | Removed obsolete tests and updated remaining test to use JsonSerializer.Deserialize directly |
| dotnet/samples/GettingStarted/Workflows/_Foundational/08_WriterCriticWorkflow/Program.cs | Updated to use JsonSerializer.Deserialize directly |
| dotnet/samples/GettingStarted/FoundryAgents/FoundryAgents_Step05_StructuredOutput/Program.cs | Updated to use JsonSerializer.Deserialize directly |
| dotnet/samples/GettingStarted/Agents/Agent_Step05_StructuredOutput/Program.cs | Updated to use JsonSerializer.Deserialize directly |
| dotnet/samples/M365Agent/Agents/WeatherForecastAgent.cs | Added local TryDeserialize helper method |
| dotnet/samples/GettingStarted/AGUI/Step05_StateManagement/Server/SharedStateAgent.cs | Added local TryDeserialize helper method |
| dotnet/samples/AGUIClientServer/AGUIDojoServer/SharedState/SharedStateAgent.cs | Added local TryDeserialize helper method |
dotnet/samples/GettingStarted/AGUI/Step05_StateManagement/Server/SharedStateAgent.cs
Show resolved
Hide resolved
dotnet/samples/GettingStarted/Workflows/_Foundational/08_WriterCriticWorkflow/Program.cs
Outdated
Show resolved
Hide resolved
dotnet/samples/GettingStarted/FoundryAgents/FoundryAgents_Step05_StructuredOutput/Program.cs
Outdated
Show resolved
Hide resolved
dotnet/samples/GettingStarted/Agents/Agent_Step05_StructuredOutput/Program.cs
Show resolved
Hide resolved
dotnet/samples/AGUIClientServer/AGUIDojoServer/SharedState/SharedStateAgent.cs
Show resolved
Hide resolved
dotnet/samples/AGUIClientServer/AGUIDojoServer/SharedState/SharedStateAgent.cs
Outdated
Show resolved
Hide resolved
…05_StructuredOutput/Program.cs Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
…rCriticWorkflow/Program.cs Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
…er/SharedStateAgent.cs Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
…redStateAgent.cs Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
dotnet/samples/GettingStarted/AGUI/Step05_StateManagement/Server/SharedStateAgent.cs
Show resolved
Hide resolved
dotnet/samples/AGUIClientServer/AGUIDojoServer/SharedState/SharedStateAgent.cs
Show resolved
Hide resolved
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
dotnet/samples/GettingStarted/AGUI/Step05_StateManagement/Server/SharedStateAgent.cs
Show resolved
Hide resolved
dotnet/samples/AGUIClientServer/AGUIDojoServer/SharedState/SharedStateAgent.cs
Show resolved
Hide resolved
rogerbarreto
approved these changes
Jan 30, 2026
westey-m
approved these changes
Jan 30, 2026
github-merge-queue bot
pushed a commit
that referenced
this pull request
Feb 13, 2026
* .NET: Delete AgentResponse.{Try}Deserialize<T> methods (#3518)
* delete deserialize method of agent response
* order usings
* Update dotnet/samples/GettingStarted/FoundryAgents/FoundryAgents_Step05_StructuredOutput/Program.cs
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
* Update dotnet/samples/GettingStarted/Workflows/_Foundational/08_WriterCriticWorkflow/Program.cs
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
* Update dotnet/samples/GettingStarted/AGUI/Step05_StateManagement/Server/SharedStateAgent.cs
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
* Update dotnet/samples/AGUIClientServer/AGUIDojoServer/SharedState/SharedStateAgent.cs
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
* Update dotnet/samples/M365Agent/Agents/WeatherForecastAgent.cs
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
---------
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
* .NET:[Breaking] Add support for structured output (#3658)
* add support for so
* restore lost xml comment part
* fix using ordering
* Update dotnet/src/Microsoft.Agents.AI.Abstractions/AIAgentStructuredOutput.cs
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
* Update dotnet/src/Microsoft.Agents.AI.Abstractions/AIAgentStructuredOutput.cs
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
* Update dotnet/tests/Microsoft.Agents.AI.UnitTests/ChatClient/ChatClientAgent_SO_WithFormatResponseTests.cs
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
* addressw pr review comments
* address pr review feedback
* address pr review comments
* fix compilation issues after the latest merge with main
* remove unnecessry options
* remove RunAsync<object> methods
* address code review feedback
* address pr review feedback
* make copy constructor protected
* address pr review feedback
---------
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
* .NET: Add decorator for structured output support (#3694)
* add decorator that adds structured output support to agents that don't natively support it.
* Update dotnet/src/Microsoft.Agents.AI/StructuredOutput/StructuredOutputAgentResponse.cs
Co-authored-by: westey <164392973+westey-m@users.noreply.github.com>
* Update dotnet/samples/GettingStarted/Agents/Agent_Step05_StructuredOutput/Program.cs
Co-authored-by: westey <164392973+westey-m@users.noreply.github.com>
* address pr review feedback
---------
Co-authored-by: westey <164392973+westey-m@users.noreply.github.com>
* .NET: Support primitives and arrays for SO (#3696)
* wrap primitives and arrays
* fix file encoding
* address review comments
* add adr
* add missed change
* fix compilation issue
* address review comments
* rename adr file name
* reflect decision to have SO decorator as a reference implementation in samples
* .NET: Move SO agent to samples (#3820)
* move SO agent to samples
* change file encoding
* fix files encoding
* .NET: Preserve caller context (#3803)
* fix stuck orchestration
* add previously removed RunAsync<T> method to DurableAIAgent
* suppress IDE0005 warning
* update changelog and remove unused constructor of AgentResponse<T>
* updatge the changelog
* address PR review feedback
* .NET: Disable irrelevant integration test (#3913)
* disable irrelevant integration test
* Update dotnet/tests/AzureAI.IntegrationTests/AIProjectClientAgentStructuredOutputRunTests.cs
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
---------
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
* forgotten change
* address pr review feedback
* disable intermittently failing integration test.
---------
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: westey <164392973+westey-m@users.noreply.github.com>
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
As part of the revision and improvement of structured output (SO) in AF, we plan to have two ways SO can be configured and consumed:
Agent{Run}Options.ResponseFormatproperty and consumed from the non-genericAgentResponsereturned by one of the non-genericAIAgent.RunAsyncoverloads.AIAgent.RunAsync<T>(will be added in following PRs) methods or one of the non-genericAIAgent.RunAsync(Type type)methods and consumed from the returned genericAgentResponse<T>.The first method of using SO is primarily intended for cases where having SO output as a text JSON in the agent response message is sufficient, and having SO output as an instance of an object is not necessary. It can be used in scenarios where a few agents are collaborating, and the SO output represented as text is obtained by one agent and passed as input to the next one.
The second method is intended for scenarios where having SO output as an instance of an object is needed. These scenarios may involve multi-agent collaboration where SO output is retrieved by one agent, transformed, and then used as input for the second agent. Additionally, it can be used in single-agent scenarios where the agent's SO output represented by an object is processed by the following code.
Description
This PR removes
AgentResponse.{Try}Deserialize<T>methods that are used to obtain an instance of SO output in the scenarios described in the first option, where the instance is not necessary as explained above.