diff --git a/dotnet/samples/GettingStarted/Steps/Step01_ChatClientAgent_Running.cs b/dotnet/samples/GettingStarted/Steps/Step01_ChatClientAgent_Running.cs index 1d9c55bfdc..f0b498c992 100644 --- a/dotnet/samples/GettingStarted/Steps/Step01_ChatClientAgent_Running.cs +++ b/dotnet/samples/GettingStarted/Steps/Step01_ChatClientAgent_Running.cs @@ -33,7 +33,7 @@ public sealed class Step01_ChatClientAgent_Running(ITestOutputHelper output) : A IChatClient chatClient = base.GetChatClient(provider); // Define the agent - AIAgent agent = new ChatClientAgent(chatClient, ParrotInstructions, ParrotName); + AIAgent agent = new ChatClientAgent(chatClient, name: ParrotName, instructions: ParrotInstructions); // Invoke the agent and output the text result. Console.WriteLine(await agent.RunAsync("Fortune favors the bold.")); @@ -52,11 +52,7 @@ public sealed class Step01_ChatClientAgent_Running(ITestOutputHelper output) : A public async Task RunWithoutThread(ChatClientProviders provider) { // Define the options for the chat client agent. - var agentOptions = new ChatClientAgentOptions - { - Name = ParrotName, - Instructions = ParrotInstructions, - }; + var agentOptions = new ChatClientAgentOptions(name: ParrotName, instructions: ParrotInstructions); // Create the server-side agent Id when applicable (depending on the provider). agentOptions.Id = await base.AgentCreateAsync(provider, agentOptions); @@ -149,11 +145,8 @@ public sealed class Step01_ChatClientAgent_Running(ITestOutputHelper output) : A public async Task RunStreamingWithThread(ChatClientProviders provider) { // Define the options for the chat client agent. - var agentOptions = new ChatClientAgentOptions + var agentOptions = new ChatClientAgentOptions(name: ParrotName, instructions: ParrotInstructions) { - Name = ParrotName, - Instructions = ParrotInstructions, - // Get chat options based on the store type, if needed. ChatOptions = base.GetChatOptions(provider), }; diff --git a/dotnet/samples/GettingStarted/Steps/Step02_ChatClientAgent_UsingFunctionTools.cs b/dotnet/samples/GettingStarted/Steps/Step02_ChatClientAgent_UsingFunctionTools.cs index 41f6959033..be945edfbf 100644 --- a/dotnet/samples/GettingStarted/Steps/Step02_ChatClientAgent_UsingFunctionTools.cs +++ b/dotnet/samples/GettingStarted/Steps/Step02_ChatClientAgent_UsingFunctionTools.cs @@ -14,49 +14,27 @@ public sealed class Step02_ChatClientAgent_UsingFunctionTools(ITestOutputHelper { [Theory] [InlineData(ChatClientProviders.AzureOpenAI)] + [InlineData(ChatClientProviders.AzureAIAgentsPersistent)] + [InlineData(ChatClientProviders.OpenAIAssistant)] [InlineData(ChatClientProviders.OpenAIChatCompletion)] - public async Task RunningWithToolsBasic(ChatClientProviders provider) - { - // Creating a MenuTools instance to be used by the agent. - var menuTools = new MenuTools(); - - // Get the chat client to use for the agent. - var chatClient = base.GetChatClient(provider); - - // Define the agent and add the GetSpecials tool. - var agent = new ChatClientAgent( - chatClient, - instructions: "Answer questions about the menu.", - tools: [AIFunctionFactory.Create(menuTools.GetSpecials)]); - - // Respond to user input, invoking functions where appropriate. - Console.WriteLine(await agent.RunAsync("What is the special soup and its price?")); - } - - [Theory] - [InlineData(ChatClientProviders.AzureOpenAI)] - [InlineData(ChatClientProviders.OpenAIChatCompletion)] + [InlineData(ChatClientProviders.OpenAIResponses)] public async Task RunningWithTools(ChatClientProviders provider) { // Creating a MenuTools instance to be used by the agent. var menuTools = new MenuTools(); // Define the options for the chat client agent. - var agentOptions = new ChatClientAgentOptions - { - Name = "Host", - Instructions = "Answer questions about the menu.", + var agentOptions = new ChatClientAgentOptions( + name: "Host", + instructions: "Answer questions about the menu", + tools: [ + AIFunctionFactory.Create(menuTools.GetMenu), + AIFunctionFactory.Create(menuTools.GetSpecials), + AIFunctionFactory.Create(menuTools.GetItemPrice) + ]); - // Provide the tools that are available to the agent - ChatOptions = new() - { - Tools = [ - AIFunctionFactory.Create(menuTools.GetMenu), - AIFunctionFactory.Create(menuTools.GetSpecials), - AIFunctionFactory.Create(menuTools.GetItemPrice) - ] - }, - }; + // Create the server-side agent Id when applicable (depending on the provider). + agentOptions.Id = await base.AgentCreateAsync(provider, agentOptions); // Get the chat client to use for the agent. using var chatClient = base.GetChatClient(provider, agentOptions); @@ -79,32 +57,34 @@ public sealed class Step02_ChatClientAgent_UsingFunctionTools(ITestOutputHelper var response = await agent.RunAsync(input, thread); this.WriteResponseOutput(response); } + + // Clean up the server-side agent after use when applicable (depending on the provider). + await base.AgentCleanUpAsync(provider, agent, thread); } [Theory] [InlineData(ChatClientProviders.AzureOpenAI)] + [InlineData(ChatClientProviders.AzureAIAgentsPersistent)] + [InlineData(ChatClientProviders.OpenAIAssistant)] [InlineData(ChatClientProviders.OpenAIChatCompletion)] + [InlineData(ChatClientProviders.OpenAIResponses)] public async Task StreamingRunWithTools(ChatClientProviders provider) { // Creating a MenuTools instance to be used by the agent. var menuTools = new MenuTools(); // Define the options for the chat client agent. - var agentOptions = new ChatClientAgentOptions - { - Name = "Host", - Instructions = "Answer questions about the menu.", + var agentOptions = new ChatClientAgentOptions( + name: "Host", + instructions: "Answer questions about the menu", + tools: [ + AIFunctionFactory.Create(menuTools.GetMenu), + AIFunctionFactory.Create(menuTools.GetSpecials), + AIFunctionFactory.Create(menuTools.GetItemPrice) + ]); - // Provide the tools that are available to the agent - ChatOptions = new() - { - Tools = [ - AIFunctionFactory.Create(menuTools.GetMenu), - AIFunctionFactory.Create(menuTools.GetSpecials), - AIFunctionFactory.Create(menuTools.GetItemPrice) - ] - }, - }; + // Create the server-side agent Id when applicable (depending on the provider). + agentOptions.Id = await base.AgentCreateAsync(provider, agentOptions); // Get the chat client to use for the agent. using var chatClient = base.GetChatClient(provider, agentOptions); @@ -129,6 +109,9 @@ public sealed class Step02_ChatClientAgent_UsingFunctionTools(ITestOutputHelper this.WriteAgentOutput(update); } } + + // Clean up the server-side agent after use when applicable (depending on the provider). + await base.AgentCleanUpAsync(provider, agent, thread); } private sealed class MenuTools diff --git a/dotnet/samples/GettingStarted/Steps/Step03_ChatClientAgent_UsingCodeInterpreterTools.cs b/dotnet/samples/GettingStarted/Steps/Step03_ChatClientAgent_UsingCodeInterpreterTools.cs index fbc98f4860..dcd2250a8b 100644 --- a/dotnet/samples/GettingStarted/Steps/Step03_ChatClientAgent_UsingCodeInterpreterTools.cs +++ b/dotnet/samples/GettingStarted/Steps/Step03_ChatClientAgent_UsingCodeInterpreterTools.cs @@ -23,12 +23,11 @@ public sealed class Step03_ChatClientAgent_UsingCodeInterpreterTools(ITestOutput { var codeInterpreterTool = new NewHostedCodeInterpreterTool(); codeInterpreterTool.FileIds.Add(await UploadFileAsync("Resources/groceries.txt", provider)); - var agentOptions = new ChatClientAgentOptions - { - Name = "HelpfulAssistant", - Instructions = "You are a helpful assistant.", - ChatOptions = new() { Tools = [codeInterpreterTool] } - }; + + var agentOptions = new ChatClientAgentOptions( + name: "HelpfulAssistant", + instructions: "You are a helpful assistant.", + tools: [codeInterpreterTool]); // Create the server-side agent Id when applicable (depending on the provider). agentOptions.Id = await base.AgentCreateAsync(provider, agentOptions); diff --git a/dotnet/samples/GettingStarted/Steps/Step04_ChatClientAgent_DependencyInjection.cs b/dotnet/samples/GettingStarted/Steps/Step04_ChatClientAgent_DependencyInjection.cs index 38bd819720..8d473ce23f 100644 --- a/dotnet/samples/GettingStarted/Steps/Step04_ChatClientAgent_DependencyInjection.cs +++ b/dotnet/samples/GettingStarted/Steps/Step04_ChatClientAgent_DependencyInjection.cs @@ -19,14 +19,9 @@ public sealed class Step04_ChatClientAgent_DependencyInjection(ITestOutputHelper // Adding multiple chat clients to the service collection. var services = new ServiceCollection(); - var agentOptions = new ChatClientAgentOptions - { - Name = "Parrot", - Instructions = "Repeat the user message in the voice of a pirate and then end with a parrot sound.", - - // Get chat options based on the store type, if needed. - ChatOptions = base.GetChatOptions(provider), - }; + var agentOptions = new ChatClientAgentOptions( + name: "Parrot", + instructions: "Repeat the user message in the voice of a pirate and then end with a parrot sound."); // Create the server-side agent Id when applicable (depending on the provider). agentOptions.Id = await base.AgentCreateAsync(provider, agentOptions); diff --git a/dotnet/samples/GettingStarted/Steps/Step05_ChatClientAgent_Telemetry.cs b/dotnet/samples/GettingStarted/Steps/Step05_ChatClientAgent_Telemetry.cs index 82e05b6da8..a929126192 100644 --- a/dotnet/samples/GettingStarted/Steps/Step05_ChatClientAgent_Telemetry.cs +++ b/dotnet/samples/GettingStarted/Steps/Step05_ChatClientAgent_Telemetry.cs @@ -33,12 +33,8 @@ public sealed class Step05_ChatClientAgent_Telemetry(ITestOutputHelper output) : .AddConsoleExporter() .Build(); - // Define agent - var agentOptions = new ChatClientAgentOptions - { - Name = "TelemetryAgent", - Instructions = "You are a helpful assistant.", - }; + // Define agent options + var agentOptions = new ChatClientAgentOptions(name: "TelemetryAgent", instructions: "You are a helpful assistant."); // Create the server-side agent Id when applicable (depending on the provider). agentOptions.Id = await base.AgentCreateAsync(provider, agentOptions); diff --git a/dotnet/src/Microsoft.Extensions.AI.Agents/ChatCompletion/ChatClientAgentOptions.cs b/dotnet/src/Microsoft.Extensions.AI.Agents/ChatCompletion/ChatClientAgentOptions.cs index 094df7a904..a8bb9d144a 100644 --- a/dotnet/src/Microsoft.Extensions.AI.Agents/ChatCompletion/ChatClientAgentOptions.cs +++ b/dotnet/src/Microsoft.Extensions.AI.Agents/ChatCompletion/ChatClientAgentOptions.cs @@ -1,5 +1,7 @@ // Copyright (c) Microsoft. All rights reserved. +using System.Collections.Generic; + namespace Microsoft.Extensions.AI.Agents; /// @@ -12,6 +14,40 @@ namespace Microsoft.Extensions.AI.Agents; /// public class ChatClientAgentOptions { + /// + /// Initializes a new instance of the class. + /// + public ChatClientAgentOptions() + { + } + + /// + /// Initializes a new instance of the class with the specified parameters. + /// + /// If is provided, a new instance is created + /// with the specified instructions and tools. + /// The instructions or guidelines for the chat client agent. Can be if not specified. + /// The name of the chat client agent. Can be if not specified. + /// The description of the chat client agent. Can be if not specified. + /// A list of instances available to the chat client agent. Can be if no + /// tools are specified. + public ChatClientAgentOptions(string? instructions, string? name = null, string? description = null, IList? tools = null) + { + this.Name = name; + this.Instructions = instructions; + this.Description = description; + + if (tools is not null) + { + (this.ChatOptions ??= new()).Tools = tools; + } + + if (instructions is not null) + { + (this.ChatOptions ??= new()).Instructions = instructions; + } + } + /// /// Gets or sets the agent id. ///