.NET: Move SO agent to samples#3820
Merged
SergeyMenshykh merged 3 commits intomicrosoft:feature-sofrom Feb 11, 2026
Merged
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
Moves the non-public StructuredOutputAgent implementation out of the .NET library/test surface and into a Getting Started sample, aligning with the decision to not include it in the public Agent Framework API while still providing a reference implementation.
Changes:
- Removed unit tests that covered
StructuredOutputAgent,StructuredOutputAgentResponse, and related builder extensions fromMicrosoft.Agents.AI.UnitTests. - Updated the Step05 Structured Output sample to host the structured-output wrapper types under the sample namespace (
SampleApp) and remove dependencies on shared diagnostics helpers. - Adjusted sample types’ accessibility to keep the implementation sample-scoped (e.g.,
internalclasses).
Reviewed changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| dotnet/tests/Microsoft.Agents.AI.UnitTests/StructuredOutput/StructuredOutputAgentTests.cs | Removed tests for StructuredOutputAgent after moving implementation to samples. |
| dotnet/tests/Microsoft.Agents.AI.UnitTests/StructuredOutput/StructuredOutputAgentResponseTests.cs | Removed tests for StructuredOutputAgentResponse after moving implementation to samples. |
| dotnet/tests/Microsoft.Agents.AI.UnitTests/StructuredOutput/AIAgentBuilderExtensionsTests.cs | Removed tests for builder extensions after moving implementation to samples. |
| dotnet/samples/GettingStarted/Agents/Agent_Step05_StructuredOutput/StructuredOutputAgentResponse.cs | Scoped the response wrapper to the sample namespace and adjusted accessibility. |
| dotnet/samples/GettingStarted/Agents/Agent_Step05_StructuredOutput/StructuredOutputAgentOptions.cs | Scoped options to the sample namespace and adjusted analyzers/accessibility. |
| dotnet/samples/GettingStarted/Agents/Agent_Step05_StructuredOutput/StructuredOutputAgent.cs | Scoped the agent wrapper to the sample namespace and replaced diagnostics null-check helper. |
| dotnet/samples/GettingStarted/Agents/Agent_Step05_StructuredOutput/AIAgentBuilderExtensions.cs | Scoped extensions to the sample namespace and replaced diagnostics null-check helper. |
Comments suppressed due to low confidence (2)
dotnet/samples/GettingStarted/Agents/Agent_Step05_StructuredOutput/StructuredOutputAgentResponse.cs:20
StructuredOutputAgentResponseisinternal, but its constructor ispublic. Since the type can’t be constructed from outside the assembly anyway, making the constructorinternalimproves encapsulation and avoids suggesting this is intended as a public API surface.
dotnet/samples/GettingStarted/Agents/Agent_Step05_StructuredOutput/AIAgentBuilderExtensions.cs:46- In
UseStructuredOutput, thechatClient ??=assignment mutates the captured parameter inside the builder lambda. If the sameAIAgentBuilderinstance is built multiple times (potentially with differentIServiceProviders), the first resolvedIChatClientwill be cached and reused on subsequent builds, which can be surprising and incorrect. Prefer resolving into a local variable without mutating the capturedchatClientparameter (or always re-resolve fromserviceswhen no explicit client was provided).
Contributor
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 7 out of 7 changed files in this pull request and generated no new comments.
Comments suppressed due to low confidence (1)
dotnet/samples/GettingStarted/Agents/Agent_Step05_StructuredOutput/AIAgentBuilderExtensions.cs:46
chatClient ??=inside the builder.Use(...) lambda mutates the capturedchatClientparameter. If the same builder is built more than once (especially with different service providers), the first resolved IChatClient instance will be cached and reused for later builds, which can produce incorrect behavior. Resolve into a local variable inside the lambda (without writing back to the captured parameter) and pass that local to StructuredOutputAgent.
westey-m
approved these changes
Feb 11, 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
The reliability of the StructuredOutputAgent in producing structured output through an additional LLM call may not be sufficient for all scenarios. As a result, it's not going to be included in the public AF API surface. However, it would be beneficial to provide a sample to demonstrate how structured output can be achieved for agents without native support. This would give users a reference implementation they can adapt to their own requirements.
Description
The StructuredOutputAgent class and related classes have been moved to the samples.