-
Notifications
You must be signed in to change notification settings - Fork 266
Add ChatClientAgent constructor overload #188
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
Add ChatClientAgent constructor overload #188
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
Adds a streamlined constructor overload to ChatClientAgent
for the most common settings and updates call sites to use it.
- Introduces a new
ChatClientAgent
constructor with parameters:instructions
,name
,description
,tools
, andloggerFactory
. - Updates existing tests to pass the full-options constructor via the named
options:
argument. - Refactors sample code to invoke the new overload directly, simplifying agent instantiation.
Reviewed Changes
Copilot reviewed 13 out of 13 changed files in this pull request and generated 1 comment.
Show a summary per file
File | Description |
---|---|
dotnet/src/Microsoft.Extensions.AI.Agents/ChatCompletion/ChatClientAgent.cs | Added overload with common parameters (instructions, name, description, tools). |
dotnet/tests/OpenAIResponse.IntegrationTests/OpenAIResponseFixture.cs | Updated ChatClientAgent calls to use named options: . |
dotnet/tests/OpenAIChatCompletion.IntegrationTests/OpenAIChatCompletionFixture.cs | Updated ChatClientAgent calls to use named options: . |
dotnet/tests/OpenAIAssistant.IntegrationTests/OpenAIAssistantFixture.cs | Updated ChatClientAgent calls to use named options: . |
dotnet/tests/Microsoft.Extensions.AI.Agents.UnitTests/ChatCompletion/ChatClientAgentThreadTests.cs | Updated ChatClientAgent calls to use named options: . |
dotnet/tests/Microsoft.Extensions.AI.Agents.UnitTests/ChatCompletion/ChatClientAgentTests.cs | Updated ChatClientAgent calls to use named options: and removed null overload. |
dotnet/tests/Microsoft.Extensions.AI.Agents.UnitTests/ChatCompletion/ChatClientAgentExtensionsTests.cs | Updated ChatClientAgent calls to use named options: . |
dotnet/tests/AzureAIAgentsPersistent.IntegrationTests/AzureAIAgentsPersistentFixture.cs | Updated ChatClientAgent calls to use named options: . |
dotnet/samples/GettingStarted/Steps/Step01_ChatClientAgent_Running.cs | Simplified sample to use new overload for instructions and name. |
dotnet/samples/GettingStarted/Steps/Step02_ChatClientAgent_UsingFunctionTools.cs | Added sample for tools overload and corrected comment. |
dotnet/samples/GettingStarted/Providers/ChatClientAgent_With_OpenAIResponseChatCompletion.cs | Refactored sample tests, updated diagnostic pragma and split theories into facts. |
dotnet/samples/GettingStarted/Providers/ChatClientAgent_With_OpenAIChatCompletion.cs | Simplified sample to use new overload for instructions and name. |
dotnet/samples/GettingStarted/Providers/ChatClientAgent_With_AzureOpenAIChatCompletion.cs | Simplified sample to use new overload for instructions and name. |
Comments suppressed due to low confidence (1)
dotnet/src/Microsoft.Extensions.AI.Agents/ChatCompletion/ChatClientAgent.cs:33
- Consider adding unit tests for this new constructor overload to verify that instructions, name, description, and tools parameters are correctly applied to the agent options.
public ChatClientAgent(IChatClient chatClient, string? instructions = null, string? name = null, string? description = null, IList<AITool>? tools = null, ILoggerFactory? loggerFactory = null)
Motivation and Context
There are some common settings which are expected to be used very often with a ChatClientAgent. One of these is tools, but to provide it the user has to provide a ChatClientOptions wrapped in a ChatClientAgentOptions, which is not intuitive.
This PR adds a ChatClientAgent constructor overload with a list of optional parameters, which contain just the most commonly used settings. This signature is not expected to grow over time with new parameters, as it should be catering for the 90% use case.
It allows for collapsing a constructor like this:
into this:
The new signature has optional instructions, name, description, tools and loggerFactory.
Id is not there since for the significant majority of IChatClient implementations there is no external id, and the agent will fall back to a Guid.
Passing an Id would only be applicable for service based agents used via IChatClient, which is currently limited to Foundry Persistent (which we plan to replace with a dedicated Agent implementation) and OpenAI Assistant (which is being deprecated).
#92
Description
Contribution Checklist