diff --git a/dotnet/Directory.Packages.props b/dotnet/Directory.Packages.props index 5ac641004d..5bf31fe08f 100644 --- a/dotnet/Directory.Packages.props +++ b/dotnet/Directory.Packages.props @@ -17,7 +17,7 @@ - + diff --git a/dotnet/samples/GettingStarted/AgentProviders/Agent_With_AzureAIAgent/Program.cs b/dotnet/samples/GettingStarted/AgentProviders/Agent_With_AzureAIAgent/Program.cs index 35e249d558..1c2628d8f9 100644 --- a/dotnet/samples/GettingStarted/AgentProviders/Agent_With_AzureAIAgent/Program.cs +++ b/dotnet/samples/GettingStarted/AgentProviders/Agent_With_AzureAIAgent/Program.cs @@ -13,14 +13,13 @@ const string JokerInstructions = "You are good at telling jokes."; const string JokerName = "JokerAgent"; // Get a client to create/retrieve/delete server side agents with Azure Foundry Agents. -var agentsClient = new AgentsClient(new Uri(endpoint), new AzureCliCredential()); +var agentsClient = new AgentClient(new Uri(endpoint), new AzureCliCredential()); // Define the agent you want to create. (Prompt Agent in this case) -var agentDefinition = new PromptAgentDefinition(model: deploymentName) { Instructions = JokerInstructions }; - +var agentVersionCreationOptions = new AgentVersionCreationOptions(new PromptAgentDefinition(model: deploymentName) { Instructions = JokerInstructions }); // Azure.AI.Agents SDK creates and manages agent by name and versions. // You can create a server side agent version with the Azure.AI.Agents SDK client below. -var agentVersion = agentsClient.CreateAgentVersion(agentName: JokerName, definition: agentDefinition); +var agentVersion = agentsClient.CreateAgentVersion(agentName: JokerName, options: agentVersionCreationOptions); // Note: // agentVersion.Id = ":", diff --git a/dotnet/samples/GettingStarted/Workflows/Declarative/DeepResearch/Program.cs b/dotnet/samples/GettingStarted/Workflows/Declarative/DeepResearch/Program.cs index e23c700637..0d1368d7ac 100644 --- a/dotnet/samples/GettingStarted/Workflows/Declarative/DeepResearch/Program.cs +++ b/dotnet/samples/GettingStarted/Workflows/Declarative/DeepResearch/Program.cs @@ -46,39 +46,39 @@ internal sealed class Program private static async Task CreateAgentsAsync(Uri foundryEndpoint, IConfiguration configuration) { - AgentsClient agentsClient = new(foundryEndpoint, new AzureCliCredential()); + AgentClient agentClient = new(foundryEndpoint, new AzureCliCredential()); - await agentsClient.CreateAgentAsync( + await agentClient.CreateAgentAsync( agentName: "ResearchAgent", agentDefinition: DefineResearchAgent(configuration), agentDescription: "Planner agent for DeepResearch workflow"); - await agentsClient.CreateAgentAsync( + await agentClient.CreateAgentAsync( agentName: "PlannerAgent", agentDefinition: DefinePlannerAgent(configuration), agentDescription: "Planner agent for DeepResearch workflow"); - await agentsClient.CreateAgentAsync( + await agentClient.CreateAgentAsync( agentName: "ManagerAgent", agentDefinition: DefineManagerAgent(configuration), agentDescription: "Manager agent for DeepResearch workflow"); - await agentsClient.CreateAgentAsync( + await agentClient.CreateAgentAsync( agentName: "SummaryAgent", agentDefinition: DefineSummaryAgent(configuration), agentDescription: "Summary agent for DeepResearch workflow"); - await agentsClient.CreateAgentAsync( + await agentClient.CreateAgentAsync( agentName: "KnowledgeAgent", agentDefinition: DefineKnowledgeAgent(configuration), agentDescription: "Research agent for DeepResearch workflow"); - await agentsClient.CreateAgentAsync( + await agentClient.CreateAgentAsync( agentName: "CoderAgent", agentDefinition: DefineCoderAgent(configuration), agentDescription: "Coder agent for DeepResearch workflow"); - await agentsClient.CreateAgentAsync( + await agentClient.CreateAgentAsync( agentName: "WeatherAgent", agentDefinition: DefineWeatherAgent(configuration), agentDescription: "Weather agent for DeepResearch workflow"); diff --git a/dotnet/samples/GettingStarted/Workflows/Declarative/FunctionTools/Program.cs b/dotnet/samples/GettingStarted/Workflows/Declarative/FunctionTools/Program.cs index 56c11cf0cf..170f9b08a0 100644 --- a/dotnet/samples/GettingStarted/Workflows/Declarative/FunctionTools/Program.cs +++ b/dotnet/samples/GettingStarted/Workflows/Declarative/FunctionTools/Program.cs @@ -55,9 +55,9 @@ internal sealed class Program private static async Task CreateAgentAsync(Uri foundryEndpoint, IConfiguration configuration, AIFunction[] functions) { - AgentsClient agentsClient = new(foundryEndpoint, new AzureCliCredential()); + AgentClient agentClient = new(foundryEndpoint, new AzureCliCredential()); - await agentsClient.CreateAgentAsync( + await agentClient.CreateAgentAsync( agentName: "MenuAgent", agentDefinition: DefineMenuAgent(configuration, functions), agentDescription: "Provides information about the restaurant menu"); diff --git a/dotnet/samples/GettingStarted/Workflows/Declarative/Marketing/Program.cs b/dotnet/samples/GettingStarted/Workflows/Declarative/Marketing/Program.cs index 95f4c92a3d..20987c6bfe 100644 --- a/dotnet/samples/GettingStarted/Workflows/Declarative/Marketing/Program.cs +++ b/dotnet/samples/GettingStarted/Workflows/Declarative/Marketing/Program.cs @@ -45,19 +45,19 @@ internal sealed class Program private static async Task CreateAgentsAsync(Uri foundryEndpoint, IConfiguration configuration) { - AgentsClient agentsClient = new(foundryEndpoint, new AzureCliCredential()); + AgentClient agentClient = new(foundryEndpoint, new AzureCliCredential()); - await agentsClient.CreateAgentAsync( + await agentClient.CreateAgentAsync( agentName: "AnalystAgent", agentDefinition: DefineAnalystAgent(configuration), agentDescription: "Analyst agent for Marketing workflow"); - await agentsClient.CreateAgentAsync( + await agentClient.CreateAgentAsync( agentName: "WriterAgent", agentDefinition: DefineWriterAgent(configuration), agentDescription: "Writer agent for Marketing workflow"); - await agentsClient.CreateAgentAsync( + await agentClient.CreateAgentAsync( agentName: "EditorAgent", agentDefinition: DefineEditorAgent(configuration), agentDescription: "Editor agent for Marketing workflow"); diff --git a/dotnet/samples/GettingStarted/Workflows/Declarative/StudentTeacher/Program.cs b/dotnet/samples/GettingStarted/Workflows/Declarative/StudentTeacher/Program.cs index 2f65758f41..d2299add5f 100644 --- a/dotnet/samples/GettingStarted/Workflows/Declarative/StudentTeacher/Program.cs +++ b/dotnet/samples/GettingStarted/Workflows/Declarative/StudentTeacher/Program.cs @@ -45,14 +45,14 @@ internal sealed class Program private static async Task CreateAgentsAsync(Uri foundryEndpoint, IConfiguration configuration) { - AgentsClient agentsClient = new(foundryEndpoint, new AzureCliCredential()); + AgentClient agentClient = new(foundryEndpoint, new AzureCliCredential()); - await agentsClient.CreateAgentAsync( + await agentClient.CreateAgentAsync( agentName: "StudentAgent", agentDefinition: DefineStudentAgent(configuration), agentDescription: "Student agent for MathChat workflow"); - await agentsClient.CreateAgentAsync( + await agentClient.CreateAgentAsync( agentName: "TeacherAgent", agentDefinition: DefineTeacherAgent(configuration), agentDescription: "Teacher agent for MathChat workflow"); diff --git a/dotnet/samples/GettingStarted/Workflows/Declarative/ToolApproval/Program.cs b/dotnet/samples/GettingStarted/Workflows/Declarative/ToolApproval/Program.cs index 0461927a02..01be1abfd5 100644 --- a/dotnet/samples/GettingStarted/Workflows/Declarative/ToolApproval/Program.cs +++ b/dotnet/samples/GettingStarted/Workflows/Declarative/ToolApproval/Program.cs @@ -46,9 +46,9 @@ internal sealed class Program private static async Task CreateAgentAsync(Uri foundryEndpoint, IConfiguration configuration) { - AgentsClient agentsClient = new(foundryEndpoint, new AzureCliCredential()); + AgentClient agentClient = new(foundryEndpoint, new AzureCliCredential()); - await agentsClient.CreateAgentAsync( + await agentClient.CreateAgentAsync( agentName: "DocumentSearchAgent", agentDefinition: DefineSearchAgent(configuration), agentDescription: "Searches documents on Microsoft Learn"); diff --git a/dotnet/src/Microsoft.Agents.AI.AzureAI/AgentsClientExtensions.cs b/dotnet/src/Microsoft.Agents.AI.AzureAI/AgentsClientExtensions.cs index 159f6cfb14..cbc14d90d1 100644 --- a/dotnet/src/Microsoft.Agents.AI.AzureAI/AgentsClientExtensions.cs +++ b/dotnet/src/Microsoft.Agents.AI.AzureAI/AgentsClientExtensions.cs @@ -13,14 +13,14 @@ using OpenAI.Responses; namespace Azure.AI.Agents; /// -/// Provides extension methods for . +/// Provides extension methods for . /// -public static class AgentsClientExtensions +public static class AgentClientExtensions { /// - /// Retrieves an existing server side agent, wrapped as a using the provided . + /// Retrieves an existing server side agent, wrapped as a using the provided . /// - /// The to create the with. Cannot be . + /// The to create the with. Cannot be . /// The name of the server side agent to create a for. Cannot be or whitespace. /// The tools to use when interacting with the agent. This is required when using prompt agent definitions with tools. /// Provides a way to customize the creation of the underlying used by the agent. @@ -28,12 +28,12 @@ public static class AgentsClientExtensions /// An optional to use for resolving services required by the instances being invoked. /// The to monitor for cancellation requests. The default is . /// A instance that can be used to perform operations based on the latest version of the named Azure AI Agent. - /// Thrown when or is . + /// Thrown when or is . /// Thrown when is empty or whitespace, or when the agent with the specified name was not found. /// The agent with the specified name was not found. /// When using prompt agent definitions with tools the parameter needs to be provided. public static ChatClientAgent GetAIAgent( - this AgentsClient agentsClient, + this AgentClient AgentClient, string name, IList? tools = null, Func? clientFactory = null, @@ -41,14 +41,14 @@ public static class AgentsClientExtensions IServiceProvider? services = null, CancellationToken cancellationToken = default) { - Throw.IfNull(agentsClient); + Throw.IfNull(AgentClient); Throw.IfNullOrWhitespace(name); - var agentRecord = agentsClient.GetAgent(name, cancellationToken).Value + var agentRecord = AgentClient.GetAgent(name, cancellationToken).Value ?? throw new InvalidOperationException($"Agent with name '{name}' not found."); return GetAIAgent( - agentsClient, + AgentClient, agentRecord, tools, clientFactory, @@ -58,9 +58,9 @@ public static class AgentsClientExtensions } /// - /// Asynchronously retrieves an existing server side agent, wrapped as a using the provided . + /// Asynchronously retrieves an existing server side agent, wrapped as a using the provided . /// - /// The to create the with. Cannot be . + /// The to create the with. Cannot be . /// The name of the server side agent to create a for. Cannot be or whitespace. /// The tools to use when interacting with the agent. This is required when using prompt agent definitions with tools. /// Provides a way to customize the creation of the underlying used by the agent. @@ -68,12 +68,12 @@ public static class AgentsClientExtensions /// An optional to use for resolving services required by the instances being invoked. /// The to monitor for cancellation requests. The default is . /// A instance that can be used to perform operations based on the latest version of the named Azure AI Agent. - /// Thrown when or is . + /// Thrown when or is . /// Thrown when is empty or whitespace, or when the agent with the specified name was not found. /// The agent with the specified name was not found. /// When using prompt agent definitions with tools the parameter needs to be provided. public static async Task GetAIAgentAsync( - this AgentsClient agentsClient, + this AgentClient AgentClient, string name, IList? tools = null, Func? clientFactory = null, @@ -81,14 +81,14 @@ public static class AgentsClientExtensions IServiceProvider? services = null, CancellationToken cancellationToken = default) { - Throw.IfNull(agentsClient); + Throw.IfNull(AgentClient); Throw.IfNullOrWhitespace(name); - var agentRecord = (await agentsClient.GetAgentAsync(name, cancellationToken).ConfigureAwait(false)).Value + var agentRecord = (await AgentClient.GetAgentAsync(name, cancellationToken).ConfigureAwait(false)).Value ?? throw new InvalidOperationException($"Agent with name '{name}' not found."); return GetAIAgent( - agentsClient, + AgentClient, agentRecord, tools, clientFactory, @@ -100,7 +100,7 @@ public static class AgentsClientExtensions /// /// Gets a runnable agent instance from the provided agent record. /// - /// The client used to interact with Azure AI Agents. Cannot be . + /// The client used to interact with Azure AI Agents. Cannot be . /// The agent record to be converted. The latest version will be used. Cannot be . /// The tools to use when interacting with the agent. This is required when using prompt agent definitions with tools. /// Provides a way to customize the creation of the underlying used by the agent. @@ -110,7 +110,7 @@ public static class AgentsClientExtensions /// A instance that can be used to perform operations based on the latest version of the Azure AI Agent. /// When using prompt agent definitions with tools the parameter needs to be provided. public static ChatClientAgent GetAIAgent( - this AgentsClient agentsClient, + this AgentClient AgentClient, AgentRecord agentRecord, IList? tools = null, Func? clientFactory = null, @@ -118,11 +118,11 @@ public static class AgentsClientExtensions IServiceProvider? services = null, CancellationToken cancellationToken = default) { - Throw.IfNull(agentsClient); + Throw.IfNull(AgentClient); Throw.IfNull(agentRecord); return GetAIAgent( - agentsClient, + AgentClient, agentRecord.Versions.Latest, tools, clientFactory, @@ -134,7 +134,7 @@ public static class AgentsClientExtensions /// /// Gets a runnable agent instance from a containing metadata about an Azure AI Agent. /// - /// The client used to interact with Azure AI Agents. Cannot be . + /// The client used to interact with Azure AI Agents. Cannot be . /// The agent version to be converted. Cannot be . /// The tools to use when interacting with the agent. This is required when using prompt agent definitions with tools. /// Provides a way to customize the creation of the underlying used by the agent. @@ -142,10 +142,10 @@ public static class AgentsClientExtensions /// An optional to use for resolving services required by the instances being invoked. /// The to monitor for cancellation requests. The default is . /// A instance that can be used to perform operations based on the provided version of the Azure AI Agent. - /// Thrown when or is . + /// Thrown when or is . /// When using prompt agent definitions with tools the parameter needs to be provided. public static ChatClientAgent GetAIAgent( - this AgentsClient agentsClient, + this AgentClient AgentClient, AgentVersion agentVersion, IList? tools = null, Func? clientFactory = null, @@ -153,13 +153,13 @@ public static class AgentsClientExtensions IServiceProvider? services = null, CancellationToken cancellationToken = default) { - Throw.IfNull(agentsClient); + Throw.IfNull(AgentClient); Throw.IfNull(agentVersion); ValidateUsingToolsParameter(agentVersion, tools); return CreateChatClientAgent( - agentsClient, + AgentClient, agentVersion, tools, clientFactory, @@ -169,25 +169,25 @@ public static class AgentsClientExtensions } /// - /// Creates a new Prompt AI Agent using the provided and options. + /// Creates a new Prompt AI Agent using the provided and options. /// - /// The client used to manage and interact with AI agents. Cannot be . + /// The client used to manage and interact with AI agents. Cannot be . /// The options for creating the agent. Cannot be . /// A factory function to customize the creation of the chat client used by the agent. /// An optional for configuring the underlying OpenAI client. /// An optional to use for resolving services required by the instances being invoked. /// A to cancel the operation if needed. /// A instance that can be used to perform operations on the newly created agent. - /// Thrown when or is . + /// Thrown when or is . public static ChatClientAgent GetAIAgent( - this AgentsClient agentsClient, + this AgentClient AgentClient, ChatClientAgentOptions options, Func? clientFactory = null, OpenAIClientOptions? openAIClientOptions = null, IServiceProvider? services = null, CancellationToken cancellationToken = default) { - Throw.IfNull(agentsClient); + Throw.IfNull(AgentClient); Throw.IfNull(options); if (string.IsNullOrWhiteSpace(options.Name)) @@ -195,7 +195,7 @@ public static class AgentsClientExtensions throw new ArgumentException("Agent name must be provided in the options.Name property", nameof(options)); } - var agentRecord = agentsClient.GetAgent(options.Name, cancellationToken).Value + var agentRecord = AgentClient.GetAgent(options.Name, cancellationToken).Value ?? throw new InvalidOperationException($"Agent with name '{options.Name}' not found."); var agentVersion = agentRecord.Versions.Latest; @@ -203,7 +203,7 @@ public static class AgentsClientExtensions var agentOptions = CreateChatClientAgentOptions(agentVersion, options, requireInvocableTools: true); return CreateChatClientAgent( - agentsClient, + AgentClient, agentVersion, agentOptions, clientFactory, @@ -213,25 +213,25 @@ public static class AgentsClientExtensions } /// - /// Creates a new Prompt AI Agent using the provided and options. + /// Creates a new Prompt AI Agent using the provided and options. /// - /// The client used to manage and interact with AI agents. Cannot be . + /// The client used to manage and interact with AI agents. Cannot be . /// The options for creating the agent. Cannot be . /// A factory function to customize the creation of the chat client used by the agent. /// An optional for configuring the underlying OpenAI client. /// An optional to use for resolving services required by the instances being invoked. /// A to cancel the operation if needed. /// A instance that can be used to perform operations on the newly created agent. - /// Thrown when or is . + /// Thrown when or is . public static async Task GetAIAgentAsync( - this AgentsClient agentsClient, + this AgentClient AgentClient, ChatClientAgentOptions options, Func? clientFactory = null, OpenAIClientOptions? openAIClientOptions = null, IServiceProvider? services = null, CancellationToken cancellationToken = default) { - Throw.IfNull(agentsClient); + Throw.IfNull(AgentClient); Throw.IfNull(options); if (string.IsNullOrWhiteSpace(options.Name)) @@ -239,7 +239,7 @@ public static class AgentsClientExtensions throw new ArgumentException("Agent name must be provided in the options.Name property", nameof(options)); } - var agentRecord = (await agentsClient.GetAgentAsync(options.Name, cancellationToken).ConfigureAwait(false)).Value + var agentRecord = (await AgentClient.GetAgentAsync(options.Name, cancellationToken).ConfigureAwait(false)).Value ?? throw new InvalidOperationException($"Agent with name '{options.Name}' not found."); var agentVersion = agentRecord.Versions.Latest; @@ -247,7 +247,7 @@ public static class AgentsClientExtensions var agentOptions = CreateChatClientAgentOptions(agentVersion, options, requireInvocableTools: true); return CreateChatClientAgent( - agentsClient, + AgentClient, agentVersion, agentOptions, clientFactory, @@ -259,43 +259,42 @@ public static class AgentsClientExtensions /// /// Creates a new Prompt AI agent using the specified configuration parameters. /// - /// The client used to manage and interact with AI agents. Cannot be . + /// The client used to manage and interact with AI agents. Cannot be . /// The name for the agent. /// The name of the model to use for the agent. Cannot be or whitespace. /// The instructions that guide the agent's behavior. Cannot be or whitespace. + /// The description for the agent. /// The tools to use when interacting with the agent, this is required when using prompt agent definitions with tools. - /// Settings that control the creation of the agent. /// A factory function to customize the creation of the chat client used by the agent. /// An optional for configuring the underlying OpenAI client. /// An optional to use for resolving services required by the instances being invoked. /// A token to monitor for cancellation requests. /// A instance that can be used to perform operations on the newly created agent. - /// Thrown when , , or is . + /// Thrown when , , or is . /// Thrown when or is empty or whitespace. /// When using prompt agent definitions with tools the parameter needs to be provided. public static ChatClientAgent CreateAIAgent( - this AgentsClient agentsClient, + this AgentClient AgentClient, string name, string model, string instructions, + string? description = null, IList? tools = null, - AgentVersionCreationOptions? creationOptions = null, Func? clientFactory = null, OpenAIClientOptions? openAIClientOptions = null, IServiceProvider? services = null, CancellationToken cancellationToken = default) { - Throw.IfNull(agentsClient); + Throw.IfNull(AgentClient); Throw.IfNullOrWhitespace(name); Throw.IfNullOrWhitespace(model); Throw.IfNullOrWhitespace(instructions); return CreateAIAgent( - agentsClient, + AgentClient, name, tools, - new PromptAgentDefinition(model) { Instructions = instructions }, - creationOptions, + new AgentVersionCreationOptions(new PromptAgentDefinition(model) { Instructions = instructions }) { Description = description }, clientFactory, openAIClientOptions, requireInvocableTools: true, @@ -306,43 +305,42 @@ public static class AgentsClientExtensions /// /// Creates a new Prompt AI agent using the specified configuration parameters. /// - /// The client used to manage and interact with AI agents. Cannot be . + /// The client used to manage and interact with AI agents. Cannot be . /// The name for the agent. /// The name of the model to use for the agent. Cannot be or whitespace. /// The instructions that guide the agent's behavior. Cannot be or whitespace. + /// The description for the agent. /// The tools to use when interacting with the agent, this is required when using prompt agent definitions with tools. - /// Settings that control the creation of the agent. /// A factory function to customize the creation of the chat client used by the agent. /// An optional for configuring the underlying OpenAI client. /// An optional to use for resolving services required by the instances being invoked. /// A token to monitor for cancellation requests. /// A instance that can be used to perform operations on the newly created agent. - /// Thrown when , , or is . + /// Thrown when , , or is . /// Thrown when or is empty or whitespace. /// When using prompt agent definitions with tools the parameter needs to be provided. public static Task CreateAIAgentAsync( - this AgentsClient agentsClient, + this AgentClient AgentClient, string name, string model, string instructions, + string? description = null, IList? tools = null, - AgentVersionCreationOptions? creationOptions = null, Func? clientFactory = null, OpenAIClientOptions? openAIClientOptions = null, IServiceProvider? services = null, CancellationToken cancellationToken = default) { - Throw.IfNull(agentsClient); + Throw.IfNull(AgentClient); Throw.IfNullOrWhitespace(name); Throw.IfNullOrWhitespace(model); Throw.IfNullOrWhitespace(instructions); return CreateAIAgentAsync( - agentsClient, + AgentClient, name, tools, - new PromptAgentDefinition(model) { Instructions = instructions }, - creationOptions, + new AgentVersionCreationOptions(new PromptAgentDefinition(model) { Instructions = instructions }) { Description = description }, clientFactory, openAIClientOptions, requireInvocableTools: true, @@ -351,9 +349,9 @@ public static class AgentsClientExtensions } /// - /// Creates a new Prompt AI Agent using the provided and options. + /// Creates a new Prompt AI Agent using the provided and options. /// - /// The client used to manage and interact with AI agents. Cannot be . + /// The client used to manage and interact with AI agents. Cannot be . /// The name of the model to use for the agent. Cannot be or whitespace. /// The options for creating the agent. Cannot be . /// A factory function to customize the creation of the chat client used by the agent. @@ -361,10 +359,10 @@ public static class AgentsClientExtensions /// An optional to use for resolving services required by the instances being invoked. /// A to cancel the operation if needed. /// A instance that can be used to perform operations on the newly created agent. - /// Thrown when or is . + /// Thrown when or is . /// Thrown when is empty or whitespace, or when the agent name is not provided in the options. public static ChatClientAgent CreateAIAgent( - this AgentsClient agentsClient, + this AgentClient AgentClient, string model, ChatClientAgentOptions options, Func? clientFactory = null, @@ -372,7 +370,7 @@ public static class AgentsClientExtensions IServiceProvider? services = null, CancellationToken cancellationToken = default) { - Throw.IfNull(agentsClient); + Throw.IfNull(AgentClient); Throw.IfNull(options); Throw.IfNullOrWhitespace(model); const bool RequireInvocableTools = true; @@ -389,18 +387,18 @@ public static class AgentsClientExtensions ApplyToolsToAgentDefinition(agentDefinition, options.ChatOptions?.Tools, RequireInvocableTools); - AgentVersionCreationOptions? versionCreationOptions = null; + AgentVersionCreationOptions? versionCreationOptions = new(agentDefinition); if (!string.IsNullOrWhiteSpace(options.Description)) { - (versionCreationOptions ??= new()).Description = options.Description; + versionCreationOptions.Description = options.Description; } - AgentVersion agentVersion = agentsClient.CreateAgentVersion(options.Name, agentDefinition, versionCreationOptions, cancellationToken).Value; + AgentVersion agentVersion = AgentClient.CreateAgentVersion(options.Name, versionCreationOptions, cancellationToken).Value; var agentOptions = CreateChatClientAgentOptions(agentVersion, options, RequireInvocableTools); return CreateChatClientAgent( - agentsClient, + AgentClient, agentVersion, agentOptions, clientFactory, @@ -410,9 +408,9 @@ public static class AgentsClientExtensions } /// - /// Creates a new Prompt AI Agent using the provided and options. + /// Creates a new Prompt AI Agent using the provided and options. /// - /// The client used to manage and interact with AI agents. Cannot be . + /// The client used to manage and interact with AI agents. Cannot be . /// The name of the model to use for the agent. Cannot be or whitespace. /// The options for creating the agent. Cannot be . /// A factory function to customize the creation of the chat client used by the agent. @@ -420,10 +418,10 @@ public static class AgentsClientExtensions /// An optional to use for resolving services required by the instances being invoked. /// A to cancel the operation if needed. /// A instance that can be used to perform operations on the newly created agent. - /// Thrown when or is . + /// Thrown when or is . /// Thrown when is empty or whitespace, or when the agent name is not provided in the options. public static async Task CreateAIAgentAsync( - this AgentsClient agentsClient, + this AgentClient AgentClient, string model, ChatClientAgentOptions options, Func? clientFactory = null, @@ -431,7 +429,7 @@ public static class AgentsClientExtensions IServiceProvider? services = null, CancellationToken cancellationToken = default) { - Throw.IfNull(agentsClient); + Throw.IfNull(AgentClient); Throw.IfNull(options); Throw.IfNullOrWhitespace(model); const bool RequireInvocableTools = true; @@ -448,18 +446,18 @@ public static class AgentsClientExtensions ApplyToolsToAgentDefinition(agentDefinition, options.ChatOptions?.Tools, RequireInvocableTools); - AgentVersionCreationOptions? versionCreationOptions = null; + AgentVersionCreationOptions? versionCreationOptions = new(agentDefinition); if (!string.IsNullOrWhiteSpace(options.Description)) { - (versionCreationOptions ??= new()).Description = options.Description; + versionCreationOptions.Description = options.Description; } - AgentVersion agentVersion = await agentsClient.CreateAgentVersionAsync(options.Name, agentDefinition, versionCreationOptions, cancellationToken).ConfigureAwait(false); + AgentVersion agentVersion = await AgentClient.CreateAgentVersionAsync(options.Name, versionCreationOptions, cancellationToken).ConfigureAwait(false); var agentOptions = CreateChatClientAgentOptions(agentVersion, options, RequireInvocableTools); return CreateChatClientAgent( - agentsClient, + AgentClient, agentVersion, agentOptions, clientFactory, @@ -471,39 +469,36 @@ public static class AgentsClientExtensions /// /// Creates a new AI agent using the specified agent definition and optional configuration parameters. /// - /// The client used to manage and interact with AI agents. Cannot be . + /// The client used to manage and interact with AI agents. Cannot be . /// The name for the agent. - /// The definition that specifies the configuration and behavior of the agent to create. Cannot be . /// Settings that control the creation of the agent. /// A factory function to customize the creation of the chat client used by the agent. /// An optional for configuring the underlying OpenAI client. /// A token to monitor for cancellation requests. /// A instance that can be used to perform operations on the newly created agent. - /// Thrown when or is . + /// Thrown when or is . /// /// When using this extension method with a the tools are only declarative and not invocable. /// Invocation of any in-process tools will need to be handled manually. /// public static ChatClientAgent CreateAIAgent( - this AgentsClient agentsClient, + this AgentClient AgentClient, string name, - AgentDefinition agentDefinition, - AgentVersionCreationOptions? creationOptions = null, + AgentVersionCreationOptions creationOptions, Func? clientFactory = null, OpenAIClientOptions? openAIClientOptions = null, CancellationToken cancellationToken = default) { - Throw.IfNull(agentsClient); + Throw.IfNull(AgentClient); Throw.IfNullOrWhitespace(name); - Throw.IfNull(agentDefinition); + Throw.IfNull(creationOptions); - var tools = (agentDefinition as PromptAgentDefinition)?.Tools.Select(t => t.AsAITool()).ToList(); + var tools = (creationOptions.Definition as PromptAgentDefinition)?.Tools.Select(t => t.AsAITool()).ToList(); return CreateAIAgent( - agentsClient, + AgentClient, name, tools, - agentDefinition, creationOptions, clientFactory, openAIClientOptions, @@ -516,40 +511,37 @@ public static class AgentsClientExtensions /// Asynchronously creates a new AI agent using the specified agent definition and optional configuration /// parameters. /// - /// The client used to manage and interact with AI agents. Cannot be . + /// The client used to manage and interact with AI agents. Cannot be . /// The name for the agent. - /// The definition that specifies the configuration and behavior of the agent to create. Cannot be . - /// Settings that control the creation of the agent. + /// Settings that control the creation of the agent. /// A factory function to customize the creation of the chat client used by the agent. /// An optional for configuring the underlying OpenAI client. /// A token to monitor for cancellation requests. /// A instance that can be used to perform operations on the newly created agent. - /// Thrown when or is . + /// Thrown when or is . /// /// When using this extension method with a the tools are only declarative and not invocable. /// Invocation of any in-process tools will need to be handled manually. /// public static Task CreateAIAgentAsync( - this AgentsClient agentsClient, + this AgentClient AgentClient, string name, - AgentDefinition agentDefinition, - AgentVersionCreationOptions? agentVersionCreationOptions = null, + AgentVersionCreationOptions creationOptions, Func? clientFactory = null, OpenAIClientOptions? openAIClientOptions = null, CancellationToken cancellationToken = default) { Throw.IfNullOrWhitespace(name); - Throw.IfNull(agentsClient); - Throw.IfNull(agentDefinition); + Throw.IfNull(AgentClient); + Throw.IfNull(creationOptions); - var tools = (agentDefinition as PromptAgentDefinition)?.Tools.Select(t => t.AsAITool()).ToList(); + var tools = (creationOptions.Definition as PromptAgentDefinition)?.Tools.Select(t => t.AsAITool()).ToList(); return CreateAIAgentAsync( - agentsClient, + AgentClient, name, tools, - agentDefinition, - agentVersionCreationOptions, + creationOptions, clientFactory, openAIClientOptions, requireInvocableTools: false, @@ -560,29 +552,28 @@ public static class AgentsClientExtensions #region Private private static ChatClientAgent CreateAIAgent( - this AgentsClient agentsClient, + this AgentClient AgentClient, string name, IList? tools, - AgentDefinition agentDefinition, - AgentVersionCreationOptions? creationOptions, + AgentVersionCreationOptions creationOptions, Func? clientFactory, OpenAIClientOptions? openAIClientOptions, bool requireInvocableTools, IServiceProvider? services, CancellationToken cancellationToken) { - Throw.IfNull(agentsClient); + Throw.IfNull(AgentClient); Throw.IfNullOrWhitespace(name); - Throw.IfNull(agentDefinition); + Throw.IfNull(creationOptions); - tools ??= (agentDefinition as PromptAgentDefinition)?.Tools.Select(t => t.AsAITool()).ToList(); + tools ??= (creationOptions.Definition as PromptAgentDefinition)?.Tools.Select(t => t.AsAITool()).ToList(); - ApplyToolsToAgentDefinition(agentDefinition, tools, requireInvocableTools); + ApplyToolsToAgentDefinition(creationOptions.Definition, tools, requireInvocableTools); - AgentVersion agentVersion = agentsClient.CreateAgentVersion(name, agentDefinition, creationOptions, cancellationToken).Value; + AgentVersion agentVersion = AgentClient.CreateAgentVersion(name, creationOptions, cancellationToken).Value; return CreateChatClientAgent( - agentsClient, + AgentClient, agentVersion, tools, clientFactory, @@ -592,11 +583,10 @@ public static class AgentsClientExtensions } private static async Task CreateAIAgentAsync( - this AgentsClient agentsClient, + this AgentClient AgentClient, string name, IList? tools, - AgentDefinition agentDefinition, - AgentVersionCreationOptions? agentVersionCreationOptions, + AgentVersionCreationOptions creationOptions, Func? clientFactory, OpenAIClientOptions? openAIClientOptions, bool requireInvocableTools, @@ -604,17 +594,17 @@ public static class AgentsClientExtensions CancellationToken cancellationToken) { Throw.IfNullOrWhitespace(name); - Throw.IfNull(agentsClient); - Throw.IfNull(agentDefinition); + Throw.IfNull(AgentClient); + Throw.IfNull(creationOptions); - tools ??= (agentDefinition as PromptAgentDefinition)?.Tools.Select(t => t.AsAITool()).ToList(); + tools ??= (creationOptions.Definition as PromptAgentDefinition)?.Tools.Select(t => t.AsAITool()).ToList(); - ApplyToolsToAgentDefinition(agentDefinition, tools, requireInvocableTools); + ApplyToolsToAgentDefinition(creationOptions.Definition, tools, requireInvocableTools); - AgentVersion agentVersion = await agentsClient.CreateAgentVersionAsync(name, agentDefinition, agentVersionCreationOptions, cancellationToken).ConfigureAwait(false); + AgentVersion agentVersion = await AgentClient.CreateAgentVersionAsync(name, creationOptions, cancellationToken).ConfigureAwait(false); return CreateChatClientAgent( - agentsClient, + AgentClient, agentVersion, tools, clientFactory, @@ -625,7 +615,7 @@ public static class AgentsClientExtensions /// This method creates an with the specified ChatClientAgentOptions. private static ChatClientAgent CreateChatClientAgent( - AgentsClient agentsClient, + AgentClient AgentClient, AgentVersion agentVersion, ChatClientAgentOptions agentOptions, Func? clientFactory, @@ -633,7 +623,7 @@ public static class AgentsClientExtensions bool requireInvocableTools, IServiceProvider? services) { - IChatClient chatClient = new AzureAIAgentChatClient(agentsClient, agentVersion, agentOptions.ChatOptions, openAIClientOptions); + IChatClient chatClient = new AzureAIAgentChatClient(AgentClient, agentVersion, agentOptions.ChatOptions, openAIClientOptions); if (clientFactory is not null) { @@ -645,7 +635,7 @@ public static class AgentsClientExtensions /// This method creates an with a auto-generated ChatClientAgentOptions from the specified configuration parameters. private static ChatClientAgent CreateChatClientAgent( - AgentsClient agentsClient, + AgentClient AgentClient, AgentVersion agentVersion, IList? tools, Func? clientFactory, @@ -653,7 +643,7 @@ public static class AgentsClientExtensions bool requireInvocableTools, IServiceProvider? services) => CreateChatClientAgent( - agentsClient, + AgentClient, agentVersion, CreateChatClientAgentOptions(agentVersion, new ChatOptions() { Tools = tools }, requireInvocableTools), clientFactory, diff --git a/dotnet/src/Microsoft.Agents.AI.AzureAI/AzureAIAgentChatClient.cs b/dotnet/src/Microsoft.Agents.AI.AzureAI/AzureAIAgentChatClient.cs index 16fe591a30..5ea96ec0c8 100644 --- a/dotnet/src/Microsoft.Agents.AI.AzureAI/AzureAIAgentChatClient.cs +++ b/dotnet/src/Microsoft.Agents.AI.AzureAI/AzureAIAgentChatClient.cs @@ -20,7 +20,7 @@ namespace Microsoft.Agents.AI.AzureAI; internal sealed class AzureAIAgentChatClient : DelegatingChatClient { private readonly ChatClientMetadata? _metadata; - private readonly AgentsClient _agentsClient; + private readonly AgentClient _agentClient; private readonly AgentVersion _agentVersion; private readonly ChatOptions? _chatOptions; @@ -33,25 +33,25 @@ internal sealed class AzureAIAgentChatClient : DelegatingChatClient /// /// Initializes a new instance of the class. /// - /// An instance of to interact with Azure AI Agents services. + /// An instance of to interact with Azure AI Agents services. /// An instance of representing the specific agent to use. /// An instance of representing the options on how the agent was predefined. /// An optional for configuring the underlying OpenAI client. /// /// The provided should be decorated with a for proper functionality. /// - internal AzureAIAgentChatClient(AgentsClient agentsClient, AgentRecord agentRecord, ChatOptions? chatOptions, OpenAIClientOptions? openAIClientOptions = null) - : this(agentsClient, Throw.IfNull(agentRecord).Versions.Latest, chatOptions, openAIClientOptions) + internal AzureAIAgentChatClient(AgentClient agentClient, AgentRecord agentRecord, ChatOptions? chatOptions, OpenAIClientOptions? openAIClientOptions = null) + : this(agentClient, Throw.IfNull(agentRecord).Versions.Latest, chatOptions, openAIClientOptions) { } - internal AzureAIAgentChatClient(AgentsClient agentsClient, AgentVersion agentVersion, ChatOptions? chatOptions, OpenAIClientOptions? openAIClientOptions = null) - : base(agentsClient + internal AzureAIAgentChatClient(AgentClient agentClient, AgentVersion agentVersion, ChatOptions? chatOptions, OpenAIClientOptions? openAIClientOptions = null) + : base(agentClient .GetOpenAIClient(openAIClientOptions) .GetOpenAIResponseClient((agentVersion.Definition as PromptAgentDefinition)?.Model ?? NoOpModel) .AsIChatClient()) { - this._agentsClient = Throw.IfNull(agentsClient); + this._agentClient = Throw.IfNull(agentClient); this._agentVersion = Throw.IfNull(agentVersion); this._metadata = new ChatClientMetadata("azure.ai.agents"); this._chatOptions = chatOptions; @@ -62,8 +62,8 @@ internal sealed class AzureAIAgentChatClient : DelegatingChatClient { return (serviceKey is null && serviceType == typeof(ChatClientMetadata)) ? this._metadata - : (serviceKey is null && serviceType == typeof(AgentsClient)) - ? this._agentsClient + : (serviceKey is null && serviceType == typeof(AgentClient)) + ? this._agentClient : (serviceKey is null && serviceType == typeof(AgentVersion)) ? this._agentVersion : base.GetService(serviceType, serviceKey); @@ -92,7 +92,7 @@ internal sealed class AzureAIAgentChatClient : DelegatingChatClient private async Task GetOrCreateConversationAsync(ChatOptions? options, CancellationToken cancellationToken) => string.IsNullOrWhiteSpace(options?.ConversationId) - ? (await this._agentsClient.GetConversationClient().CreateConversationAsync(cancellationToken: cancellationToken).ConfigureAwait(false)).Value.Id + ? (await this._agentClient.GetConversationClient().CreateConversationAsync(cancellationToken: cancellationToken).ConfigureAwait(false)).Value.Id : options.ConversationId; private ChatOptions GetConversationEnabledChatOptions(ChatOptions? chatOptions, string conversationId) diff --git a/dotnet/src/Microsoft.Agents.AI.Workflows.Declarative/AzureAgentProvider.cs b/dotnet/src/Microsoft.Agents.AI.Workflows.Declarative/AzureAgentProvider.cs index 857989b21c..d2f19aeb27 100644 --- a/dotnet/src/Microsoft.Agents.AI.Workflows.Declarative/AzureAgentProvider.cs +++ b/dotnet/src/Microsoft.Agents.AI.Workflows.Declarative/AzureAgentProvider.cs @@ -29,7 +29,7 @@ public sealed class AzureAgentProvider(Uri projectEndpoint, TokenCredential proj private readonly Dictionary _versionCache = []; private readonly Dictionary _agentCache = []; - private AgentsClient? _agentsClient; + private AgentClient? _agentClient; private ConversationClient? _conversationClient; /// @@ -112,7 +112,7 @@ public sealed class AzureAgentProvider(Uri projectEndpoint, TokenCredential proj return targetAgent; } - AgentsClient client = this.GetAgentsClient(); + AgentClient client = this.GetAgentClient(); if (string.IsNullOrEmpty(agentVersion)) { @@ -137,17 +137,17 @@ public sealed class AzureAgentProvider(Uri projectEndpoint, TokenCredential proj return targetAgent; } - private async Task GetAgentAsync(AgentVersion agentDefinition, CancellationToken cancellationToken = default) + private async Task GetAgentAsync(AgentVersion agentVersion, CancellationToken cancellationToken = default) { - if (this._agentCache.TryGetValue(agentDefinition.Id, out AIAgent? agent)) + if (this._agentCache.TryGetValue(agentVersion.Id, out AIAgent? agent)) { return agent; } - AgentsClient client = this.GetAgentsClient(); + AgentClient client = this.GetAgentClient(); IList? tools = null; - if (agentDefinition.Definition is PromptAgentDefinition promptAgent) + if (agentVersion.Definition is PromptAgentDefinition promptAgent) { tools = promptAgent.Tools @@ -155,7 +155,7 @@ public sealed class AzureAgentProvider(Uri projectEndpoint, TokenCredential proj .ToArray(); } - agent = client.GetAIAgent(agentDefinition, tools, clientFactory: null, openAIClientOptions: null, requireInvocableTools: false, cancellationToken); + agent = client.GetAIAgent(agentVersion, tools, clientFactory: null, openAIClientOptions: null, services: null, cancellationToken); FunctionInvokingChatClient? functionInvokingClient = agent.GetService(); if (functionInvokingClient is not null) @@ -178,7 +178,7 @@ public sealed class AzureAgentProvider(Uri projectEndpoint, TokenCredential proj } } - this._agentCache[agentDefinition.Id] = agent; + this._agentCache[agentVersion.Id] = agent; return agent; } @@ -200,7 +200,7 @@ public sealed class AzureAgentProvider(Uri projectEndpoint, TokenCredential proj bool newestFirst = false, [EnumeratorCancellation] CancellationToken cancellationToken = default) { - AgentsListOrder order = newestFirst ? AgentsListOrder.Asc : AgentsListOrder.Desc; + AgentListOrder order = newestFirst ? AgentListOrder.Ascending : AgentListOrder.Descending; await foreach (AgentResponseItem responseItem in this.GetConversationClient().GetConversationItemsAsync(conversationId, limit, order, after, before, itemType: null, cancellationToken).ConfigureAwait(false)) { ResponseItem[] items = [responseItem.AsOpenAIResponseItem()]; @@ -211,30 +211,30 @@ public sealed class AzureAgentProvider(Uri projectEndpoint, TokenCredential proj } } - private AgentsClient GetAgentsClient() + private AgentClient GetAgentClient() { - if (this._agentsClient is null) + if (this._agentClient is null) { - AgentsClientOptions clientOptions = new(); + AgentClientOptions clientOptions = new(); if (httpClient is not null) { clientOptions.Transport = new HttpClientPipelineTransport(httpClient); } - AgentsClient newClient = new(projectEndpoint, projectCredentials, clientOptions); + AgentClient newClient = new(projectEndpoint, projectCredentials, clientOptions); - Interlocked.CompareExchange(ref this._agentsClient, newClient, null); + Interlocked.CompareExchange(ref this._agentClient, newClient, null); } - return this._agentsClient; + return this._agentClient; } private ConversationClient GetConversationClient() { if (this._conversationClient is null) { - ConversationClient conversationClient = this.GetAgentsClient().GetConversationClient(); + ConversationClient conversationClient = this.GetAgentClient().GetConversationClient(); Interlocked.CompareExchange(ref this._conversationClient, conversationClient, null); } diff --git a/dotnet/src/Shared/Foundry/Agents/AgentFactory.cs b/dotnet/src/Shared/Foundry/Agents/AgentFactory.cs index 1302ade588..b3dc267f40 100644 --- a/dotnet/src/Shared/Foundry/Agents/AgentFactory.cs +++ b/dotnet/src/Shared/Foundry/Agents/AgentFactory.cs @@ -11,13 +11,13 @@ namespace Shared.Foundry; internal static class AgentFactory { public static async ValueTask CreateAgentAsync( - this AgentsClient agentsClient, + this AgentClient agentClient, string agentName, PromptAgentDefinition agentDefinition, string agentDescription) { AgentVersionCreationOptions options = - new() + new(agentDefinition) { Description = agentDescription, Metadata = @@ -27,7 +27,7 @@ internal static class AgentFactory }, }; - AgentVersion agentVersion = await agentsClient.CreateAgentVersionAsync(agentName, agentDefinition, options).ConfigureAwait(false); + AgentVersion agentVersion = await agentClient.CreateAgentVersionAsync(agentName, options).ConfigureAwait(false); Console.ForegroundColor = ConsoleColor.Cyan; try diff --git a/dotnet/tests/Microsoft.Agents.AI.AzureAI.UnitTests/AgentsClientExtensionsTests.cs b/dotnet/tests/Microsoft.Agents.AI.AzureAI.UnitTests/AgentsClientExtensionsTests.cs index 497340b298..e8a6fb18b0 100644 --- a/dotnet/tests/Microsoft.Agents.AI.AzureAI.UnitTests/AgentsClientExtensionsTests.cs +++ b/dotnet/tests/Microsoft.Agents.AI.AzureAI.UnitTests/AgentsClientExtensionsTests.cs @@ -18,27 +18,27 @@ using OpenAI.Responses; namespace Microsoft.Agents.AI.AzureAI.UnitTests; /// -/// Unit tests for the class. +/// Unit tests for the class. /// -public sealed class AgentsClientExtensionsTests +public sealed class AgentClientExtensionsTests { - #region GetAIAgent(AgentsClient, AgentRecord) Tests + #region GetAIAgent(AgentClient, AgentRecord) Tests /// - /// Verify that GetAIAgent throws ArgumentNullException when agentsClient is null. + /// Verify that GetAIAgent throws ArgumentNullException when AgentClient is null. /// [Fact] public void GetAIAgent_WithAgentRecord_WithNullClient_ThrowsArgumentNullException() { // Arrange - AgentsClient? client = null; + AgentClient? client = null; AgentRecord agentRecord = this.CreateTestAgentRecord(); // Act & Assert var exception = Assert.Throws(() => client!.GetAIAgent(agentRecord)); - Assert.Equal("agentsClient", exception.ParamName); + Assert.Equal("AgentClient", exception.ParamName); } /// @@ -48,7 +48,7 @@ public sealed class AgentsClientExtensionsTests public void GetAIAgent_WithAgentRecord_WithNullAgentRecord_ThrowsArgumentNullException() { // Arrange - var mockClient = new Mock(); + var mockClient = new Mock(); // Act & Assert var exception = Assert.Throws(() => @@ -64,7 +64,7 @@ public sealed class AgentsClientExtensionsTests public void GetAIAgent_WithAgentRecord_CreatesValidAgent() { // Arrange - AgentsClient client = this.CreateTestAgentsClient(); + AgentClient client = this.CreateTestAgentClient(); AgentRecord agentRecord = this.CreateTestAgentRecord(); // Act @@ -82,7 +82,7 @@ public sealed class AgentsClientExtensionsTests public void GetAIAgent_WithAgentRecord_WithClientFactory_AppliesFactoryCorrectly() { // Arrange - AgentsClient client = this.CreateTestAgentsClient(); + AgentClient client = this.CreateTestAgentClient(); AgentRecord agentRecord = this.CreateTestAgentRecord(); TestChatClient? testChatClient = null; @@ -100,23 +100,23 @@ public sealed class AgentsClientExtensionsTests #endregion - #region GetAIAgent(AgentsClient, AgentVersion) Tests + #region GetAIAgent(AgentClient, AgentVersion) Tests /// - /// Verify that GetAIAgent throws ArgumentNullException when agentsClient is null. + /// Verify that GetAIAgent throws ArgumentNullException when AgentClient is null. /// [Fact] public void GetAIAgent_WithAgentVersion_WithNullClient_ThrowsArgumentNullException() { // Arrange - AgentsClient? client = null; + AgentClient? client = null; AgentVersion agentVersion = this.CreateTestAgentVersion(); // Act & Assert var exception = Assert.Throws(() => client!.GetAIAgent(agentVersion)); - Assert.Equal("agentsClient", exception.ParamName); + Assert.Equal("AgentClient", exception.ParamName); } /// @@ -126,7 +126,7 @@ public sealed class AgentsClientExtensionsTests public void GetAIAgent_WithAgentVersion_WithNullAgentVersion_ThrowsArgumentNullException() { // Arrange - var mockClient = new Mock(); + var mockClient = new Mock(); // Act & Assert var exception = Assert.Throws(() => @@ -142,7 +142,7 @@ public sealed class AgentsClientExtensionsTests public void GetAIAgent_WithAgentVersion_CreatesValidAgent() { // Arrange - AgentsClient client = this.CreateTestAgentsClient(); + AgentClient client = this.CreateTestAgentClient(); AgentVersion agentVersion = this.CreateTestAgentVersion(); // Act @@ -160,7 +160,7 @@ public sealed class AgentsClientExtensionsTests public void GetAIAgent_WithAgentVersion_WithClientFactory_AppliesFactoryCorrectly() { // Arrange - AgentsClient client = this.CreateTestAgentsClient(); + AgentClient client = this.CreateTestAgentClient(); AgentVersion agentVersion = this.CreateTestAgentVersion(); TestChatClient? testChatClient = null; @@ -183,7 +183,7 @@ public sealed class AgentsClientExtensionsTests public void GetAIAgent_WithAgentVersion_WithRequireInvocableToolsTrue_EnforcesInvocableTools() { // Arrange - AgentsClient client = this.CreateTestAgentsClient(); + AgentClient client = this.CreateTestAgentClient(); AgentVersion agentVersion = this.CreateTestAgentVersion(); var tools = new List { @@ -191,7 +191,7 @@ public sealed class AgentsClientExtensionsTests }; // Act - var agent = client.GetAIAgent(agentVersion, tools: tools, requireInvocableTools: true); + var agent = client.GetAIAgent(agentVersion, tools: tools); // Assert Assert.NotNull(agent); @@ -205,11 +205,11 @@ public sealed class AgentsClientExtensionsTests public void GetAIAgent_WithAgentVersion_WithRequireInvocableToolsFalse_AllowsDeclarativeFunctions() { // Arrange - AgentsClient client = this.CreateTestAgentsClient(); + AgentClient client = this.CreateTestAgentClient(); AgentVersion agentVersion = this.CreateTestAgentVersion(); // Act - should not throw even without tools when requireInvocableTools is false - var agent = client.GetAIAgent(agentVersion, requireInvocableTools: false); + var agent = client.GetAIAgent(agentVersion); // Assert Assert.NotNull(agent); @@ -218,7 +218,7 @@ public sealed class AgentsClientExtensionsTests #endregion - #region GetAIAgent(AgentsClient, ChatClientAgentOptions) Tests + #region GetAIAgent(AgentClient, ChatClientAgentOptions) Tests /// /// Verify that GetAIAgent with ChatClientAgentOptions throws ArgumentNullException when client is null. @@ -227,14 +227,14 @@ public sealed class AgentsClientExtensionsTests public void GetAIAgent_WithOptions_WithNullClient_ThrowsArgumentNullException() { // Arrange - AgentsClient? client = null; + AgentClient? client = null; var options = new ChatClientAgentOptions { Name = "test-agent" }; // Act & Assert var exception = Assert.Throws(() => client!.GetAIAgent(options)); - Assert.Equal("agentsClient", exception.ParamName); + Assert.Equal("AgentClient", exception.ParamName); } /// @@ -244,7 +244,7 @@ public sealed class AgentsClientExtensionsTests public void GetAIAgent_WithOptions_WithNullOptions_ThrowsArgumentNullException() { // Arrange - var mockClient = new Mock(); + var mockClient = new Mock(); // Act & Assert var exception = Assert.Throws(() => @@ -260,7 +260,7 @@ public sealed class AgentsClientExtensionsTests public void GetAIAgent_WithOptions_WithoutName_ThrowsArgumentException() { // Arrange - AgentsClient client = this.CreateTestAgentsClient(); + AgentClient client = this.CreateTestAgentClient(); var options = new ChatClientAgentOptions(); // Act & Assert @@ -277,7 +277,7 @@ public sealed class AgentsClientExtensionsTests public void GetAIAgent_WithOptions_CreatesValidAgent() { // Arrange - AgentsClient client = this.CreateTestAgentsClient(agentName: "test-agent"); + AgentClient client = this.CreateTestAgentClient(agentName: "test-agent"); var options = new ChatClientAgentOptions { Name = "test-agent" }; // Act @@ -295,7 +295,7 @@ public sealed class AgentsClientExtensionsTests public void GetAIAgent_WithOptions_WithClientFactory_AppliesFactoryCorrectly() { // Arrange - AgentsClient client = this.CreateTestAgentsClient(agentName: "test-agent"); + AgentClient client = this.CreateTestAgentClient(agentName: "test-agent"); var options = new ChatClientAgentOptions { Name = "test-agent" }; TestChatClient? testChatClient = null; @@ -313,7 +313,7 @@ public sealed class AgentsClientExtensionsTests #endregion - #region GetAIAgentAsync(AgentsClient, ChatClientAgentOptions) Tests + #region GetAIAgentAsync(AgentClient, ChatClientAgentOptions) Tests /// /// Verify that GetAIAgentAsync with ChatClientAgentOptions throws ArgumentNullException when client is null. @@ -322,14 +322,14 @@ public sealed class AgentsClientExtensionsTests public async Task GetAIAgentAsync_WithOptions_WithNullClient_ThrowsArgumentNullExceptionAsync() { // Arrange - AgentsClient? client = null; + AgentClient? client = null; var options = new ChatClientAgentOptions { Name = "test-agent" }; // Act & Assert var exception = await Assert.ThrowsAsync(() => client!.GetAIAgentAsync(options)); - Assert.Equal("agentsClient", exception.ParamName); + Assert.Equal("AgentClient", exception.ParamName); } /// @@ -339,7 +339,7 @@ public sealed class AgentsClientExtensionsTests public async Task GetAIAgentAsync_WithOptions_WithNullOptions_ThrowsArgumentNullExceptionAsync() { // Arrange - var mockClient = new Mock(); + var mockClient = new Mock(); // Act & Assert var exception = await Assert.ThrowsAsync(() => @@ -355,7 +355,7 @@ public sealed class AgentsClientExtensionsTests public async Task GetAIAgentAsync_WithOptions_CreatesValidAgentAsync() { // Arrange - AgentsClient client = this.CreateTestAgentsClient(agentName: "test-agent"); + AgentClient client = this.CreateTestAgentClient(agentName: "test-agent"); var options = new ChatClientAgentOptions { Name = "test-agent" }; // Act @@ -368,22 +368,22 @@ public sealed class AgentsClientExtensionsTests #endregion - #region GetAIAgent(AgentsClient, string) Tests + #region GetAIAgent(AgentClient, string) Tests /// - /// Verify that GetAIAgent throws ArgumentNullException when agentsClient is null. + /// Verify that GetAIAgent throws ArgumentNullException when AgentClient is null. /// [Fact] public void GetAIAgent_ByName_WithNullClient_ThrowsArgumentNullException() { // Arrange - AgentsClient? client = null; + AgentClient? client = null; // Act & Assert var exception = Assert.Throws(() => client!.GetAIAgent("test-agent")); - Assert.Equal("agentsClient", exception.ParamName); + Assert.Equal("AgentClient", exception.ParamName); } /// @@ -393,7 +393,7 @@ public sealed class AgentsClientExtensionsTests public void GetAIAgent_ByName_WithNullName_ThrowsArgumentNullException() { // Arrange - var mockClient = new Mock(); + var mockClient = new Mock(); // Act & Assert var exception = Assert.Throws(() => @@ -409,7 +409,7 @@ public sealed class AgentsClientExtensionsTests public void GetAIAgent_ByName_WithEmptyName_ThrowsArgumentException() { // Arrange - var mockClient = new Mock(); + var mockClient = new Mock(); // Act & Assert var exception = Assert.Throws(() => @@ -425,7 +425,7 @@ public sealed class AgentsClientExtensionsTests public void GetAIAgent_ByName_WithNonExistentAgent_ThrowsInvalidOperationException() { // Arrange - var mockClient = new Mock(); + var mockClient = new Mock(); mockClient.Setup(c => c.GetAgent(It.IsAny(), It.IsAny())) .Returns(ClientResult.FromOptionalValue((AgentRecord)null!, new MockPipelineResponse(200))); @@ -438,22 +438,22 @@ public sealed class AgentsClientExtensionsTests #endregion - #region GetAIAgentAsync(AgentsClient, string) Tests + #region GetAIAgentAsync(AgentClient, string) Tests /// - /// Verify that GetAIAgentAsync throws ArgumentNullException when agentsClient is null. + /// Verify that GetAIAgentAsync throws ArgumentNullException when AgentClient is null. /// [Fact] public async Task GetAIAgentAsync_ByName_WithNullClient_ThrowsArgumentNullExceptionAsync() { // Arrange - AgentsClient? client = null; + AgentClient? client = null; // Act & Assert var exception = await Assert.ThrowsAsync(() => client!.GetAIAgentAsync("test-agent")); - Assert.Equal("agentsClient", exception.ParamName); + Assert.Equal("AgentClient", exception.ParamName); } /// @@ -463,7 +463,7 @@ public sealed class AgentsClientExtensionsTests public async Task GetAIAgentAsync_ByName_WithNullName_ThrowsArgumentNullExceptionAsync() { // Arrange - var mockClient = new Mock(); + var mockClient = new Mock(); // Act & Assert var exception = await Assert.ThrowsAsync(() => @@ -479,7 +479,7 @@ public sealed class AgentsClientExtensionsTests public async Task GetAIAgentAsync_ByName_WithNonExistentAgent_ThrowsInvalidOperationExceptionAsync() { // Arrange - var mockClient = new Mock(); + var mockClient = new Mock(); mockClient.Setup(c => c.GetAgentAsync(It.IsAny(), It.IsAny())) .ReturnsAsync(ClientResult.FromOptionalValue((AgentRecord)null!, new MockPipelineResponse(200))); @@ -492,7 +492,7 @@ public sealed class AgentsClientExtensionsTests #endregion - #region GetAIAgent(AgentsClient, AgentRecord) with tools Tests + #region GetAIAgent(AgentClient, AgentRecord) with tools Tests /// /// Verify that GetAIAgent with tools parameter passes tools to the agent. @@ -501,7 +501,7 @@ public sealed class AgentsClientExtensionsTests public void GetAIAgent_WithAgentRecordAndTools_PassesToolsToAgent() { // Arrange - AgentsClient client = this.CreateTestAgentsClient(); + AgentClient client = this.CreateTestAgentClient(); AgentRecord agentRecord = this.CreateTestAgentRecord(); var tools = new List { @@ -527,7 +527,7 @@ public sealed class AgentsClientExtensionsTests public void GetAIAgent_WithAgentRecordAndNullTools_WorksCorrectly() { // Arrange - AgentsClient client = this.CreateTestAgentsClient(); + AgentClient client = this.CreateTestAgentClient(); AgentRecord agentRecord = this.CreateTestAgentRecord(); // Act @@ -540,7 +540,7 @@ public sealed class AgentsClientExtensionsTests #endregion - #region GetAIAgentAsync(AgentsClient, string) with tools Tests + #region GetAIAgentAsync(AgentClient, string) with tools Tests /// /// Verify that GetAIAgentAsync with tools parameter creates an agent. @@ -549,7 +549,7 @@ public sealed class AgentsClientExtensionsTests public async Task GetAIAgentAsync_WithNameAndTools_CreatesAgentAsync() { // Arrange - AgentsClient client = this.CreateTestAgentsClient(); + AgentClient client = this.CreateTestAgentClient(); var tools = new List { AIFunctionFactory.Create(() => "test", "test_function", "A test function") @@ -565,22 +565,22 @@ public sealed class AgentsClientExtensionsTests #endregion - #region CreateAIAgent(AgentsClient, string, string) Tests + #region CreateAIAgent(AgentClient, string, string) Tests /// - /// Verify that CreateAIAgent throws ArgumentNullException when agentsClient is null. + /// Verify that CreateAIAgent throws ArgumentNullException when AgentClient is null. /// [Fact] public void CreateAIAgent_WithBasicParams_WithNullClient_ThrowsArgumentNullException() { // Arrange - AgentsClient? client = null; + AgentClient? client = null; // Act & Assert var exception = Assert.Throws(() => client!.CreateAIAgent("test-agent", "model", "instructions")); - Assert.Equal("agentsClient", exception.ParamName); + Assert.Equal("AgentClient", exception.ParamName); } /// @@ -590,7 +590,7 @@ public sealed class AgentsClientExtensionsTests public void CreateAIAgent_WithBasicParams_WithNullName_ThrowsArgumentNullException() { // Arrange - var mockClient = new Mock(); + var mockClient = new Mock(); // Act & Assert var exception = Assert.Throws(() => @@ -601,23 +601,24 @@ public sealed class AgentsClientExtensionsTests #endregion - #region CreateAIAgent(AgentsClient, string, AgentDefinition) Tests + #region CreateAIAgent(AgentClient, string, AgentDefinition) Tests /// - /// Verify that CreateAIAgent throws ArgumentNullException when agentsClient is null. + /// Verify that CreateAIAgent throws ArgumentNullException when AgentClient is null. /// [Fact] public void CreateAIAgent_WithAgentDefinition_WithNullClient_ThrowsArgumentNullException() { // Arrange - AgentsClient? client = null; + AgentClient? client = null; var definition = new PromptAgentDefinition("test-model"); + var options = new AgentVersionCreationOptions(definition); // Act & Assert var exception = Assert.Throws(() => - client!.CreateAIAgent("test-agent", definition)); + client!.CreateAIAgent("test-agent", options)); - Assert.Equal("agentsClient", exception.ParamName); + Assert.Equal("AgentClient", exception.ParamName); } /// @@ -627,51 +628,52 @@ public sealed class AgentsClientExtensionsTests public void CreateAIAgent_WithAgentDefinition_WithNullName_ThrowsArgumentNullException() { // Arrange - var mockClient = new Mock(); + var mockClient = new Mock(); var definition = new PromptAgentDefinition("test-model"); + var options = new AgentVersionCreationOptions(definition); // Act & Assert var exception = Assert.Throws(() => - mockClient.Object.CreateAIAgent(null!, definition)); + mockClient.Object.CreateAIAgent(null!, options)); Assert.Equal("name", exception.ParamName); } /// - /// Verify that CreateAIAgent throws ArgumentNullException when agentDefinition is null. + /// Verify that CreateAIAgent throws ArgumentNullException when creationOptions is null. /// [Fact] public void CreateAIAgent_WithAgentDefinition_WithNullDefinition_ThrowsArgumentNullException() { // Arrange - var mockClient = new Mock(); + var mockClient = new Mock(); // Act & Assert var exception = Assert.Throws(() => - mockClient.Object.CreateAIAgent("test-agent", (AgentDefinition)null!)); + mockClient.Object.CreateAIAgent("test-agent", (AgentVersionCreationOptions)null!)); - Assert.Equal("agentDefinition", exception.ParamName); + Assert.Equal("creationOptions", exception.ParamName); } #endregion - #region CreateAIAgent(AgentsClient, ChatClientAgentOptions, string) Tests + #region CreateAIAgent(AgentClient, ChatClientAgentOptions, string) Tests /// - /// Verify that CreateAIAgent throws ArgumentNullException when agentsClient is null. + /// Verify that CreateAIAgent throws ArgumentNullException when AgentClient is null. /// [Fact] public void CreateAIAgent_WithOptions_WithNullClient_ThrowsArgumentNullException() { // Arrange - AgentsClient? client = null; + AgentClient? client = null; var options = new ChatClientAgentOptions { Name = "test-agent" }; // Act & Assert var exception = Assert.Throws(() => client!.CreateAIAgent("model", options)); - Assert.Equal("agentsClient", exception.ParamName); + Assert.Equal("AgentClient", exception.ParamName); } /// @@ -681,7 +683,7 @@ public sealed class AgentsClientExtensionsTests public void CreateAIAgent_WithOptions_WithNullOptions_ThrowsArgumentNullException() { // Arrange - var mockClient = new Mock(); + var mockClient = new Mock(); // Act & Assert var exception = Assert.Throws(() => @@ -697,7 +699,7 @@ public sealed class AgentsClientExtensionsTests public void CreateAIAgent_WithOptions_WithNullModel_ThrowsArgumentNullException() { // Arrange - var mockClient = new Mock(); + var mockClient = new Mock(); var options = new ChatClientAgentOptions { Name = "test-agent" }; // Act & Assert @@ -714,7 +716,7 @@ public sealed class AgentsClientExtensionsTests public void CreateAIAgent_WithOptions_WithoutName_ThrowsException() { // Arrange - AgentsClient client = this.CreateTestAgentsClient(); + AgentClient client = this.CreateTestAgentClient(); var options = new ChatClientAgentOptions(); // Act & Assert @@ -731,7 +733,7 @@ public sealed class AgentsClientExtensionsTests public void CreateAIAgent_WithModelAndOptions_CreatesValidAgent() { // Arrange - AgentsClient client = this.CreateTestAgentsClient(agentName: "test-agent", instructions: "Test instructions"); + AgentClient client = this.CreateTestAgentClient(agentName: "test-agent", instructions: "Test instructions"); var options = new ChatClientAgentOptions { Name = "test-agent", @@ -754,7 +756,7 @@ public sealed class AgentsClientExtensionsTests public void CreateAIAgent_WithModelAndOptions_WithClientFactory_AppliesFactoryCorrectly() { // Arrange - AgentsClient client = this.CreateTestAgentsClient(agentName: "test-agent", instructions: "Test instructions"); + AgentClient client = this.CreateTestAgentClient(agentName: "test-agent", instructions: "Test instructions"); var options = new ChatClientAgentOptions { Name = "test-agent", @@ -782,7 +784,7 @@ public sealed class AgentsClientExtensionsTests public async Task CreateAIAgentAsync_WithModelAndOptions_CreatesValidAgentAsync() { // Arrange - AgentsClient client = this.CreateTestAgentsClient(agentName: "test-agent", instructions: "Test instructions"); + AgentClient client = this.CreateTestAgentClient(agentName: "test-agent", instructions: "Test instructions"); var options = new ChatClientAgentOptions { Name = "test-agent", @@ -805,7 +807,7 @@ public sealed class AgentsClientExtensionsTests public async Task CreateAIAgentAsync_WithModelAndOptions_WithClientFactory_AppliesFactoryCorrectlyAsync() { // Arrange - AgentsClient client = this.CreateTestAgentsClient(agentName: "test-agent", instructions: "Test instructions"); + AgentClient client = this.CreateTestAgentClient(agentName: "test-agent", instructions: "Test instructions"); var options = new ChatClientAgentOptions { Name = "test-agent", @@ -828,39 +830,40 @@ public sealed class AgentsClientExtensionsTests #endregion - #region CreateAIAgentAsync(AgentsClient, string, AgentDefinition) Tests + #region CreateAIAgentAsync(AgentClient, string, AgentDefinition) Tests /// - /// Verify that CreateAIAgentAsync throws ArgumentNullException when agentsClient is null. + /// Verify that CreateAIAgentAsync throws ArgumentNullException when AgentClient is null. /// [Fact] public async Task CreateAIAgentAsync_WithAgentDefinition_WithNullClient_ThrowsArgumentNullExceptionAsync() { // Arrange - AgentsClient? client = null; + AgentClient? client = null; var definition = new PromptAgentDefinition("test-model"); + var options = new AgentVersionCreationOptions(definition); // Act & Assert var exception = await Assert.ThrowsAsync(() => - client!.CreateAIAgentAsync("agent-name", definition)); + client!.CreateAIAgentAsync("agent-name", options)); - Assert.Equal("agentsClient", exception.ParamName); + Assert.Equal("AgentClient", exception.ParamName); } /// - /// Verify that CreateAIAgentAsync throws ArgumentNullException when agentDefinition is null. + /// Verify that CreateAIAgentAsync throws ArgumentNullException when creationOptions is null. /// [Fact] public async Task CreateAIAgentAsync_WithAgentDefinition_WithNullDefinition_ThrowsArgumentNullExceptionAsync() { // Arrange - var mockClient = new Mock(); + var mockClient = new Mock(); // Act & Assert var exception = await Assert.ThrowsAsync(() => - mockClient.Object.CreateAIAgentAsync(name: "agent-name", null!)); + mockClient.Object.CreateAIAgentAsync(name: "agent-name", (AgentVersionCreationOptions)null!)); - Assert.Equal("agentDefinition", exception.ParamName); + Assert.Equal("creationOptions", exception.ParamName); } #endregion @@ -874,11 +877,12 @@ public sealed class AgentsClientExtensionsTests public void CreateAIAgent_WithDefinition_CreatesAgentSuccessfully() { // Arrange - AgentsClient client = this.CreateTestAgentsClient(); + AgentClient client = this.CreateTestAgentClient(); var definition = new PromptAgentDefinition("test-model") { Instructions = "Test" }; + var options = new AgentVersionCreationOptions(definition); // Act - var agent = client.CreateAIAgent("test-agent", definition); + var agent = client.CreateAIAgent("test-agent", options); // Assert Assert.NotNull(agent); @@ -895,10 +899,12 @@ public sealed class AgentsClientExtensionsTests var definition = new PromptAgentDefinition("test-model") { Instructions = "Test" }; var definitionResponse = GeneratePromptDefinitionResponse(definition, null); - AgentsClient client = this.CreateTestAgentsClient(agentName: "test-agent", agentDefinitionResponse: definitionResponse); + AgentClient client = this.CreateTestAgentClient(agentName: "test-agent", agentDefinitionResponse: definitionResponse); + + var options = new AgentVersionCreationOptions(definition); // Act - var agent = client.CreateAIAgent("test-agent", definition); + var agent = client.CreateAIAgent("test-agent", options); // Assert Assert.NotNull(agent); @@ -913,10 +919,12 @@ public sealed class AgentsClientExtensionsTests { // Arrange var definition = new PromptAgentDefinition("test-model") { Instructions = "Test" }; - AgentsClient client = this.CreateTestAgentsClient(agentName: "test-agent", agentDefinitionResponse: definition); + AgentClient client = this.CreateTestAgentClient(agentName: "test-agent", agentDefinitionResponse: definition); + + var options = new AgentVersionCreationOptions(definition); // Act - var agent = client.CreateAIAgent("test-agent", definition); + var agent = client.CreateAIAgent("test-agent", options); // Assert Assert.NotNull(agent); @@ -937,10 +945,12 @@ public sealed class AgentsClientExtensionsTests // Create a response definition with the same tool var definitionResponse = GeneratePromptDefinitionResponse(definition, definition.Tools.Select(t => t.AsAITool()).ToList()); - AgentsClient client = this.CreateTestAgentsClient(agentName: "test-agent", agentDefinitionResponse: definitionResponse); + AgentClient client = this.CreateTestAgentClient(agentName: "test-agent", agentDefinitionResponse: definitionResponse); + + var options = new AgentVersionCreationOptions(definition); // Act - var agent = client.CreateAIAgent("test-agent", definition); + var agent = client.CreateAIAgent("test-agent", options); // Assert Assert.NotNull(agent); @@ -965,10 +975,12 @@ public sealed class AgentsClientExtensionsTests var definition = new PromptAgentDefinition("test-model"); var agentDefinitionResponse = GeneratePromptDefinitionResponse(definition, null); - AgentsClient client = this.CreateTestAgentsClient(agentName: "test-agent", agentDefinitionResponse: agentDefinitionResponse); + AgentClient client = this.CreateTestAgentClient(agentName: "test-agent", agentDefinitionResponse: agentDefinitionResponse); + + var options = new AgentVersionCreationOptions(definition); // Act - var agent = client.CreateAIAgent("test-agent", definition); + var agent = client.CreateAIAgent("test-agent", options); // Assert Assert.NotNull(agent); @@ -982,7 +994,7 @@ public sealed class AgentsClientExtensionsTests public void GetAIAgent_WithInlineToolsInDefinition_ThrowsArgumentException() { // Arrange - AgentsClient client = this.CreateTestAgentsClient(); + AgentClient client = this.CreateTestAgentClient(); var agentVersion = this.CreateTestAgentVersion(); // Manually add tools to the definition to simulate inline tools @@ -1009,7 +1021,7 @@ public sealed class AgentsClientExtensionsTests public void GetAIAgent_WithParameterTools_AcceptsTools() { // Arrange - AgentsClient client = this.CreateTestAgentsClient(); + AgentClient client = this.CreateTestAgentClient(); AgentRecord agentRecord = this.CreateTestAgentRecord(); var tools = new List { @@ -1042,10 +1054,12 @@ public sealed class AgentsClientExtensionsTests // Simulate agent definition response with the tools var definitionResponse = GeneratePromptDefinitionResponse(definition, definition.Tools.Select(t => t.AsAITool()).ToList()); - AgentsClient client = this.CreateTestAgentsClient(agentDefinitionResponse: definitionResponse); + AgentClient client = this.CreateTestAgentClient(agentDefinitionResponse: definitionResponse); + + var options = new AgentVersionCreationOptions(definition); // Act - var agent = client.CreateAIAgent("test-agent", definition); + var agent = client.CreateAIAgent("test-agent", options); // Assert Assert.NotNull(agent); @@ -1078,10 +1092,12 @@ public sealed class AgentsClientExtensionsTests definitionResponse.Tools.Add(tool); } - AgentsClient client = this.CreateTestAgentsClient(agentDefinitionResponse: definitionResponse); + AgentClient client = this.CreateTestAgentClient(agentDefinitionResponse: definitionResponse); + + var options = new AgentVersionCreationOptions(definition); // Act - var agent = client.CreateAIAgent("test-agent", definition); + var agent = client.CreateAIAgent("test-agent", options); // Assert Assert.NotNull(agent); @@ -1125,15 +1141,17 @@ public sealed class AgentsClientExtensionsTests definition.Tools.Add((ResponseTool)AgentTool.CreateOpenApiTool(new OpenApiFunctionDefinition("name", BinaryData.FromString(OpenAPISpec), new OpenApiAnonymousAuthDetails()))); definition.Tools.Add((ResponseTool)AgentTool.CreateSharepointTool(sharepointParameters)); definition.Tools.Add((ResponseTool)AgentTool.CreateStructuredOutputsTool(structuredOutputs)); - definition.Tools.Add((ResponseTool)new AzureAISearchAgentTool(new())); + definition.Tools.Add((ResponseTool)AgentTool.CreateAzureAISearchTool(new AzureAISearchToolOptions([new AzureAISearchIndex() { IndexName = "name" }]))); // Generate agent definition response with the tools var definitionResponse = GeneratePromptDefinitionResponse(definition, definition.Tools.Select(t => t.AsAITool()).ToList()); - AgentsClient client = this.CreateTestAgentsClient(agentDefinitionResponse: definitionResponse); + AgentClient client = this.CreateTestAgentClient(agentDefinitionResponse: definitionResponse); + + var options = new AgentVersionCreationOptions(definition); // Act - var agent = client.CreateAIAgent("test-agent", definition); + var agent = client.CreateAIAgent("test-agent", options); // Assert Assert.NotNull(agent); @@ -1161,7 +1179,7 @@ public sealed class AgentsClientExtensionsTests var definitionResponse = GeneratePromptDefinitionResponse(new PromptAgentDefinition("test-model") { Instructions = "Test instructions" }, tools); - AgentsClient client = this.CreateTestAgentsClient(agentName: "test-agent", agentDefinitionResponse: definitionResponse); + AgentClient client = this.CreateTestAgentClient(agentName: "test-agent", agentDefinitionResponse: definitionResponse); // Act var agent = client.CreateAIAgent( @@ -1189,12 +1207,14 @@ public sealed class AgentsClientExtensionsTests public async Task CreateAIAgentAsync_WithDefinitionTools_CreatesAgentAsync() { // Arrange - AgentsClient client = this.CreateTestAgentsClient(); + AgentClient client = this.CreateTestAgentClient(); var definition = new PromptAgentDefinition("test-model") { Instructions = "Test instructions" }; definition.Tools.Add(ResponseTool.CreateFunctionTool("async_tool", BinaryData.FromString("{}"), strictModeEnabled: false)); + var options = new AgentVersionCreationOptions(definition); + // Act - var agent = await client.CreateAIAgentAsync("test-agent", definition); + var agent = await client.CreateAIAgentAsync("test-agent", options); // Assert Assert.NotNull(agent); @@ -1208,7 +1228,7 @@ public sealed class AgentsClientExtensionsTests public async Task GetAIAgentAsync_WithToolsParameter_CreatesAgentAsync() { // Arrange - AgentsClient client = this.CreateTestAgentsClient(); + AgentClient client = this.CreateTestAgentClient(); var tools = new List { AIFunctionFactory.Create(() => "async_get_result", "async_get_tool", "An async get tool") @@ -1233,7 +1253,7 @@ public sealed class AgentsClientExtensionsTests public void CreateAIAgent_WithDeclarativeFunctionInDefinition_AcceptsDeclarativeFunction() { // Arrange - AgentsClient client = this.CreateTestAgentsClient(); + AgentClient client = this.CreateTestAgentClient(); var definition = new PromptAgentDefinition("test-model") { Instructions = "Test" }; // Create a declarative function (not invocable) using AIFunctionFactory.CreateDeclaration @@ -1243,8 +1263,10 @@ public sealed class AgentsClientExtensionsTests // Add to definition definition.Tools.Add(declarativeFunction.AsOpenAIResponseTool() ?? throw new InvalidOperationException()); + var options = new AgentVersionCreationOptions(definition); + // Act - var agent = client.CreateAIAgent("test-agent", definition); + var agent = client.CreateAIAgent("test-agent", options); // Assert Assert.NotNull(agent); @@ -1271,10 +1293,12 @@ public sealed class AgentsClientExtensionsTests var definitionResponse = new PromptAgentDefinition("test-model") { Instructions = "Test" }; definitionResponse.Tools.Add(declarativeFunction.AsOpenAIResponseTool() ?? throw new InvalidOperationException()); - AgentsClient client = this.CreateTestAgentsClient(agentName: "test-agent", agentDefinitionResponse: definitionResponse); + AgentClient client = this.CreateTestAgentClient(agentName: "test-agent", agentDefinitionResponse: definitionResponse); + + var options = new AgentVersionCreationOptions(definition); // Act - var agent = client.CreateAIAgent("test-agent", definition); + var agent = client.CreateAIAgent("test-agent", options); // Assert Assert.NotNull(agent); @@ -1302,10 +1326,12 @@ public sealed class AgentsClientExtensionsTests var definitionResponse = new PromptAgentDefinition("test-model") { Instructions = "Test" }; definitionResponse.Tools.Add(functionTool); - AgentsClient client = this.CreateTestAgentsClient(agentName: "test-agent", agentDefinitionResponse: definitionResponse); + AgentClient client = this.CreateTestAgentClient(agentName: "test-agent", agentDefinitionResponse: definitionResponse); + + var options = new AgentVersionCreationOptions(definition); // Act - var agent = client.CreateAIAgent("test-agent", definition); + var agent = client.CreateAIAgent("test-agent", options); // Assert Assert.NotNull(agent); @@ -1335,10 +1361,12 @@ public sealed class AgentsClientExtensionsTests var definitionResponse = new PromptAgentDefinition("test-model") { Instructions = "Test" }; definitionResponse.Tools.Add(functionTool); - AgentsClient client = this.CreateTestAgentsClient(agentName: "test-agent", agentDefinitionResponse: definitionResponse); + AgentClient client = this.CreateTestAgentClient(agentName: "test-agent", agentDefinitionResponse: definitionResponse); + + var options = new AgentVersionCreationOptions(definition); // Act - var agent = await client.CreateAIAgentAsync("test-agent", definition); + var agent = await client.CreateAIAgentAsync("test-agent", options); // Assert Assert.NotNull(agent); @@ -1352,7 +1380,7 @@ public sealed class AgentsClientExtensionsTests public async Task CreateAIAgentAsync_WithDeclarativeFunctionFromDefinition_AcceptsDeclarativeFunctionAsync() { // Arrange - AgentsClient client = this.CreateTestAgentsClient(); + AgentClient client = this.CreateTestAgentClient(); var definition = new PromptAgentDefinition("test-model") { Instructions = "Test" }; // Create a declarative function (not invocable) using AIFunctionFactory.CreateDeclaration @@ -1362,8 +1390,10 @@ public sealed class AgentsClientExtensionsTests // Add to definition definition.Tools.Add(declarativeFunction.AsOpenAIResponseTool() ?? throw new InvalidOperationException()); + var options = new AgentVersionCreationOptions(definition); + // Act - var agent = await client.CreateAIAgentAsync("test-agent", definition); + var agent = await client.CreateAIAgentAsync("test-agent", options); // Assert Assert.NotNull(agent); @@ -1390,10 +1420,12 @@ public sealed class AgentsClientExtensionsTests var definitionResponse = new PromptAgentDefinition("test-model") { Instructions = "Test" }; definitionResponse.Tools.Add(declarativeFunction.AsOpenAIResponseTool() ?? throw new InvalidOperationException()); - AgentsClient client = this.CreateTestAgentsClient(agentName: "test-agent", agentDefinitionResponse: definitionResponse); + AgentClient client = this.CreateTestAgentClient(agentName: "test-agent", agentDefinitionResponse: definitionResponse); + + var options = new AgentVersionCreationOptions(definition); // Act - var agent = await client.CreateAIAgentAsync("test-agent", definition); + var agent = await client.CreateAIAgentAsync("test-agent", options); // Assert Assert.NotNull(agent); @@ -1414,10 +1446,12 @@ public sealed class AgentsClientExtensionsTests var definition = new PromptAgentDefinition("test-model") { Instructions = "Test instructions" }; var definitionResponse = GeneratePromptDefinitionResponse(definition, null); - AgentsClient client = this.CreateTestAgentsClient(agentName: "test-agent", agentDefinitionResponse: definitionResponse); + AgentClient client = this.CreateTestAgentClient(agentName: "test-agent", agentDefinitionResponse: definitionResponse); + + var options = new AgentVersionCreationOptions(definition); // Act - var agent = client.CreateAIAgent("test-agent", definition); + var agent = client.CreateAIAgent("test-agent", options); // Assert Assert.NotNull(agent); @@ -1434,7 +1468,7 @@ public sealed class AgentsClientExtensionsTests public void GetAIAgent_WithOptions_PreservesCustomProperties() { // Arrange - AgentsClient client = this.CreateTestAgentsClient(agentName: "test-agent", instructions: "Custom instructions", description: "Custom description"); + AgentClient client = this.CreateTestAgentClient(agentName: "test-agent", instructions: "Custom instructions", description: "Custom description"); var options = new ChatClientAgentOptions { Name = "test-agent", @@ -1468,7 +1502,7 @@ public sealed class AgentsClientExtensionsTests new PromptAgentDefinition("test-model") { Instructions = "Test" }, tools); - AgentsClient client = this.CreateTestAgentsClient(agentName: "test-agent", agentDefinitionResponse: definitionResponse); + AgentClient client = this.CreateTestAgentClient(agentName: "test-agent", agentDefinitionResponse: definitionResponse); var options = new ChatClientAgentOptions { @@ -1502,7 +1536,7 @@ public sealed class AgentsClientExtensionsTests public void GetAIAgent_WithClientFactory_WrapsUnderlyingChatClient() { // Arrange - AgentsClient client = this.CreateTestAgentsClient(); + AgentClient client = this.CreateTestAgentClient(); AgentRecord agentRecord = this.CreateTestAgentRecord(); int factoryCallCount = 0; @@ -1529,14 +1563,16 @@ public sealed class AgentsClientExtensionsTests public void CreateAIAgent_WithClientFactory_ReceivesCorrectUnderlyingClient() { // Arrange - AgentsClient client = this.CreateTestAgentsClient(); + AgentClient client = this.CreateTestAgentClient(); var definition = new PromptAgentDefinition("test-model") { Instructions = "Test" }; IChatClient? receivedClient = null; + var options = new AgentVersionCreationOptions(definition); + // Act var agent = client.CreateAIAgent( "test-agent", - definition, + options, clientFactory: (innerClient) => { receivedClient = innerClient; @@ -1557,7 +1593,7 @@ public sealed class AgentsClientExtensionsTests public void GetAIAgent_MultipleCallsWithClientFactory_CreatesIndependentClients() { // Arrange - AgentsClient client = this.CreateTestAgentsClient(); + AgentClient client = this.CreateTestAgentClient(); AgentRecord agentRecord = this.CreateTestAgentRecord(); // Act @@ -1589,7 +1625,7 @@ public sealed class AgentsClientExtensionsTests const string AgentName = "test-agent"; const string Model = "test-model"; const string Instructions = "Test instructions"; - AgentsClient client = this.CreateTestAgentsClient(AgentName, Instructions); + AgentClient client = this.CreateTestAgentClient(AgentName, Instructions); // Act var agent = client.CreateAIAgent( @@ -1616,12 +1652,14 @@ public sealed class AgentsClientExtensionsTests var definition = new PromptAgentDefinition("test-model") { Instructions = "Test" }; var agentDefinitionResponse = GeneratePromptDefinitionResponse(definition, null); - AgentsClient client = this.CreateTestAgentsClient(agentName: "test-agent", agentDefinitionResponse: agentDefinitionResponse); + AgentClient client = this.CreateTestAgentClient(agentName: "test-agent", agentDefinitionResponse: agentDefinitionResponse); + + var options = new AgentVersionCreationOptions(definition); // Act var agent = client.CreateAIAgent( "test-agent", - definition, + options, clientFactory: (innerClient) => new TestChatClient(innerClient)); // Assert @@ -1637,11 +1675,11 @@ public sealed class AgentsClientExtensionsTests #region Helper Methods /// - /// Creates a test AgentsClient with fake behavior. + /// Creates a test AgentClient with fake behavior. /// - private FakeAgentsClient CreateTestAgentsClient(string? agentName = null, string? instructions = null, string? description = null, AgentDefinition? agentDefinitionResponse = null) + private FakeAgentClient CreateTestAgentClient(string? agentName = null, string? instructions = null, string? description = null, AgentDefinition? agentDefinitionResponse = null) { - return new FakeAgentsClient(agentName, instructions, description, agentDefinitionResponse); + return new FakeAgentClient(agentName, instructions, description, agentDefinitionResponse); } /// @@ -1732,16 +1770,16 @@ public sealed class AgentsClientExtensionsTests } /// - /// Fake AgentsClient for testing. + /// Fake AgentClient for testing. /// - private sealed class FakeAgentsClient : AgentsClient + private sealed class FakeAgentClient : AgentClient { private readonly string? _agentName; private readonly string? _instructions; private readonly string? _description; private readonly AgentDefinition? _agentDefinition; - public FakeAgentsClient(string? agentName = null, string? instructions = null, string? description = null, AgentDefinition? agentDefinitionResponse = null) + public FakeAgentClient(string? agentName = null, string? instructions = null, string? description = null, AgentDefinition? agentDefinitionResponse = null) { this._agentName = agentName; this._instructions = instructions; @@ -1764,12 +1802,12 @@ public sealed class AgentsClientExtensionsTests return Task.FromResult(ClientResult.FromValue(ModelReaderWriter.Read(BinaryData.FromString(this.ApplyResponseChanges(AgentTestJsonObject)))!, new MockPipelineResponse(200))); } - public override ClientResult CreateAgentVersion(string agentName, AgentDefinition definition, AgentVersionCreationOptions? options = null, CancellationToken cancellationToken = default) + public override ClientResult CreateAgentVersion(string agentName, AgentVersionCreationOptions? options = null, CancellationToken cancellationToken = default) { return ClientResult.FromValue(ModelReaderWriter.Read(BinaryData.FromString(this.ApplyResponseChanges(AgentVersionTestJsonObject)))!, new MockPipelineResponse(200)); } - public override Task> CreateAgentVersionAsync(string agentName, AgentDefinition definition, AgentVersionCreationOptions? options = null, CancellationToken cancellationToken = default) + public override Task> CreateAgentVersionAsync(string agentName, AgentVersionCreationOptions? options = null, CancellationToken cancellationToken = default) { return Task.FromResult(ClientResult.FromValue(ModelReaderWriter.Read(BinaryData.FromString(this.ApplyResponseChanges(AgentVersionTestJsonObject)))!, new MockPipelineResponse(200))); } @@ -1819,46 +1857,6 @@ public sealed class AgentsClientExtensionsTests return modifiedJson; } - - public override ClientResult CreateAgent(string name, AgentDefinition definition, AgentCreationOptions? options = null, CancellationToken cancellationToken = default) - { - string agentJson = AgentTestJsonObject.Replace("\"agent_abc123\"", $"\"{name}\""); - var agentRecord = ModelReaderWriter.Read(BinaryData.FromString(agentJson))!; - - // Update the agent version's definition to match the provided definition - if (agentRecord.Versions.Latest is AgentVersion agentVersion && - definition is PromptAgentDefinition promptDef && - agentVersion.Definition is PromptAgentDefinition versionPromptDef) - { - // Copy tools from the provided definition to the version's definition - foreach (var tool in promptDef.Tools) - { - versionPromptDef.Tools.Add(tool); - } - } - - return ClientResult.FromValue(agentRecord, new MockPipelineResponse(200)); - } - - public override Task> CreateAgentAsync(string name, AgentDefinition definition, AgentCreationOptions? options = null, CancellationToken cancellationToken = default) - { - string agentJson = AgentTestJsonObject.Replace("\"agent_abc123\"", $"\"{name}\""); - var agentRecord = ModelReaderWriter.Read(BinaryData.FromString(agentJson))!; - - // Update the agent version's definition to match the provided definition - if (agentRecord.Versions.Latest is AgentVersion agentVersion && - definition is PromptAgentDefinition promptDef && - agentVersion.Definition is PromptAgentDefinition versionPromptDef) - { - // Copy tools from the provided definition to the version's definition - foreach (var tool in promptDef.Tools) - { - versionPromptDef.Tools.Add(tool); - } - } - - return Task.FromResult(ClientResult.FromValue(agentRecord, new MockPipelineResponse(200))); - } } private static PromptAgentDefinition GeneratePromptDefinitionResponse(PromptAgentDefinition inputDefinition, List? tools) diff --git a/dotnet/tests/Microsoft.Agents.AI.Workflows.Declarative.IntegrationTests/Agents/FunctionToolAgentProvider.cs b/dotnet/tests/Microsoft.Agents.AI.Workflows.Declarative.IntegrationTests/Agents/FunctionToolAgentProvider.cs index 514aac94fe..d9e9544e08 100644 --- a/dotnet/tests/Microsoft.Agents.AI.Workflows.Declarative.IntegrationTests/Agents/FunctionToolAgentProvider.cs +++ b/dotnet/tests/Microsoft.Agents.AI.Workflows.Declarative.IntegrationTests/Agents/FunctionToolAgentProvider.cs @@ -23,10 +23,10 @@ internal sealed class FunctionToolAgentProvider(IConfiguration configuration) : AIFunctionFactory.Create(menuPlugin.GetItemPrice), ]; - AgentsClient agentsClient = new(foundryEndpoint, new AzureCliCredential()); + AgentClient agentClient = new(foundryEndpoint, new AzureCliCredential()); yield return - await agentsClient.CreateAgentAsync( + await agentClient.CreateAgentAsync( agentName: "MenuAgent", agentDefinition: this.DefineMenuAgent(functions), agentDescription: "Provides information about the restaurant menu"); diff --git a/dotnet/tests/Microsoft.Agents.AI.Workflows.Declarative.IntegrationTests/Agents/MarketingAgentProvider.cs b/dotnet/tests/Microsoft.Agents.AI.Workflows.Declarative.IntegrationTests/Agents/MarketingAgentProvider.cs index ac5b20cb61..f8a4a02e5c 100644 --- a/dotnet/tests/Microsoft.Agents.AI.Workflows.Declarative.IntegrationTests/Agents/MarketingAgentProvider.cs +++ b/dotnet/tests/Microsoft.Agents.AI.Workflows.Declarative.IntegrationTests/Agents/MarketingAgentProvider.cs @@ -13,22 +13,22 @@ internal sealed class MarketingAgentProvider(IConfiguration configuration) : Age { protected override async IAsyncEnumerable CreateAgentsAsync(Uri foundryEndpoint) { - AgentsClient agentsClient = new(foundryEndpoint, new AzureCliCredential()); + AgentClient agentClient = new(foundryEndpoint, new AzureCliCredential()); yield return - await agentsClient.CreateAgentAsync( + await agentClient.CreateAgentAsync( agentName: "AnalystAgent", agentDefinition: this.DefineAnalystAgent(), agentDescription: "Analyst agent for Marketing workflow"); yield return - await agentsClient.CreateAgentAsync( + await agentClient.CreateAgentAsync( agentName: "WriterAgent", agentDefinition: this.DefineWriterAgent(), agentDescription: "Writer agent for Marketing workflow"); yield return - await agentsClient.CreateAgentAsync( + await agentClient.CreateAgentAsync( agentName: "EditorAgent", agentDefinition: this.DefineEditorAgent(), agentDescription: "Editor agent for Marketing workflow"); diff --git a/dotnet/tests/Microsoft.Agents.AI.Workflows.Declarative.IntegrationTests/Agents/MathChatAgentProvider.cs b/dotnet/tests/Microsoft.Agents.AI.Workflows.Declarative.IntegrationTests/Agents/MathChatAgentProvider.cs index 8fb352ea92..a86f75d96a 100644 --- a/dotnet/tests/Microsoft.Agents.AI.Workflows.Declarative.IntegrationTests/Agents/MathChatAgentProvider.cs +++ b/dotnet/tests/Microsoft.Agents.AI.Workflows.Declarative.IntegrationTests/Agents/MathChatAgentProvider.cs @@ -13,16 +13,16 @@ internal sealed class MathChatAgentProvider(IConfiguration configuration) : Agen { protected override async IAsyncEnumerable CreateAgentsAsync(Uri foundryEndpoint) { - AgentsClient agentsClient = new(foundryEndpoint, new AzureCliCredential()); + AgentClient agentClient = new(foundryEndpoint, new AzureCliCredential()); yield return - await agentsClient.CreateAgentAsync( + await agentClient.CreateAgentAsync( agentName: "StudentAgent", agentDefinition: this.DefineStudentAgent(), agentDescription: "Student agent for MathChat workflow"); yield return - await agentsClient.CreateAgentAsync( + await agentClient.CreateAgentAsync( agentName: "TeacherAgent", agentDefinition: this.DefineTeacherAgent(), agentDescription: "Teacher agent for MathChat workflow"); diff --git a/dotnet/tests/Microsoft.Agents.AI.Workflows.Declarative.IntegrationTests/Agents/TestAgentProvider.cs b/dotnet/tests/Microsoft.Agents.AI.Workflows.Declarative.IntegrationTests/Agents/TestAgentProvider.cs index c84ca52ca6..0f129e174a 100644 --- a/dotnet/tests/Microsoft.Agents.AI.Workflows.Declarative.IntegrationTests/Agents/TestAgentProvider.cs +++ b/dotnet/tests/Microsoft.Agents.AI.Workflows.Declarative.IntegrationTests/Agents/TestAgentProvider.cs @@ -13,10 +13,10 @@ internal sealed class TestAgentProvider(IConfiguration configuration) : AgentPro { protected override async IAsyncEnumerable CreateAgentsAsync(Uri foundryEndpoint) { - AgentsClient agentsClient = new(foundryEndpoint, new AzureCliCredential()); + AgentClient agentClient = new(foundryEndpoint, new AzureCliCredential()); yield return - await agentsClient.CreateAgentAsync( + await agentClient.CreateAgentAsync( agentName: "TestAgent", agentDefinition: this.DefineMenuAgent(), agentDescription: "Provides information about the restaurant menu"); diff --git a/dotnet/tests/Microsoft.Agents.AI.Workflows.Declarative.IntegrationTests/MediaInputTest.cs b/dotnet/tests/Microsoft.Agents.AI.Workflows.Declarative.IntegrationTests/MediaInputTest.cs index 735a985c20..fce0952cd2 100644 --- a/dotnet/tests/Microsoft.Agents.AI.Workflows.Declarative.IntegrationTests/MediaInputTest.cs +++ b/dotnet/tests/Microsoft.Agents.AI.Workflows.Declarative.IntegrationTests/MediaInputTest.cs @@ -42,7 +42,7 @@ public sealed class MediaInputTest(ITestOutputHelper output) : IntegrationTest(o public async Task ValidateImageUploadAsync() { byte[] imageData = await DownloadFileAsync(); - AgentsClient client = new(this.TestEndpoint, new AzureCliCredential()); + AgentClient client = new(this.TestEndpoint, new AzureCliCredential()); using MemoryStream contentStream = new(imageData); OpenAIFileClient fileClient = client.GetOpenAIClient().GetOpenAIFileClient(); OpenAIFile fileInfo = await fileClient.UploadFileAsync(contentStream, "basic-text.pdf", FileUploadPurpose.Assistants);