-
Notifications
You must be signed in to change notification settings - Fork 1.2k
.NET: [Breaking] Structured Output improvements #3761
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
Merged
Merged
Changes from all commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
3df8fe3
.NET: Delete AgentResponse.{Try}Deserialize<T> methods (#3518)
SergeyMenshykh 0709f6d
Merge branch 'main' into feature-so
SergeyMenshykh 1e20c69
.NET:[Breaking] Add support for structured output (#3658)
SergeyMenshykh 9991eb6
.NET: Add decorator for structured output support (#3694)
SergeyMenshykh c26a773
.NET: Support primitives and arrays for SO (#3696)
SergeyMenshykh 30fe0ee
add adr
SergeyMenshykh 7966410
merge with latest main
SergeyMenshykh be90442
add missed change
SergeyMenshykh 6f64fdb
fix compilation issue
SergeyMenshykh 7b48633
address review comments
SergeyMenshykh 8635783
rename adr file name
SergeyMenshykh 04abdbd
reflect decision to have SO decorator as a reference implementation i…
SergeyMenshykh 6dda25c
.NET: Move SO agent to samples (#3820)
SergeyMenshykh 19ff980
.NET: Preserve caller context (#3803)
SergeyMenshykh 2f7c8c5
Merge branch 'main' into feature-so
SergeyMenshykh 2168d59
.NET: Disable irrelevant integration test (#3913)
SergeyMenshykh 87b97da
merge with latest main
SergeyMenshykh b77dbbf
forgotten change
SergeyMenshykh b4e5f8a
address pr review feedback
SergeyMenshykh 24ebbb7
disable intermittently failing integration test.
SergeyMenshykh File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
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
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
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
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
49 changes: 49 additions & 0 deletions
49
...t/samples/GettingStarted/Agents/Agent_Step05_StructuredOutput/AIAgentBuilderExtensions.cs
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,49 @@ | ||
| // Copyright (c) Microsoft. All rights reserved. | ||
|
|
||
| using Microsoft.Agents.AI; | ||
| using Microsoft.Extensions.AI; | ||
| using Microsoft.Extensions.DependencyInjection; | ||
|
|
||
| namespace SampleApp; | ||
|
|
||
| /// <summary> | ||
| /// Provides extension methods for adding structured output capabilities to <see cref="AIAgentBuilder"/> instances. | ||
| /// </summary> | ||
| internal static class AIAgentBuilderExtensions | ||
| { | ||
| /// <summary> | ||
| /// Adds structured output capabilities to the agent pipeline, enabling conversion of text responses to structured JSON format. | ||
| /// </summary> | ||
| /// <param name="builder">The <see cref="AIAgentBuilder"/> to which structured output support will be added.</param> | ||
| /// <param name="chatClient"> | ||
| /// The chat client used to transform text responses into structured JSON format. | ||
| /// If <see langword="null"/>, the chat client will be resolved from the service provider. | ||
| /// </param> | ||
| /// <param name="optionsFactory"> | ||
| /// An optional factory function that returns the <see cref="StructuredOutputAgentOptions"/> instance to use. | ||
| /// This allows for fine-tuning the structured output behavior such as setting the response format or system message. | ||
| /// </param> | ||
| /// <returns>The <see cref="AIAgentBuilder"/> with structured output capabilities added, enabling method chaining.</returns> | ||
| /// <remarks> | ||
| /// <para> | ||
| /// A <see cref="ChatResponseFormatJson"/> must be specified either through the | ||
| /// <see cref="AgentRunOptions.ResponseFormat"/> at runtime or the <see cref="StructuredOutputAgentOptions.ChatOptions"/> | ||
| /// provided during configuration. | ||
| /// </para> | ||
| /// </remarks> | ||
| public static AIAgentBuilder UseStructuredOutput( | ||
| this AIAgentBuilder builder, | ||
| IChatClient? chatClient = null, | ||
| Func<StructuredOutputAgentOptions>? optionsFactory = null) | ||
| { | ||
| ArgumentNullException.ThrowIfNull(builder); | ||
|
|
||
| return builder.Use((innerAgent, services) => | ||
| { | ||
| chatClient ??= services?.GetService<IChatClient>() | ||
| ?? throw new InvalidOperationException($"No {nameof(IChatClient)} was provided and none could be resolved from the service provider. Either provide an {nameof(IChatClient)} explicitly or register one in the dependency injection container."); | ||
|
|
||
| return new StructuredOutputAgent(innerAgent, chatClient, optionsFactory?.Invoke()); | ||
| }); | ||
| } | ||
| } |
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
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.