diff --git a/dotnet/README.md b/dotnet/README.md index 1d29dbbc2a..4e52260f56 100644 --- a/dotnet/README.md +++ b/dotnet/README.md @@ -21,7 +21,7 @@ var deploymentName = Environment.GetEnvironmentVariable("AZURE_OPENAI_DEPLOYMENT var agent = new AzureOpenAIClient(new Uri(endpoint), new AzureCliCredential()) .GetOpenAIResponseClient(deploymentName) - .CreateAIAgent(name: "HaikuBot", instructions: "You are an upbeat assistant that writes beautifully."); + .AsAIAgent(name: "HaikuBot", instructions: "You are an upbeat assistant that writes beautifully."); Console.WriteLine(await agent.RunAsync("Write a haiku about Microsoft Agent Framework.")); ``` diff --git a/dotnet/samples/A2AClientServer/A2AClient/HostClientAgent.cs b/dotnet/samples/A2AClientServer/A2AClient/HostClientAgent.cs index 5ebae80ffe..4daf2c542b 100644 --- a/dotnet/samples/A2AClientServer/A2AClient/HostClientAgent.cs +++ b/dotnet/samples/A2AClientServer/A2AClient/HostClientAgent.cs @@ -29,7 +29,7 @@ internal async Task InitializeAgentAsync(string modelId, string apiKey, string[] // Create the agent that uses the remote agents as tools this.Agent = new OpenAIClient(new ApiKeyCredential(apiKey)) .GetChatClient(modelId) - .CreateAIAgent(instructions: "You specialize in handling queries for users and using your tools to provide answers.", name: "HostClient", tools: tools); + .AsAIAgent(instructions: "You specialize in handling queries for users and using your tools to provide answers.", name: "HostClient", tools: tools); } catch (Exception ex) { diff --git a/dotnet/samples/A2AClientServer/A2AServer/HostAgentFactory.cs b/dotnet/samples/A2AClientServer/A2AServer/HostAgentFactory.cs index 9c4fbaaf2c..8af2b01daf 100644 --- a/dotnet/samples/A2AClientServer/A2AServer/HostAgentFactory.cs +++ b/dotnet/samples/A2AClientServer/A2AServer/HostAgentFactory.cs @@ -35,7 +35,7 @@ internal static class HostAgentFactory { AIAgent agent = new OpenAIClient(apiKey) .GetChatClient(model) - .CreateAIAgent(instructions, name, tools: tools); + .AsAIAgent(instructions, name, tools: tools); AgentCard agentCard = agentType.ToUpperInvariant() switch { diff --git a/dotnet/samples/AGUIClientServer/AGUIClient/Program.cs b/dotnet/samples/AGUIClientServer/AGUIClient/Program.cs index a4bec13009..1906b4d913 100644 --- a/dotnet/samples/AGUIClientServer/AGUIClient/Program.cs +++ b/dotnet/samples/AGUIClientServer/AGUIClient/Program.cs @@ -83,7 +83,7 @@ private static async Task HandleCommandsAsync(CancellationToken cancellationToke serverUrl, jsonSerializerOptions: AGUIClientSerializerContext.Default.Options); - AIAgent agent = chatClient.CreateAIAgent( + AIAgent agent = chatClient.AsAIAgent( name: "agui-client", description: "AG-UI Client Agent", tools: [changeBackground, readClientClimateSensors]); diff --git a/dotnet/samples/AGUIClientServer/AGUIDojoServer/ChatClientAgentFactory.cs b/dotnet/samples/AGUIClientServer/AGUIDojoServer/ChatClientAgentFactory.cs index 58f5ad4ae9..d14755db3f 100644 --- a/dotnet/samples/AGUIClientServer/AGUIDojoServer/ChatClientAgentFactory.cs +++ b/dotnet/samples/AGUIClientServer/AGUIDojoServer/ChatClientAgentFactory.cs @@ -33,7 +33,7 @@ public static ChatClientAgent CreateAgenticChat() { ChatClient chatClient = s_azureOpenAIClient!.GetChatClient(s_deploymentName!); - return chatClient.AsIChatClient().CreateAIAgent( + return chatClient.AsIChatClient().AsAIAgent( name: "AgenticChat", description: "A simple chat agent using Azure OpenAI"); } @@ -42,7 +42,7 @@ public static ChatClientAgent CreateBackendToolRendering() { ChatClient chatClient = s_azureOpenAIClient!.GetChatClient(s_deploymentName!); - return chatClient.AsIChatClient().CreateAIAgent( + return chatClient.AsIChatClient().AsAIAgent( name: "BackendToolRenderer", description: "An agent that can render backend tools using Azure OpenAI", tools: [AIFunctionFactory.Create( @@ -56,7 +56,7 @@ public static ChatClientAgent CreateHumanInTheLoop() { ChatClient chatClient = s_azureOpenAIClient!.GetChatClient(s_deploymentName!); - return chatClient.AsIChatClient().CreateAIAgent( + return chatClient.AsIChatClient().AsAIAgent( name: "HumanInTheLoopAgent", description: "An agent that involves human feedback in its decision-making process using Azure OpenAI"); } @@ -65,7 +65,7 @@ public static ChatClientAgent CreateToolBasedGenerativeUI() { ChatClient chatClient = s_azureOpenAIClient!.GetChatClient(s_deploymentName!); - return chatClient.AsIChatClient().CreateAIAgent( + return chatClient.AsIChatClient().AsAIAgent( name: "ToolBasedGenerativeUIAgent", description: "An agent that uses tools to generate user interfaces using Azure OpenAI"); } @@ -73,7 +73,7 @@ public static ChatClientAgent CreateToolBasedGenerativeUI() public static AIAgent CreateAgenticUI(JsonSerializerOptions options) { ChatClient chatClient = s_azureOpenAIClient!.GetChatClient(s_deploymentName!); - var baseAgent = chatClient.AsIChatClient().CreateAIAgent(new ChatClientAgentOptions + var baseAgent = chatClient.AsIChatClient().AsAIAgent(new ChatClientAgentOptions { Name = "AgenticUIAgent", Description = "An agent that generates agentic user interfaces using Azure OpenAI", @@ -116,7 +116,7 @@ public static AIAgent CreateSharedState(JsonSerializerOptions options) { ChatClient chatClient = s_azureOpenAIClient!.GetChatClient(s_deploymentName!); - var baseAgent = chatClient.AsIChatClient().CreateAIAgent( + var baseAgent = chatClient.AsIChatClient().AsAIAgent( name: "SharedStateAgent", description: "An agent that demonstrates shared state patterns using Azure OpenAI"); @@ -127,7 +127,7 @@ public static AIAgent CreatePredictiveStateUpdates(JsonSerializerOptions options { ChatClient chatClient = s_azureOpenAIClient!.GetChatClient(s_deploymentName!); - var baseAgent = chatClient.AsIChatClient().CreateAIAgent(new ChatClientAgentOptions + var baseAgent = chatClient.AsIChatClient().AsAIAgent(new ChatClientAgentOptions { Name = "PredictiveStateUpdatesAgent", Description = "An agent that demonstrates predictive state updates using Azure OpenAI", diff --git a/dotnet/samples/AGUIClientServer/AGUIServer/Program.cs b/dotnet/samples/AGUIClientServer/AGUIServer/Program.cs index bcfd86e60d..418f72ad43 100644 --- a/dotnet/samples/AGUIClientServer/AGUIServer/Program.cs +++ b/dotnet/samples/AGUIClientServer/AGUIServer/Program.cs @@ -23,7 +23,7 @@ new Uri(endpoint), new DefaultAzureCredential()) .GetChatClient(deploymentName) - .CreateAIAgent( + .AsAIAgent( name: "AGUIAssistant", tools: [ AIFunctionFactory.Create( diff --git a/dotnet/samples/AGUIClientServer/README.md b/dotnet/samples/AGUIClientServer/README.md index d624c6f4b6..2e4887cde9 100644 --- a/dotnet/samples/AGUIClientServer/README.md +++ b/dotnet/samples/AGUIClientServer/README.md @@ -119,7 +119,7 @@ The `AGUIServer` uses the `MapAGUI` extension method to expose an agent through ```csharp AIAgent agent = new OpenAIClient(apiKey) .GetChatClient(model) - .CreateAIAgent( + .AsAIAgent( instructions: "You are a helpful assistant.", name: "AGUIAssistant"); @@ -144,7 +144,7 @@ var chatClient = new AGUIChatClient( modelId: "agui-client", jsonSerializerOptions: null); -AIAgent agent = chatClient.CreateAIAgent( +AIAgent agent = chatClient.AsAIAgent( instructions: null, name: "agui-client", description: "AG-UI Client Agent", diff --git a/dotnet/samples/AGUIWebChat/README.md b/dotnet/samples/AGUIWebChat/README.md index 75af0872c1..bdb8ae25d2 100644 --- a/dotnet/samples/AGUIWebChat/README.md +++ b/dotnet/samples/AGUIWebChat/README.md @@ -74,7 +74,7 @@ AzureOpenAIClient azureOpenAIClient = new AzureOpenAIClient( ChatClient chatClient = azureOpenAIClient.GetChatClient(deploymentName); // Create AI agent -ChatClientAgent agent = chatClient.AsIChatClient().CreateAIAgent( +ChatClientAgent agent = chatClient.AsIChatClient().AsAIAgent( name: "ChatAssistant", instructions: "You are a helpful assistant."); @@ -162,7 +162,7 @@ dotnet run Edit the instructions in `Server/Program.cs`: ```csharp -ChatClientAgent agent = chatClient.AsIChatClient().CreateAIAgent( +ChatClientAgent agent = chatClient.AsIChatClient().AsAIAgent( name: "ChatAssistant", instructions: "You are a helpful coding assistant specializing in C# and .NET."); ``` diff --git a/dotnet/samples/AGUIWebChat/Server/Program.cs b/dotnet/samples/AGUIWebChat/Server/Program.cs index 1683a7e3ed..eb5b259016 100644 --- a/dotnet/samples/AGUIWebChat/Server/Program.cs +++ b/dotnet/samples/AGUIWebChat/Server/Program.cs @@ -25,7 +25,7 @@ ChatClient chatClient = azureOpenAIClient.GetChatClient(deploymentName); -ChatClientAgent agent = chatClient.AsIChatClient().CreateAIAgent( +ChatClientAgent agent = chatClient.AsIChatClient().AsAIAgent( name: "ChatAssistant", instructions: "You are a helpful assistant."); diff --git a/dotnet/samples/AzureFunctions/01_SingleAgent/Program.cs b/dotnet/samples/AzureFunctions/01_SingleAgent/Program.cs index 39b020e137..609ba162c9 100644 --- a/dotnet/samples/AzureFunctions/01_SingleAgent/Program.cs +++ b/dotnet/samples/AzureFunctions/01_SingleAgent/Program.cs @@ -25,7 +25,7 @@ const string JokerName = "Joker"; const string JokerInstructions = "You are good at telling jokes."; -AIAgent agent = client.GetChatClient(deploymentName).CreateAIAgent(JokerInstructions, JokerName); +AIAgent agent = client.GetChatClient(deploymentName).AsAIAgent(JokerInstructions, JokerName); // Configure the function app to host the AI agent. // This will automatically generate HTTP API endpoints for the agent. diff --git a/dotnet/samples/AzureFunctions/02_AgentOrchestration_Chaining/Program.cs b/dotnet/samples/AzureFunctions/02_AgentOrchestration_Chaining/Program.cs index 3776ecd062..ba16578935 100644 --- a/dotnet/samples/AzureFunctions/02_AgentOrchestration_Chaining/Program.cs +++ b/dotnet/samples/AzureFunctions/02_AgentOrchestration_Chaining/Program.cs @@ -29,7 +29,7 @@ when given an improved sentence you polish it further. """; -AIAgent writerAgent = client.GetChatClient(deploymentName).CreateAIAgent(WriterInstructions, WriterName); +AIAgent writerAgent = client.GetChatClient(deploymentName).AsAIAgent(WriterInstructions, WriterName); using IHost app = FunctionsApplication .CreateBuilder(args) diff --git a/dotnet/samples/AzureFunctions/03_AgentOrchestration_Concurrency/Program.cs b/dotnet/samples/AzureFunctions/03_AgentOrchestration_Concurrency/Program.cs index dfc2049d45..b180c8139f 100644 --- a/dotnet/samples/AzureFunctions/03_AgentOrchestration_Concurrency/Program.cs +++ b/dotnet/samples/AzureFunctions/03_AgentOrchestration_Concurrency/Program.cs @@ -28,8 +28,8 @@ const string ChemistName = "ChemistAgent"; const string ChemistInstructions = "You are an expert in chemistry. You answer questions from a chemistry perspective."; -AIAgent physicistAgent = client.GetChatClient(deploymentName).CreateAIAgent(PhysicistInstructions, PhysicistName); -AIAgent chemistAgent = client.GetChatClient(deploymentName).CreateAIAgent(ChemistInstructions, ChemistName); +AIAgent physicistAgent = client.GetChatClient(deploymentName).AsAIAgent(PhysicistInstructions, PhysicistName); +AIAgent chemistAgent = client.GetChatClient(deploymentName).AsAIAgent(ChemistInstructions, ChemistName); using IHost app = FunctionsApplication .CreateBuilder(args) diff --git a/dotnet/samples/AzureFunctions/04_AgentOrchestration_Conditionals/Program.cs b/dotnet/samples/AzureFunctions/04_AgentOrchestration_Conditionals/Program.cs index a04b4c3e70..07dcd302cc 100644 --- a/dotnet/samples/AzureFunctions/04_AgentOrchestration_Conditionals/Program.cs +++ b/dotnet/samples/AzureFunctions/04_AgentOrchestration_Conditionals/Program.cs @@ -29,10 +29,10 @@ const string EmailAssistantInstructions = "You are an email assistant that helps users draft responses to emails with professionalism."; AIAgent spamDetectionAgent = client.GetChatClient(deploymentName) - .CreateAIAgent(SpamDetectionInstructions, SpamDetectionName); + .AsAIAgent(SpamDetectionInstructions, SpamDetectionName); AIAgent emailAssistantAgent = client.GetChatClient(deploymentName) - .CreateAIAgent(EmailAssistantInstructions, EmailAssistantName); + .AsAIAgent(EmailAssistantInstructions, EmailAssistantName); using IHost app = FunctionsApplication .CreateBuilder(args) diff --git a/dotnet/samples/AzureFunctions/05_AgentOrchestration_HITL/Program.cs b/dotnet/samples/AzureFunctions/05_AgentOrchestration_HITL/Program.cs index 741e5407e0..77e2dfa2d4 100644 --- a/dotnet/samples/AzureFunctions/05_AgentOrchestration_HITL/Program.cs +++ b/dotnet/samples/AzureFunctions/05_AgentOrchestration_HITL/Program.cs @@ -29,7 +29,7 @@ You are a professional content writer who creates high-quality articles on vario You write engaging, informative, and well-structured content that follows best practices for readability and accuracy. """; -AIAgent writerAgent = client.GetChatClient(deploymentName).CreateAIAgent(WriterInstructions, WriterName); +AIAgent writerAgent = client.GetChatClient(deploymentName).AsAIAgent(WriterInstructions, WriterName); using IHost app = FunctionsApplication .CreateBuilder(args) diff --git a/dotnet/samples/AzureFunctions/06_LongRunningTools/Program.cs b/dotnet/samples/AzureFunctions/06_LongRunningTools/Program.cs index 581b2bce11..e4d88d3ae7 100644 --- a/dotnet/samples/AzureFunctions/06_LongRunningTools/Program.cs +++ b/dotnet/samples/AzureFunctions/06_LongRunningTools/Program.cs @@ -33,7 +33,7 @@ You are a professional content writer who creates high-quality articles on vario You write engaging, informative, and well-structured content that follows best practices for readability and accuracy. """; -AIAgent writerAgent = client.GetChatClient(deploymentName).CreateAIAgent(WriterAgentInstructions, WriterAgentName); +AIAgent writerAgent = client.GetChatClient(deploymentName).AsAIAgent(WriterAgentInstructions, WriterAgentName); // Agent that can start content generation workflows using tools const string PublisherAgentName = "Publisher"; @@ -57,7 +57,7 @@ You are a publishing agent that can manage content generation workflows. // Initialize the tools to be used by the agent. Tools publisherTools = new(sp.GetRequiredService>()); - return client.GetChatClient(deploymentName).CreateAIAgent( + return client.GetChatClient(deploymentName).AsAIAgent( instructions: PublisherAgentInstructions, name: PublisherAgentName, services: sp, diff --git a/dotnet/samples/AzureFunctions/07_AgentAsMcpTool/Program.cs b/dotnet/samples/AzureFunctions/07_AgentAsMcpTool/Program.cs index bc0a69cbf2..2503037a8c 100644 --- a/dotnet/samples/AzureFunctions/07_AgentAsMcpTool/Program.cs +++ b/dotnet/samples/AzureFunctions/07_AgentAsMcpTool/Program.cs @@ -28,13 +28,13 @@ : new AzureOpenAIClient(new Uri(endpoint), new AzureCliCredential()); // Define three AI agents we are going to use in this application. -AIAgent agent1 = client.GetChatClient(deploymentName).CreateAIAgent("You are good at telling jokes.", "Joker"); +AIAgent agent1 = client.GetChatClient(deploymentName).AsAIAgent("You are good at telling jokes.", "Joker"); AIAgent agent2 = client.GetChatClient(deploymentName) - .CreateAIAgent("Check stock prices.", "StockAdvisor"); + .AsAIAgent("Check stock prices.", "StockAdvisor"); AIAgent agent3 = client.GetChatClient(deploymentName) - .CreateAIAgent("Recommend plants.", "PlantAdvisor", description: "Get plant recommendations."); + .AsAIAgent("Recommend plants.", "PlantAdvisor", description: "Get plant recommendations."); using IHost app = FunctionsApplication .CreateBuilder(args) diff --git a/dotnet/samples/AzureFunctions/08_ReliableStreaming/Program.cs b/dotnet/samples/AzureFunctions/08_ReliableStreaming/Program.cs index 6c48ed4177..c279b968a3 100644 --- a/dotnet/samples/AzureFunctions/08_ReliableStreaming/Program.cs +++ b/dotnet/samples/AzureFunctions/08_ReliableStreaming/Program.cs @@ -70,7 +70,7 @@ to make the itinerary easy to scan and visually appealing. // Define the Travel Planner agent with tools for weather and events options.AddAIAgentFactory(TravelPlannerName, sp => { - return client.GetChatClient(deploymentName).CreateAIAgent( + return client.GetChatClient(deploymentName).AsAIAgent( instructions: TravelPlannerInstructions, name: TravelPlannerName, services: sp, diff --git a/dotnet/samples/GettingStarted/A2A/A2AAgent_AsFunctionTools/Program.cs b/dotnet/samples/GettingStarted/A2A/A2AAgent_AsFunctionTools/Program.cs index c813464d0c..d1384d2c21 100644 --- a/dotnet/samples/GettingStarted/A2A/A2AAgent_AsFunctionTools/Program.cs +++ b/dotnet/samples/GettingStarted/A2A/A2AAgent_AsFunctionTools/Program.cs @@ -23,14 +23,14 @@ AgentCard agentCard = await agentCardResolver.GetAgentCardAsync(); // Create an instance of the AIAgent for an existing A2A agent specified by the agent card. -AIAgent a2aAgent = agentCard.GetAIAgent(); +AIAgent a2aAgent = agentCard.AsAIAgent(); // Create the main agent, and provide the a2a agent skills as a function tools. AIAgent agent = new AzureOpenAIClient( new Uri(endpoint), new AzureCliCredential()) .GetChatClient(deploymentName) - .CreateAIAgent( + .AsAIAgent( instructions: "You are a helpful assistant that helps people with travel planning.", tools: [.. CreateFunctionTools(a2aAgent, agentCard)] ); diff --git a/dotnet/samples/GettingStarted/A2A/A2AAgent_PollingForTaskCompletion/Program.cs b/dotnet/samples/GettingStarted/A2A/A2AAgent_PollingForTaskCompletion/Program.cs index 1062cc4b6f..de5cc79ebf 100644 --- a/dotnet/samples/GettingStarted/A2A/A2AAgent_PollingForTaskCompletion/Program.cs +++ b/dotnet/samples/GettingStarted/A2A/A2AAgent_PollingForTaskCompletion/Program.cs @@ -14,7 +14,7 @@ AgentCard agentCard = await agentCardResolver.GetAgentCardAsync(); // Create an instance of the AIAgent for an existing A2A agent specified by the agent card. -AIAgent agent = agentCard.GetAIAgent(); +AIAgent agent = agentCard.AsAIAgent(); AgentThread thread = await agent.GetNewThreadAsync(); diff --git a/dotnet/samples/GettingStarted/AGUI/Step01_GettingStarted/Client/Program.cs b/dotnet/samples/GettingStarted/AGUI/Step01_GettingStarted/Client/Program.cs index 78bacc949c..b3e74e7efd 100644 --- a/dotnet/samples/GettingStarted/AGUI/Step01_GettingStarted/Client/Program.cs +++ b/dotnet/samples/GettingStarted/AGUI/Step01_GettingStarted/Client/Program.cs @@ -16,7 +16,7 @@ AGUIChatClient chatClient = new(httpClient, serverUrl); -AIAgent agent = chatClient.CreateAIAgent( +AIAgent agent = chatClient.AsAIAgent( name: "agui-client", description: "AG-UI Client Agent"); diff --git a/dotnet/samples/GettingStarted/AGUI/Step01_GettingStarted/Server/Program.cs b/dotnet/samples/GettingStarted/AGUI/Step01_GettingStarted/Server/Program.cs index 1bfb9a97aa..fb3cbe401e 100644 --- a/dotnet/samples/GettingStarted/AGUI/Step01_GettingStarted/Server/Program.cs +++ b/dotnet/samples/GettingStarted/AGUI/Step01_GettingStarted/Server/Program.cs @@ -24,7 +24,7 @@ new DefaultAzureCredential()) .GetChatClient(deploymentName); -AIAgent agent = chatClient.AsIChatClient().CreateAIAgent( +AIAgent agent = chatClient.AsIChatClient().AsAIAgent( name: "AGUIAssistant", instructions: "You are a helpful assistant."); diff --git a/dotnet/samples/GettingStarted/AGUI/Step02_BackendTools/Client/Program.cs b/dotnet/samples/GettingStarted/AGUI/Step02_BackendTools/Client/Program.cs index 6c22071a61..9544d4286b 100644 --- a/dotnet/samples/GettingStarted/AGUI/Step02_BackendTools/Client/Program.cs +++ b/dotnet/samples/GettingStarted/AGUI/Step02_BackendTools/Client/Program.cs @@ -16,7 +16,7 @@ AGUIChatClient chatClient = new(httpClient, serverUrl); -AIAgent agent = chatClient.CreateAIAgent( +AIAgent agent = chatClient.AsAIAgent( name: "agui-client", description: "AG-UI Client Agent"); diff --git a/dotnet/samples/GettingStarted/AGUI/Step02_BackendTools/Server/Program.cs b/dotnet/samples/GettingStarted/AGUI/Step02_BackendTools/Server/Program.cs index 2867721d02..73ece031fc 100644 --- a/dotnet/samples/GettingStarted/AGUI/Step02_BackendTools/Server/Program.cs +++ b/dotnet/samples/GettingStarted/AGUI/Step02_BackendTools/Server/Program.cs @@ -79,7 +79,7 @@ static RestaurantSearchResponse SearchRestaurants( new DefaultAzureCredential()) .GetChatClient(deploymentName); -ChatClientAgent agent = chatClient.AsIChatClient().CreateAIAgent( +ChatClientAgent agent = chatClient.AsIChatClient().AsAIAgent( name: "AGUIAssistant", instructions: "You are a helpful assistant with access to restaurant information.", tools: tools); diff --git a/dotnet/samples/GettingStarted/AGUI/Step03_FrontendTools/Client/Program.cs b/dotnet/samples/GettingStarted/AGUI/Step03_FrontendTools/Client/Program.cs index e675d5cca5..fa760e9a6e 100644 --- a/dotnet/samples/GettingStarted/AGUI/Step03_FrontendTools/Client/Program.cs +++ b/dotnet/samples/GettingStarted/AGUI/Step03_FrontendTools/Client/Program.cs @@ -28,7 +28,7 @@ static string GetUserLocation() AGUIChatClient chatClient = new(httpClient, serverUrl); -AIAgent agent = chatClient.CreateAIAgent( +AIAgent agent = chatClient.AsAIAgent( name: "agui-client", description: "AG-UI Client Agent", tools: frontendTools); diff --git a/dotnet/samples/GettingStarted/AGUI/Step03_FrontendTools/Server/Program.cs b/dotnet/samples/GettingStarted/AGUI/Step03_FrontendTools/Server/Program.cs index 1bfb9a97aa..fb3cbe401e 100644 --- a/dotnet/samples/GettingStarted/AGUI/Step03_FrontendTools/Server/Program.cs +++ b/dotnet/samples/GettingStarted/AGUI/Step03_FrontendTools/Server/Program.cs @@ -24,7 +24,7 @@ new DefaultAzureCredential()) .GetChatClient(deploymentName); -AIAgent agent = chatClient.AsIChatClient().CreateAIAgent( +AIAgent agent = chatClient.AsIChatClient().AsAIAgent( name: "AGUIAssistant", instructions: "You are a helpful assistant."); diff --git a/dotnet/samples/GettingStarted/AGUI/Step04_HumanInLoop/Client/Program.cs b/dotnet/samples/GettingStarted/AGUI/Step04_HumanInLoop/Client/Program.cs index e93446ecb1..e66087bad7 100644 --- a/dotnet/samples/GettingStarted/AGUI/Step04_HumanInLoop/Client/Program.cs +++ b/dotnet/samples/GettingStarted/AGUI/Step04_HumanInLoop/Client/Program.cs @@ -16,7 +16,7 @@ AGUIChatClient chatClient = new(httpClient, serverUrl); // Create agent -ChatClientAgent baseAgent = chatClient.CreateAIAgent( +ChatClientAgent baseAgent = chatClient.AsAIAgent( name: "AGUIAssistant", instructions: "You are a helpful assistant."); diff --git a/dotnet/samples/GettingStarted/AGUI/Step04_HumanInLoop/Server/Program.cs b/dotnet/samples/GettingStarted/AGUI/Step04_HumanInLoop/Server/Program.cs index 1af163435a..023b3327ba 100644 --- a/dotnet/samples/GettingStarted/AGUI/Step04_HumanInLoop/Server/Program.cs +++ b/dotnet/samples/GettingStarted/AGUI/Step04_HumanInLoop/Server/Program.cs @@ -57,7 +57,7 @@ static string ApproveExpenseReport(string expenseReportId) new DefaultAzureCredential()) .GetChatClient(deploymentName); -ChatClientAgent baseAgent = openAIChatClient.AsIChatClient().CreateAIAgent( +ChatClientAgent baseAgent = openAIChatClient.AsIChatClient().AsAIAgent( name: "AGUIAssistant", instructions: "You are a helpful assistant in charge of approving expenses", tools: tools); diff --git a/dotnet/samples/GettingStarted/AGUI/Step05_StateManagement/Client/Program.cs b/dotnet/samples/GettingStarted/AGUI/Step05_StateManagement/Client/Program.cs index 1946bfc051..0072f62845 100644 --- a/dotnet/samples/GettingStarted/AGUI/Step05_StateManagement/Client/Program.cs +++ b/dotnet/samples/GettingStarted/AGUI/Step05_StateManagement/Client/Program.cs @@ -19,7 +19,7 @@ AGUIChatClient chatClient = new(httpClient, serverUrl); -AIAgent baseAgent = chatClient.CreateAIAgent( +AIAgent baseAgent = chatClient.AsAIAgent( name: "recipe-client", description: "AG-UI Recipe Client Agent"); diff --git a/dotnet/samples/GettingStarted/AGUI/Step05_StateManagement/Server/Program.cs b/dotnet/samples/GettingStarted/AGUI/Step05_StateManagement/Server/Program.cs index 40c51887d1..a6bd6f5ef6 100644 --- a/dotnet/samples/GettingStarted/AGUI/Step05_StateManagement/Server/Program.cs +++ b/dotnet/samples/GettingStarted/AGUI/Step05_StateManagement/Server/Program.cs @@ -34,7 +34,7 @@ new DefaultAzureCredential()) .GetChatClient(deploymentName); -AIAgent baseAgent = chatClient.AsIChatClient().CreateAIAgent( +AIAgent baseAgent = chatClient.AsIChatClient().AsAIAgent( name: "RecipeAgent", instructions: """ You are a helpful recipe assistant. When users ask you to create or suggest a recipe, diff --git a/dotnet/samples/GettingStarted/AgentProviders/Agent_With_A2A/README.md b/dotnet/samples/GettingStarted/AgentProviders/Agent_With_A2A/README.md index 534eacfdb5..f76af52f02 100644 --- a/dotnet/samples/GettingStarted/AgentProviders/Agent_With_A2A/README.md +++ b/dotnet/samples/GettingStarted/AgentProviders/Agent_With_A2A/README.md @@ -26,7 +26,7 @@ using Microsoft.Agents.AI.A2A; A2AClient a2aClient = new(new Uri("https://your-a2a-agent-host/echo")); // Create an AIAgent from the A2AClient -AIAgent agent = a2aClient.GetAIAgent(); +AIAgent agent = a2aClient.AsAIAgent(); // Run the agent AgentResponse response = await agent.RunAsync("Tell me a joke about a pirate."); diff --git a/dotnet/samples/GettingStarted/AgentProviders/Agent_With_Anthropic/Program.cs b/dotnet/samples/GettingStarted/AgentProviders/Agent_With_Anthropic/Program.cs index df070c335b..ad49c9229e 100644 --- a/dotnet/samples/GettingStarted/AgentProviders/Agent_With_Anthropic/Program.cs +++ b/dotnet/samples/GettingStarted/AgentProviders/Agent_With_Anthropic/Program.cs @@ -26,7 +26,7 @@ ? new AnthropicFoundryClient(new AnthropicFoundryApiKeyCredentials(apiKey, resource)) // If an apiKey is provided, use Foundry with ApiKey authentication : new AnthropicFoundryClient(new AnthropicAzureTokenCredential(new AzureCliCredential(), resource)); // Otherwise, use Foundry with Azure Client authentication -AIAgent agent = client.CreateAIAgent(model: deploymentName, instructions: JokerInstructions, name: JokerName); +AIAgent agent = client.AsAIAgent(model: deploymentName, instructions: JokerInstructions, name: JokerName); // Invoke the agent and output the text result. Console.WriteLine(await agent.RunAsync("Tell me a joke about a pirate.")); diff --git a/dotnet/samples/GettingStarted/AgentProviders/Agent_With_AzureAIProject/Program.cs b/dotnet/samples/GettingStarted/AgentProviders/Agent_With_AzureAIProject/Program.cs index b7b175b2cf..4ca52aa268 100644 --- a/dotnet/samples/GettingStarted/AgentProviders/Agent_With_AzureAIProject/Program.cs +++ b/dotnet/samples/GettingStarted/AgentProviders/Agent_With_AzureAIProject/Program.cs @@ -27,7 +27,7 @@ // agentVersion.Name = // You can retrieve an AIAgent for an already created server side agent version. -AIAgent existingJokerAgent = aiProjectClient.GetAIAgent(createdAgentVersion); +AIAgent existingJokerAgent = aiProjectClient.AsAIAgent(createdAgentVersion); // You can also create another AIAgent version by providing the same name with a different definition. AIAgent newJokerAgent = aiProjectClient.CreateAIAgent(name: JokerName, model: deploymentName, instructions: "You are extremely hilarious at telling jokes."); diff --git a/dotnet/samples/GettingStarted/AgentProviders/Agent_With_AzureFoundryModel/Program.cs b/dotnet/samples/GettingStarted/AgentProviders/Agent_With_AzureFoundryModel/Program.cs index 5ed66d3e4b..d22fc627ff 100644 --- a/dotnet/samples/GettingStarted/AgentProviders/Agent_With_AzureFoundryModel/Program.cs +++ b/dotnet/samples/GettingStarted/AgentProviders/Agent_With_AzureFoundryModel/Program.cs @@ -25,7 +25,7 @@ AIAgent agent = client .GetChatClient(model) - .CreateAIAgent(instructions: "You are good at telling jokes.", name: "Joker"); + .AsAIAgent(instructions: "You are good at telling jokes.", name: "Joker"); // Invoke the agent and output the text result. Console.WriteLine(await agent.RunAsync("Tell me a joke about a pirate.")); diff --git a/dotnet/samples/GettingStarted/AgentProviders/Agent_With_AzureOpenAIChatCompletion/Program.cs b/dotnet/samples/GettingStarted/AgentProviders/Agent_With_AzureOpenAIChatCompletion/Program.cs index cf717550d2..ea647c2d4f 100644 --- a/dotnet/samples/GettingStarted/AgentProviders/Agent_With_AzureOpenAIChatCompletion/Program.cs +++ b/dotnet/samples/GettingStarted/AgentProviders/Agent_With_AzureOpenAIChatCompletion/Program.cs @@ -14,7 +14,7 @@ new Uri(endpoint), new AzureCliCredential()) .GetChatClient(deploymentName) - .CreateAIAgent(instructions: "You are good at telling jokes.", name: "Joker"); + .AsAIAgent(instructions: "You are good at telling jokes.", name: "Joker"); // Invoke the agent and output the text result. Console.WriteLine(await agent.RunAsync("Tell me a joke about a pirate.")); diff --git a/dotnet/samples/GettingStarted/AgentProviders/Agent_With_AzureOpenAIResponses/Program.cs b/dotnet/samples/GettingStarted/AgentProviders/Agent_With_AzureOpenAIResponses/Program.cs index 5ce85b2b91..31a24b6585 100644 --- a/dotnet/samples/GettingStarted/AgentProviders/Agent_With_AzureOpenAIResponses/Program.cs +++ b/dotnet/samples/GettingStarted/AgentProviders/Agent_With_AzureOpenAIResponses/Program.cs @@ -14,7 +14,7 @@ new Uri(endpoint), new AzureCliCredential()) .GetResponsesClient(deploymentName) - .CreateAIAgent(instructions: "You are good at telling jokes.", name: "Joker"); + .AsAIAgent(instructions: "You are good at telling jokes.", name: "Joker"); // Invoke the agent and output the text result. Console.WriteLine(await agent.RunAsync("Tell me a joke about a pirate.")); diff --git a/dotnet/samples/GettingStarted/AgentProviders/Agent_With_ONNX/Program.cs b/dotnet/samples/GettingStarted/AgentProviders/Agent_With_ONNX/Program.cs index d6c306bfd1..5385aab7a1 100644 --- a/dotnet/samples/GettingStarted/AgentProviders/Agent_With_ONNX/Program.cs +++ b/dotnet/samples/GettingStarted/AgentProviders/Agent_With_ONNX/Program.cs @@ -12,7 +12,7 @@ // Get a chat client for ONNX and use it to construct an AIAgent. using OnnxRuntimeGenAIChatClient chatClient = new(modelPath); -AIAgent agent = chatClient.CreateAIAgent(instructions: "You are good at telling jokes.", name: "Joker"); +AIAgent agent = chatClient.AsAIAgent(instructions: "You are good at telling jokes.", name: "Joker"); // Invoke the agent and output the text result. Console.WriteLine(await agent.RunAsync("Tell me a joke about a pirate.")); diff --git a/dotnet/samples/GettingStarted/AgentProviders/Agent_With_Ollama/Program.cs b/dotnet/samples/GettingStarted/AgentProviders/Agent_With_Ollama/Program.cs index 8cacfef3ef..89f92a98a4 100644 --- a/dotnet/samples/GettingStarted/AgentProviders/Agent_With_Ollama/Program.cs +++ b/dotnet/samples/GettingStarted/AgentProviders/Agent_With_Ollama/Program.cs @@ -11,7 +11,7 @@ // Get a chat client for Ollama and use it to construct an AIAgent. AIAgent agent = new OllamaApiClient(new Uri(endpoint), modelName) - .CreateAIAgent(instructions: "You are good at telling jokes.", name: "Joker"); + .AsAIAgent(instructions: "You are good at telling jokes.", name: "Joker"); // Invoke the agent and output the text result. Console.WriteLine(await agent.RunAsync("Tell me a joke about a pirate.")); diff --git a/dotnet/samples/GettingStarted/AgentProviders/Agent_With_OpenAIChatCompletion/Program.cs b/dotnet/samples/GettingStarted/AgentProviders/Agent_With_OpenAIChatCompletion/Program.cs index b4c6d626fc..3b22c21b3b 100644 --- a/dotnet/samples/GettingStarted/AgentProviders/Agent_With_OpenAIChatCompletion/Program.cs +++ b/dotnet/samples/GettingStarted/AgentProviders/Agent_With_OpenAIChatCompletion/Program.cs @@ -13,7 +13,7 @@ AIAgent agent = new OpenAIClient( apiKey) .GetChatClient(model) - .CreateAIAgent(instructions: "You are good at telling jokes.", name: "Joker"); + .AsAIAgent(instructions: "You are good at telling jokes.", name: "Joker"); // Invoke the agent and output the text result. Console.WriteLine(await agent.RunAsync("Tell me a joke about a pirate.")); diff --git a/dotnet/samples/GettingStarted/AgentProviders/Agent_With_OpenAIResponses/Program.cs b/dotnet/samples/GettingStarted/AgentProviders/Agent_With_OpenAIResponses/Program.cs index b0d0285928..1e5883c67d 100644 --- a/dotnet/samples/GettingStarted/AgentProviders/Agent_With_OpenAIResponses/Program.cs +++ b/dotnet/samples/GettingStarted/AgentProviders/Agent_With_OpenAIResponses/Program.cs @@ -12,7 +12,7 @@ AIAgent agent = new OpenAIClient( apiKey) .GetResponsesClient(model) - .CreateAIAgent(instructions: "You are good at telling jokes.", name: "Joker"); + .AsAIAgent(instructions: "You are good at telling jokes.", name: "Joker"); // Invoke the agent and output the text result. Console.WriteLine(await agent.RunAsync("Tell me a joke about a pirate.")); diff --git a/dotnet/samples/GettingStarted/AgentWithAnthropic/Agent_Anthropic_Step01_Running/Program.cs b/dotnet/samples/GettingStarted/AgentWithAnthropic/Agent_Anthropic_Step01_Running/Program.cs index cf7e29c2fe..085fbfd989 100644 --- a/dotnet/samples/GettingStarted/AgentWithAnthropic/Agent_Anthropic_Step01_Running/Program.cs +++ b/dotnet/samples/GettingStarted/AgentWithAnthropic/Agent_Anthropic_Step01_Running/Program.cs @@ -11,7 +11,7 @@ var model = Environment.GetEnvironmentVariable("ANTHROPIC_MODEL") ?? "claude-haiku-4-5"; AIAgent agent = new AnthropicClient(new ClientOptions { APIKey = apiKey }) - .CreateAIAgent(model: model, instructions: "You are good at telling jokes.", name: "Joker"); + .AsAIAgent(model: model, instructions: "You are good at telling jokes.", name: "Joker"); // Invoke the agent and output the text result. var response = await agent.RunAsync("Tell me a joke about a pirate."); diff --git a/dotnet/samples/GettingStarted/AgentWithAnthropic/Agent_Anthropic_Step02_Reasoning/Program.cs b/dotnet/samples/GettingStarted/AgentWithAnthropic/Agent_Anthropic_Step02_Reasoning/Program.cs index d362a9dd0d..120402ee14 100644 --- a/dotnet/samples/GettingStarted/AgentWithAnthropic/Agent_Anthropic_Step02_Reasoning/Program.cs +++ b/dotnet/samples/GettingStarted/AgentWithAnthropic/Agent_Anthropic_Step02_Reasoning/Program.cs @@ -14,7 +14,7 @@ var thinkingTokens = 2048; var agent = new AnthropicClient(new ClientOptions { APIKey = apiKey }) - .CreateAIAgent( + .AsAIAgent( model: model, clientFactory: (chatClient) => chatClient .AsBuilder() diff --git a/dotnet/samples/GettingStarted/AgentWithAnthropic/Agent_Anthropic_Step03_UsingFunctionTools/Program.cs b/dotnet/samples/GettingStarted/AgentWithAnthropic/Agent_Anthropic_Step03_UsingFunctionTools/Program.cs index fae850ca0e..4253e8819f 100644 --- a/dotnet/samples/GettingStarted/AgentWithAnthropic/Agent_Anthropic_Step03_UsingFunctionTools/Program.cs +++ b/dotnet/samples/GettingStarted/AgentWithAnthropic/Agent_Anthropic_Step03_UsingFunctionTools/Program.cs @@ -23,7 +23,7 @@ static string GetWeather([Description("The location to get the weather for.")] s // Get anthropic client to create agents. AIAgent agent = new AnthropicClient { APIKey = apiKey } - .CreateAIAgent(model: model, instructions: AssistantInstructions, name: AssistantName, tools: [tool]); + .AsAIAgent(model: model, instructions: AssistantInstructions, name: AssistantName, tools: [tool]); // Non-streaming agent interaction with function tools. AgentThread thread = await agent.GetNewThreadAsync(); diff --git a/dotnet/samples/GettingStarted/AgentWithMemory/AgentWithMemory_Step01_ChatHistoryMemory/Program.cs b/dotnet/samples/GettingStarted/AgentWithMemory/AgentWithMemory_Step01_ChatHistoryMemory/Program.cs index 3acd6fbc2b..b8fe566dc9 100644 --- a/dotnet/samples/GettingStarted/AgentWithMemory/AgentWithMemory_Step01_ChatHistoryMemory/Program.cs +++ b/dotnet/samples/GettingStarted/AgentWithMemory/AgentWithMemory_Step01_ChatHistoryMemory/Program.cs @@ -30,7 +30,7 @@ new Uri(endpoint), new AzureCliCredential()) .GetChatClient(deploymentName) - .CreateAIAgent(new ChatClientAgentOptions + .AsAIAgent(new ChatClientAgentOptions { ChatOptions = new() { Instructions = "You are good at telling jokes." }, Name = "Joker", diff --git a/dotnet/samples/GettingStarted/AgentWithMemory/AgentWithMemory_Step02_MemoryUsingMem0/Program.cs b/dotnet/samples/GettingStarted/AgentWithMemory/AgentWithMemory_Step02_MemoryUsingMem0/Program.cs index 18390718f9..da0e816448 100644 --- a/dotnet/samples/GettingStarted/AgentWithMemory/AgentWithMemory_Step02_MemoryUsingMem0/Program.cs +++ b/dotnet/samples/GettingStarted/AgentWithMemory/AgentWithMemory_Step02_MemoryUsingMem0/Program.cs @@ -28,7 +28,7 @@ new Uri(endpoint), new AzureCliCredential()) .GetChatClient(deploymentName) - .CreateAIAgent(new ChatClientAgentOptions() + .AsAIAgent(new ChatClientAgentOptions() { ChatOptions = new() { Instructions = "You are a friendly travel assistant. Use known memories about the user when responding, and do not invent details." }, AIContextProviderFactory = (ctx, ct) => new ValueTask(ctx.SerializedState.ValueKind is not JsonValueKind.Null and not JsonValueKind.Undefined diff --git a/dotnet/samples/GettingStarted/AgentWithMemory/AgentWithMemory_Step03_CustomMemory/Program.cs b/dotnet/samples/GettingStarted/AgentWithMemory/AgentWithMemory_Step03_CustomMemory/Program.cs index 1069d0cd44..4e84a4b53c 100644 --- a/dotnet/samples/GettingStarted/AgentWithMemory/AgentWithMemory_Step03_CustomMemory/Program.cs +++ b/dotnet/samples/GettingStarted/AgentWithMemory/AgentWithMemory_Step03_CustomMemory/Program.cs @@ -30,7 +30,7 @@ // and preferably shared between multiple threads used by the same user, ensure that the // factory reads the user id from the current context and scopes the memory component // and its storage to that user id. -AIAgent agent = chatClient.CreateAIAgent(new ChatClientAgentOptions() +AIAgent agent = chatClient.AsAIAgent(new ChatClientAgentOptions() { ChatOptions = new() { Instructions = "You are a friendly assistant. Always address the user by their name." }, AIContextProviderFactory = (ctx, ct) => new ValueTask(new UserInfoMemory(chatClient.AsIChatClient(), ctx.SerializedState, ctx.JsonSerializerOptions)) diff --git a/dotnet/samples/GettingStarted/AgentWithOpenAI/Agent_OpenAI_Step01_Running/Program.cs b/dotnet/samples/GettingStarted/AgentWithOpenAI/Agent_OpenAI_Step01_Running/Program.cs index ccd42a2007..78ea76e03f 100644 --- a/dotnet/samples/GettingStarted/AgentWithOpenAI/Agent_OpenAI_Step01_Running/Program.cs +++ b/dotnet/samples/GettingStarted/AgentWithOpenAI/Agent_OpenAI_Step01_Running/Program.cs @@ -12,7 +12,7 @@ AIAgent agent = new OpenAIClient(apiKey) .GetChatClient(model) - .CreateAIAgent(instructions: "You are good at telling jokes.", name: "Joker"); + .AsAIAgent(instructions: "You are good at telling jokes.", name: "Joker"); UserChatMessage chatMessage = new("Tell me a joke about a pirate."); diff --git a/dotnet/samples/GettingStarted/AgentWithRAG/AgentWithRAG_Step01_BasicTextRAG/Program.cs b/dotnet/samples/GettingStarted/AgentWithRAG/AgentWithRAG_Step01_BasicTextRAG/Program.cs index 3b446b5bec..a4904ecf77 100644 --- a/dotnet/samples/GettingStarted/AgentWithRAG/AgentWithRAG_Step01_BasicTextRAG/Program.cs +++ b/dotnet/samples/GettingStarted/AgentWithRAG/AgentWithRAG_Step01_BasicTextRAG/Program.cs @@ -59,7 +59,7 @@ // Create the AI agent with the TextSearchProvider as the AI context provider. AIAgent agent = azureOpenAIClient .GetChatClient(deploymentName) - .CreateAIAgent(new ChatClientAgentOptions + .AsAIAgent(new ChatClientAgentOptions { ChatOptions = new() { Instructions = "You are a helpful support specialist for Contoso Outdoors. Answer questions using the provided context and cite the source document when available." }, AIContextProviderFactory = (ctx, ct) => new ValueTask(new TextSearchProvider(SearchAdapter, ctx.SerializedState, ctx.JsonSerializerOptions, textSearchOptions)), diff --git a/dotnet/samples/GettingStarted/AgentWithRAG/AgentWithRAG_Step02_CustomVectorStoreRAG/Program.cs b/dotnet/samples/GettingStarted/AgentWithRAG/AgentWithRAG_Step02_CustomVectorStoreRAG/Program.cs index 83ed7857f6..40e2834317 100644 --- a/dotnet/samples/GettingStarted/AgentWithRAG/AgentWithRAG_Step02_CustomVectorStoreRAG/Program.cs +++ b/dotnet/samples/GettingStarted/AgentWithRAG/AgentWithRAG_Step02_CustomVectorStoreRAG/Program.cs @@ -68,7 +68,7 @@ // Create the AI agent with the TextSearchProvider as the AI context provider. AIAgent agent = azureOpenAIClient .GetChatClient(deploymentName) - .CreateAIAgent(new ChatClientAgentOptions + .AsAIAgent(new ChatClientAgentOptions { ChatOptions = new() { Instructions = "You are a helpful support specialist for the Microsoft Agent Framework. Answer questions using the provided context and cite the source document when available. Keep responses brief." }, AIContextProviderFactory = (ctx, ct) => new ValueTask(new TextSearchProvider(SearchAdapter, ctx.SerializedState, ctx.JsonSerializerOptions, textSearchOptions)) diff --git a/dotnet/samples/GettingStarted/AgentWithRAG/AgentWithRAG_Step03_CustomRAGDataSource/Program.cs b/dotnet/samples/GettingStarted/AgentWithRAG/AgentWithRAG_Step03_CustomRAGDataSource/Program.cs index 960278b512..a8b21ec287 100644 --- a/dotnet/samples/GettingStarted/AgentWithRAG/AgentWithRAG_Step03_CustomRAGDataSource/Program.cs +++ b/dotnet/samples/GettingStarted/AgentWithRAG/AgentWithRAG_Step03_CustomRAGDataSource/Program.cs @@ -26,7 +26,7 @@ new Uri(endpoint), new AzureCliCredential()) .GetChatClient(deploymentName) - .CreateAIAgent(new ChatClientAgentOptions + .AsAIAgent(new ChatClientAgentOptions { ChatOptions = new() { Instructions = "You are a helpful support specialist for Contoso Outdoors. Answer questions using the provided context and cite the source document when available." }, AIContextProviderFactory = (ctx, ct) => new ValueTask(new TextSearchProvider(MockSearchAsync, ctx.SerializedState, ctx.JsonSerializerOptions, textSearchOptions)) diff --git a/dotnet/samples/GettingStarted/Agents/Agent_Step01_Running/Program.cs b/dotnet/samples/GettingStarted/Agents/Agent_Step01_Running/Program.cs index 889045c228..3ce20975b9 100644 --- a/dotnet/samples/GettingStarted/Agents/Agent_Step01_Running/Program.cs +++ b/dotnet/samples/GettingStarted/Agents/Agent_Step01_Running/Program.cs @@ -14,7 +14,7 @@ new Uri(endpoint), new AzureCliCredential()) .GetChatClient(deploymentName) - .CreateAIAgent(instructions: "You are good at telling jokes.", name: "Joker"); + .AsAIAgent(instructions: "You are good at telling jokes.", name: "Joker"); // Invoke the agent and output the text result. Console.WriteLine(await agent.RunAsync("Tell me a joke about a pirate.")); diff --git a/dotnet/samples/GettingStarted/Agents/Agent_Step02_MultiturnConversation/Program.cs b/dotnet/samples/GettingStarted/Agents/Agent_Step02_MultiturnConversation/Program.cs index b08ef1cb3a..22e5078498 100644 --- a/dotnet/samples/GettingStarted/Agents/Agent_Step02_MultiturnConversation/Program.cs +++ b/dotnet/samples/GettingStarted/Agents/Agent_Step02_MultiturnConversation/Program.cs @@ -14,7 +14,7 @@ new Uri(endpoint), new AzureCliCredential()) .GetChatClient(deploymentName) - .CreateAIAgent(instructions: "You are good at telling jokes.", name: "Joker"); + .AsAIAgent(instructions: "You are good at telling jokes.", name: "Joker"); // Invoke the agent with a multi-turn conversation, where the context is preserved in the thread object. AgentThread thread = await agent.GetNewThreadAsync(); diff --git a/dotnet/samples/GettingStarted/Agents/Agent_Step03_UsingFunctionTools/Program.cs b/dotnet/samples/GettingStarted/Agents/Agent_Step03_UsingFunctionTools/Program.cs index ae41572cc2..87cc021fb3 100644 --- a/dotnet/samples/GettingStarted/Agents/Agent_Step03_UsingFunctionTools/Program.cs +++ b/dotnet/samples/GettingStarted/Agents/Agent_Step03_UsingFunctionTools/Program.cs @@ -22,7 +22,7 @@ static string GetWeather([Description("The location to get the weather for.")] s new Uri(endpoint), new AzureCliCredential()) .GetChatClient(deploymentName) - .CreateAIAgent(instructions: "You are a helpful assistant", tools: [AIFunctionFactory.Create(GetWeather)]); + .AsAIAgent(instructions: "You are a helpful assistant", tools: [AIFunctionFactory.Create(GetWeather)]); // Non-streaming agent interaction with function tools. Console.WriteLine(await agent.RunAsync("What is the weather like in Amsterdam?")); diff --git a/dotnet/samples/GettingStarted/Agents/Agent_Step04_UsingFunctionToolsWithApprovals/Program.cs b/dotnet/samples/GettingStarted/Agents/Agent_Step04_UsingFunctionToolsWithApprovals/Program.cs index 169cabcb47..b12bf48e6e 100644 --- a/dotnet/samples/GettingStarted/Agents/Agent_Step04_UsingFunctionToolsWithApprovals/Program.cs +++ b/dotnet/samples/GettingStarted/Agents/Agent_Step04_UsingFunctionToolsWithApprovals/Program.cs @@ -27,7 +27,7 @@ static string GetWeather([Description("The location to get the weather for.")] s new Uri(endpoint), new AzureCliCredential()) .GetChatClient(deploymentName) - .CreateAIAgent(instructions: "You are a helpful assistant", tools: [new ApprovalRequiredAIFunction(AIFunctionFactory.Create(GetWeather))]); + .AsAIAgent(instructions: "You are a helpful assistant", tools: [new ApprovalRequiredAIFunction(AIFunctionFactory.Create(GetWeather))]); // Call the agent and check if there are any user input requests to handle. AgentThread thread = await agent.GetNewThreadAsync(); diff --git a/dotnet/samples/GettingStarted/Agents/Agent_Step05_StructuredOutput/Program.cs b/dotnet/samples/GettingStarted/Agents/Agent_Step05_StructuredOutput/Program.cs index e7fc4088df..38762ebfd1 100644 --- a/dotnet/samples/GettingStarted/Agents/Agent_Step05_StructuredOutput/Program.cs +++ b/dotnet/samples/GettingStarted/Agents/Agent_Step05_StructuredOutput/Program.cs @@ -21,7 +21,7 @@ .GetChatClient(deploymentName); // Create the ChatClientAgent with the specified name and instructions. -ChatClientAgent agent = chatClient.CreateAIAgent(name: "HelpfulAssistant", instructions: "You are a helpful assistant."); +ChatClientAgent agent = chatClient.AsAIAgent(name: "HelpfulAssistant", instructions: "You are a helpful assistant."); // Set PersonInfo as the type parameter of RunAsync method to specify the expected structured output from the agent and invoke the agent with some unstructured input. AgentResponse response = await agent.RunAsync("Please provide information about John Smith, who is a 35-year-old software engineer."); @@ -33,7 +33,7 @@ Console.WriteLine($"Occupation: {response.Result.Occupation}"); // Create the ChatClientAgent with the specified name, instructions, and expected structured output the agent should produce. -ChatClientAgent agentWithPersonInfo = chatClient.CreateAIAgent(new ChatClientAgentOptions() +ChatClientAgent agentWithPersonInfo = chatClient.AsAIAgent(new ChatClientAgentOptions() { Name = "HelpfulAssistant", ChatOptions = new() { Instructions = "You are a helpful assistant.", ResponseFormat = Microsoft.Extensions.AI.ChatResponseFormat.ForJsonSchema() } diff --git a/dotnet/samples/GettingStarted/Agents/Agent_Step06_PersistedConversations/Program.cs b/dotnet/samples/GettingStarted/Agents/Agent_Step06_PersistedConversations/Program.cs index 462d26e3d7..b23e1abe78 100644 --- a/dotnet/samples/GettingStarted/Agents/Agent_Step06_PersistedConversations/Program.cs +++ b/dotnet/samples/GettingStarted/Agents/Agent_Step06_PersistedConversations/Program.cs @@ -16,7 +16,7 @@ new Uri(endpoint), new AzureCliCredential()) .GetChatClient(deploymentName) - .CreateAIAgent(instructions: "You are good at telling jokes.", name: "Joker"); + .AsAIAgent(instructions: "You are good at telling jokes.", name: "Joker"); // Start a new thread for the agent conversation. AgentThread thread = await agent.GetNewThreadAsync(); diff --git a/dotnet/samples/GettingStarted/Agents/Agent_Step07_3rdPartyThreadStorage/Program.cs b/dotnet/samples/GettingStarted/Agents/Agent_Step07_3rdPartyThreadStorage/Program.cs index 32d38b9e29..a03b3bb349 100644 --- a/dotnet/samples/GettingStarted/Agents/Agent_Step07_3rdPartyThreadStorage/Program.cs +++ b/dotnet/samples/GettingStarted/Agents/Agent_Step07_3rdPartyThreadStorage/Program.cs @@ -27,7 +27,7 @@ new Uri(endpoint), new AzureCliCredential()) .GetChatClient(deploymentName) - .CreateAIAgent(new ChatClientAgentOptions + .AsAIAgent(new ChatClientAgentOptions { ChatOptions = new() { Instructions = "You are good at telling jokes." }, Name = "Joker", diff --git a/dotnet/samples/GettingStarted/Agents/Agent_Step08_Observability/Program.cs b/dotnet/samples/GettingStarted/Agents/Agent_Step08_Observability/Program.cs index e43e80d664..6a969d7512 100644 --- a/dotnet/samples/GettingStarted/Agents/Agent_Step08_Observability/Program.cs +++ b/dotnet/samples/GettingStarted/Agents/Agent_Step08_Observability/Program.cs @@ -29,7 +29,7 @@ // Create the agent, and enable OpenTelemetry instrumentation. AIAgent agent = new AzureOpenAIClient(new Uri(endpoint), new AzureCliCredential()) .GetChatClient(deploymentName) - .CreateAIAgent(instructions: "You are good at telling jokes.", name: "Joker") + .AsAIAgent(instructions: "You are good at telling jokes.", name: "Joker") .AsBuilder() .UseOpenTelemetry(sourceName: sourceName) .Build(); diff --git a/dotnet/samples/GettingStarted/Agents/Agent_Step11_UsingImages/Program.cs b/dotnet/samples/GettingStarted/Agents/Agent_Step11_UsingImages/Program.cs index 901d6ddbfc..b517e3ee95 100644 --- a/dotnet/samples/GettingStarted/Agents/Agent_Step11_UsingImages/Program.cs +++ b/dotnet/samples/GettingStarted/Agents/Agent_Step11_UsingImages/Program.cs @@ -13,7 +13,7 @@ var agent = new AzureOpenAIClient(new Uri(endpoint), new AzureCliCredential()) .GetChatClient(deploymentName) - .CreateAIAgent( + .AsAIAgent( name: "VisionAgent", instructions: "You are a helpful agent that can analyze images"); diff --git a/dotnet/samples/GettingStarted/Agents/Agent_Step12_AsFunctionTool/Program.cs b/dotnet/samples/GettingStarted/Agents/Agent_Step12_AsFunctionTool/Program.cs index 5e37ff4039..765174072f 100644 --- a/dotnet/samples/GettingStarted/Agents/Agent_Step12_AsFunctionTool/Program.cs +++ b/dotnet/samples/GettingStarted/Agents/Agent_Step12_AsFunctionTool/Program.cs @@ -21,7 +21,7 @@ static string GetWeather([Description("The location to get the weather for.")] s new Uri(endpoint), new AzureCliCredential()) .GetChatClient(deploymentName) - .CreateAIAgent( + .AsAIAgent( instructions: "You answer questions about the weather.", name: "WeatherAgent", description: "An agent that answers questions about the weather.", @@ -32,7 +32,7 @@ static string GetWeather([Description("The location to get the weather for.")] s new Uri(endpoint), new AzureCliCredential()) .GetChatClient(deploymentName) - .CreateAIAgent(instructions: "You are a helpful assistant who responds in French.", tools: [weatherAgent.AsAIFunction()]); + .AsAIAgent(instructions: "You are a helpful assistant who responds in French.", tools: [weatherAgent.AsAIFunction()]); // Invoke the agent and output the text result. Console.WriteLine(await agent.RunAsync("What is the weather like in Amsterdam?")); diff --git a/dotnet/samples/GettingStarted/Agents/Agent_Step13_BackgroundResponsesWithToolsAndPersistence/Program.cs b/dotnet/samples/GettingStarted/Agents/Agent_Step13_BackgroundResponsesWithToolsAndPersistence/Program.cs index 98f85a7593..fee7b2900c 100644 --- a/dotnet/samples/GettingStarted/Agents/Agent_Step13_BackgroundResponsesWithToolsAndPersistence/Program.cs +++ b/dotnet/samples/GettingStarted/Agents/Agent_Step13_BackgroundResponsesWithToolsAndPersistence/Program.cs @@ -23,7 +23,7 @@ new Uri(endpoint), new AzureCliCredential()) .GetResponsesClient(deploymentName) - .CreateAIAgent( + .AsAIAgent( name: "SpaceNovelWriter", instructions: "You are a space novel writer. Always research relevant facts and generate character profiles for the main characters before writing novels." + "Write complete chapters without asking for approval or feedback. Do not ask the user about tone, style, pace, or format preferences - just write the novel based on the request.", diff --git a/dotnet/samples/GettingStarted/Agents/Agent_Step15_Plugins/Program.cs b/dotnet/samples/GettingStarted/Agents/Agent_Step15_Plugins/Program.cs index 38cd20b8d6..54f977352b 100644 --- a/dotnet/samples/GettingStarted/Agents/Agent_Step15_Plugins/Program.cs +++ b/dotnet/samples/GettingStarted/Agents/Agent_Step15_Plugins/Program.cs @@ -31,7 +31,7 @@ new Uri(endpoint), new AzureCliCredential()) .GetChatClient(deploymentName) - .CreateAIAgent( + .AsAIAgent( instructions: "You are a helpful assistant that helps people find information.", name: "Assistant", tools: [.. serviceProvider.GetRequiredService().AsAITools()], diff --git a/dotnet/samples/GettingStarted/Agents/Agent_Step16_ChatReduction/Program.cs b/dotnet/samples/GettingStarted/Agents/Agent_Step16_ChatReduction/Program.cs index 61e7b2b48a..a80dd0fed0 100644 --- a/dotnet/samples/GettingStarted/Agents/Agent_Step16_ChatReduction/Program.cs +++ b/dotnet/samples/GettingStarted/Agents/Agent_Step16_ChatReduction/Program.cs @@ -20,7 +20,7 @@ new Uri(endpoint), new AzureCliCredential()) .GetChatClient(deploymentName) - .CreateAIAgent(new ChatClientAgentOptions + .AsAIAgent(new ChatClientAgentOptions { ChatOptions = new() { Instructions = "You are good at telling jokes." }, Name = "Joker", diff --git a/dotnet/samples/GettingStarted/Agents/Agent_Step17_BackgroundResponses/Program.cs b/dotnet/samples/GettingStarted/Agents/Agent_Step17_BackgroundResponses/Program.cs index d35b42a780..ae0151c8ab 100644 --- a/dotnet/samples/GettingStarted/Agents/Agent_Step17_BackgroundResponses/Program.cs +++ b/dotnet/samples/GettingStarted/Agents/Agent_Step17_BackgroundResponses/Program.cs @@ -14,7 +14,7 @@ new Uri(endpoint), new AzureCliCredential()) .GetResponsesClient(deploymentName) - .CreateAIAgent(); + .AsAIAgent(); // Enable background responses (only supported by OpenAI Responses at this time). AgentRunOptions options = new() { AllowBackgroundResponses = true }; diff --git a/dotnet/samples/GettingStarted/ModelContextProtocol/Agent_MCP_Server/Program.cs b/dotnet/samples/GettingStarted/ModelContextProtocol/Agent_MCP_Server/Program.cs index 774c33ed58..568830bb04 100644 --- a/dotnet/samples/GettingStarted/ModelContextProtocol/Agent_MCP_Server/Program.cs +++ b/dotnet/samples/GettingStarted/ModelContextProtocol/Agent_MCP_Server/Program.cs @@ -27,7 +27,7 @@ new Uri(endpoint), new AzureCliCredential()) .GetChatClient(deploymentName) - .CreateAIAgent(instructions: "You answer questions related to GitHub repositories only.", tools: [.. mcpTools.Cast()]); + .AsAIAgent(instructions: "You answer questions related to GitHub repositories only.", tools: [.. mcpTools.Cast()]); // Invoke the agent and output the text result. Console.WriteLine(await agent.RunAsync("Summarize the last four commits to the microsoft/semantic-kernel repository?")); diff --git a/dotnet/samples/GettingStarted/ModelContextProtocol/Agent_MCP_Server_Auth/Program.cs b/dotnet/samples/GettingStarted/ModelContextProtocol/Agent_MCP_Server_Auth/Program.cs index c9197c573c..1a08945680 100644 --- a/dotnet/samples/GettingStarted/ModelContextProtocol/Agent_MCP_Server_Auth/Program.cs +++ b/dotnet/samples/GettingStarted/ModelContextProtocol/Agent_MCP_Server_Auth/Program.cs @@ -50,7 +50,7 @@ new Uri(endpoint), new AzureCliCredential()) .GetChatClient(deploymentName) - .CreateAIAgent(instructions: "You answer questions related to the weather.", tools: [.. mcpTools]); + .AsAIAgent(instructions: "You answer questions related to the weather.", tools: [.. mcpTools]); // Invoke the agent and output the text result. Console.WriteLine(await agent.RunAsync("Get current weather alerts for New York?")); diff --git a/dotnet/samples/GettingStarted/ModelContextProtocol/ResponseAgent_Hosted_MCP/Program.cs b/dotnet/samples/GettingStarted/ModelContextProtocol/ResponseAgent_Hosted_MCP/Program.cs index 3b90adb1c6..986e7d0977 100644 --- a/dotnet/samples/GettingStarted/ModelContextProtocol/ResponseAgent_Hosted_MCP/Program.cs +++ b/dotnet/samples/GettingStarted/ModelContextProtocol/ResponseAgent_Hosted_MCP/Program.cs @@ -31,7 +31,7 @@ new Uri(endpoint), new AzureCliCredential()) .GetResponsesClient(deploymentName) - .CreateAIAgent( + .AsAIAgent( instructions: "You answer questions by searching the Microsoft Learn content only.", name: "MicrosoftLearnAgent", tools: [mcpTool]); @@ -58,7 +58,7 @@ new Uri(endpoint), new AzureCliCredential()) .GetResponsesClient(deploymentName) - .CreateAIAgent( + .AsAIAgent( instructions: "You answer questions by searching the Microsoft Learn content only.", name: "MicrosoftLearnAgentWithApproval", tools: [mcpToolWithApproval]); diff --git a/dotnet/src/Microsoft.Agents.AI.A2A/Extensions/A2AAgentCardExtensions.cs b/dotnet/src/Microsoft.Agents.AI.A2A/Extensions/A2AAgentCardExtensions.cs index 39d7107430..1998d020b5 100644 --- a/dotnet/src/Microsoft.Agents.AI.A2A/Extensions/A2AAgentCardExtensions.cs +++ b/dotnet/src/Microsoft.Agents.AI.A2A/Extensions/A2AAgentCardExtensions.cs @@ -27,11 +27,11 @@ public static class A2AAgentCardExtensions /// The to use for HTTP requests. /// The logger factory for enabling logging within the agent. /// An instance backed by the A2A agent. - public static AIAgent GetAIAgent(this AgentCard card, HttpClient? httpClient = null, ILoggerFactory? loggerFactory = null) + public static AIAgent AsAIAgent(this AgentCard card, HttpClient? httpClient = null, ILoggerFactory? loggerFactory = null) { // Create the A2A client using the agent URL from the card. var a2aClient = new A2AClient(new Uri(card.Url), httpClient); - return a2aClient.GetAIAgent(name: card.Name, description: card.Description, loggerFactory: loggerFactory); + return a2aClient.AsAIAgent(name: card.Name, description: card.Description, loggerFactory: loggerFactory); } } diff --git a/dotnet/src/Microsoft.Agents.AI.A2A/Extensions/A2ACardResolverExtensions.cs b/dotnet/src/Microsoft.Agents.AI.A2A/Extensions/A2ACardResolverExtensions.cs index 2da58222b8..6a32822fea 100644 --- a/dotnet/src/Microsoft.Agents.AI.A2A/Extensions/A2ACardResolverExtensions.cs +++ b/dotnet/src/Microsoft.Agents.AI.A2A/Extensions/A2ACardResolverExtensions.cs @@ -42,6 +42,6 @@ public static async Task GetAIAgentAsync(this A2ACardResolver resolver, // Obtain the agent card from the resolver. var agentCard = await resolver.GetAgentCardAsync(cancellationToken).ConfigureAwait(false); - return agentCard.GetAIAgent(httpClient, loggerFactory); + return agentCard.AsAIAgent(httpClient, loggerFactory); } } diff --git a/dotnet/src/Microsoft.Agents.AI.A2A/Extensions/A2AClientExtensions.cs b/dotnet/src/Microsoft.Agents.AI.A2A/Extensions/A2AClientExtensions.cs index d57ed4cb42..cd93ca0bac 100644 --- a/dotnet/src/Microsoft.Agents.AI.A2A/Extensions/A2AClientExtensions.cs +++ b/dotnet/src/Microsoft.Agents.AI.A2A/Extensions/A2AClientExtensions.cs @@ -35,6 +35,6 @@ public static class A2AClientExtensions /// The description of the agent. /// Optional logger factory for enabling logging within the agent. /// An instance backed by the A2A agent. - public static AIAgent GetAIAgent(this A2AClient client, string? id = null, string? name = null, string? description = null, ILoggerFactory? loggerFactory = null) => + public static AIAgent AsAIAgent(this A2AClient client, string? id = null, string? name = null, string? description = null, ILoggerFactory? loggerFactory = null) => new A2AAgent(client, id, name, description, loggerFactory); } diff --git a/dotnet/src/Microsoft.Agents.AI.Anthropic/AnthropicBetaServiceExtensions.cs b/dotnet/src/Microsoft.Agents.AI.Anthropic/AnthropicBetaServiceExtensions.cs index 6b4f872a63..06c7cbaf15 100644 --- a/dotnet/src/Microsoft.Agents.AI.Anthropic/AnthropicBetaServiceExtensions.cs +++ b/dotnet/src/Microsoft.Agents.AI.Anthropic/AnthropicBetaServiceExtensions.cs @@ -31,7 +31,7 @@ public static class AnthropicBetaServiceExtensions /// Optional logger factory for enabling logging within the agent. /// An optional to use for resolving services required by the instances being invoked. /// The created AI agent. - public static ChatClientAgent CreateAIAgent( + public static ChatClientAgent AsAIAgent( this IBetaService betaService, string model, string? instructions = null, @@ -81,7 +81,7 @@ public static ChatClientAgent CreateAIAgent( /// An optional to use for resolving services required by the instances being invoked. /// An instance backed by the Anthropic Chat Completion service. /// Thrown when or is . - public static ChatClientAgent CreateAIAgent( + public static ChatClientAgent AsAIAgent( this IBetaService betaService, ChatClientAgentOptions options, Func? clientFactory = null, diff --git a/dotnet/src/Microsoft.Agents.AI.Anthropic/AnthropicClientExtensions.cs b/dotnet/src/Microsoft.Agents.AI.Anthropic/AnthropicClientExtensions.cs index b4b8e2bc1e..c0bbd4715d 100644 --- a/dotnet/src/Microsoft.Agents.AI.Anthropic/AnthropicClientExtensions.cs +++ b/dotnet/src/Microsoft.Agents.AI.Anthropic/AnthropicClientExtensions.cs @@ -31,7 +31,7 @@ public static class AnthropicClientExtensions /// Optional logger factory for enabling logging within the agent. /// An optional to use for resolving services required by the instances being invoked. /// The created AI agent. - public static ChatClientAgent CreateAIAgent( + public static ChatClientAgent AsAIAgent( this IAnthropicClient client, string model, string? instructions = null, @@ -81,7 +81,7 @@ public static ChatClientAgent CreateAIAgent( /// An optional to use for resolving services required by the instances being invoked. /// An instance backed by the Anthropic Chat Completion service. /// Thrown when or is . - public static ChatClientAgent CreateAIAgent( + public static ChatClientAgent AsAIAgent( this IAnthropicClient client, ChatClientAgentOptions options, Func? clientFactory = null, diff --git a/dotnet/src/Microsoft.Agents.AI.AzureAI.Persistent/PersistentAgentsClientExtensions.cs b/dotnet/src/Microsoft.Agents.AI.AzureAI.Persistent/PersistentAgentsClientExtensions.cs index 5ca1436587..55c3c4f0bf 100644 --- a/dotnet/src/Microsoft.Agents.AI.AzureAI.Persistent/PersistentAgentsClientExtensions.cs +++ b/dotnet/src/Microsoft.Agents.AI.AzureAI.Persistent/PersistentAgentsClientExtensions.cs @@ -19,7 +19,7 @@ public static class PersistentAgentsClientExtensions /// Provides a way to customize the creation of the underlying used by the agent. /// An optional to use for resolving services required by the instances being invoked. /// A instance that can be used to perform operations on the persistent agent. - public static ChatClientAgent GetAIAgent( + public static ChatClientAgent AsAIAgent( this PersistentAgentsClient persistentAgentsClient, Response persistentAgentResponse, ChatOptions? chatOptions = null, @@ -31,7 +31,7 @@ public static ChatClientAgent GetAIAgent( throw new ArgumentNullException(nameof(persistentAgentResponse)); } - return GetAIAgent(persistentAgentsClient, persistentAgentResponse.Value, chatOptions, clientFactory, services); + return AsAIAgent(persistentAgentsClient, persistentAgentResponse.Value, chatOptions, clientFactory, services); } /// @@ -43,7 +43,7 @@ public static ChatClientAgent GetAIAgent( /// Provides a way to customize the creation of the underlying used by the agent. /// An optional to use for resolving services required by the instances being invoked. /// A instance that can be used to perform operations on the persistent agent. - public static ChatClientAgent GetAIAgent( + public static ChatClientAgent AsAIAgent( this PersistentAgentsClient persistentAgentsClient, PersistentAgent persistentAgentMetadata, ChatOptions? chatOptions = null, @@ -112,7 +112,7 @@ public static ChatClientAgent GetAIAgent( } var persistentAgentResponse = persistentAgentsClient.Administration.GetAgent(agentId, cancellationToken); - return persistentAgentsClient.GetAIAgent(persistentAgentResponse, chatOptions, clientFactory, services); + return persistentAgentsClient.AsAIAgent(persistentAgentResponse, chatOptions, clientFactory, services); } /// @@ -145,7 +145,7 @@ public static async Task GetAIAgentAsync( } var persistentAgentResponse = await persistentAgentsClient.Administration.GetAgentAsync(agentId, cancellationToken).ConfigureAwait(false); - return persistentAgentsClient.GetAIAgent(persistentAgentResponse, chatOptions, clientFactory, services); + return persistentAgentsClient.AsAIAgent(persistentAgentResponse, chatOptions, clientFactory, services); } /// @@ -158,7 +158,7 @@ public static async Task GetAIAgentAsync( /// An optional to use for resolving services required by the instances being invoked. /// A instance that can be used to perform operations on the persistent agent. /// Thrown when or is . - public static ChatClientAgent GetAIAgent( + public static ChatClientAgent AsAIAgent( this PersistentAgentsClient persistentAgentsClient, Response persistentAgentResponse, ChatClientAgentOptions options, @@ -170,7 +170,7 @@ public static ChatClientAgent GetAIAgent( throw new ArgumentNullException(nameof(persistentAgentResponse)); } - return GetAIAgent(persistentAgentsClient, persistentAgentResponse.Value, options, clientFactory, services); + return AsAIAgent(persistentAgentsClient, persistentAgentResponse.Value, options, clientFactory, services); } /// @@ -183,7 +183,7 @@ public static ChatClientAgent GetAIAgent( /// An optional to use for resolving services required by the instances being invoked. /// A instance that can be used to perform operations on the persistent agent. /// Thrown when or is . - public static ChatClientAgent GetAIAgent( + public static ChatClientAgent AsAIAgent( this PersistentAgentsClient persistentAgentsClient, PersistentAgent persistentAgentMetadata, ChatClientAgentOptions options, @@ -268,7 +268,7 @@ public static ChatClientAgent GetAIAgent( } var persistentAgentResponse = persistentAgentsClient.Administration.GetAgent(agentId, cancellationToken); - return persistentAgentsClient.GetAIAgent(persistentAgentResponse, options, clientFactory, services); + return persistentAgentsClient.AsAIAgent(persistentAgentResponse, options, clientFactory, services); } /// @@ -307,7 +307,7 @@ public static async Task GetAIAgentAsync( } var persistentAgentResponse = await persistentAgentsClient.Administration.GetAgentAsync(agentId, cancellationToken).ConfigureAwait(false); - return persistentAgentsClient.GetAIAgent(persistentAgentResponse, options, clientFactory, services); + return persistentAgentsClient.AsAIAgent(persistentAgentResponse, options, clientFactory, services); } /// diff --git a/dotnet/src/Microsoft.Agents.AI.AzureAI/AzureAIProjectChatClientExtensions.cs b/dotnet/src/Microsoft.Agents.AI.AzureAI/AzureAIProjectChatClientExtensions.cs index 7319bb13eb..8e03a33be3 100644 --- a/dotnet/src/Microsoft.Agents.AI.AzureAI/AzureAIProjectChatClientExtensions.cs +++ b/dotnet/src/Microsoft.Agents.AI.AzureAI/AzureAIProjectChatClientExtensions.cs @@ -91,7 +91,7 @@ public static ChatClientAgent GetAIAgent( AgentRecord agentRecord = GetAgentRecordByName(aiProjectClient, name, cancellationToken); - return GetAIAgent( + return AsAIAgent( aiProjectClient, agentRecord, tools, @@ -125,7 +125,7 @@ public static async Task GetAIAgentAsync( AgentRecord agentRecord = await GetAgentRecordByNameAsync(aiProjectClient, name, cancellationToken).ConfigureAwait(false); - return GetAIAgent( + return AsAIAgent( aiProjectClient, agentRecord, tools, @@ -143,7 +143,7 @@ public static async Task GetAIAgentAsync( /// An optional to use for resolving services required by the instances being invoked. /// A instance that can be used to perform operations based on the latest version of the Azure AI Agent. /// Thrown when or is . - public static ChatClientAgent GetAIAgent( + public static ChatClientAgent AsAIAgent( this AIProjectClient aiProjectClient, AgentRecord agentRecord, IList? tools = null, @@ -174,7 +174,7 @@ public static ChatClientAgent GetAIAgent( /// An optional to use for resolving services required by the instances being invoked. /// A instance that can be used to perform operations based on the provided version of the Azure AI Agent. /// Thrown when or is . - public static ChatClientAgent GetAIAgent( + public static ChatClientAgent AsAIAgent( this AIProjectClient aiProjectClient, AgentVersion agentVersion, IList? tools = null, diff --git a/dotnet/src/Microsoft.Agents.AI.Hosting.AzureFunctions/README.md b/dotnet/src/Microsoft.Agents.AI.Hosting.AzureFunctions/README.md index ee50c78ff5..2b3c87c348 100644 --- a/dotnet/src/Microsoft.Agents.AI.Hosting.AzureFunctions/README.md +++ b/dotnet/src/Microsoft.Agents.AI.Hosting.AzureFunctions/README.md @@ -36,13 +36,13 @@ This package provides a `ConfigureDurableAgents` extension method on the `Functi // Invocable via HTTP via http://localhost:7071/api/agents/SpamDetectionAgent/run AIAgent spamDetector = new AzureOpenAIClient(new Uri(endpoint), new AzureCliCredential()) .GetChatClient(deploymentName) - .CreateAIAgent( + .AsAIAgent( instructions: "You are a spam detection assistant that identifies spam emails.", name: "SpamDetectionAgent"); AIAgent emailAssistant = new AzureOpenAIClient(new Uri(endpoint), new AzureCliCredential()) .GetChatClient(deploymentName) - .CreateAIAgent( + .AsAIAgent( instructions: "You are an email assistant that helps users draft responses to emails with professionalism.", name: "EmailAssistantAgent"); @@ -156,7 +156,7 @@ These tools are registered with the agent using the `tools` parameter when creat Tools tools = new(); AIAgent agent = new AzureOpenAIClient(new Uri(endpoint), new AzureCliCredential()) .GetChatClient(deploymentName) - .CreateAIAgent( + .AsAIAgent( instructions: "You are a content generation assistant that helps users generate content.", name: "ContentGenerationAgent", tools: [ diff --git a/dotnet/src/Microsoft.Agents.AI.OpenAI/Extensions/OpenAIAssistantClientExtensions.cs b/dotnet/src/Microsoft.Agents.AI.OpenAI/Extensions/OpenAIAssistantClientExtensions.cs index 881266fe8b..291ff56091 100644 --- a/dotnet/src/Microsoft.Agents.AI.OpenAI/Extensions/OpenAIAssistantClientExtensions.cs +++ b/dotnet/src/Microsoft.Agents.AI.OpenAI/Extensions/OpenAIAssistantClientExtensions.cs @@ -30,7 +30,7 @@ public static class OpenAIAssistantClientExtensions /// An optional to use for resolving services required by the instances being invoked. /// A instance that can be used to perform operations on the assistant. [Obsolete("The Assistants API has been deprecated. Please use the Responses API instead.")] - public static ChatClientAgent GetAIAgent( + public static ChatClientAgent AsAIAgent( this AssistantClient assistantClient, ClientResult assistantClientResult, ChatOptions? chatOptions = null, @@ -42,7 +42,7 @@ public static ChatClientAgent GetAIAgent( throw new ArgumentNullException(nameof(assistantClientResult)); } - return assistantClient.GetAIAgent(assistantClientResult.Value, chatOptions, clientFactory, services); + return assistantClient.AsAIAgent(assistantClientResult.Value, chatOptions, clientFactory, services); } /// @@ -55,7 +55,7 @@ public static ChatClientAgent GetAIAgent( /// An optional to use for resolving services required by the instances being invoked. /// A instance that can be used to perform operations on the assistant. [Obsolete("The Assistants API has been deprecated. Please use the Responses API instead.")] - public static ChatClientAgent GetAIAgent( + public static ChatClientAgent AsAIAgent( this AssistantClient assistantClient, Assistant assistantMetadata, ChatOptions? chatOptions = null, @@ -123,7 +123,7 @@ public static ChatClientAgent GetAIAgent( } var assistant = assistantClient.GetAssistant(agentId, cancellationToken); - return assistantClient.GetAIAgent(assistant, chatOptions, clientFactory, services); + return assistantClient.AsAIAgent(assistant, chatOptions, clientFactory, services); } /// @@ -156,7 +156,7 @@ public static async Task GetAIAgentAsync( } var assistantResponse = await assistantClient.GetAssistantAsync(agentId, cancellationToken).ConfigureAwait(false); - return assistantClient.GetAIAgent(assistantResponse, chatOptions, clientFactory, services); + return assistantClient.AsAIAgent(assistantResponse, chatOptions, clientFactory, services); } /// @@ -170,7 +170,7 @@ public static async Task GetAIAgentAsync( /// A instance that can be used to perform operations on the assistant. /// or is . [Obsolete("The Assistants API has been deprecated. Please use the Responses API instead.")] - public static ChatClientAgent GetAIAgent( + public static ChatClientAgent AsAIAgent( this AssistantClient assistantClient, ClientResult assistantClientResult, ChatClientAgentOptions options, @@ -182,7 +182,7 @@ public static ChatClientAgent GetAIAgent( throw new ArgumentNullException(nameof(assistantClientResult)); } - return assistantClient.GetAIAgent(assistantClientResult.Value, options, clientFactory, services); + return assistantClient.AsAIAgent(assistantClientResult.Value, options, clientFactory, services); } /// @@ -196,7 +196,7 @@ public static ChatClientAgent GetAIAgent( /// A instance that can be used to perform operations on the assistant. /// or is . [Obsolete("The Assistants API has been deprecated. Please use the Responses API instead.")] - public static ChatClientAgent GetAIAgent( + public static ChatClientAgent AsAIAgent( this AssistantClient assistantClient, Assistant assistantMetadata, ChatClientAgentOptions options, @@ -282,7 +282,7 @@ public static ChatClientAgent GetAIAgent( } var assistant = assistantClient.GetAssistant(agentId, cancellationToken); - return assistantClient.GetAIAgent(assistant, options, clientFactory, services); + return assistantClient.AsAIAgent(assistant, options, clientFactory, services); } /// @@ -322,7 +322,7 @@ public static async Task GetAIAgentAsync( } var assistantResponse = await assistantClient.GetAssistantAsync(agentId, cancellationToken).ConfigureAwait(false); - return assistantClient.GetAIAgent(assistantResponse, options, clientFactory, services); + return assistantClient.AsAIAgent(assistantResponse, options, clientFactory, services); } /// diff --git a/dotnet/src/Microsoft.Agents.AI.OpenAI/Extensions/OpenAIChatClientExtensions.cs b/dotnet/src/Microsoft.Agents.AI.OpenAI/Extensions/OpenAIChatClientExtensions.cs index aa4f38e5f4..be3216083c 100644 --- a/dotnet/src/Microsoft.Agents.AI.OpenAI/Extensions/OpenAIChatClientExtensions.cs +++ b/dotnet/src/Microsoft.Agents.AI.OpenAI/Extensions/OpenAIChatClientExtensions.cs @@ -32,7 +32,7 @@ public static class OpenAIChatClientExtensions /// An optional to use for resolving services required by the instances being invoked. /// An instance backed by the OpenAI Chat Completion service. /// Thrown when is . - public static ChatClientAgent CreateAIAgent( + public static ChatClientAgent AsAIAgent( this ChatClient client, string? instructions = null, string? name = null, @@ -41,7 +41,7 @@ public static ChatClientAgent CreateAIAgent( Func? clientFactory = null, ILoggerFactory? loggerFactory = null, IServiceProvider? services = null) => - client.CreateAIAgent( + client.AsAIAgent( new ChatClientAgentOptions() { Name = name, @@ -66,7 +66,7 @@ public static ChatClientAgent CreateAIAgent( /// An optional to use for resolving services required by the instances being invoked. /// An instance backed by the OpenAI Chat Completion service. /// Thrown when or is . - public static ChatClientAgent CreateAIAgent( + public static ChatClientAgent AsAIAgent( this ChatClient client, ChatClientAgentOptions options, Func? clientFactory = null, diff --git a/dotnet/src/Microsoft.Agents.AI.OpenAI/Extensions/OpenAIResponseClientExtensions.cs b/dotnet/src/Microsoft.Agents.AI.OpenAI/Extensions/OpenAIResponseClientExtensions.cs index 224bf5db95..bc9f28c37d 100644 --- a/dotnet/src/Microsoft.Agents.AI.OpenAI/Extensions/OpenAIResponseClientExtensions.cs +++ b/dotnet/src/Microsoft.Agents.AI.OpenAI/Extensions/OpenAIResponseClientExtensions.cs @@ -32,7 +32,7 @@ public static class OpenAIResponseClientExtensions /// An optional to use for resolving services required by the instances being invoked. /// An instance backed by the OpenAI Response service. /// Thrown when is . - public static ChatClientAgent CreateAIAgent( + public static ChatClientAgent AsAIAgent( this ResponsesClient client, string? instructions = null, string? name = null, @@ -44,7 +44,7 @@ public static ChatClientAgent CreateAIAgent( { Throw.IfNull(client); - return client.CreateAIAgent( + return client.AsAIAgent( new ChatClientAgentOptions() { Name = name, @@ -70,7 +70,7 @@ public static ChatClientAgent CreateAIAgent( /// An optional to use for resolving services required by the instances being invoked. /// An instance backed by the OpenAI Response service. /// Thrown when or is . - public static ChatClientAgent CreateAIAgent( + public static ChatClientAgent AsAIAgent( this ResponsesClient client, ChatClientAgentOptions options, Func? clientFactory = null, diff --git a/dotnet/src/Microsoft.Agents.AI.Purview/README.md b/dotnet/src/Microsoft.Agents.AI.Purview/README.md index 6df5ec4c3d..1a9fc70725 100644 --- a/dotnet/src/Microsoft.Agents.AI.Purview/README.md +++ b/dotnet/src/Microsoft.Agents.AI.Purview/README.md @@ -186,7 +186,7 @@ AIAgent agent = new AzureOpenAIClient( new Uri(endpoint), new AzureCliCredential()) .GetChatClient(deploymentName) - .CreateAIAgent("You are a helpful assistant.") + .AsAIAgent("You are a helpful assistant.") .AsBuilder() .WithPurview(browserCredential, new PurviewSettings("Agent Framework Test App")) .Build(); diff --git a/dotnet/src/Microsoft.Agents.AI.Workflows.Declarative.AzureAI/AzureAgentProvider.cs b/dotnet/src/Microsoft.Agents.AI.Workflows.Declarative.AzureAI/AzureAgentProvider.cs index 322ab7606a..a86e2a2f4a 100644 --- a/dotnet/src/Microsoft.Agents.AI.Workflows.Declarative.AzureAI/AzureAgentProvider.cs +++ b/dotnet/src/Microsoft.Agents.AI.Workflows.Declarative.AzureAI/AzureAgentProvider.cs @@ -174,7 +174,7 @@ private async Task GetAgentAsync(AgentVersion agentVersion, Cancellatio AIProjectClient client = this.GetAgentClient(); - agent = client.GetAIAgent(agentVersion, tools: null, clientFactory: null, services: null); + agent = client.AsAIAgent(agentVersion, tools: null, clientFactory: null, services: null); FunctionInvokingChatClient? functionInvokingClient = agent.GetService(); if (functionInvokingClient is not null) diff --git a/dotnet/src/Microsoft.Agents.AI/ChatClient/ChatClientBuilderExtensions.cs b/dotnet/src/Microsoft.Agents.AI/ChatClient/ChatClientBuilderExtensions.cs index fd4b6df60a..ee782dce52 100644 --- a/dotnet/src/Microsoft.Agents.AI/ChatClient/ChatClientBuilderExtensions.cs +++ b/dotnet/src/Microsoft.Agents.AI/ChatClient/ChatClientBuilderExtensions.cs @@ -49,7 +49,7 @@ public static ChatClientAgent BuildAIAgent( IList? tools = null, ILoggerFactory? loggerFactory = null, IServiceProvider? services = null) => - Throw.IfNull(builder).Build(services).CreateAIAgent( + Throw.IfNull(builder).Build(services).AsAIAgent( instructions: instructions, name: name, description: description, @@ -78,7 +78,7 @@ public static ChatClientAgent BuildAIAgent( ChatClientAgentOptions? options, ILoggerFactory? loggerFactory = null, IServiceProvider? services = null) => - Throw.IfNull(builder).Build(services).CreateAIAgent( + Throw.IfNull(builder).Build(services).AsAIAgent( options: options, loggerFactory: loggerFactory, services: services); diff --git a/dotnet/src/Microsoft.Agents.AI/ChatClient/ChatClientExtensions.cs b/dotnet/src/Microsoft.Agents.AI/ChatClient/ChatClientExtensions.cs index f65d41efe7..653f198402 100644 --- a/dotnet/src/Microsoft.Agents.AI/ChatClient/ChatClientExtensions.cs +++ b/dotnet/src/Microsoft.Agents.AI/ChatClient/ChatClientExtensions.cs @@ -20,7 +20,7 @@ public static class ChatClientExtensions /// /// /// A new instance. - public static ChatClientAgent CreateAIAgent( + public static ChatClientAgent AsAIAgent( this IChatClient chatClient, string? instructions = null, string? name = null, @@ -42,7 +42,7 @@ public static ChatClientAgent CreateAIAgent( /// /// /// A new instance. - public static ChatClientAgent CreateAIAgent( + public static ChatClientAgent AsAIAgent( this IChatClient chatClient, ChatClientAgentOptions? options, ILoggerFactory? loggerFactory = null, diff --git a/dotnet/tests/Microsoft.Agents.AI.A2A.UnitTests/Extensions/A2AAgentCardExtensionsTests.cs b/dotnet/tests/Microsoft.Agents.AI.A2A.UnitTests/Extensions/A2AAgentCardExtensionsTests.cs index 16e80b4b26..f644109b38 100644 --- a/dotnet/tests/Microsoft.Agents.AI.A2A.UnitTests/Extensions/A2AAgentCardExtensionsTests.cs +++ b/dotnet/tests/Microsoft.Agents.AI.A2A.UnitTests/Extensions/A2AAgentCardExtensionsTests.cs @@ -34,7 +34,7 @@ public A2AAgentCardExtensionsTests() public void GetAIAgent_ReturnsAIAgent() { // Act - var agent = this._agentCard.GetAIAgent(); + var agent = this._agentCard.AsAIAgent(); // Assert Assert.NotNull(agent); @@ -56,7 +56,7 @@ public async Task RunIAgentAsync_SendsRequestToTheUrlSpecifiedInAgentCardAsync() Parts = [new TextPart { Text = "Response" }], }); - var agent = this._agentCard.GetAIAgent(httpClient); + var agent = this._agentCard.AsAIAgent(httpClient); // Act await agent.RunAsync("Test input"); diff --git a/dotnet/tests/Microsoft.Agents.AI.A2A.UnitTests/Extensions/A2AClientExtensionsTests.cs b/dotnet/tests/Microsoft.Agents.AI.A2A.UnitTests/Extensions/A2AClientExtensionsTests.cs index 5b84324e8b..9ad4d982a9 100644 --- a/dotnet/tests/Microsoft.Agents.AI.A2A.UnitTests/Extensions/A2AClientExtensionsTests.cs +++ b/dotnet/tests/Microsoft.Agents.AI.A2A.UnitTests/Extensions/A2AClientExtensionsTests.cs @@ -21,7 +21,7 @@ public void GetAIAgent_WithAllParameters_ReturnsA2AAgentWithSpecifiedProperties( const string TestDescription = "This is a test agent description"; // Act - var agent = a2aClient.GetAIAgent(TestId, TestName, TestDescription); + var agent = a2aClient.AsAIAgent(TestId, TestName, TestDescription); // Assert Assert.NotNull(agent); diff --git a/dotnet/tests/Microsoft.Agents.AI.AGUI.UnitTests/AGUIChatClientTests.cs b/dotnet/tests/Microsoft.Agents.AI.AGUI.UnitTests/AGUIChatClientTests.cs index 009b109891..9109118f73 100644 --- a/dotnet/tests/Microsoft.Agents.AI.AGUI.UnitTests/AGUIChatClientTests.cs +++ b/dotnet/tests/Microsoft.Agents.AI.AGUI.UnitTests/AGUIChatClientTests.cs @@ -30,7 +30,7 @@ public async Task RunAsync_AggregatesStreamingUpdates_ReturnsCompleteMessagesAsy ]); var chatClient = new AGUIChatClient(httpClient, "http://localhost/agent", null, AGUIJsonSerializerContext.Default.Options); - AIAgent agent = chatClient.CreateAIAgent(instructions: null, name: "agent1", description: "Test agent", tools: []); + AIAgent agent = chatClient.AsAIAgent(instructions: null, name: "agent1", description: "Test agent", tools: []); List messages = [new ChatMessage(ChatRole.User, "Test")]; // Act @@ -55,7 +55,7 @@ public async Task RunAsync_WithEmptyUpdateStream_ContainsOnlyMetadataMessagesAsy ]); var chatClient = new AGUIChatClient(httpClient, "http://localhost/agent", null, AGUIJsonSerializerContext.Default.Options); - AIAgent agent = chatClient.CreateAIAgent(instructions: null, name: "agent1", description: "Test agent", tools: []); + AIAgent agent = chatClient.AsAIAgent(instructions: null, name: "agent1", description: "Test agent", tools: []); List messages = [new ChatMessage(ChatRole.User, "Test")]; // Act @@ -74,7 +74,7 @@ public async Task RunAsync_WithNullMessages_ThrowsArgumentNullExceptionAsync() // Arrange using HttpClient httpClient = new(); var chatClient = new AGUIChatClient(httpClient, "http://localhost/agent", null, AGUIJsonSerializerContext.Default.Options); - AIAgent agent = chatClient.CreateAIAgent(instructions: "Test agent", name: "agent1"); + AIAgent agent = chatClient.AsAIAgent(instructions: "Test agent", name: "agent1"); // Act & Assert await Assert.ThrowsAsync(() => agent.RunAsync(messages: null!)); @@ -91,7 +91,7 @@ public async Task RunAsync_WithNullThread_CreatesNewThreadAsync() ]); var chatClient = new AGUIChatClient(httpClient, "http://localhost/agent", null, AGUIJsonSerializerContext.Default.Options); - AIAgent agent = chatClient.CreateAIAgent(instructions: "Test agent", name: "agent1"); + AIAgent agent = chatClient.AsAIAgent(instructions: "Test agent", name: "agent1"); List messages = [new ChatMessage(ChatRole.User, "Test")]; // Act @@ -115,7 +115,7 @@ public async Task RunStreamingAsync_YieldsAllEvents_FromServerStreamAsync() ]); var chatClient = new AGUIChatClient(httpClient, "http://localhost/agent", null, AGUIJsonSerializerContext.Default.Options); - AIAgent agent = chatClient.CreateAIAgent(instructions: "Test agent", name: "agent1"); + AIAgent agent = chatClient.AsAIAgent(instructions: "Test agent", name: "agent1"); List messages = [new ChatMessage(ChatRole.User, "Test")]; // Act @@ -139,7 +139,7 @@ public async Task RunStreamingAsync_WithNullMessages_ThrowsArgumentNullException // Arrange using HttpClient httpClient = new(); var chatClient = new AGUIChatClient(httpClient, "http://localhost/agent", null, AGUIJsonSerializerContext.Default.Options); - AIAgent agent = chatClient.CreateAIAgent(instructions: "Test agent", name: "agent1"); + AIAgent agent = chatClient.AsAIAgent(instructions: "Test agent", name: "agent1"); // Act & Assert await Assert.ThrowsAsync(async () => @@ -162,7 +162,7 @@ public async Task RunStreamingAsync_WithNullThread_CreatesNewThreadAsync() ]); var chatClient = new AGUIChatClient(httpClient, "http://localhost/agent", null, AGUIJsonSerializerContext.Default.Options); - AIAgent agent = chatClient.CreateAIAgent(instructions: "Test agent", name: "agent1"); + AIAgent agent = chatClient.AsAIAgent(instructions: "Test agent", name: "agent1"); List messages = [new ChatMessage(ChatRole.User, "Test")]; // Act @@ -195,7 +195,7 @@ public async Task RunStreamingAsync_GeneratesUniqueRunId_ForEachInvocationAsync( using HttpClient httpClient = new(handler); var chatClient = new AGUIChatClient(httpClient, "http://localhost/agent", null, AGUIJsonSerializerContext.Default.Options); - AIAgent agent = chatClient.CreateAIAgent(instructions: null, name: "agent1", description: "Test agent", tools: []); + AIAgent agent = chatClient.AsAIAgent(instructions: null, name: "agent1", description: "Test agent", tools: []); List messages = [new ChatMessage(ChatRole.User, "Test")]; // Act @@ -227,7 +227,7 @@ public async Task RunStreamingAsync_ReturnsStreamingUpdates_AfterCompletionAsync ]); var chatClient = new AGUIChatClient(httpClient, "http://localhost/agent", null, AGUIJsonSerializerContext.Default.Options); - AIAgent agent = chatClient.CreateAIAgent(instructions: null, name: "agent1", description: "Test agent", tools: []); + AIAgent agent = chatClient.AsAIAgent(instructions: null, name: "agent1", description: "Test agent", tools: []); AgentThread thread = await agent.GetNewThreadAsync(); List messages = [new ChatMessage(ChatRole.User, "Hello")]; @@ -249,7 +249,7 @@ public async Task DeserializeThread_WithValidState_ReturnsChatClientAgentThreadA // Arrange using var httpClient = new HttpClient(); var chatClient = new AGUIChatClient(httpClient, "http://localhost/agent", null, AGUIJsonSerializerContext.Default.Options); - AIAgent agent = chatClient.CreateAIAgent(instructions: null, name: "agent1", description: "Test agent", tools: []); + AIAgent agent = chatClient.AsAIAgent(instructions: null, name: "agent1", description: "Test agent", tools: []); AgentThread originalThread = await agent.GetNewThreadAsync(); JsonElement serialized = originalThread.Serialize(); @@ -301,7 +301,7 @@ public async Task RunStreamingAsync_InvokesTools_WhenFunctionCallsReturnedAsync( ]); var chatClient = new AGUIChatClient(httpClient, "http://localhost/agent", null, AGUIJsonSerializerContext.Default.Options); - AIAgent agent = chatClient.CreateAIAgent(instructions: null, name: "agent1", description: "Test agent", tools: [testTool]); + AIAgent agent = chatClient.AsAIAgent(instructions: null, name: "agent1", description: "Test agent", tools: [testTool]); List messages = [new ChatMessage(ChatRole.User, "What's the weather?")]; // Act @@ -353,7 +353,7 @@ public async Task RunStreamingAsync_DoesNotInvokeTools_WhenSomeToolsNotAvailable using HttpClient httpClient = new(handler); var chatClient = new AGUIChatClient(httpClient, "http://localhost/agent", null, AGUIJsonSerializerContext.Default.Options); - AIAgent agent = chatClient.CreateAIAgent(instructions: null, name: "agent1", description: "Test agent", tools: [tool1]); // Only tool1, not tool2 + AIAgent agent = chatClient.AsAIAgent(instructions: null, name: "agent1", description: "Test agent", tools: [tool1]); // Only tool1, not tool2 List messages = [new ChatMessage(ChatRole.User, "Test")]; // Act @@ -403,7 +403,7 @@ public async Task RunStreamingAsync_HandlesToolInvocationErrors_GracefullyAsync( ]); var chatClient = new AGUIChatClient(httpClient, "http://localhost/agent", null, AGUIJsonSerializerContext.Default.Options); - AIAgent agent = chatClient.CreateAIAgent(instructions: null, name: "agent1", description: "Test agent", tools: [faultyTool]); + AIAgent agent = chatClient.AsAIAgent(instructions: null, name: "agent1", description: "Test agent", tools: [faultyTool]); List messages = [new ChatMessage(ChatRole.User, "Test")]; // Act @@ -448,7 +448,7 @@ public async Task RunStreamingAsync_InvokesMultipleTools_InSingleTurnAsync() ]); var chatClient = new AGUIChatClient(httpClient, "http://localhost/agent", null, AGUIJsonSerializerContext.Default.Options); - AIAgent agent = chatClient.CreateAIAgent(instructions: null, name: "agent1", description: "Test agent", tools: [tool1, tool2]); + AIAgent agent = chatClient.AsAIAgent(instructions: null, name: "agent1", description: "Test agent", tools: [tool1, tool2]); List messages = [new ChatMessage(ChatRole.User, "Test")]; // Act @@ -486,7 +486,7 @@ public async Task RunStreamingAsync_UpdatesThreadWithToolMessages_AfterCompletio ]); var chatClient = new AGUIChatClient(httpClient, "http://localhost/agent", null, AGUIJsonSerializerContext.Default.Options); - AIAgent agent = chatClient.CreateAIAgent(instructions: null, name: "agent1", description: "Test agent", tools: [testTool]); + AIAgent agent = chatClient.AsAIAgent(instructions: null, name: "agent1", description: "Test agent", tools: [testTool]); AgentThread thread = await agent.GetNewThreadAsync(); List messages = [new ChatMessage(ChatRole.User, "Test")]; diff --git a/dotnet/tests/Microsoft.Agents.AI.Anthropic.UnitTests/Extensions/AnthropicBetaServiceExtensionsTests.cs b/dotnet/tests/Microsoft.Agents.AI.Anthropic.UnitTests/Extensions/AnthropicBetaServiceExtensionsTests.cs index 400bcf5456..91d2cb988a 100644 --- a/dotnet/tests/Microsoft.Agents.AI.Anthropic.UnitTests/Extensions/AnthropicBetaServiceExtensionsTests.cs +++ b/dotnet/tests/Microsoft.Agents.AI.Anthropic.UnitTests/Extensions/AnthropicBetaServiceExtensionsTests.cs @@ -34,7 +34,7 @@ public void CreateAIAgent_WithClientFactory_AppliesFactoryCorrectly() var testChatClient = new TestChatClient(chatClient.Beta.AsIChatClient()); // Act - var agent = chatClient.Beta.CreateAIAgent( + var agent = chatClient.Beta.AsAIAgent( model: "test-model", instructions: "Test instructions", name: "Test Agent", @@ -63,7 +63,7 @@ public void CreateAIAgent_WithClientFactoryUsingAsBuilder_AppliesFactoryCorrectl TestChatClient? testChatClient = null; // Act - var agent = chatClient.Beta.CreateAIAgent( + var agent = chatClient.Beta.AsAIAgent( model: "test-model", instructions: "Test instructions", clientFactory: (innerClient) => @@ -95,7 +95,7 @@ public void CreateAIAgent_WithOptionsAndClientFactory_AppliesFactoryCorrectly() }; // Act - var agent = chatClient.Beta.CreateAIAgent( + var agent = chatClient.Beta.AsAIAgent( options, clientFactory: (innerClient) => testChatClient); @@ -120,7 +120,7 @@ public void CreateAIAgent_WithoutClientFactory_WorksNormally() var chatClient = new TestAnthropicChatClient(); // Act - var agent = chatClient.Beta.CreateAIAgent( + var agent = chatClient.Beta.AsAIAgent( model: "test-model", instructions: "Test instructions", name: "Test Agent"); @@ -144,7 +144,7 @@ public void CreateAIAgent_WithNullClientFactory_WorksNormally() var chatClient = new TestAnthropicChatClient(); // Act - var agent = chatClient.Beta.CreateAIAgent( + var agent = chatClient.Beta.AsAIAgent( model: "test-model", instructions: "Test instructions", name: "Test Agent", @@ -167,7 +167,7 @@ public void CreateAIAgent_WithNullClient_ThrowsArgumentNullException() { // Act & Assert var exception = Assert.Throws(() => - ((IBetaService)null!).CreateAIAgent("test-model")); + ((IBetaService)null!).AsAIAgent("test-model")); Assert.Equal("betaService", exception.ParamName); } @@ -183,7 +183,7 @@ public void CreateAIAgent_WithNullOptions_ThrowsArgumentNullException() // Act & Assert var exception = Assert.Throws(() => - chatClient.Beta.CreateAIAgent((ChatClientAgentOptions)null!)); + chatClient.Beta.AsAIAgent((ChatClientAgentOptions)null!)); Assert.Equal("options", exception.ParamName); } diff --git a/dotnet/tests/Microsoft.Agents.AI.Anthropic.UnitTests/Extensions/AnthropicClientExtensionsTests.cs b/dotnet/tests/Microsoft.Agents.AI.Anthropic.UnitTests/Extensions/AnthropicClientExtensionsTests.cs index c8bf4d6a5e..90f20d15c3 100644 --- a/dotnet/tests/Microsoft.Agents.AI.Anthropic.UnitTests/Extensions/AnthropicClientExtensionsTests.cs +++ b/dotnet/tests/Microsoft.Agents.AI.Anthropic.UnitTests/Extensions/AnthropicClientExtensionsTests.cs @@ -101,7 +101,7 @@ public void CreateAIAgent_WithClientFactory_AppliesFactoryCorrectly() var testChatClient = new TestChatClient(chatClient.AsIChatClient()); // Act - var agent = chatClient.CreateAIAgent( + var agent = chatClient.AsAIAgent( model: "test-model", instructions: "Test instructions", name: "Test Agent", @@ -130,7 +130,7 @@ public void CreateAIAgent_WithClientFactoryUsingAsBuilder_AppliesFactoryCorrectl TestChatClient? testChatClient = null; // Act - var agent = chatClient.CreateAIAgent( + var agent = chatClient.AsAIAgent( model: "test-model", instructions: "Test instructions", clientFactory: (innerClient) => @@ -162,7 +162,7 @@ public void CreateAIAgent_WithOptionsAndClientFactory_AppliesFactoryCorrectly() }; // Act - var agent = chatClient.CreateAIAgent( + var agent = chatClient.AsAIAgent( options, clientFactory: (innerClient) => testChatClient); @@ -187,7 +187,7 @@ public void CreateAIAgent_WithoutClientFactory_WorksNormally() var chatClient = new TestAnthropicChatClient(); // Act - var agent = chatClient.CreateAIAgent( + var agent = chatClient.AsAIAgent( model: "test-model", instructions: "Test instructions", name: "Test Agent"); @@ -211,7 +211,7 @@ public void CreateAIAgent_WithNullClientFactory_WorksNormally() var chatClient = new TestAnthropicChatClient(); // Act - var agent = chatClient.CreateAIAgent( + var agent = chatClient.AsAIAgent( model: "test-model", instructions: "Test instructions", name: "Test Agent", @@ -234,7 +234,7 @@ public void CreateAIAgent_WithNullClient_ThrowsArgumentNullException() { // Act & Assert var exception = Assert.Throws(() => - ((TestAnthropicChatClient)null!).CreateAIAgent("test-model")); + ((TestAnthropicChatClient)null!).AsAIAgent("test-model")); Assert.Equal("client", exception.ParamName); } @@ -250,7 +250,7 @@ public void CreateAIAgent_WithNullOptions_ThrowsArgumentNullException() // Act & Assert var exception = Assert.Throws(() => - chatClient.CreateAIAgent((ChatClientAgentOptions)null!)); + chatClient.AsAIAgent((ChatClientAgentOptions)null!)); Assert.Equal("options", exception.ParamName); } diff --git a/dotnet/tests/Microsoft.Agents.AI.AzureAI.Persistent.UnitTests/Extensions/PersistentAgentsClientExtensionsTests.cs b/dotnet/tests/Microsoft.Agents.AI.AzureAI.Persistent.UnitTests/Extensions/PersistentAgentsClientExtensionsTests.cs index b661a392be..a3d3be27fe 100644 --- a/dotnet/tests/Microsoft.Agents.AI.AzureAI.Persistent.UnitTests/Extensions/PersistentAgentsClientExtensionsTests.cs +++ b/dotnet/tests/Microsoft.Agents.AI.AzureAI.Persistent.UnitTests/Extensions/PersistentAgentsClientExtensionsTests.cs @@ -42,7 +42,7 @@ public void GetAIAgent_WithNullOrWhitespaceAgentId_ThrowsArgumentException() // Act & Assert - null agentId var exception1 = Assert.Throws(() => - mockClient.Object.GetAIAgent((string)null!)); + mockClient.Object.GetAIAgent(null!)); Assert.Equal("agentId", exception1.ParamName); // Act & Assert - empty agentId @@ -314,7 +314,7 @@ public void GetAIAgent_WithResponseAndOptions_WorksCorrectly() }; // Act - var agent = client.GetAIAgent(response, options); + var agent = client.AsAIAgent(response, options); // Assert Assert.NotNull(agent); @@ -341,7 +341,7 @@ public void GetAIAgent_WithPersistentAgentAndOptions_WorksCorrectly() }; // Act - var agent = client.GetAIAgent(persistentAgent, options); + var agent = client.AsAIAgent(persistentAgent, options); // Assert Assert.NotNull(agent); @@ -363,7 +363,7 @@ public void GetAIAgent_WithPersistentAgentAndOptionsWithNullFields_FallsBackToAg var options = new ChatClientAgentOptions(); // Empty options // Act - var agent = client.GetAIAgent(persistentAgent, options); + var agent = client.AsAIAgent(persistentAgent, options); // Assert Assert.NotNull(agent); @@ -443,7 +443,7 @@ public void GetAIAgent_WithOptionsAndClientFactory_AppliesFactoryCorrectly() }; // Act - var agent = client.GetAIAgent( + var agent = client.AsAIAgent( persistentAgent, options, clientFactory: (innerClient) => testChatClient); @@ -470,7 +470,7 @@ public void GetAIAgent_WithNullResponse_ThrowsArgumentNullException() // Act & Assert var exception = Assert.Throws(() => - client.GetAIAgent((Response)null!, options)); + client.AsAIAgent(null!, options)); Assert.Equal("persistentAgentResponse", exception.ParamName); } @@ -487,7 +487,7 @@ public void GetAIAgent_WithNullPersistentAgent_ThrowsArgumentNullException() // Act & Assert var exception = Assert.Throws(() => - client.GetAIAgent((PersistentAgent)null!, options)); + client.AsAIAgent((PersistentAgent)null!, options)); Assert.Equal("persistentAgentMetadata", exception.ParamName); } @@ -504,7 +504,7 @@ public void GetAIAgent_WithNullOptions_ThrowsArgumentNullException() // Act & Assert var exception = Assert.Throws(() => - client.GetAIAgent(persistentAgent, (ChatClientAgentOptions)null!)); + client.AsAIAgent(persistentAgent, (ChatClientAgentOptions)null!)); Assert.Equal("options", exception.ParamName); } diff --git a/dotnet/tests/Microsoft.Agents.AI.AzureAI.UnitTests/AzureAIProjectChatClientExtensionsTests.cs b/dotnet/tests/Microsoft.Agents.AI.AzureAI.UnitTests/AzureAIProjectChatClientExtensionsTests.cs index 4ca2b7f461..528dc323af 100644 --- a/dotnet/tests/Microsoft.Agents.AI.AzureAI.UnitTests/AzureAIProjectChatClientExtensionsTests.cs +++ b/dotnet/tests/Microsoft.Agents.AI.AzureAI.UnitTests/AzureAIProjectChatClientExtensionsTests.cs @@ -25,13 +25,13 @@ namespace Microsoft.Agents.AI.AzureAI.UnitTests; /// public sealed class AzureAIProjectChatClientExtensionsTests { - #region GetAIAgent(AIProjectClient, AgentRecord) Tests + #region AsAIAgent(AIProjectClient, AgentRecord) Tests /// - /// Verify that GetAIAgent throws ArgumentNullException when AIProjectClient is null. + /// Verify that AsAIAgent throws ArgumentNullException when AIProjectClient is null. /// [Fact] - public void GetAIAgent_WithAgentRecord_WithNullClient_ThrowsArgumentNullException() + public void AsAIAgent_WithAgentRecord_WithNullClient_ThrowsArgumentNullException() { // Arrange AIProjectClient? client = null; @@ -39,39 +39,39 @@ public void GetAIAgent_WithAgentRecord_WithNullClient_ThrowsArgumentNullExceptio // Act & Assert var exception = Assert.Throws(() => - client!.GetAIAgent(agentRecord)); + client!.AsAIAgent(agentRecord)); Assert.Equal("aiProjectClient", exception.ParamName); } /// - /// Verify that GetAIAgent throws ArgumentNullException when agentRecord is null. + /// Verify that AsAIAgent throws ArgumentNullException when agentRecord is null. /// [Fact] - public void GetAIAgent_WithAgentRecord_WithNullAgentRecord_ThrowsArgumentNullException() + public void AsAIAgent_WithAgentRecord_WithNullAgentRecord_ThrowsArgumentNullException() { // Arrange var mockClient = new Mock(); // Act & Assert var exception = Assert.Throws(() => - mockClient.Object.GetAIAgent((AgentRecord)null!)); + mockClient.Object.AsAIAgent((AgentRecord)null!)); Assert.Equal("agentRecord", exception.ParamName); } /// - /// Verify that GetAIAgent with AgentRecord creates a valid agent. + /// Verify that AsAIAgent with AgentRecord creates a valid agent. /// [Fact] - public void GetAIAgent_WithAgentRecord_CreatesValidAgent() + public void AsAIAgent_WithAgentRecord_CreatesValidAgent() { // Arrange AIProjectClient client = this.CreateTestAgentClient(); AgentRecord agentRecord = this.CreateTestAgentRecord(); // Act - var agent = client.GetAIAgent(agentRecord); + var agent = client.AsAIAgent(agentRecord); // Assert Assert.NotNull(agent); @@ -79,10 +79,10 @@ public void GetAIAgent_WithAgentRecord_CreatesValidAgent() } /// - /// Verify that GetAIAgent with AgentRecord and clientFactory applies the factory. + /// Verify that AsAIAgent with AgentRecord and clientFactory applies the factory. /// [Fact] - public void GetAIAgent_WithAgentRecord_WithClientFactory_AppliesFactoryCorrectly() + public void AsAIAgent_WithAgentRecord_WithClientFactory_AppliesFactoryCorrectly() { // Arrange AIProjectClient client = this.CreateTestAgentClient(); @@ -90,7 +90,7 @@ public void GetAIAgent_WithAgentRecord_WithClientFactory_AppliesFactoryCorrectly TestChatClient? testChatClient = null; // Act - var agent = client.GetAIAgent( + var agent = client.AsAIAgent( agentRecord, clientFactory: (innerClient) => testChatClient = new TestChatClient(innerClient)); @@ -103,13 +103,13 @@ public void GetAIAgent_WithAgentRecord_WithClientFactory_AppliesFactoryCorrectly #endregion - #region GetAIAgent(AIProjectClient, AgentVersion) Tests + #region AsAIAgent(AIProjectClient, AgentVersion) Tests /// - /// Verify that GetAIAgent throws ArgumentNullException when AIProjectClient is null. + /// Verify that AsAIAgent throws ArgumentNullException when AIProjectClient is null. /// [Fact] - public void GetAIAgent_WithAgentVersion_WithNullClient_ThrowsArgumentNullException() + public void AsAIAgent_WithAgentVersion_WithNullClient_ThrowsArgumentNullException() { // Arrange AIProjectClient? client = null; @@ -117,39 +117,39 @@ public void GetAIAgent_WithAgentVersion_WithNullClient_ThrowsArgumentNullExcepti // Act & Assert var exception = Assert.Throws(() => - client!.GetAIAgent(agentVersion)); + client!.AsAIAgent(agentVersion)); Assert.Equal("aiProjectClient", exception.ParamName); } /// - /// Verify that GetAIAgent throws ArgumentNullException when agentVersion is null. + /// Verify that AsAIAgent throws ArgumentNullException when agentVersion is null. /// [Fact] - public void GetAIAgent_WithAgentVersion_WithNullAgentVersion_ThrowsArgumentNullException() + public void AsAIAgent_WithAgentVersion_WithNullAgentVersion_ThrowsArgumentNullException() { // Arrange var mockClient = new Mock(); // Act & Assert var exception = Assert.Throws(() => - mockClient.Object.GetAIAgent((AgentVersion)null!)); + mockClient.Object.AsAIAgent((AgentVersion)null!)); Assert.Equal("agentVersion", exception.ParamName); } /// - /// Verify that GetAIAgent with AgentVersion creates a valid agent. + /// Verify that AsAIAgent with AgentVersion creates a valid agent. /// [Fact] - public void GetAIAgent_WithAgentVersion_CreatesValidAgent() + public void AsAIAgent_WithAgentVersion_CreatesValidAgent() { // Arrange AIProjectClient client = this.CreateTestAgentClient(); AgentVersion agentVersion = this.CreateTestAgentVersion(); // Act - var agent = client.GetAIAgent(agentVersion); + var agent = client.AsAIAgent(agentVersion); // Assert Assert.NotNull(agent); @@ -157,10 +157,10 @@ public void GetAIAgent_WithAgentVersion_CreatesValidAgent() } /// - /// Verify that GetAIAgent with AgentVersion and clientFactory applies the factory. + /// Verify that AsAIAgent with AgentVersion and clientFactory applies the factory. /// [Fact] - public void GetAIAgent_WithAgentVersion_WithClientFactory_AppliesFactoryCorrectly() + public void AsAIAgent_WithAgentVersion_WithClientFactory_AppliesFactoryCorrectly() { // Arrange AIProjectClient client = this.CreateTestAgentClient(); @@ -168,7 +168,7 @@ public void GetAIAgent_WithAgentVersion_WithClientFactory_AppliesFactoryCorrectl TestChatClient? testChatClient = null; // Act - var agent = client.GetAIAgent( + var agent = client.AsAIAgent( agentVersion, clientFactory: (innerClient) => testChatClient = new TestChatClient(innerClient)); @@ -183,7 +183,7 @@ public void GetAIAgent_WithAgentVersion_WithClientFactory_AppliesFactoryCorrectl /// Verify that GetAIAgent with requireInvocableTools=true enforces invocable tools. /// [Fact] - public void GetAIAgent_WithAgentVersion_WithRequireInvocableToolsTrue_EnforcesInvocableTools() + public void AsAIAgent_WithAgentVersion_WithRequireInvocableToolsTrue_EnforcesInvocableTools() { // Arrange AIProjectClient client = this.CreateTestAgentClient(); @@ -194,7 +194,7 @@ public void GetAIAgent_WithAgentVersion_WithRequireInvocableToolsTrue_EnforcesIn }; // Act - var agent = client.GetAIAgent(agentVersion, tools: tools); + var agent = client.AsAIAgent(agentVersion, tools: tools); // Assert Assert.NotNull(agent); @@ -205,14 +205,14 @@ public void GetAIAgent_WithAgentVersion_WithRequireInvocableToolsTrue_EnforcesIn /// Verify that GetAIAgent with requireInvocableTools=false allows declarative functions. /// [Fact] - public void GetAIAgent_WithAgentVersion_WithRequireInvocableToolsFalse_AllowsDeclarativeFunctions() + public void AsAIAgent_WithAgentVersion_WithRequireInvocableToolsFalse_AllowsDeclarativeFunctions() { // Arrange AIProjectClient client = this.CreateTestAgentClient(); AgentVersion agentVersion = this.CreateTestAgentVersion(); // Act - should not throw even without tools when requireInvocableTools is false - var agent = client.GetAIAgent(agentVersion); + var agent = client.AsAIAgent(agentVersion); // Assert Assert.NotNull(agent); @@ -374,7 +374,7 @@ public async Task GetAIAgentAsync_WithOptions_CreatesValidAgentAsync() #region GetAIAgent(AIProjectClient, string) Tests /// - /// Verify that GetAIAgent throws ArgumentNullException when AIProjectClient is null. + /// Verify that AsAIAgent throws ArgumentNullException when AIProjectClient is null. /// [Fact] public void GetAIAgent_ByName_WithNullClient_ThrowsArgumentNullException() @@ -390,7 +390,7 @@ public void GetAIAgent_ByName_WithNullClient_ThrowsArgumentNullException() } /// - /// Verify that GetAIAgent throws ArgumentNullException when name is null. + /// Verify that AsAIAgent throws ArgumentNullException when name is null. /// [Fact] public void GetAIAgent_ByName_WithNullName_ThrowsArgumentNullException() @@ -406,7 +406,7 @@ public void GetAIAgent_ByName_WithNullName_ThrowsArgumentNullException() } /// - /// Verify that GetAIAgent throws ArgumentException when name is empty. + /// Verify that AsAIAgent throws ArgumentException when name is empty. /// [Fact] public void GetAIAgent_ByName_WithEmptyName_ThrowsArgumentException() @@ -422,7 +422,7 @@ public void GetAIAgent_ByName_WithEmptyName_ThrowsArgumentException() } /// - /// Verify that GetAIAgent throws InvalidOperationException when agent is not found. + /// Verify that AsAIAgent throws InvalidOperationException when agent is not found. /// [Fact] public void GetAIAgent_ByName_WithNonExistentAgent_ThrowsInvalidOperationException() @@ -505,13 +505,13 @@ public async Task GetAIAgentAsync_ByName_WithNonExistentAgent_ThrowsInvalidOpera #endregion - #region GetAIAgent(AIProjectClient, AgentRecord) with tools Tests + #region AsAIAgent(AIProjectClient, AgentRecord) with tools Tests /// - /// Verify that GetAIAgent with additional tools when the definition has no tools does not throw and results in an agent with no tools. + /// Verify that AsAIAgent with additional tools when the definition has no tools does not throw and results in an agent with no tools. /// [Fact] - public void GetAIAgent_WithAgentRecordAndAdditionalTools_WhenDefinitionHasNoTools_ShouldNotThrow() + public void AsAIAgent_WithAgentRecordAndAdditionalTools_WhenDefinitionHasNoTools_ShouldNotThrow() { // Arrange AIProjectClient client = this.CreateTestAgentClient(); @@ -522,7 +522,7 @@ public void GetAIAgent_WithAgentRecordAndAdditionalTools_WhenDefinitionHasNoTool }; // Act - var agent = client.GetAIAgent(agentRecord, tools: tools); + var agent = client.AsAIAgent(agentRecord, tools: tools); // Assert Assert.NotNull(agent); @@ -536,17 +536,17 @@ public void GetAIAgent_WithAgentRecordAndAdditionalTools_WhenDefinitionHasNoTool } /// - /// Verify that GetAIAgent with null tools works correctly. + /// Verify that AsAIAgent with null tools works correctly. /// [Fact] - public void GetAIAgent_WithAgentRecordAndNullTools_WorksCorrectly() + public void AsAIAgent_WithAgentRecordAndNullTools_WorksCorrectly() { // Arrange AIProjectClient client = this.CreateTestAgentClient(); AgentRecord agentRecord = this.CreateTestAgentRecord(); // Act - var agent = client.GetAIAgent(agentRecord, tools: null); + var agent = client.AsAIAgent(agentRecord, tools: null); // Assert Assert.NotNull(agent); @@ -1104,7 +1104,7 @@ public void GetAIAgent_AdditionalAITools_WhenNotInTheDefinitionAreIgnored() var shouldBeIgnoredTool = AIFunctionFactory.Create(() => "test", "additional_tool", "An additional test function that should be ignored"); // Act & Assert - var agent = client.GetAIAgent(agentVersion, tools: [invocableInlineAITool, shouldBeIgnoredTool]); + var agent = client.AsAIAgent(agentVersion, tools: [invocableInlineAITool, shouldBeIgnoredTool]); Assert.NotNull(agent); var version = agent.GetService(); Assert.NotNull(version); @@ -1136,7 +1136,7 @@ public void GetAIAgent_WithParameterTools_AcceptsTools() }; // Act - var agent = client.GetAIAgent(agentRecord, tools: tools); + var agent = client.AsAIAgent(agentRecord, tools: tools); // Assert Assert.NotNull(agent); @@ -1632,7 +1632,7 @@ public void CreateAIAgent_WithOptionsAndTools_GeneratesCorrectOptions() #region AgentName Validation Tests /// - /// Verify that GetAIAgent throws ArgumentException when agent name is invalid. + /// Verify that AsAIAgent throws ArgumentException when agent name is invalid. /// [Theory] [MemberData(nameof(InvalidAgentNameTestData.GetInvalidAgentNames), MemberType = typeof(InvalidAgentNameTestData))] @@ -1846,7 +1846,7 @@ public void GetAIAgent_WithAgentReference_WithInvalidAgentName_ThrowsArgumentExc /// Verify that the underlying chat client created by extension methods can be wrapped with clientFactory. /// [Fact] - public void GetAIAgent_WithClientFactory_WrapsUnderlyingChatClient() + public void AsAIAgent_WithClientFactory_WrapsUnderlyingChatClient() { // Arrange AIProjectClient client = this.CreateTestAgentClient(); @@ -1854,7 +1854,7 @@ public void GetAIAgent_WithClientFactory_WrapsUnderlyingChatClient() int factoryCallCount = 0; // Act - var agent = client.GetAIAgent( + var agent = client.AsAIAgent( agentRecord, clientFactory: (innerClient) => { @@ -1903,18 +1903,18 @@ public void CreateAIAgent_WithClientFactory_ReceivesCorrectUnderlyingClient() /// Verify that multiple clientFactory calls create independent wrapped clients. /// [Fact] - public void GetAIAgent_MultipleCallsWithClientFactory_CreatesIndependentClients() + public void AsAIAgent_MultipleCallsWithClientFactory_CreatesIndependentClients() { // Arrange AIProjectClient client = this.CreateTestAgentClient(); AgentRecord agentRecord = this.CreateTestAgentRecord(); // Act - var agent1 = client.GetAIAgent( + var agent1 = client.AsAIAgent( agentRecord, clientFactory: (innerClient) => new TestChatClient(innerClient)); - var agent2 = client.GetAIAgent( + var agent2 = client.AsAIAgent( agentRecord, clientFactory: (innerClient) => new TestChatClient(innerClient)); @@ -2165,7 +2165,7 @@ public async Task GetAIAgent_UserAgentHeaderAddedToRequestsAsync() #region GetAIAgent(AIProjectClient, AgentReference) Tests /// - /// Verify that GetAIAgent throws ArgumentNullException when AIProjectClient is null. + /// Verify that AsAIAgent throws ArgumentNullException when AIProjectClient is null. /// [Fact] public void GetAIAgent_WithAgentReference_WithNullClient_ThrowsArgumentNullException() @@ -2182,7 +2182,7 @@ public void GetAIAgent_WithAgentReference_WithNullClient_ThrowsArgumentNullExcep } /// - /// Verify that GetAIAgent throws ArgumentNullException when agentReference is null. + /// Verify that AsAIAgent throws ArgumentNullException when agentReference is null. /// [Fact] public void GetAIAgent_WithAgentReference_WithNullAgentReference_ThrowsArgumentNullException() @@ -2297,7 +2297,7 @@ public void GetService_WithAgentRecord_ReturnsAgentRecord() AgentRecord agentRecord = this.CreateTestAgentRecord(); // Act - var agent = client.GetAIAgent(agentRecord); + var agent = client.AsAIAgent(agentRecord); var retrievedRecord = agent.GetService(); // Assert @@ -2338,7 +2338,7 @@ public void GetService_WithAgentVersion_ReturnsAgentVersion() AgentVersion agentVersion = this.CreateTestAgentVersion(); // Act - var agent = client.GetAIAgent(agentVersion); + var agent = client.AsAIAgent(agentVersion); var retrievedVersion = agent.GetService(); // Assert @@ -2379,7 +2379,7 @@ public void ChatClientMetadata_WithAgentRecord_IsPopulatedCorrectly() AgentRecord agentRecord = this.CreateTestAgentRecord(); // Act - var agent = client.GetAIAgent(agentRecord); + var agent = client.AsAIAgent(agentRecord); var metadata = agent.GetService(); // Assert @@ -2402,7 +2402,7 @@ public void ChatClientMetadata_WithPromptAgentDefinition_SetsDefaultModelIdFromM AgentRecord agentRecord = this.CreateTestAgentRecord(definition); // Act - var agent = client.GetAIAgent(agentRecord); + var agent = client.AsAIAgent(agentRecord); var metadata = agent.GetService(); // Assert @@ -2423,7 +2423,7 @@ public void ChatClientMetadata_WithAgentVersion_IsPopulatedCorrectly() AgentVersion agentVersion = this.CreateTestAgentVersion(); // Act - var agent = client.GetAIAgent(agentVersion); + var agent = client.AsAIAgent(agentVersion); var metadata = agent.GetService(); // Assert @@ -2467,7 +2467,7 @@ public void GetService_WithAgentRecord_ReturnsAlsoAgentReference() AgentRecord agentRecord = this.CreateTestAgentRecord(); // Act - var agent = client.GetAIAgent(agentRecord); + var agent = client.AsAIAgent(agentRecord); var retrievedReference = agent.GetService(); // Assert @@ -2486,7 +2486,7 @@ public void GetService_WithAgentVersion_ReturnsAlsoAgentReference() AgentVersion agentVersion = this.CreateTestAgentVersion(); // Act - var agent = client.GetAIAgent(agentVersion); + var agent = client.AsAIAgent(agentVersion); var retrievedReference = agent.GetService(); // Assert diff --git a/dotnet/tests/Microsoft.Agents.AI.DurableTask.IntegrationTests/AgentEntityTests.cs b/dotnet/tests/Microsoft.Agents.AI.DurableTask.IntegrationTests/AgentEntityTests.cs index afd5d0a573..f0b5caf9bd 100644 --- a/dotnet/tests/Microsoft.Agents.AI.DurableTask.IntegrationTests/AgentEntityTests.cs +++ b/dotnet/tests/Microsoft.Agents.AI.DurableTask.IntegrationTests/AgentEntityTests.cs @@ -41,7 +41,7 @@ public sealed class AgentEntityTests(ITestOutputHelper outputHelper) : IDisposab public async Task EntityNamePrefixAsync() { // Setup - AIAgent simpleAgent = TestHelper.GetAzureOpenAIChatClient(s_configuration).CreateAIAgent( + AIAgent simpleAgent = TestHelper.GetAzureOpenAIChatClient(s_configuration).AsAIAgent( name: "TestAgent", instructions: "You are a helpful assistant that always responds with a friendly greeting." ); @@ -88,7 +88,7 @@ await simpleAgentProxy.RunAsync( public async Task RunAgentMethodNamesAllWorkAsync(string runAgentMethodName) { // Setup - AIAgent simpleAgent = TestHelper.GetAzureOpenAIChatClient(s_configuration).CreateAIAgent( + AIAgent simpleAgent = TestHelper.GetAzureOpenAIChatClient(s_configuration).AsAIAgent( name: "TestAgent", instructions: "You are a helpful assistant that always responds with a friendly greeting." ); @@ -143,7 +143,7 @@ await client.Entities.SignalEntityAsync( public async Task OrchestrationIdSetDuringOrchestrationAsync() { // Arrange - AIAgent simpleAgent = TestHelper.GetAzureOpenAIChatClient(s_configuration).CreateAIAgent( + AIAgent simpleAgent = TestHelper.GetAzureOpenAIChatClient(s_configuration).AsAIAgent( name: "TestAgent", instructions: "You are a helpful assistant that always responds with a friendly greeting." ); diff --git a/dotnet/tests/Microsoft.Agents.AI.DurableTask.IntegrationTests/ExternalClientTests.cs b/dotnet/tests/Microsoft.Agents.AI.DurableTask.IntegrationTests/ExternalClientTests.cs index 6131d56367..9e266dde00 100644 --- a/dotnet/tests/Microsoft.Agents.AI.DurableTask.IntegrationTests/ExternalClientTests.cs +++ b/dotnet/tests/Microsoft.Agents.AI.DurableTask.IntegrationTests/ExternalClientTests.cs @@ -41,7 +41,7 @@ public sealed class ExternalClientTests(ITestOutputHelper outputHelper) : IDispo public async Task SimplePromptAsync() { // Setup - AIAgent simpleAgent = TestHelper.GetAzureOpenAIChatClient(s_configuration).CreateAIAgent( + AIAgent simpleAgent = TestHelper.GetAzureOpenAIChatClient(s_configuration).AsAIAgent( instructions: "You are a helpful assistant that always responds with a friendly greeting.", name: "TestAgent"); @@ -94,7 +94,7 @@ string SuggestPackingList(string weather, bool isSunny) return isSunny ? "Pack sunglasses and sunscreen." : "Pack a raincoat and umbrella."; } - AIAgent tripPlanningAgent = TestHelper.GetAzureOpenAIChatClient(s_configuration).CreateAIAgent( + AIAgent tripPlanningAgent = TestHelper.GetAzureOpenAIChatClient(s_configuration).AsAIAgent( instructions: "You are a trip planning assistant. Use the weather tool and packing list tool as needed.", name: "TripPlanningAgent", description: "An agent to help plan your day trips", @@ -174,7 +174,7 @@ async Task RunWorkflowAsync(TaskOrchestrationContext context, string nam // This is the agent that will be used to start the workflow agents.AddAIAgentFactory( "WorkflowAgent", - sp => TestHelper.GetAzureOpenAIChatClient(s_configuration).CreateAIAgent( + sp => TestHelper.GetAzureOpenAIChatClient(s_configuration).AsAIAgent( name: "WorkflowAgent", instructions: "You can start greeting workflows and check their status.", services: sp, @@ -184,7 +184,7 @@ async Task RunWorkflowAsync(TaskOrchestrationContext context, string nam ])); // This is the agent that will be called by the workflow - agents.AddAIAgent(TestHelper.GetAzureOpenAIChatClient(s_configuration).CreateAIAgent( + agents.AddAIAgent(TestHelper.GetAzureOpenAIChatClient(s_configuration).AsAIAgent( name: "SimpleAgent", instructions: "You are a simple assistant." )); @@ -217,14 +217,14 @@ await workflowManagerAgentProxy.RunAsync( public void AsDurableAgentProxy_ThrowsWhenAgentNotRegistered() { // Setup: Register one agent but try to use a different one - AIAgent registeredAgent = TestHelper.GetAzureOpenAIChatClient(s_configuration).CreateAIAgent( + AIAgent registeredAgent = TestHelper.GetAzureOpenAIChatClient(s_configuration).AsAIAgent( instructions: "You are a helpful assistant.", name: "RegisteredAgent"); using TestHelper testHelper = TestHelper.Start([registeredAgent], this._outputHelper); // Create an agent with a different name that isn't registered - AIAgent unregisteredAgent = TestHelper.GetAzureOpenAIChatClient(s_configuration).CreateAIAgent( + AIAgent unregisteredAgent = TestHelper.GetAzureOpenAIChatClient(s_configuration).AsAIAgent( instructions: "You are a helpful assistant.", name: "UnregisteredAgent"); diff --git a/dotnet/tests/Microsoft.Agents.AI.DurableTask.IntegrationTests/OrchestrationTests.cs b/dotnet/tests/Microsoft.Agents.AI.DurableTask.IntegrationTests/OrchestrationTests.cs index 0c702e6062..641cb57dc8 100644 --- a/dotnet/tests/Microsoft.Agents.AI.DurableTask.IntegrationTests/OrchestrationTests.cs +++ b/dotnet/tests/Microsoft.Agents.AI.DurableTask.IntegrationTests/OrchestrationTests.cs @@ -57,7 +57,7 @@ static async Task TestOrchestrationAsync(TaskOrchestrationContext contex // Register a different agent, but not "NonExistentAgent" agents.AddAIAgentFactory( "OtherAgent", - sp => TestHelper.GetAzureOpenAIChatClient(s_configuration).CreateAIAgent( + sp => TestHelper.GetAzureOpenAIChatClient(s_configuration).AsAIAgent( name: "OtherAgent", instructions: "You are a test agent.")); }, diff --git a/dotnet/tests/Microsoft.Agents.AI.DurableTask.IntegrationTests/TimeToLiveTests.cs b/dotnet/tests/Microsoft.Agents.AI.DurableTask.IntegrationTests/TimeToLiveTests.cs index f9a1e44404..5437b7cdfa 100644 --- a/dotnet/tests/Microsoft.Agents.AI.DurableTask.IntegrationTests/TimeToLiveTests.cs +++ b/dotnet/tests/Microsoft.Agents.AI.DurableTask.IntegrationTests/TimeToLiveTests.cs @@ -40,7 +40,7 @@ public async Task EntityExpiresAfterTTLAsync() { // Arrange: Create agent with short TTL (10 seconds) TimeSpan ttl = TimeSpan.FromSeconds(10); - AIAgent simpleAgent = TestHelper.GetAzureOpenAIChatClient(s_configuration).CreateAIAgent( + AIAgent simpleAgent = TestHelper.GetAzureOpenAIChatClient(s_configuration).AsAIAgent( name: "TTLTestAgent", instructions: "You are a helpful assistant." ); @@ -105,7 +105,7 @@ public async Task EntityTTLResetsOnInteractionAsync() { // Arrange: Create agent with short TTL TimeSpan ttl = TimeSpan.FromSeconds(6); - AIAgent simpleAgent = TestHelper.GetAzureOpenAIChatClient(s_configuration).CreateAIAgent( + AIAgent simpleAgent = TestHelper.GetAzureOpenAIChatClient(s_configuration).AsAIAgent( name: "TTLResetTestAgent", instructions: "You are a helpful assistant." ); diff --git a/dotnet/tests/Microsoft.Agents.AI.Hosting.AGUI.AspNetCore.IntegrationTests/BasicStreamingTests.cs b/dotnet/tests/Microsoft.Agents.AI.Hosting.AGUI.AspNetCore.IntegrationTests/BasicStreamingTests.cs index 950861ce42..12d0daffc7 100644 --- a/dotnet/tests/Microsoft.Agents.AI.Hosting.AGUI.AspNetCore.IntegrationTests/BasicStreamingTests.cs +++ b/dotnet/tests/Microsoft.Agents.AI.Hosting.AGUI.AspNetCore.IntegrationTests/BasicStreamingTests.cs @@ -30,7 +30,7 @@ public async Task ClientReceivesStreamedAssistantMessageAsync() // Arrange await this.SetupTestServerAsync(); var chatClient = new AGUIChatClient(this._client!, "", null); - AIAgent agent = chatClient.CreateAIAgent(instructions: null, name: "assistant", description: "Sample assistant", tools: []); + AIAgent agent = chatClient.AsAIAgent(instructions: null, name: "assistant", description: "Sample assistant", tools: []); ChatClientAgentThread thread = (ChatClientAgentThread)await agent.GetNewThreadAsync(); ChatMessage userMessage = new(ChatRole.User, "hello"); @@ -61,7 +61,7 @@ public async Task ClientReceivesRunLifecycleEventsAsync() // Arrange await this.SetupTestServerAsync(); var chatClient = new AGUIChatClient(this._client!, "", null); - AIAgent agent = chatClient.CreateAIAgent(instructions: null, name: "assistant", description: "Sample assistant", tools: []); + AIAgent agent = chatClient.AsAIAgent(instructions: null, name: "assistant", description: "Sample assistant", tools: []); ChatClientAgentThread thread = (ChatClientAgentThread)await agent.GetNewThreadAsync(); ChatMessage userMessage = new(ChatRole.User, "test"); @@ -105,7 +105,7 @@ public async Task RunAsyncAggregatesStreamingUpdatesAsync() // Arrange await this.SetupTestServerAsync(); var chatClient = new AGUIChatClient(this._client!, "", null); - AIAgent agent = chatClient.CreateAIAgent(instructions: null, name: "assistant", description: "Sample assistant", tools: []); + AIAgent agent = chatClient.AsAIAgent(instructions: null, name: "assistant", description: "Sample assistant", tools: []); ChatClientAgentThread thread = (ChatClientAgentThread)await agent.GetNewThreadAsync(); ChatMessage userMessage = new(ChatRole.User, "hello"); @@ -124,7 +124,7 @@ public async Task MultiTurnConversationPreservesAllMessagesInThreadAsync() // Arrange await this.SetupTestServerAsync(); var chatClient = new AGUIChatClient(this._client!, "", null); - AIAgent agent = chatClient.CreateAIAgent(instructions: null, name: "assistant", description: "Sample assistant", tools: []); + AIAgent agent = chatClient.AsAIAgent(instructions: null, name: "assistant", description: "Sample assistant", tools: []); ChatClientAgentThread chatClientThread = (ChatClientAgentThread)await agent.GetNewThreadAsync(); ChatMessage firstUserMessage = new(ChatRole.User, "First question"); @@ -168,7 +168,7 @@ public async Task AgentSendsMultipleMessagesInOneTurnAsync() // Arrange await this.SetupTestServerAsync(useMultiMessageAgent: true); var chatClient = new AGUIChatClient(this._client!, "", null); - AIAgent agent = chatClient.CreateAIAgent(instructions: null, name: "assistant", description: "Sample assistant", tools: []); + AIAgent agent = chatClient.AsAIAgent(instructions: null, name: "assistant", description: "Sample assistant", tools: []); ChatClientAgentThread chatClientThread = (ChatClientAgentThread)await agent.GetNewThreadAsync(); ChatMessage userMessage = new(ChatRole.User, "Tell me a story"); @@ -200,7 +200,7 @@ public async Task UserSendsMultipleMessagesAtOnceAsync() // Arrange await this.SetupTestServerAsync(); var chatClient = new AGUIChatClient(this._client!, "", null); - AIAgent agent = chatClient.CreateAIAgent(instructions: null, name: "assistant", description: "Sample assistant", tools: []); + AIAgent agent = chatClient.AsAIAgent(instructions: null, name: "assistant", description: "Sample assistant", tools: []); ChatClientAgentThread chatClientThread = (ChatClientAgentThread)await agent.GetNewThreadAsync(); // Multiple user messages sent in one turn diff --git a/dotnet/tests/Microsoft.Agents.AI.Hosting.AGUI.AspNetCore.IntegrationTests/SharedStateTests.cs b/dotnet/tests/Microsoft.Agents.AI.Hosting.AGUI.AspNetCore.IntegrationTests/SharedStateTests.cs index 1e8e613b31..14675e4019 100644 --- a/dotnet/tests/Microsoft.Agents.AI.Hosting.AGUI.AspNetCore.IntegrationTests/SharedStateTests.cs +++ b/dotnet/tests/Microsoft.Agents.AI.Hosting.AGUI.AspNetCore.IntegrationTests/SharedStateTests.cs @@ -33,7 +33,7 @@ public async Task StateSnapshot_IsReturnedAsDataContent_WithCorrectMediaTypeAsyn await this.SetupTestServerAsync(fakeAgent); var chatClient = new AGUIChatClient(this._client!, "", null); - AIAgent agent = chatClient.CreateAIAgent(instructions: null, name: "assistant", description: "Sample assistant", tools: []); + AIAgent agent = chatClient.AsAIAgent(instructions: null, name: "assistant", description: "Sample assistant", tools: []); ChatClientAgentThread thread = (ChatClientAgentThread)await agent.GetNewThreadAsync(); string stateJson = JsonSerializer.Serialize(initialState); @@ -76,7 +76,7 @@ public async Task StateSnapshot_HasCorrectAdditionalPropertiesAsync() await this.SetupTestServerAsync(fakeAgent); var chatClient = new AGUIChatClient(this._client!, "", null); - AIAgent agent = chatClient.CreateAIAgent(instructions: null, name: "assistant", description: "Sample assistant", tools: []); + AIAgent agent = chatClient.AsAIAgent(instructions: null, name: "assistant", description: "Sample assistant", tools: []); ChatClientAgentThread thread = (ChatClientAgentThread)await agent.GetNewThreadAsync(); string stateJson = JsonSerializer.Serialize(initialState); @@ -118,7 +118,7 @@ public async Task ComplexState_WithNestedObjectsAndArrays_RoundTripsCorrectlyAsy await this.SetupTestServerAsync(fakeAgent); var chatClient = new AGUIChatClient(this._client!, "", null); - AIAgent agent = chatClient.CreateAIAgent(instructions: null, name: "assistant", description: "Sample assistant", tools: []); + AIAgent agent = chatClient.AsAIAgent(instructions: null, name: "assistant", description: "Sample assistant", tools: []); ChatClientAgentThread thread = (ChatClientAgentThread)await agent.GetNewThreadAsync(); string stateJson = JsonSerializer.Serialize(complexState); @@ -158,7 +158,7 @@ public async Task StateSnapshot_CanBeUsedInSubsequentRequest_ForStateRoundTripAs await this.SetupTestServerAsync(fakeAgent); var chatClient = new AGUIChatClient(this._client!, "", null); - AIAgent agent = chatClient.CreateAIAgent(instructions: null, name: "assistant", description: "Sample assistant", tools: []); + AIAgent agent = chatClient.AsAIAgent(instructions: null, name: "assistant", description: "Sample assistant", tools: []); ChatClientAgentThread thread = (ChatClientAgentThread)await agent.GetNewThreadAsync(); string stateJson = JsonSerializer.Serialize(initialState); @@ -209,7 +209,7 @@ public async Task WithoutState_AgentBehavesNormally_NoStateSnapshotReturnedAsync await this.SetupTestServerAsync(fakeAgent); var chatClient = new AGUIChatClient(this._client!, "", null); - AIAgent agent = chatClient.CreateAIAgent(instructions: null, name: "assistant", description: "Sample assistant", tools: []); + AIAgent agent = chatClient.AsAIAgent(instructions: null, name: "assistant", description: "Sample assistant", tools: []); ChatClientAgentThread thread = (ChatClientAgentThread)await agent.GetNewThreadAsync(); ChatMessage userMessage = new(ChatRole.User, "hello"); @@ -242,7 +242,7 @@ public async Task EmptyState_DoesNotTriggerStateHandlingAsync() await this.SetupTestServerAsync(fakeAgent); var chatClient = new AGUIChatClient(this._client!, "", null); - AIAgent agent = chatClient.CreateAIAgent(instructions: null, name: "assistant", description: "Sample assistant", tools: []); + AIAgent agent = chatClient.AsAIAgent(instructions: null, name: "assistant", description: "Sample assistant", tools: []); ChatClientAgentThread thread = (ChatClientAgentThread)await agent.GetNewThreadAsync(); string stateJson = JsonSerializer.Serialize(emptyState); @@ -279,7 +279,7 @@ public async Task NonStreamingRunAsync_WithState_ReturnsStateInResponseAsync() await this.SetupTestServerAsync(fakeAgent); var chatClient = new AGUIChatClient(this._client!, "", null); - AIAgent agent = chatClient.CreateAIAgent(instructions: null, name: "assistant", description: "Sample assistant", tools: []); + AIAgent agent = chatClient.AsAIAgent(instructions: null, name: "assistant", description: "Sample assistant", tools: []); ChatClientAgentThread thread = (ChatClientAgentThread)await agent.GetNewThreadAsync(); string stateJson = JsonSerializer.Serialize(initialState); diff --git a/dotnet/tests/Microsoft.Agents.AI.Hosting.AGUI.AspNetCore.IntegrationTests/ToolCallingTests.cs b/dotnet/tests/Microsoft.Agents.AI.Hosting.AGUI.AspNetCore.IntegrationTests/ToolCallingTests.cs index e744e52d34..5d5f145733 100644 --- a/dotnet/tests/Microsoft.Agents.AI.Hosting.AGUI.AspNetCore.IntegrationTests/ToolCallingTests.cs +++ b/dotnet/tests/Microsoft.Agents.AI.Hosting.AGUI.AspNetCore.IntegrationTests/ToolCallingTests.cs @@ -44,7 +44,7 @@ public async Task ServerTriggersSingleFunctionCallAsync() await this.SetupTestServerAsync(serverTools: [serverTool]); var chatClient = new AGUIChatClient(this._client!, "", null); - AIAgent agent = chatClient.CreateAIAgent(instructions: null, name: "assistant", description: "Test assistant", tools: []); + AIAgent agent = chatClient.AsAIAgent(instructions: null, name: "assistant", description: "Test assistant", tools: []); AgentThread thread = await agent.GetNewThreadAsync(); ChatMessage userMessage = new(ChatRole.User, "Call the server function"); @@ -92,7 +92,7 @@ public async Task ServerTriggersMultipleFunctionCallsAsync() await this.SetupTestServerAsync(serverTools: [getWeatherTool, getTimeTool]); var chatClient = new AGUIChatClient(this._client!, "", null); - AIAgent agent = chatClient.CreateAIAgent(instructions: null, name: "assistant", description: "Test assistant", tools: []); + AIAgent agent = chatClient.AsAIAgent(instructions: null, name: "assistant", description: "Test assistant", tools: []); AgentThread thread = await agent.GetNewThreadAsync(); ChatMessage userMessage = new(ChatRole.User, "What's the weather and time?"); @@ -133,7 +133,7 @@ public async Task ClientTriggersSingleFunctionCallAsync() await this.SetupTestServerAsync(); var chatClient = new AGUIChatClient(this._client!, "", null); - AIAgent agent = chatClient.CreateAIAgent(instructions: null, name: "assistant", description: "Test assistant", tools: [clientTool]); + AIAgent agent = chatClient.AsAIAgent(instructions: null, name: "assistant", description: "Test assistant", tools: [clientTool]); AgentThread thread = await agent.GetNewThreadAsync(); ChatMessage userMessage = new(ChatRole.User, "Call the client function"); @@ -181,7 +181,7 @@ public async Task ClientTriggersMultipleFunctionCallsAsync() await this.SetupTestServerAsync(); var chatClient = new AGUIChatClient(this._client!, "", null); - AIAgent agent = chatClient.CreateAIAgent(instructions: null, name: "assistant", description: "Test assistant", tools: [calculateTool, formatTool]); + AIAgent agent = chatClient.AsAIAgent(instructions: null, name: "assistant", description: "Test assistant", tools: [calculateTool, formatTool]); AgentThread thread = await agent.GetNewThreadAsync(); ChatMessage userMessage = new(ChatRole.User, "Calculate 5 + 3 and format 'hello'"); @@ -232,7 +232,7 @@ public async Task ServerAndClientTriggerFunctionCallsSimultaneouslyAsync() await this.SetupTestServerAsync(serverTools: [serverTool]); var chatClient = new AGUIChatClient(this._client!, "", null); - AIAgent agent = chatClient.CreateAIAgent(instructions: null, name: "assistant", description: "Test assistant", tools: [clientTool]); + AIAgent agent = chatClient.AsAIAgent(instructions: null, name: "assistant", description: "Test assistant", tools: [clientTool]); AgentThread thread = await agent.GetNewThreadAsync(); ChatMessage userMessage = new(ChatRole.User, "Get both server and client data"); @@ -297,7 +297,7 @@ public async Task FunctionCallsPreserveCallIdAndNameAsync() await this.SetupTestServerAsync(serverTools: [testTool]); var chatClient = new AGUIChatClient(this._client!, "", null); - AIAgent agent = chatClient.CreateAIAgent(instructions: null, name: "assistant", description: "Test assistant", tools: []); + AIAgent agent = chatClient.AsAIAgent(instructions: null, name: "assistant", description: "Test assistant", tools: []); AgentThread thread = await agent.GetNewThreadAsync(); ChatMessage userMessage = new(ChatRole.User, "Call the test function"); @@ -341,7 +341,7 @@ public async Task ParallelFunctionCallsFromServerAreHandledCorrectlyAsync() await this.SetupTestServerAsync(serverTools: [func1, func2], triggerParallelCalls: true); var chatClient = new AGUIChatClient(this._client!, "", null); - AIAgent agent = chatClient.CreateAIAgent(instructions: null, name: "assistant", description: "Test assistant", tools: []); + AIAgent agent = chatClient.AsAIAgent(instructions: null, name: "assistant", description: "Test assistant", tools: []); AgentThread thread = await agent.GetNewThreadAsync(); ChatMessage userMessage = new(ChatRole.User, "Call both functions in parallel"); @@ -427,7 +427,7 @@ public async Task ServerToolCallWithCustomArgumentsAsync() await this.SetupTestServerAsync(serverTools: [serverTool], jsonSerializerOptions: ServerJsonContext.Default.Options); var chatClient = new AGUIChatClient(this._client!, "", null, ServerJsonContext.Default.Options); - AIAgent agent = chatClient.CreateAIAgent(instructions: null, name: "assistant", description: "Test assistant", tools: []); + AIAgent agent = chatClient.AsAIAgent(instructions: null, name: "assistant", description: "Test assistant", tools: []); AgentThread thread = await agent.GetNewThreadAsync(); ChatMessage userMessage = new(ChatRole.User, "Get server forecast for Seattle for 5 days"); @@ -473,7 +473,7 @@ public async Task ClientToolCallWithCustomArgumentsAsync() await this.SetupTestServerAsync(); var chatClient = new AGUIChatClient(this._client!, "", null, ClientJsonContext.Default.Options); - AIAgent agent = chatClient.CreateAIAgent(instructions: null, name: "assistant", description: "Test assistant", tools: [clientTool]); + AIAgent agent = chatClient.AsAIAgent(instructions: null, name: "assistant", description: "Test assistant", tools: [clientTool]); AgentThread thread = await agent.GetNewThreadAsync(); ChatMessage userMessage = new(ChatRole.User, "Get client forecast for Portland with hourly data"); @@ -518,7 +518,7 @@ private async Task SetupTestServerAsync( this._app = builder.Build(); // FakeChatClient will receive options.Tools containing both server and client tools (merged by framework) var fakeChatClient = new FakeToolCallingChatClient(triggerParallelCalls, this._output, jsonSerializerOptions: jsonSerializerOptions); - AIAgent baseAgent = fakeChatClient.CreateAIAgent(instructions: null, name: "base-agent", description: "A base agent for tool testing", tools: serverTools ?? []); + AIAgent baseAgent = fakeChatClient.AsAIAgent(instructions: null, name: "base-agent", description: "A base agent for tool testing", tools: serverTools ?? []); this._app.MapAGUI("/agent", baseAgent); await this._app.StartAsync(); diff --git a/dotnet/tests/Microsoft.Agents.AI.OpenAI.UnitTests/Extensions/OpenAIAssistantClientExtensionsTests.cs b/dotnet/tests/Microsoft.Agents.AI.OpenAI.UnitTests/Extensions/OpenAIAssistantClientExtensionsTests.cs index 3e9fe4d82a..8400adfbcc 100644 --- a/dotnet/tests/Microsoft.Agents.AI.OpenAI.UnitTests/Extensions/OpenAIAssistantClientExtensionsTests.cs +++ b/dotnet/tests/Microsoft.Agents.AI.OpenAI.UnitTests/Extensions/OpenAIAssistantClientExtensionsTests.cs @@ -210,10 +210,10 @@ public void CreateAIAgent_WithNullOptions_ThrowsArgumentNullException() } /// - /// Verify that GetAIAgent with ClientResult and options works correctly. + /// Verify that AsAIAgent with ClientResult and options works correctly. /// [Fact] - public void GetAIAgent_WithClientResultAndOptions_WorksCorrectly() + public void AsAIAgent_WithClientResultAndOptions_WorksCorrectly() { // Arrange var assistantClient = new TestAssistantClient(); @@ -228,7 +228,7 @@ public void GetAIAgent_WithClientResultAndOptions_WorksCorrectly() }; // Act - var agent = assistantClient.GetAIAgent(clientResult, options); + var agent = assistantClient.AsAIAgent(clientResult, options); // Assert Assert.NotNull(agent); @@ -238,10 +238,10 @@ public void GetAIAgent_WithClientResultAndOptions_WorksCorrectly() } /// - /// Verify that GetAIAgent with Assistant and options works correctly. + /// Verify that AsAIAgent with Assistant and options works correctly. /// [Fact] - public void GetAIAgent_WithAssistantAndOptions_WorksCorrectly() + public void AsAIAgent_WithAssistantAndOptions_WorksCorrectly() { // Arrange var assistantClient = new TestAssistantClient(); @@ -255,7 +255,7 @@ public void GetAIAgent_WithAssistantAndOptions_WorksCorrectly() }; // Act - var agent = assistantClient.GetAIAgent(assistant, options); + var agent = assistantClient.AsAIAgent(assistant, options); // Assert Assert.NotNull(agent); @@ -265,10 +265,10 @@ public void GetAIAgent_WithAssistantAndOptions_WorksCorrectly() } /// - /// Verify that GetAIAgent with Assistant and options falls back to assistant metadata when options are null. + /// Verify that AsAIAgent with Assistant and options falls back to assistant metadata when options are null. /// [Fact] - public void GetAIAgent_WithAssistantAndOptionsWithNullFields_FallsBackToAssistantMetadata() + public void AsAIAgent_WithAssistantAndOptionsWithNullFields_FallsBackToAssistantMetadata() { // Arrange var assistantClient = new TestAssistantClient(); @@ -277,7 +277,7 @@ public void GetAIAgent_WithAssistantAndOptionsWithNullFields_FallsBackToAssistan var options = new ChatClientAgentOptions(); // Empty options // Act - var agent = assistantClient.GetAIAgent(assistant, options); + var agent = assistantClient.AsAIAgent(assistant, options); // Assert Assert.NotNull(agent); @@ -341,10 +341,10 @@ public async Task GetAIAgentAsync_WithAgentIdAndOptions_WorksCorrectlyAsync() } /// - /// Verify that GetAIAgent with clientFactory parameter correctly applies the factory. + /// Verify that AsAIAgent with clientFactory parameter correctly applies the factory. /// [Fact] - public void GetAIAgent_WithClientFactory_AppliesFactoryCorrectly() + public void AsAIAgent_WithClientFactory_AppliesFactoryCorrectly() { // Arrange var assistantClient = new TestAssistantClient(); @@ -357,7 +357,7 @@ public void GetAIAgent_WithClientFactory_AppliesFactoryCorrectly() }; // Act - var agent = assistantClient.GetAIAgent( + var agent = assistantClient.AsAIAgent( assistant, options, clientFactory: (innerClient) => testChatClient); @@ -373,10 +373,10 @@ public void GetAIAgent_WithClientFactory_AppliesFactoryCorrectly() } /// - /// Verify that GetAIAgent throws ArgumentNullException when assistantClientResult is null. + /// Verify that AsAIAgent throws ArgumentNullException when assistantClientResult is null. /// [Fact] - public void GetAIAgent_WithNullClientResult_ThrowsArgumentNullException() + public void AsAIAgent_WithNullClientResult_ThrowsArgumentNullException() { // Arrange var assistantClient = new TestAssistantClient(); @@ -384,16 +384,16 @@ public void GetAIAgent_WithNullClientResult_ThrowsArgumentNullException() // Act & Assert var exception = Assert.Throws(() => - assistantClient.GetAIAgent((ClientResult)null!, options)); + assistantClient.AsAIAgent(null!, options)); Assert.Equal("assistantClientResult", exception.ParamName); } /// - /// Verify that GetAIAgent throws ArgumentNullException when assistant is null. + /// Verify that AsAIAgent throws ArgumentNullException when assistant is null. /// [Fact] - public void GetAIAgent_WithNullAssistant_ThrowsArgumentNullException() + public void AsAIAgent_WithNullAssistant_ThrowsArgumentNullException() { // Arrange var assistantClient = new TestAssistantClient(); @@ -401,16 +401,16 @@ public void GetAIAgent_WithNullAssistant_ThrowsArgumentNullException() // Act & Assert var exception = Assert.Throws(() => - assistantClient.GetAIAgent((Assistant)null!, options)); + assistantClient.AsAIAgent((Assistant)null!, options)); Assert.Equal("assistantMetadata", exception.ParamName); } /// - /// Verify that GetAIAgent throws ArgumentNullException when options is null. + /// Verify that AsAIAgent throws ArgumentNullException when options is null. /// [Fact] - public void GetAIAgent_WithNullOptions_ThrowsArgumentNullException() + public void AsAIAgent_WithNullOptions_ThrowsArgumentNullException() { // Arrange var assistantClient = new TestAssistantClient(); @@ -418,7 +418,7 @@ public void GetAIAgent_WithNullOptions_ThrowsArgumentNullException() // Act & Assert var exception = Assert.Throws(() => - assistantClient.GetAIAgent(assistant, (ChatClientAgentOptions)null!)); + assistantClient.AsAIAgent(assistant, (ChatClientAgentOptions)null!)); Assert.Equal("options", exception.ParamName); } @@ -518,10 +518,10 @@ public void CreateAIAgent_WithOptionsAndServices_PassesServicesToAgent() } /// - /// Verify that GetAIAgent with services parameter correctly passes it through to the ChatClientAgent. + /// Verify that AsAIAgent with services parameter correctly passes it through to the ChatClientAgent. /// [Fact] - public void GetAIAgent_WithServices_PassesServicesToAgent() + public void AsAIAgent_WithServices_PassesServicesToAgent() { // Arrange var assistantClient = new TestAssistantClient(); @@ -529,7 +529,7 @@ public void GetAIAgent_WithServices_PassesServicesToAgent() var assistant = ModelReaderWriter.Read(BinaryData.FromString("""{"id": "asst_abc123", "name": "Test Agent"}"""))!; // Act - var agent = assistantClient.GetAIAgent(assistant, services: serviceProvider); + var agent = assistantClient.AsAIAgent(assistant, services: serviceProvider); // Assert Assert.NotNull(agent); diff --git a/dotnet/tests/Microsoft.Agents.AI.OpenAI.UnitTests/Extensions/OpenAIChatClientExtensionsTests.cs b/dotnet/tests/Microsoft.Agents.AI.OpenAI.UnitTests/Extensions/OpenAIChatClientExtensionsTests.cs index 09c36ef218..42ed26c6ef 100644 --- a/dotnet/tests/Microsoft.Agents.AI.OpenAI.UnitTests/Extensions/OpenAIChatClientExtensionsTests.cs +++ b/dotnet/tests/Microsoft.Agents.AI.OpenAI.UnitTests/Extensions/OpenAIChatClientExtensionsTests.cs @@ -76,7 +76,7 @@ public void CreateAIAgent_WithClientFactory_AppliesFactoryCorrectly() var testChatClient = new TestChatClient(chatClient.AsIChatClient()); // Act - var agent = chatClient.CreateAIAgent( + var agent = chatClient.AsAIAgent( instructions: "Test instructions", name: "Test Agent", description: "Test description", @@ -104,7 +104,7 @@ public void CreateAIAgent_WithClientFactoryUsingAsBuilder_AppliesFactoryCorrectl TestChatClient? testChatClient = null; // Act - var agent = chatClient.CreateAIAgent( + var agent = chatClient.AsAIAgent( instructions: "Test instructions", clientFactory: (innerClient) => innerClient.AsBuilder().Use((innerClient) => testChatClient = new TestChatClient(innerClient)).Build()); @@ -135,7 +135,7 @@ public void CreateAIAgent_WithOptionsAndClientFactory_AppliesFactoryCorrectly() }; // Act - var agent = chatClient.CreateAIAgent( + var agent = chatClient.AsAIAgent( options, clientFactory: (innerClient) => testChatClient); @@ -160,7 +160,7 @@ public void CreateAIAgent_WithoutClientFactory_WorksNormally() var chatClient = new TestOpenAIChatClient(); // Act - var agent = chatClient.CreateAIAgent( + var agent = chatClient.AsAIAgent( instructions: "Test instructions", name: "Test Agent"); @@ -183,7 +183,7 @@ public void CreateAIAgent_WithNullClientFactory_WorksNormally() var chatClient = new TestOpenAIChatClient(); // Act - var agent = chatClient.CreateAIAgent( + var agent = chatClient.AsAIAgent( instructions: "Test instructions", name: "Test Agent", clientFactory: null); @@ -205,7 +205,7 @@ public void CreateAIAgent_WithNullClient_ThrowsArgumentNullException() { // Act & Assert var exception = Assert.Throws(() => - ((OpenAIChatClient)null!).CreateAIAgent()); + ((OpenAIChatClient)null!).AsAIAgent()); Assert.Equal("client", exception.ParamName); } @@ -221,7 +221,7 @@ public void CreateAIAgent_WithNullOptions_ThrowsArgumentNullException() // Act & Assert var exception = Assert.Throws(() => - chatClient.CreateAIAgent((ChatClientAgentOptions)null!)); + chatClient.AsAIAgent((ChatClientAgentOptions)null!)); Assert.Equal("options", exception.ParamName); } diff --git a/dotnet/tests/Microsoft.Agents.AI.OpenAI.UnitTests/Extensions/OpenAIResponseClientExtensionsTests.cs b/dotnet/tests/Microsoft.Agents.AI.OpenAI.UnitTests/Extensions/OpenAIResponseClientExtensionsTests.cs index 127fe1a58f..8723deeac9 100644 --- a/dotnet/tests/Microsoft.Agents.AI.OpenAI.UnitTests/Extensions/OpenAIResponseClientExtensionsTests.cs +++ b/dotnet/tests/Microsoft.Agents.AI.OpenAI.UnitTests/Extensions/OpenAIResponseClientExtensionsTests.cs @@ -75,7 +75,7 @@ public void CreateAIAgent_WithClientFactory_AppliesFactoryCorrectly() var testChatClient = new TestChatClient(responseClient.AsIChatClient()); // Act - var agent = responseClient.CreateAIAgent( + var agent = responseClient.AsAIAgent( instructions: "Test instructions", name: "Test Agent", description: "Test description", @@ -102,7 +102,7 @@ public void CreateAIAgent_WithoutClientFactory_WorksNormally() var responseClient = new TestOpenAIResponseClient(); // Act - var agent = responseClient.CreateAIAgent( + var agent = responseClient.AsAIAgent( instructions: "Test instructions", name: "Test Agent"); @@ -125,7 +125,7 @@ public void CreateAIAgent_WithNullClientFactory_WorksNormally() var responseClient = new TestOpenAIResponseClient(); // Act - var agent = responseClient.CreateAIAgent( + var agent = responseClient.AsAIAgent( instructions: "Test instructions", name: "Test Agent", clientFactory: null); @@ -147,7 +147,7 @@ public void CreateAIAgent_WithNullClient_ThrowsArgumentNullException() { // Act & Assert var exception = Assert.Throws(() => - ((ResponsesClient)null!).CreateAIAgent()); + ((ResponsesClient)null!).AsAIAgent()); Assert.Equal("client", exception.ParamName); } @@ -163,7 +163,7 @@ public void CreateAIAgent_WithNullOptions_ThrowsArgumentNullException() // Act & Assert var exception = Assert.Throws(() => - responseClient.CreateAIAgent((ChatClientAgentOptions)null!)); + responseClient.AsAIAgent((ChatClientAgentOptions)null!)); Assert.Equal("options", exception.ParamName); } @@ -179,7 +179,7 @@ public void CreateAIAgent_WithServices_PassesServicesToAgent() var serviceProvider = new TestServiceProvider(); // Act - var agent = responseClient.CreateAIAgent( + var agent = responseClient.AsAIAgent( instructions: "Test instructions", name: "Test Agent", services: serviceProvider); @@ -211,7 +211,7 @@ public void CreateAIAgent_WithOptionsAndServices_PassesServicesToAgent() }; // Act - var agent = responseClient.CreateAIAgent(options, services: serviceProvider); + var agent = responseClient.AsAIAgent(options, services: serviceProvider); // Assert Assert.NotNull(agent); @@ -237,7 +237,7 @@ public void CreateAIAgent_WithClientFactoryAndServices_AppliesBothCorrectly() var testChatClient = new TestChatClient(responseClient.AsIChatClient()); // Act - var agent = responseClient.CreateAIAgent( + var agent = responseClient.AsAIAgent( instructions: "Test instructions", name: "Test Agent", clientFactory: (innerClient) => testChatClient, diff --git a/dotnet/tests/Microsoft.Agents.AI.UnitTests/ChatClient/ChatClientExtensionsTests.cs b/dotnet/tests/Microsoft.Agents.AI.UnitTests/ChatClient/ChatClientExtensionsTests.cs index 51beb6aa2e..484b0a6fff 100644 --- a/dotnet/tests/Microsoft.Agents.AI.UnitTests/ChatClient/ChatClientExtensionsTests.cs +++ b/dotnet/tests/Microsoft.Agents.AI.UnitTests/ChatClient/ChatClientExtensionsTests.cs @@ -19,7 +19,7 @@ public void CreateAIAgent_WithBasicParameters_CreatesAgent() var chatClientMock = new Mock(); // Act - var agent = chatClientMock.Object.CreateAIAgent( + var agent = chatClientMock.Object.AsAIAgent( instructions: "Test instructions", name: "TestAgent", description: "Test description" @@ -40,7 +40,7 @@ public void CreateAIAgent_WithTools_SetsToolsInOptions() var tools = new List { new Mock().Object }; // Act - var agent = chatClientMock.Object.CreateAIAgent(tools: tools); + var agent = chatClientMock.Object.AsAIAgent(tools: tools); // Assert Assert.NotNull(agent); @@ -62,7 +62,7 @@ public void CreateAIAgent_WithOptions_CreatesAgentWithOptions() }; // Act - var agent = chatClientMock.Object.CreateAIAgent(options); + var agent = chatClientMock.Object.AsAIAgent(options); // Assert Assert.NotNull(agent); @@ -79,7 +79,7 @@ public void CreateAIAgent_WithNullClient_Throws() IChatClient chatClient = null!; // Act & Assert - Assert.Throws(() => chatClient.CreateAIAgent(instructions: "instructions")); + Assert.Throws(() => chatClient.AsAIAgent(instructions: "instructions")); } [Fact] @@ -89,6 +89,6 @@ public void CreateAIAgent_WithNullClientAndOptions_Throws() IChatClient chatClient = null!; // Act & Assert - Assert.Throws(() => chatClient.CreateAIAgent(options: new() { ChatOptions = new() { Instructions = "instructions" } })); + Assert.Throws(() => chatClient.AsAIAgent(options: new() { ChatOptions = new() { Instructions = "instructions" } })); } }