-
Notifications
You must be signed in to change notification settings - Fork 1.1k
.NET: Move SO agent to samples #3820
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
.NET: Move SO agent to samples #3820
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
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.