-
Notifications
You must be signed in to change notification settings - Fork 246
.NET: Improve structured output for chat client agent #1172
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
base: main
Are you sure you want to change the base?
.NET: Improve structured output for chat client agent #1172
Conversation
// Notify the AIContextProvider of all new messages. | ||
await NotifyAIContextProviderOfSuccessAsync(safeThread, inputMessages, chatResponse.Messages, cancellationToken).ConfigureAwait(false); | ||
|
||
return new AgentRunResponse<T>(chatResponse) { AgentId = this.Id }; |
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.
Do you need to duplicate all the code from RunAsync? Seems like the only things that differ are the GetResponseAsync call and the construction of the response at the end, in which case you could share most of it using a delegate or interface and two implementations or something like that?
AgentThread? thread = null, | ||
JsonSerializerOptions? serializerOptions = null, | ||
AgentRunOptions? options = null, | ||
bool? useJsonSchemaResponseFormat = null, |
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.
I don't know how useful useJsonSchemaResponseFormat: false is. I guess we can keep exposing it, as it's just mirroring what the underlying API provides, but I don't see folks using false and it's not actually using structured output so its results are questionable.
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.
The AgentRunResponse<T>
class can potentially be used by other agents that may support structural output; hence, it should be declared in the Microsoft.Agents.AI.Abstractions
project rather than the Microsoft.Agents.AI
one.
The reason it's declared in the Microsoft.Agents.AI
project is that the class depends on the ChatResponse<T>
class from Microsoft.Extension.AI
package, and moving the class to Microsoft.Agents.AI.Abstractions
project would require adding a dependency on Microsoft.Extension.AI
package to the project, which does not seem like the right thing to do.
This PR adds several overloads of the
RunAsync<T>
methods toChatClientAgent
, improving the development experience when using the agent to produce structured output from non-streaming APIs.Code before
Code after