Skip to content

Conversation

westey-m
Copy link
Contributor

@westey-m westey-m commented Jul 15, 2025

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:

        var agent = new ChatClientAgent(
            chatClient,
            options: new()
            {
                Instructions = "Answer questions about the menu.",
                ChatOptions = new()
                {
                    Tools = [AIFunctionFactory.Create(menuTools.GetSpecials)]
                }
            });

into this:

        var agent = new ChatClientAgent(
            chatClient,
            instructions: "Answer questions about the menu.",
            tools: [AIFunctionFactory.Create(menuTools.GetSpecials)]);

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

  • Added a constructor overload with the most common options
  • Refactored some samples to make use of the new signature

Contribution Checklist

  • The code builds clean without any errors or warnings
  • The PR follows the SK Contribution Guidelines
  • All unit tests pass, and I have added new tests where possible
  • I didn't break anyone 😄

@Copilot Copilot AI review requested due to automatic review settings July 15, 2025 10:46
Copy link
Contributor

@Copilot Copilot AI left a 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, and loggerFactory.
  • 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)

@westey-m westey-m enabled auto-merge July 16, 2025 13:23
@westey-m westey-m added this pull request to the merge queue Jul 16, 2025
Merged via the queue into microsoft:main with commit 95a3264 Jul 16, 2025
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants