diff --git a/dotnet/samples/A2AClientServer/A2AClient/Program.cs b/dotnet/samples/A2AClientServer/A2AClient/Program.cs index bdf942a0cc..0b9696e3a1 100644 --- a/dotnet/samples/A2AClientServer/A2AClient/Program.cs +++ b/dotnet/samples/A2AClientServer/A2AClient/Program.cs @@ -42,7 +42,7 @@ private static async Task HandleCommandsAsync(CancellationToken cancellationToke // Create the Host agent var hostAgent = new HostClientAgent(loggerFactory); await hostAgent.InitializeAgentAsync(modelId, apiKey, agentUrls!.Split(";")); - AgentSession session = await hostAgent.Agent!.GetNewSessionAsync(cancellationToken); + AgentSession session = await hostAgent.Agent!.CreateSessionAsync(cancellationToken); try { while (true) diff --git a/dotnet/samples/AGUIClientServer/AGUIClient/Program.cs b/dotnet/samples/AGUIClientServer/AGUIClient/Program.cs index e6be9472da..1e5b6d6fee 100644 --- a/dotnet/samples/AGUIClientServer/AGUIClient/Program.cs +++ b/dotnet/samples/AGUIClientServer/AGUIClient/Program.cs @@ -88,7 +88,7 @@ private static async Task HandleCommandsAsync(CancellationToken cancellationToke description: "AG-UI Client Agent", tools: [changeBackground, readClientClimateSensors]); - AgentSession session = await agent.GetNewSessionAsync(cancellationToken); + AgentSession session = await agent.CreateSessionAsync(cancellationToken); List messages = [new(ChatRole.System, "You are a helpful assistant.")]; try { diff --git a/dotnet/samples/Durable/Agents/AzureFunctions/01_SingleAgent/Program.cs b/dotnet/samples/Durable/Agents/AzureFunctions/01_SingleAgent/Program.cs index 609ba162c9..e629f3ee2c 100644 --- a/dotnet/samples/Durable/Agents/AzureFunctions/01_SingleAgent/Program.cs +++ b/dotnet/samples/Durable/Agents/AzureFunctions/01_SingleAgent/Program.cs @@ -1,5 +1,7 @@ // Copyright (c) Microsoft. All rights reserved. +#pragma warning disable IDE0002 // Simplify Member Access + using Azure; using Azure.AI.OpenAI; using Azure.Identity; diff --git a/dotnet/samples/Durable/Agents/AzureFunctions/02_AgentOrchestration_Chaining/FunctionTriggers.cs b/dotnet/samples/Durable/Agents/AzureFunctions/02_AgentOrchestration_Chaining/FunctionTriggers.cs index 02f8cceced..7f67b8a6df 100644 --- a/dotnet/samples/Durable/Agents/AzureFunctions/02_AgentOrchestration_Chaining/FunctionTriggers.cs +++ b/dotnet/samples/Durable/Agents/AzureFunctions/02_AgentOrchestration_Chaining/FunctionTriggers.cs @@ -19,7 +19,7 @@ public sealed record TextResponse(string Text); public static async Task RunOrchestrationAsync([OrchestrationTrigger] TaskOrchestrationContext context) { DurableAIAgent writer = context.GetAgent("WriterAgent"); - AgentSession writerSession = await writer.GetNewSessionAsync(); + AgentSession writerSession = await writer.CreateSessionAsync(); AgentResponse initial = await writer.RunAsync( message: "Write a concise inspirational sentence about learning.", diff --git a/dotnet/samples/Durable/Agents/AzureFunctions/02_AgentOrchestration_Chaining/Program.cs b/dotnet/samples/Durable/Agents/AzureFunctions/02_AgentOrchestration_Chaining/Program.cs index d906714c5c..7ab6a23477 100644 --- a/dotnet/samples/Durable/Agents/AzureFunctions/02_AgentOrchestration_Chaining/Program.cs +++ b/dotnet/samples/Durable/Agents/AzureFunctions/02_AgentOrchestration_Chaining/Program.cs @@ -1,5 +1,7 @@ // Copyright (c) Microsoft. All rights reserved. +#pragma warning disable IDE0002 // Simplify Member Access + using Azure; using Azure.AI.OpenAI; using Azure.Identity; diff --git a/dotnet/samples/Durable/Agents/AzureFunctions/03_AgentOrchestration_Concurrency/Program.cs b/dotnet/samples/Durable/Agents/AzureFunctions/03_AgentOrchestration_Concurrency/Program.cs index b180c8139f..621e093c67 100644 --- a/dotnet/samples/Durable/Agents/AzureFunctions/03_AgentOrchestration_Concurrency/Program.cs +++ b/dotnet/samples/Durable/Agents/AzureFunctions/03_AgentOrchestration_Concurrency/Program.cs @@ -1,5 +1,7 @@ // Copyright (c) Microsoft. All rights reserved. +#pragma warning disable IDE0002 // Simplify Member Access + using Azure; using Azure.AI.OpenAI; using Azure.Identity; diff --git a/dotnet/samples/Durable/Agents/AzureFunctions/04_AgentOrchestration_Conditionals/FunctionTriggers.cs b/dotnet/samples/Durable/Agents/AzureFunctions/04_AgentOrchestration_Conditionals/FunctionTriggers.cs index fcb0952394..868c2be487 100644 --- a/dotnet/samples/Durable/Agents/AzureFunctions/04_AgentOrchestration_Conditionals/FunctionTriggers.cs +++ b/dotnet/samples/Durable/Agents/AzureFunctions/04_AgentOrchestration_Conditionals/FunctionTriggers.cs @@ -21,7 +21,7 @@ public static async Task RunOrchestrationAsync([OrchestrationTrigger] Ta // Get the spam detection agent DurableAIAgent spamDetectionAgent = context.GetAgent("SpamDetectionAgent"); - AgentSession spamSession = await spamDetectionAgent.GetNewSessionAsync(); + AgentSession spamSession = await spamDetectionAgent.CreateSessionAsync(); // Step 1: Check if the email is spam AgentResponse spamDetectionResponse = await spamDetectionAgent.RunAsync( @@ -43,7 +43,7 @@ public static async Task RunOrchestrationAsync([OrchestrationTrigger] Ta // Generate and send response for legitimate email DurableAIAgent emailAssistantAgent = context.GetAgent("EmailAssistantAgent"); - AgentSession emailSession = await emailAssistantAgent.GetNewSessionAsync(); + AgentSession emailSession = await emailAssistantAgent.CreateSessionAsync(); AgentResponse emailAssistantResponse = await emailAssistantAgent.RunAsync( message: diff --git a/dotnet/samples/Durable/Agents/AzureFunctions/04_AgentOrchestration_Conditionals/Program.cs b/dotnet/samples/Durable/Agents/AzureFunctions/04_AgentOrchestration_Conditionals/Program.cs index 07dcd302cc..b6638edf04 100644 --- a/dotnet/samples/Durable/Agents/AzureFunctions/04_AgentOrchestration_Conditionals/Program.cs +++ b/dotnet/samples/Durable/Agents/AzureFunctions/04_AgentOrchestration_Conditionals/Program.cs @@ -1,5 +1,7 @@ // Copyright (c) Microsoft. All rights reserved. +#pragma warning disable IDE0002 // Simplify Member Access + using Azure; using Azure.AI.OpenAI; using Azure.Identity; diff --git a/dotnet/samples/Durable/Agents/AzureFunctions/05_AgentOrchestration_HITL/FunctionTriggers.cs b/dotnet/samples/Durable/Agents/AzureFunctions/05_AgentOrchestration_HITL/FunctionTriggers.cs index b5cd6c43db..46282eec59 100644 --- a/dotnet/samples/Durable/Agents/AzureFunctions/05_AgentOrchestration_HITL/FunctionTriggers.cs +++ b/dotnet/samples/Durable/Agents/AzureFunctions/05_AgentOrchestration_HITL/FunctionTriggers.cs @@ -24,7 +24,7 @@ public static async Task RunOrchestrationAsync( // Get the writer agent DurableAIAgent writerAgent = context.GetAgent("WriterAgent"); - AgentSession writerSession = await writerAgent.GetNewSessionAsync(); + AgentSession writerSession = await writerAgent.CreateSessionAsync(); // Set initial status context.SetCustomStatus($"Starting content generation for topic: {input.Topic}"); diff --git a/dotnet/samples/Durable/Agents/AzureFunctions/05_AgentOrchestration_HITL/Program.cs b/dotnet/samples/Durable/Agents/AzureFunctions/05_AgentOrchestration_HITL/Program.cs index 77e2dfa2d4..284a6af3ba 100644 --- a/dotnet/samples/Durable/Agents/AzureFunctions/05_AgentOrchestration_HITL/Program.cs +++ b/dotnet/samples/Durable/Agents/AzureFunctions/05_AgentOrchestration_HITL/Program.cs @@ -1,5 +1,7 @@ // Copyright (c) Microsoft. All rights reserved. +#pragma warning disable IDE0002 // Simplify Member Access + using Azure; using Azure.AI.OpenAI; using Azure.Identity; diff --git a/dotnet/samples/Durable/Agents/AzureFunctions/06_LongRunningTools/FunctionTriggers.cs b/dotnet/samples/Durable/Agents/AzureFunctions/06_LongRunningTools/FunctionTriggers.cs index 3f85749880..ed66be8bdd 100644 --- a/dotnet/samples/Durable/Agents/AzureFunctions/06_LongRunningTools/FunctionTriggers.cs +++ b/dotnet/samples/Durable/Agents/AzureFunctions/06_LongRunningTools/FunctionTriggers.cs @@ -20,7 +20,7 @@ public static async Task RunOrchestrationAsync( // Get the writer agent DurableAIAgent writerAgent = context.GetAgent("Writer"); - AgentSession writerSession = await writerAgent.GetNewSessionAsync(); + AgentSession writerSession = await writerAgent.CreateSessionAsync(); // Set initial status context.SetCustomStatus($"Starting content generation for topic: {input.Topic}"); diff --git a/dotnet/samples/Durable/Agents/AzureFunctions/06_LongRunningTools/Program.cs b/dotnet/samples/Durable/Agents/AzureFunctions/06_LongRunningTools/Program.cs index e4d88d3ae7..149e020614 100644 --- a/dotnet/samples/Durable/Agents/AzureFunctions/06_LongRunningTools/Program.cs +++ b/dotnet/samples/Durable/Agents/AzureFunctions/06_LongRunningTools/Program.cs @@ -1,5 +1,7 @@ // Copyright (c) Microsoft. All rights reserved. +#pragma warning disable IDE0002 // Simplify Member Access + using Azure; using Azure.AI.OpenAI; using Azure.Identity; diff --git a/dotnet/samples/Durable/Agents/AzureFunctions/07_AgentAsMcpTool/Program.cs b/dotnet/samples/Durable/Agents/AzureFunctions/07_AgentAsMcpTool/Program.cs index 2503037a8c..3625eaa9eb 100644 --- a/dotnet/samples/Durable/Agents/AzureFunctions/07_AgentAsMcpTool/Program.cs +++ b/dotnet/samples/Durable/Agents/AzureFunctions/07_AgentAsMcpTool/Program.cs @@ -5,6 +5,8 @@ // generate a remote MCP endpoint for the app at /runtime/webhooks/mcp with a agent-specific // query tool name. +#pragma warning disable IDE0002 // Simplify Member Access + using Azure; using Azure.AI.OpenAI; using Azure.Identity; diff --git a/dotnet/samples/Durable/Agents/AzureFunctions/08_ReliableStreaming/FunctionTriggers.cs b/dotnet/samples/Durable/Agents/AzureFunctions/08_ReliableStreaming/FunctionTriggers.cs index f4fb251726..8ae1ee348e 100644 --- a/dotnet/samples/Durable/Agents/AzureFunctions/08_ReliableStreaming/FunctionTriggers.cs +++ b/dotnet/samples/Durable/Agents/AzureFunctions/08_ReliableStreaming/FunctionTriggers.cs @@ -95,7 +95,7 @@ public async Task CreateAsync( AIAgent agentProxy = durableClient.AsDurableAgentProxy(context, "TravelPlanner"); // Create a new agent session - AgentSession session = await agentProxy.GetNewSessionAsync(cancellationToken); + AgentSession session = await agentProxy.CreateSessionAsync(cancellationToken); string agentSessionId = session.GetService().ToString(); this._logger.LogInformation("Creating new agent session: {AgentSessionId}", agentSessionId); diff --git a/dotnet/samples/Durable/Agents/AzureFunctions/08_ReliableStreaming/Program.cs b/dotnet/samples/Durable/Agents/AzureFunctions/08_ReliableStreaming/Program.cs index c279b968a3..dd90af2287 100644 --- a/dotnet/samples/Durable/Agents/AzureFunctions/08_ReliableStreaming/Program.cs +++ b/dotnet/samples/Durable/Agents/AzureFunctions/08_ReliableStreaming/Program.cs @@ -8,6 +8,8 @@ // This pattern is inspired by OpenAI's background mode for the Responses API, which allows clients // to disconnect and reconnect to ongoing agent responses without losing messages. +#pragma warning disable IDE0002 // Simplify Member Access + using Azure; using Azure.AI.OpenAI; using Azure.Identity; diff --git a/dotnet/samples/Durable/Agents/ConsoleApps/01_SingleAgent/Program.cs b/dotnet/samples/Durable/Agents/ConsoleApps/01_SingleAgent/Program.cs index 8fa004470c..188d29ea46 100644 --- a/dotnet/samples/Durable/Agents/ConsoleApps/01_SingleAgent/Program.cs +++ b/dotnet/samples/Durable/Agents/ConsoleApps/01_SingleAgent/Program.cs @@ -61,7 +61,7 @@ Console.WriteLine(); // Create a session for the conversation -AgentSession session = await agentProxy.GetNewSessionAsync(); +AgentSession session = await agentProxy.CreateSessionAsync(); while (true) { diff --git a/dotnet/samples/Durable/Agents/ConsoleApps/02_AgentOrchestration_Chaining/Program.cs b/dotnet/samples/Durable/Agents/ConsoleApps/02_AgentOrchestration_Chaining/Program.cs index e7b736a068..91b9d2da67 100644 --- a/dotnet/samples/Durable/Agents/ConsoleApps/02_AgentOrchestration_Chaining/Program.cs +++ b/dotnet/samples/Durable/Agents/ConsoleApps/02_AgentOrchestration_Chaining/Program.cs @@ -47,7 +47,7 @@ when given an improved sentence you polish it further. static async Task RunOrchestratorAsync(TaskOrchestrationContext context) { DurableAIAgent writer = context.GetAgent("WriterAgent"); - AgentSession writerSession = await writer.GetNewSessionAsync(); + AgentSession writerSession = await writer.CreateSessionAsync(); AgentResponse initial = await writer.RunAsync( message: "Write a concise inspirational sentence about learning.", diff --git a/dotnet/samples/Durable/Agents/ConsoleApps/04_AgentOrchestration_Conditionals/Program.cs b/dotnet/samples/Durable/Agents/ConsoleApps/04_AgentOrchestration_Conditionals/Program.cs index e9e3fca3a1..e4062779f6 100644 --- a/dotnet/samples/Durable/Agents/ConsoleApps/04_AgentOrchestration_Conditionals/Program.cs +++ b/dotnet/samples/Durable/Agents/ConsoleApps/04_AgentOrchestration_Conditionals/Program.cs @@ -56,7 +56,7 @@ static async Task RunOrchestratorAsync(TaskOrchestrationContext context, { // Get the spam detection agent DurableAIAgent spamDetectionAgent = context.GetAgent(SpamDetectionAgentName); - AgentSession spamSession = await spamDetectionAgent.GetNewSessionAsync(); + AgentSession spamSession = await spamDetectionAgent.CreateSessionAsync(); // Step 1: Check if the email is spam AgentResponse spamDetectionResponse = await spamDetectionAgent.RunAsync( @@ -78,7 +78,7 @@ static async Task RunOrchestratorAsync(TaskOrchestrationContext context, // Generate and send response for legitimate email DurableAIAgent emailAssistantAgent = context.GetAgent(EmailAssistantAgentName); - AgentSession emailSession = await emailAssistantAgent.GetNewSessionAsync(); + AgentSession emailSession = await emailAssistantAgent.CreateSessionAsync(); AgentResponse emailAssistantResponse = await emailAssistantAgent.RunAsync( message: diff --git a/dotnet/samples/Durable/Agents/ConsoleApps/05_AgentOrchestration_HITL/Program.cs b/dotnet/samples/Durable/Agents/ConsoleApps/05_AgentOrchestration_HITL/Program.cs index 8dc2186571..c114ee6b48 100644 --- a/dotnet/samples/Durable/Agents/ConsoleApps/05_AgentOrchestration_HITL/Program.cs +++ b/dotnet/samples/Durable/Agents/ConsoleApps/05_AgentOrchestration_HITL/Program.cs @@ -48,7 +48,7 @@ static async Task RunOrchestratorAsync(TaskOrchestrationContext context, { // Get the writer agent DurableAIAgent writerAgent = context.GetAgent("WriterAgent"); - AgentSession writerSession = await writerAgent.GetNewSessionAsync(); + AgentSession writerSession = await writerAgent.CreateSessionAsync(); // Set initial status context.SetCustomStatus($"Starting content generation for topic: {input.Topic}"); diff --git a/dotnet/samples/Durable/Agents/ConsoleApps/06_LongRunningTools/Program.cs b/dotnet/samples/Durable/Agents/ConsoleApps/06_LongRunningTools/Program.cs index 0e493a0ffc..8a593020c3 100644 --- a/dotnet/samples/Durable/Agents/ConsoleApps/06_LongRunningTools/Program.cs +++ b/dotnet/samples/Durable/Agents/ConsoleApps/06_LongRunningTools/Program.cs @@ -59,7 +59,7 @@ static async Task RunOrchestratorAsync(TaskOrchestrationContext context, { // Get the writer agent DurableAIAgent writerAgent = context.GetAgent(WriterAgentName); - AgentSession writerSession = await writerAgent.GetNewSessionAsync(); + AgentSession writerSession = await writerAgent.CreateSessionAsync(); // Set initial status context.SetCustomStatus($"Starting content generation for topic: {input.Topic}"); @@ -299,7 +299,7 @@ static async Task SubmitHumanFeedbackAsync( Console.WriteLine(); // Create a session for the conversation -AgentSession session = await agentProxy.GetNewSessionAsync(); +AgentSession session = await agentProxy.CreateSessionAsync(); using CancellationTokenSource cts = new(); Console.CancelKeyPress += (sender, e) => diff --git a/dotnet/samples/Durable/Agents/ConsoleApps/07_ReliableStreaming/Program.cs b/dotnet/samples/Durable/Agents/ConsoleApps/07_ReliableStreaming/Program.cs index 720e2d7030..516ee889d8 100644 --- a/dotnet/samples/Durable/Agents/ConsoleApps/07_ReliableStreaming/Program.cs +++ b/dotnet/samples/Durable/Agents/ConsoleApps/07_ReliableStreaming/Program.cs @@ -305,7 +305,7 @@ async Task ReadStreamTask(string conversationId, string? cursor, CancellationTok } // Create a new agent session -AgentSession session = await agentProxy.GetNewSessionAsync(); +AgentSession session = await agentProxy.CreateSessionAsync(); AgentSessionId sessionId = session.GetService(); string conversationId = sessionId.ToString(); diff --git a/dotnet/samples/GettingStarted/A2A/A2AAgent_PollingForTaskCompletion/Program.cs b/dotnet/samples/GettingStarted/A2A/A2AAgent_PollingForTaskCompletion/Program.cs index ddc330f321..e1731604a9 100644 --- a/dotnet/samples/GettingStarted/A2A/A2AAgent_PollingForTaskCompletion/Program.cs +++ b/dotnet/samples/GettingStarted/A2A/A2AAgent_PollingForTaskCompletion/Program.cs @@ -16,7 +16,7 @@ // Create an instance of the AIAgent for an existing A2A agent specified by the agent card. AIAgent agent = agentCard.AsAIAgent(); -AgentSession session = await agent.GetNewSessionAsync(); +AgentSession session = await agent.CreateSessionAsync(); // Start the initial run with a long-running task. AgentResponse response = await agent.RunAsync("Conduct a comprehensive analysis of quantum computing applications in cryptography, including recent breakthroughs, implementation challenges, and future roadmap. Please include diagrams and visual representations to illustrate complex concepts.", session); diff --git a/dotnet/samples/GettingStarted/AGUI/Step01_GettingStarted/Client/Program.cs b/dotnet/samples/GettingStarted/AGUI/Step01_GettingStarted/Client/Program.cs index 56d289ce7b..cff6cbbfde 100644 --- a/dotnet/samples/GettingStarted/AGUI/Step01_GettingStarted/Client/Program.cs +++ b/dotnet/samples/GettingStarted/AGUI/Step01_GettingStarted/Client/Program.cs @@ -20,7 +20,7 @@ name: "agui-client", description: "AG-UI Client Agent"); -AgentSession session = await agent.GetNewSessionAsync(); +AgentSession session = await agent.CreateSessionAsync(); List messages = [ new(ChatRole.System, "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 8ab9d11b76..203a2a0802 100644 --- a/dotnet/samples/GettingStarted/AGUI/Step02_BackendTools/Client/Program.cs +++ b/dotnet/samples/GettingStarted/AGUI/Step02_BackendTools/Client/Program.cs @@ -20,7 +20,7 @@ name: "agui-client", description: "AG-UI Client Agent"); -AgentSession session = await agent.GetNewSessionAsync(); +AgentSession session = await agent.CreateSessionAsync(); List messages = [ new(ChatRole.System, "You are a helpful assistant.") diff --git a/dotnet/samples/GettingStarted/AGUI/Step03_FrontendTools/Client/Program.cs b/dotnet/samples/GettingStarted/AGUI/Step03_FrontendTools/Client/Program.cs index 06ce9e8b55..7f3806a721 100644 --- a/dotnet/samples/GettingStarted/AGUI/Step03_FrontendTools/Client/Program.cs +++ b/dotnet/samples/GettingStarted/AGUI/Step03_FrontendTools/Client/Program.cs @@ -33,7 +33,7 @@ static string GetUserLocation() description: "AG-UI Client Agent", tools: frontendTools); -AgentSession session = await agent.GetNewSessionAsync(); +AgentSession session = await agent.CreateSessionAsync(); List messages = [ new(ChatRole.System, "You are a helpful assistant.") diff --git a/dotnet/samples/GettingStarted/AGUI/Step05_StateManagement/Client/Program.cs b/dotnet/samples/GettingStarted/AGUI/Step05_StateManagement/Client/Program.cs index 8db46493d2..a358956ce8 100644 --- a/dotnet/samples/GettingStarted/AGUI/Step05_StateManagement/Client/Program.cs +++ b/dotnet/samples/GettingStarted/AGUI/Step05_StateManagement/Client/Program.cs @@ -30,7 +30,7 @@ }; StatefulAgent agent = new(baseAgent, jsonOptions, new AgentState()); -AgentSession session = await agent.GetNewSessionAsync(); +AgentSession session = await agent.CreateSessionAsync(); List messages = [ new(ChatRole.System, "You are a helpful recipe assistant.") diff --git a/dotnet/samples/GettingStarted/AgentOpenTelemetry/Program.cs b/dotnet/samples/GettingStarted/AgentOpenTelemetry/Program.cs index 1b09b43588..b818de2e44 100644 --- a/dotnet/samples/GettingStarted/AgentOpenTelemetry/Program.cs +++ b/dotnet/samples/GettingStarted/AgentOpenTelemetry/Program.cs @@ -128,7 +128,7 @@ static async Task GetWeatherAsync([Description("The location to get the .UseOpenTelemetry(SourceName, configure: (cfg) => cfg.EnableSensitiveData = true) // enable telemetry at the agent level .Build(); -var session = await agent.GetNewSessionAsync(); +var session = await agent.CreateSessionAsync(); appLogger.LogInformation("Agent created successfully with ID: {AgentId}", agent.Id); diff --git a/dotnet/samples/GettingStarted/AgentProviders/Agent_With_AzureAIAgentsPersistent/Program.cs b/dotnet/samples/GettingStarted/AgentProviders/Agent_With_AzureAIAgentsPersistent/Program.cs index 38836b90d3..07b160e880 100644 --- a/dotnet/samples/GettingStarted/AgentProviders/Agent_With_AzureAIAgentsPersistent/Program.cs +++ b/dotnet/samples/GettingStarted/AgentProviders/Agent_With_AzureAIAgentsPersistent/Program.cs @@ -31,7 +31,7 @@ instructions: JokerInstructions); // You can then invoke the agent like any other AIAgent. -AgentSession session = await agent1.GetNewSessionAsync(); +AgentSession session = await agent1.CreateSessionAsync(); Console.WriteLine(await agent1.RunAsync("Tell me a joke about a pirate.", session)); // Cleanup for sample purposes. diff --git a/dotnet/samples/GettingStarted/AgentProviders/Agent_With_AzureAIProject/Program.cs b/dotnet/samples/GettingStarted/AgentProviders/Agent_With_AzureAIProject/Program.cs index d4dd7e7d3a..4ac6f40022 100644 --- a/dotnet/samples/GettingStarted/AgentProviders/Agent_With_AzureAIProject/Program.cs +++ b/dotnet/samples/GettingStarted/AgentProviders/Agent_With_AzureAIProject/Program.cs @@ -40,7 +40,7 @@ Console.WriteLine($"Latest agent version id: {latestAgentVersion.Id}"); // Once you have the AIAgent, you can invoke it like any other AIAgent. -AgentSession session = await jokerAgentLatest.GetNewSessionAsync(); +AgentSession session = await jokerAgentLatest.CreateSessionAsync(); Console.WriteLine(await jokerAgentLatest.RunAsync("Tell me a joke about a pirate.", session)); // This will use the same session to continue the conversation. diff --git a/dotnet/samples/GettingStarted/AgentProviders/Agent_With_CustomImplementation/Program.cs b/dotnet/samples/GettingStarted/AgentProviders/Agent_With_CustomImplementation/Program.cs index 980a4eda40..1e6190ca6b 100644 --- a/dotnet/samples/GettingStarted/AgentProviders/Agent_With_CustomImplementation/Program.cs +++ b/dotnet/samples/GettingStarted/AgentProviders/Agent_With_CustomImplementation/Program.cs @@ -28,7 +28,7 @@ internal sealed class UpperCaseParrotAgent : AIAgent { public override string? Name => "UpperCaseParrotAgent"; - public override ValueTask GetNewSessionAsync(CancellationToken cancellationToken = default) + public override ValueTask CreateSessionAsync(CancellationToken cancellationToken = default) => new(new CustomAgentSession()); public override ValueTask DeserializeSessionAsync(JsonElement serializedSession, JsonSerializerOptions? jsonSerializerOptions = null, CancellationToken cancellationToken = default) @@ -37,7 +37,7 @@ public override ValueTask DeserializeSessionAsync(JsonElement seri protected override async Task RunCoreAsync(IEnumerable messages, AgentSession? session = null, AgentRunOptions? options = null, CancellationToken cancellationToken = default) { // Create a session if the user didn't supply one. - session ??= await this.GetNewSessionAsync(cancellationToken); + session ??= await this.CreateSessionAsync(cancellationToken); if (session is not CustomAgentSession typedSession) { @@ -69,7 +69,7 @@ protected override async Task RunCoreAsync(IEnumerable RunCoreStreamingAsync(IEnumerable messages, AgentSession? session = null, AgentRunOptions? options = null, [EnumeratorCancellation] CancellationToken cancellationToken = default) { // Create a session if the user didn't supply one. - session ??= await this.GetNewSessionAsync(cancellationToken); + session ??= await this.CreateSessionAsync(cancellationToken); if (session is not CustomAgentSession typedSession) { diff --git a/dotnet/samples/GettingStarted/AgentProviders/Agent_With_OpenAIAssistants/Program.cs b/dotnet/samples/GettingStarted/AgentProviders/Agent_With_OpenAIAssistants/Program.cs index 69bd31d971..fa7edfb52c 100644 --- a/dotnet/samples/GettingStarted/AgentProviders/Agent_With_OpenAIAssistants/Program.cs +++ b/dotnet/samples/GettingStarted/AgentProviders/Agent_With_OpenAIAssistants/Program.cs @@ -33,7 +33,7 @@ instructions: JokerInstructions); // You can invoke the agent like any other AIAgent. -AgentSession session = await agent1.GetNewSessionAsync(); +AgentSession session = await agent1.CreateSessionAsync(); Console.WriteLine(await agent1.RunAsync("Tell me a joke about a pirate.", session)); // Cleanup for sample purposes. 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 f9634d9212..2a1b97e83d 100644 --- a/dotnet/samples/GettingStarted/AgentWithAnthropic/Agent_Anthropic_Step03_UsingFunctionTools/Program.cs +++ b/dotnet/samples/GettingStarted/AgentWithAnthropic/Agent_Anthropic_Step03_UsingFunctionTools/Program.cs @@ -26,11 +26,11 @@ static string GetWeather([Description("The location to get the weather for.")] s .AsAIAgent(model: model, instructions: AssistantInstructions, name: AssistantName, tools: [tool]); // Non-streaming agent interaction with function tools. -AgentSession session = await agent.GetNewSessionAsync(); +AgentSession session = await agent.CreateSessionAsync(); Console.WriteLine(await agent.RunAsync("What is the weather like in Amsterdam?", session)); // Streaming agent interaction with function tools. -session = await agent.GetNewSessionAsync(); +session = await agent.CreateSessionAsync(); await foreach (AgentResponseUpdate update in agent.RunStreamingAsync("What is the weather like in Amsterdam?", session)) { Console.WriteLine(update); diff --git a/dotnet/samples/GettingStarted/AgentWithMemory/AgentWithMemory_Step01_ChatHistoryMemory/Program.cs b/dotnet/samples/GettingStarted/AgentWithMemory/AgentWithMemory_Step01_ChatHistoryMemory/Program.cs index 6299f6381a..ec55abf3a4 100644 --- a/dotnet/samples/GettingStarted/AgentWithMemory/AgentWithMemory_Step01_ChatHistoryMemory/Program.cs +++ b/dotnet/samples/GettingStarted/AgentWithMemory/AgentWithMemory_Step01_ChatHistoryMemory/Program.cs @@ -47,14 +47,14 @@ }); // Start a new session for the agent conversation. -AgentSession session = await agent.GetNewSessionAsync(); +AgentSession session = await agent.CreateSessionAsync(); // Run the agent with the session that stores conversation history in the vector store. Console.WriteLine(await agent.RunAsync("I like jokes about Pirates. Tell me a joke about a pirate.", session)); // Start a second session. Since we configured the search scope to be across all sessions for the user, // the agent should remember that the user likes pirate jokes. -AgentSession? session2 = await agent.GetNewSessionAsync(); +AgentSession? session2 = await agent.CreateSessionAsync(); // Run the agent with the second session. Console.WriteLine(await agent.RunAsync("Tell me a joke that I might like.", session2)); diff --git a/dotnet/samples/GettingStarted/AgentWithMemory/AgentWithMemory_Step02_MemoryUsingMem0/Program.cs b/dotnet/samples/GettingStarted/AgentWithMemory/AgentWithMemory_Step02_MemoryUsingMem0/Program.cs index ab0f1735c0..30cccde55a 100644 --- a/dotnet/samples/GettingStarted/AgentWithMemory/AgentWithMemory_Step02_MemoryUsingMem0/Program.cs +++ b/dotnet/samples/GettingStarted/AgentWithMemory/AgentWithMemory_Step02_MemoryUsingMem0/Program.cs @@ -40,7 +40,7 @@ : new Mem0Provider(mem0HttpClient, ctx.SerializedState, ctx.JsonSerializerOptions)) }); -AgentSession session = await agent.GetNewSessionAsync(); +AgentSession session = await agent.CreateSessionAsync(); // Clear any existing memories for this scope to demonstrate fresh behavior. Mem0Provider mem0Provider = session.GetService()!; @@ -60,5 +60,5 @@ Console.WriteLine(await agent.RunAsync("Can you recap the personal details you remember?", restoredSession)); Console.WriteLine("\n>> Start a new session that shares the same Mem0 scope\n"); -AgentSession newSession = await agent.GetNewSessionAsync(); +AgentSession newSession = await agent.CreateSessionAsync(); Console.WriteLine(await agent.RunAsync("Summarize what you already know about me.", newSession)); diff --git a/dotnet/samples/GettingStarted/AgentWithMemory/AgentWithMemory_Step03_CustomMemory/Program.cs b/dotnet/samples/GettingStarted/AgentWithMemory/AgentWithMemory_Step03_CustomMemory/Program.cs index cf8e0dd943..42a5e15b64 100644 --- a/dotnet/samples/GettingStarted/AgentWithMemory/AgentWithMemory_Step03_CustomMemory/Program.cs +++ b/dotnet/samples/GettingStarted/AgentWithMemory/AgentWithMemory_Step03_CustomMemory/Program.cs @@ -37,7 +37,7 @@ }); // Create a new session for the conversation. -AgentSession session = await agent.GetNewSessionAsync(); +AgentSession session = await agent.CreateSessionAsync(); Console.WriteLine(">> Use session with blank memory\n"); @@ -68,7 +68,7 @@ // It is also possible to set the memories in a memory component on an individual session. // This is useful if we want to start a new session, but have it share the same memories as a previous session. -var newSession = await agent.GetNewSessionAsync(); +var newSession = await agent.CreateSessionAsync(); if (userInfo is not null && newSession.GetService() is UserInfoMemory newSessionMemory) { newSessionMemory.UserInfo = userInfo; diff --git a/dotnet/samples/GettingStarted/AgentWithOpenAI/Agent_OpenAI_Step05_Conversation/Program.cs b/dotnet/samples/GettingStarted/AgentWithOpenAI/Agent_OpenAI_Step05_Conversation/Program.cs index 5311f14778..9659d3dc40 100644 --- a/dotnet/samples/GettingStarted/AgentWithOpenAI/Agent_OpenAI_Step05_Conversation/Program.cs +++ b/dotnet/samples/GettingStarted/AgentWithOpenAI/Agent_OpenAI_Step05_Conversation/Program.cs @@ -30,7 +30,7 @@ string conversationId = createConversationResultAsJson.RootElement.GetProperty("id"u8)!.GetString()!; // Create a session for the conversation - this enables conversation state management for subsequent turns -AgentSession session = await agent.GetNewSessionAsync(conversationId); +AgentSession session = await agent.CreateSessionAsync(conversationId); Console.WriteLine("=== Multi-turn Conversation Demo ===\n"); diff --git a/dotnet/samples/GettingStarted/AgentWithOpenAI/Agent_OpenAI_Step05_Conversation/README.md b/dotnet/samples/GettingStarted/AgentWithOpenAI/Agent_OpenAI_Step05_Conversation/README.md index 2b4c282ead..9706ca05f1 100644 --- a/dotnet/samples/GettingStarted/AgentWithOpenAI/Agent_OpenAI_Step05_Conversation/README.md +++ b/dotnet/samples/GettingStarted/AgentWithOpenAI/Agent_OpenAI_Step05_Conversation/README.md @@ -33,7 +33,7 @@ The `AgentSession` works with `ChatClientAgentRunOptions` to link the agent to a ChatClientAgentRunOptions agentRunOptions = new() { ChatOptions = new ChatOptions() { ConversationId = conversationId } }; // Create a session for the conversation -AgentSession session = await agent.GetNewSessionAsync(); +AgentSession session = await agent.CreateSessionAsync(); // First call links the session to the conversation ChatCompletion firstResponse = await agent.RunAsync([firstMessage], session, agentRunOptions); @@ -59,7 +59,7 @@ foreach (ClientResult result in getConversationItemsResults.GetRawPages()) 1. **Create an OpenAI Client**: Initialize an `OpenAIClient` with your API key 2. **Create a Conversation**: Use `ConversationClient` to create a server-side conversation 3. **Create an Agent**: Initialize an `OpenAIResponseClientAgent` with the desired model and instructions -4. **Create a Session**: Call `agent.GetNewSessionAsync()` to create a new conversation session +4. **Create a Session**: Call `agent.CreateSessionAsync()` to create a new conversation session 5. **Link Session to Conversation**: Pass `ChatClientAgentRunOptions` with the `ConversationId` on the first call 6. **Send Messages**: Subsequent calls to `agent.RunAsync()` only need the session - context is maintained 7. **Cleanup**: Delete the conversation when done using `conversationClient.DeleteConversation()` diff --git a/dotnet/samples/GettingStarted/AgentWithRAG/AgentWithRAG_Step01_BasicTextRAG/Program.cs b/dotnet/samples/GettingStarted/AgentWithRAG/AgentWithRAG_Step01_BasicTextRAG/Program.cs index 0beb0063a4..ca798aa333 100644 --- a/dotnet/samples/GettingStarted/AgentWithRAG/AgentWithRAG_Step01_BasicTextRAG/Program.cs +++ b/dotnet/samples/GettingStarted/AgentWithRAG/AgentWithRAG_Step01_BasicTextRAG/Program.cs @@ -70,7 +70,7 @@ .WithAIContextProviderMessageRemoval()), }); -AgentSession session = await agent.GetNewSessionAsync(); +AgentSession session = await agent.CreateSessionAsync(); Console.WriteLine(">> Asking about returns\n"); Console.WriteLine(await agent.RunAsync("Hi! I need help understanding the return policy.", session)); diff --git a/dotnet/samples/GettingStarted/AgentWithRAG/AgentWithRAG_Step02_CustomVectorStoreRAG/Program.cs b/dotnet/samples/GettingStarted/AgentWithRAG/AgentWithRAG_Step02_CustomVectorStoreRAG/Program.cs index 486fdbe44d..3648ccc898 100644 --- a/dotnet/samples/GettingStarted/AgentWithRAG/AgentWithRAG_Step02_CustomVectorStoreRAG/Program.cs +++ b/dotnet/samples/GettingStarted/AgentWithRAG/AgentWithRAG_Step02_CustomVectorStoreRAG/Program.cs @@ -74,7 +74,7 @@ AIContextProviderFactory = (ctx, ct) => new ValueTask(new TextSearchProvider(SearchAdapter, ctx.SerializedState, ctx.JsonSerializerOptions, textSearchOptions)) }); -AgentSession session = await agent.GetNewSessionAsync(); +AgentSession session = await agent.CreateSessionAsync(); Console.WriteLine(">> Asking about SK sessions\n"); Console.WriteLine(await agent.RunAsync("Hi! How do I create a thread/session in Semantic Kernel?", session)); diff --git a/dotnet/samples/GettingStarted/AgentWithRAG/AgentWithRAG_Step03_CustomRAGDataSource/Program.cs b/dotnet/samples/GettingStarted/AgentWithRAG/AgentWithRAG_Step03_CustomRAGDataSource/Program.cs index dd258faf81..bcc823de46 100644 --- a/dotnet/samples/GettingStarted/AgentWithRAG/AgentWithRAG_Step03_CustomRAGDataSource/Program.cs +++ b/dotnet/samples/GettingStarted/AgentWithRAG/AgentWithRAG_Step03_CustomRAGDataSource/Program.cs @@ -32,7 +32,7 @@ AIContextProviderFactory = (ctx, ct) => new ValueTask(new TextSearchProvider(MockSearchAsync, ctx.SerializedState, ctx.JsonSerializerOptions, textSearchOptions)) }); -AgentSession session = await agent.GetNewSessionAsync(); +AgentSession session = await agent.CreateSessionAsync(); Console.WriteLine(">> Asking about returns\n"); Console.WriteLine(await agent.RunAsync("Hi! I need help understanding the return policy.", session)); diff --git a/dotnet/samples/GettingStarted/AgentWithRAG/AgentWithRAG_Step04_FoundryServiceRAG/Program.cs b/dotnet/samples/GettingStarted/AgentWithRAG/AgentWithRAG_Step04_FoundryServiceRAG/Program.cs index c7faa71ed5..cfb40f4029 100644 --- a/dotnet/samples/GettingStarted/AgentWithRAG/AgentWithRAG_Step04_FoundryServiceRAG/Program.cs +++ b/dotnet/samples/GettingStarted/AgentWithRAG/AgentWithRAG_Step04_FoundryServiceRAG/Program.cs @@ -43,7 +43,7 @@ instructions: "You are a helpful support specialist for Contoso Outdoors. Answer questions using the provided context and cite the source document when available.", tools: [fileSearchTool]); -AgentSession session = await agent.GetNewSessionAsync(); +AgentSession session = await agent.CreateSessionAsync(); Console.WriteLine(">> Asking about returns\n"); Console.WriteLine(await agent.RunAsync("Hi! I need help understanding the return policy.", session)); diff --git a/dotnet/samples/GettingStarted/Agents/Agent_Step02_MultiturnConversation/Program.cs b/dotnet/samples/GettingStarted/Agents/Agent_Step02_MultiturnConversation/Program.cs index 73a9a76786..6a60de132d 100644 --- a/dotnet/samples/GettingStarted/Agents/Agent_Step02_MultiturnConversation/Program.cs +++ b/dotnet/samples/GettingStarted/Agents/Agent_Step02_MultiturnConversation/Program.cs @@ -17,12 +17,12 @@ .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 session object. -AgentSession session = await agent.GetNewSessionAsync(); +AgentSession session = await agent.CreateSessionAsync(); Console.WriteLine(await agent.RunAsync("Tell me a joke about a pirate.", session)); Console.WriteLine(await agent.RunAsync("Now add some emojis to the joke and tell it in the voice of a pirate's parrot.", session)); // Invoke the agent with a multi-turn conversation and streaming, where the context is preserved in the session object. -session = await agent.GetNewSessionAsync(); +session = await agent.CreateSessionAsync(); await foreach (var update in agent.RunStreamingAsync("Tell me a joke about a pirate.", session)) { Console.WriteLine(update); diff --git a/dotnet/samples/GettingStarted/Agents/Agent_Step04_UsingFunctionToolsWithApprovals/Program.cs b/dotnet/samples/GettingStarted/Agents/Agent_Step04_UsingFunctionToolsWithApprovals/Program.cs index ad4303583c..f13aa8ff26 100644 --- a/dotnet/samples/GettingStarted/Agents/Agent_Step04_UsingFunctionToolsWithApprovals/Program.cs +++ b/dotnet/samples/GettingStarted/Agents/Agent_Step04_UsingFunctionToolsWithApprovals/Program.cs @@ -30,7 +30,7 @@ static string GetWeather([Description("The location to get the weather for.")] s .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. -AgentSession session = await agent.GetNewSessionAsync(); +AgentSession session = await agent.CreateSessionAsync(); var response = await agent.RunAsync("What is the weather like in Amsterdam?", session); var userInputRequests = response.UserInputRequests.ToList(); diff --git a/dotnet/samples/GettingStarted/Agents/Agent_Step06_PersistedConversations/Program.cs b/dotnet/samples/GettingStarted/Agents/Agent_Step06_PersistedConversations/Program.cs index c76ec1ab6e..84ba3a918d 100644 --- a/dotnet/samples/GettingStarted/Agents/Agent_Step06_PersistedConversations/Program.cs +++ b/dotnet/samples/GettingStarted/Agents/Agent_Step06_PersistedConversations/Program.cs @@ -19,7 +19,7 @@ .AsAIAgent(instructions: "You are good at telling jokes.", name: "Joker"); // Start a new session for the agent conversation. -AgentSession session = await agent.GetNewSessionAsync(); +AgentSession session = await agent.CreateSessionAsync(); // Run the agent with a new session. Console.WriteLine(await agent.RunAsync("Tell me a joke about a pirate.", session)); diff --git a/dotnet/samples/GettingStarted/Agents/Agent_Step07_3rdPartyThreadStorage/Program.cs b/dotnet/samples/GettingStarted/Agents/Agent_Step07_3rdPartyThreadStorage/Program.cs index b4dc0e8e0e..a1898ea426 100644 --- a/dotnet/samples/GettingStarted/Agents/Agent_Step07_3rdPartyThreadStorage/Program.cs +++ b/dotnet/samples/GettingStarted/Agents/Agent_Step07_3rdPartyThreadStorage/Program.cs @@ -39,7 +39,7 @@ }); // Start a new session for the agent conversation. -AgentSession session = await agent.GetNewSessionAsync(); +AgentSession session = await agent.CreateSessionAsync(); // Run the agent with the session that stores chat history in the vector store. Console.WriteLine(await agent.RunAsync("Tell me a joke about a pirate.", session)); diff --git a/dotnet/samples/GettingStarted/Agents/Agent_Step09_DependencyInjection/Program.cs b/dotnet/samples/GettingStarted/Agents/Agent_Step09_DependencyInjection/Program.cs index 0f25862ffd..1eb0c16742 100644 --- a/dotnet/samples/GettingStarted/Agents/Agent_Step09_DependencyInjection/Program.cs +++ b/dotnet/samples/GettingStarted/Agents/Agent_Step09_DependencyInjection/Program.cs @@ -49,7 +49,7 @@ internal sealed class SampleService(AIAgent agent, IHostApplicationLifetime appL public async Task StartAsync(CancellationToken cancellationToken) { // Create a session that will be used for the entirety of the service lifetime so that the user can ask follow up questions. - this._session = await agent.GetNewSessionAsync(cancellationToken); + this._session = await agent.CreateSessionAsync(cancellationToken); _ = this.RunAsync(appLifetime.ApplicationStopping); } diff --git a/dotnet/samples/GettingStarted/Agents/Agent_Step11_UsingImages/Program.cs b/dotnet/samples/GettingStarted/Agents/Agent_Step11_UsingImages/Program.cs index 4cbff0efe0..9e5985b8c0 100644 --- a/dotnet/samples/GettingStarted/Agents/Agent_Step11_UsingImages/Program.cs +++ b/dotnet/samples/GettingStarted/Agents/Agent_Step11_UsingImages/Program.cs @@ -22,7 +22,7 @@ new UriContent("https://upload.wikimedia.org/wikipedia/commons/thumb/d/dd/Gfp-wisconsin-madison-the-nature-boardwalk.jpg/2560px-Gfp-wisconsin-madison-the-nature-boardwalk.jpg", "image/jpeg") ]); -var session = await agent.GetNewSessionAsync(); +var session = await agent.CreateSessionAsync(); await foreach (var update in agent.RunStreamingAsync(message, session)) { diff --git a/dotnet/samples/GettingStarted/Agents/Agent_Step13_BackgroundResponsesWithToolsAndPersistence/Program.cs b/dotnet/samples/GettingStarted/Agents/Agent_Step13_BackgroundResponsesWithToolsAndPersistence/Program.cs index 9332e0f05e..5dfae17df0 100644 --- a/dotnet/samples/GettingStarted/Agents/Agent_Step13_BackgroundResponsesWithToolsAndPersistence/Program.cs +++ b/dotnet/samples/GettingStarted/Agents/Agent_Step13_BackgroundResponsesWithToolsAndPersistence/Program.cs @@ -32,7 +32,7 @@ // Enable background responses (only supported by {Azure}OpenAI Responses at this time). AgentRunOptions options = new() { AllowBackgroundResponses = true }; -AgentSession session = await agent.GetNewSessionAsync(); +AgentSession session = await agent.CreateSessionAsync(); // Start the initial run. AgentResponse response = await agent.RunAsync("Write a very long novel about a team of astronauts exploring an uncharted galaxy.", session, options); diff --git a/dotnet/samples/GettingStarted/Agents/Agent_Step14_Middleware/Program.cs b/dotnet/samples/GettingStarted/Agents/Agent_Step14_Middleware/Program.cs index 049160046e..f3bc09bdec 100644 --- a/dotnet/samples/GettingStarted/Agents/Agent_Step14_Middleware/Program.cs +++ b/dotnet/samples/GettingStarted/Agents/Agent_Step14_Middleware/Program.cs @@ -45,7 +45,7 @@ static string GetDateTime() .Use(GuardrailMiddleware, null) .Build(); -var session = await middlewareEnabledAgent.GetNewSessionAsync(); +var session = await middlewareEnabledAgent.CreateSessionAsync(); Console.WriteLine("\n\n=== Example 1: Wording Guardrail ==="); var guardRailedResponse = await middlewareEnabledAgent.RunAsync("Tell me something harmful."); diff --git a/dotnet/samples/GettingStarted/Agents/Agent_Step16_ChatReduction/Program.cs b/dotnet/samples/GettingStarted/Agents/Agent_Step16_ChatReduction/Program.cs index 525a65e609..f9a5a1fc01 100644 --- a/dotnet/samples/GettingStarted/Agents/Agent_Step16_ChatReduction/Program.cs +++ b/dotnet/samples/GettingStarted/Agents/Agent_Step16_ChatReduction/Program.cs @@ -27,7 +27,7 @@ ChatHistoryProviderFactory = (ctx, ct) => new ValueTask(new InMemoryChatHistoryProvider(new MessageCountingChatReducer(2), ctx.SerializedState, ctx.JsonSerializerOptions)) }); -AgentSession session = await agent.GetNewSessionAsync(); +AgentSession session = await agent.CreateSessionAsync(); // Invoke the agent and output the text result. Console.WriteLine(await agent.RunAsync("Tell me a joke about a pirate.", session)); diff --git a/dotnet/samples/GettingStarted/Agents/Agent_Step17_BackgroundResponses/Program.cs b/dotnet/samples/GettingStarted/Agents/Agent_Step17_BackgroundResponses/Program.cs index 55dbfa6199..1fa436b156 100644 --- a/dotnet/samples/GettingStarted/Agents/Agent_Step17_BackgroundResponses/Program.cs +++ b/dotnet/samples/GettingStarted/Agents/Agent_Step17_BackgroundResponses/Program.cs @@ -19,7 +19,7 @@ // Enable background responses (only supported by OpenAI Responses at this time). AgentRunOptions options = new() { AllowBackgroundResponses = true }; -AgentSession session = await agent.GetNewSessionAsync(); +AgentSession session = await agent.CreateSessionAsync(); // Start the initial run. AgentResponse response = await agent.RunAsync("Write a very long novel about otters in space.", session, options); @@ -41,7 +41,7 @@ // Reset options and session for streaming. options = new() { AllowBackgroundResponses = true }; -session = await agent.GetNewSessionAsync(); +session = await agent.CreateSessionAsync(); AgentResponseUpdate? lastReceivedUpdate = null; // Start streaming. diff --git a/dotnet/samples/GettingStarted/Agents/Agent_Step18_DeepResearch/Program.cs b/dotnet/samples/GettingStarted/Agents/Agent_Step18_DeepResearch/Program.cs index 2c55c5294f..d7ebc9fca4 100644 --- a/dotnet/samples/GettingStarted/Agents/Agent_Step18_DeepResearch/Program.cs +++ b/dotnet/samples/GettingStarted/Agents/Agent_Step18_DeepResearch/Program.cs @@ -39,7 +39,7 @@ try { - AgentSession session = await agent.GetNewSessionAsync(); + AgentSession session = await agent.CreateSessionAsync(); await foreach (var response in agent.RunStreamingAsync(Task, session)) { diff --git a/dotnet/samples/GettingStarted/Agents/Agent_Step20_AdditionalAIContext/Program.cs b/dotnet/samples/GettingStarted/Agents/Agent_Step20_AdditionalAIContext/Program.cs index c3b4d6f979..52e5c37cb8 100644 --- a/dotnet/samples/GettingStarted/Agents/Agent_Step20_AdditionalAIContext/Program.cs +++ b/dotnet/samples/GettingStarted/Agents/Agent_Step20_AdditionalAIContext/Program.cs @@ -58,7 +58,7 @@ You remind users of upcoming calendar events when the user interacts with you. }); // Invoke the agent and output the text result. -AgentSession session = await agent.GetNewSessionAsync(); +AgentSession session = await agent.CreateSessionAsync(); Console.WriteLine(await agent.RunAsync("I need to pick up milk from the supermarket.", session) + "\n"); Console.WriteLine(await agent.RunAsync("I need to take Sally for soccer practice.", session) + "\n"); Console.WriteLine(await agent.RunAsync("I need to make a dentist appointment for Jimmy.", session) + "\n"); diff --git a/dotnet/samples/GettingStarted/FoundryAgents/FoundryAgents_Step02_MultiturnConversation/Program.cs b/dotnet/samples/GettingStarted/FoundryAgents/FoundryAgents_Step02_MultiturnConversation/Program.cs index f55e57cc65..1e1e7d72a8 100644 --- a/dotnet/samples/GettingStarted/FoundryAgents/FoundryAgents_Step02_MultiturnConversation/Program.cs +++ b/dotnet/samples/GettingStarted/FoundryAgents/FoundryAgents_Step02_MultiturnConversation/Program.cs @@ -29,13 +29,13 @@ // Providing the conversation Id is not strictly necessary, but by not providing it no information will show up in the Foundry Project UI as conversations. // Sessions that don't have a conversation Id will work based on the `PreviousResponseId`. -AgentSession session = await jokerAgent.GetNewSessionAsync(conversation.Id); +AgentSession session = await jokerAgent.CreateSessionAsync(conversation.Id); Console.WriteLine(await jokerAgent.RunAsync("Tell me a joke about a pirate.", session)); Console.WriteLine(await jokerAgent.RunAsync("Now add some emojis to the joke and tell it in the voice of a pirate's parrot.", session)); // Invoke the agent with a multi-turn conversation and streaming, where the context is preserved in the session object. -session = await jokerAgent.GetNewSessionAsync(conversation.Id); +session = await jokerAgent.CreateSessionAsync(conversation.Id); await foreach (AgentResponseUpdate update in jokerAgent.RunStreamingAsync("Tell me a joke about a pirate.", session)) { Console.WriteLine(update); diff --git a/dotnet/samples/GettingStarted/FoundryAgents/FoundryAgents_Step02_MultiturnConversation/README.md b/dotnet/samples/GettingStarted/FoundryAgents/FoundryAgents_Step02_MultiturnConversation/README.md index 4cbe5a5922..6611287bd9 100644 --- a/dotnet/samples/GettingStarted/FoundryAgents/FoundryAgents_Step02_MultiturnConversation/README.md +++ b/dotnet/samples/GettingStarted/FoundryAgents/FoundryAgents_Step02_MultiturnConversation/README.md @@ -54,6 +54,6 @@ The sample will: When working with multi-turn conversations, there are two approaches: -- **With Conversation ID**: By passing a `conversation.Id` to `GetNewSessionAsync()`, the conversation will be visible in the Azure Foundry Project UI. This is useful for tracking and debugging conversations. +- **With Conversation ID**: By passing a `conversation.Id` to `CreateSessionAsync()`, the conversation will be visible in the Azure Foundry Project UI. This is useful for tracking and debugging conversations. - **Without Conversation ID**: Sessions created without a conversation ID still work correctly, maintaining context via `PreviousResponseId`. However, these conversations may not appear in the Foundry UI. diff --git a/dotnet/samples/GettingStarted/FoundryAgents/FoundryAgents_Step03_UsingFunctionTools/Program.cs b/dotnet/samples/GettingStarted/FoundryAgents/FoundryAgents_Step03_UsingFunctionTools/Program.cs index 4ff34d86f6..9393b71b9a 100644 --- a/dotnet/samples/GettingStarted/FoundryAgents/FoundryAgents_Step03_UsingFunctionTools/Program.cs +++ b/dotnet/samples/GettingStarted/FoundryAgents/FoundryAgents_Step03_UsingFunctionTools/Program.cs @@ -37,11 +37,11 @@ static string GetWeather([Description("The location to get the weather for.")] s var existingAgent = await aiProjectClient.GetAIAgentAsync(name: AssistantName, tools: [tool]); // Non-streaming agent interaction with function tools. -AgentSession session = await existingAgent.GetNewSessionAsync(); +AgentSession session = await existingAgent.CreateSessionAsync(); Console.WriteLine(await existingAgent.RunAsync("What is the weather like in Amsterdam?", session)); // Streaming agent interaction with function tools. -session = await existingAgent.GetNewSessionAsync(); +session = await existingAgent.CreateSessionAsync(); await foreach (AgentResponseUpdate update in existingAgent.RunStreamingAsync("What is the weather like in Amsterdam?", session)) { Console.WriteLine(update); diff --git a/dotnet/samples/GettingStarted/FoundryAgents/FoundryAgents_Step04_UsingFunctionToolsWithApprovals/Program.cs b/dotnet/samples/GettingStarted/FoundryAgents/FoundryAgents_Step04_UsingFunctionToolsWithApprovals/Program.cs index b030ca8c64..1e09f95161 100644 --- a/dotnet/samples/GettingStarted/FoundryAgents/FoundryAgents_Step04_UsingFunctionToolsWithApprovals/Program.cs +++ b/dotnet/samples/GettingStarted/FoundryAgents/FoundryAgents_Step04_UsingFunctionToolsWithApprovals/Program.cs @@ -32,7 +32,7 @@ static string GetWeather([Description("The location to get the weather for.")] s // Call the agent with approval-required function tools. // The agent will request approval before invoking the function. -AgentSession session = await agent.GetNewSessionAsync(); +AgentSession session = await agent.CreateSessionAsync(); AgentResponse response = await agent.RunAsync("What is the weather like in Amsterdam?", session); // Check if there are any user input requests (approvals needed). diff --git a/dotnet/samples/GettingStarted/FoundryAgents/FoundryAgents_Step06_PersistedConversations/Program.cs b/dotnet/samples/GettingStarted/FoundryAgents/FoundryAgents_Step06_PersistedConversations/Program.cs index 9d55230e50..20e3471df0 100644 --- a/dotnet/samples/GettingStarted/FoundryAgents/FoundryAgents_Step06_PersistedConversations/Program.cs +++ b/dotnet/samples/GettingStarted/FoundryAgents/FoundryAgents_Step06_PersistedConversations/Program.cs @@ -19,7 +19,7 @@ AIAgent agent = await aiProjectClient.CreateAIAgentAsync(name: JokerName, model: deploymentName, instructions: JokerInstructions); // Start a new session for the agent conversation. -AgentSession session = await agent.GetNewSessionAsync(); +AgentSession session = await agent.CreateSessionAsync(); // Run the agent with a new session. Console.WriteLine(await agent.RunAsync("Tell me a joke about a pirate.", session)); diff --git a/dotnet/samples/GettingStarted/FoundryAgents/FoundryAgents_Step07_Observability/Program.cs b/dotnet/samples/GettingStarted/FoundryAgents/FoundryAgents_Step07_Observability/Program.cs index 1ac24011b4..ac0dc23012 100644 --- a/dotnet/samples/GettingStarted/FoundryAgents/FoundryAgents_Step07_Observability/Program.cs +++ b/dotnet/samples/GettingStarted/FoundryAgents/FoundryAgents_Step07_Observability/Program.cs @@ -38,11 +38,11 @@ .Build(); // Invoke the agent and output the text result. -AgentSession session = await agent.GetNewSessionAsync(); +AgentSession session = await agent.CreateSessionAsync(); Console.WriteLine(await agent.RunAsync("Tell me a joke about a pirate.", session)); // Invoke the agent with streaming support. -session = await agent.GetNewSessionAsync(); +session = await agent.CreateSessionAsync(); await foreach (AgentResponseUpdate update in agent.RunStreamingAsync("Tell me a joke about a pirate.", session)) { Console.WriteLine(update); diff --git a/dotnet/samples/GettingStarted/FoundryAgents/FoundryAgents_Step08_DependencyInjection/Program.cs b/dotnet/samples/GettingStarted/FoundryAgents/FoundryAgents_Step08_DependencyInjection/Program.cs index dcded5c0ab..4c53d4ab9c 100644 --- a/dotnet/samples/GettingStarted/FoundryAgents/FoundryAgents_Step08_DependencyInjection/Program.cs +++ b/dotnet/samples/GettingStarted/FoundryAgents/FoundryAgents_Step08_DependencyInjection/Program.cs @@ -54,7 +54,7 @@ internal sealed class SampleService(AIProjectClient client, AIAgent agent, IHost public async Task StartAsync(CancellationToken cancellationToken) { // Create a session that will be used for the entirety of the service lifetime so that the user can ask follow up questions. - this._session = await agent.GetNewSessionAsync(cancellationToken); + this._session = await agent.CreateSessionAsync(cancellationToken); _ = this.RunAsync(appLifetime.ApplicationStopping); } diff --git a/dotnet/samples/GettingStarted/FoundryAgents/FoundryAgents_Step10_UsingImages/Program.cs b/dotnet/samples/GettingStarted/FoundryAgents/FoundryAgents_Step10_UsingImages/Program.cs index 547998fb27..8f38378626 100644 --- a/dotnet/samples/GettingStarted/FoundryAgents/FoundryAgents_Step10_UsingImages/Program.cs +++ b/dotnet/samples/GettingStarted/FoundryAgents/FoundryAgents_Step10_UsingImages/Program.cs @@ -24,7 +24,7 @@ new DataContent(File.ReadAllBytes("assets/walkway.jpg"), "image/jpeg") ]); -AgentSession session = await agent.GetNewSessionAsync(); +AgentSession session = await agent.CreateSessionAsync(); await foreach (AgentResponseUpdate update in agent.RunStreamingAsync(message, session)) { diff --git a/dotnet/samples/GettingStarted/FoundryAgents/FoundryAgents_Step11_AsFunctionTool/Program.cs b/dotnet/samples/GettingStarted/FoundryAgents/FoundryAgents_Step11_AsFunctionTool/Program.cs index 29a1eda312..ccf0a0f012 100644 --- a/dotnet/samples/GettingStarted/FoundryAgents/FoundryAgents_Step11_AsFunctionTool/Program.cs +++ b/dotnet/samples/GettingStarted/FoundryAgents/FoundryAgents_Step11_AsFunctionTool/Program.cs @@ -39,7 +39,7 @@ static string GetWeather([Description("The location to get the weather for.")] s tools: [weatherAgent.AsAIFunction()]); // Invoke the agent and output the text result. -AgentSession session = await agent.GetNewSessionAsync(); +AgentSession session = await agent.CreateSessionAsync(); Console.WriteLine(await agent.RunAsync("What is the weather like in Amsterdam?", session)); // Cleanup by agent name removes the agent versions created. diff --git a/dotnet/samples/GettingStarted/FoundryAgents/FoundryAgents_Step12_Middleware/Program.cs b/dotnet/samples/GettingStarted/FoundryAgents/FoundryAgents_Step12_Middleware/Program.cs index d8c9fb3d15..11bfe1ae45 100644 --- a/dotnet/samples/GettingStarted/FoundryAgents/FoundryAgents_Step12_Middleware/Program.cs +++ b/dotnet/samples/GettingStarted/FoundryAgents/FoundryAgents_Step12_Middleware/Program.cs @@ -49,7 +49,7 @@ static string GetDateTime() .Use(GuardrailMiddleware, null) .Build(); -AgentSession session = await middlewareEnabledAgent.GetNewSessionAsync(); +AgentSession session = await middlewareEnabledAgent.CreateSessionAsync(); Console.WriteLine("\n\n=== Example 1: Wording Guardrail ==="); AgentResponse guardRailedResponse = await middlewareEnabledAgent.RunAsync("Tell me something harmful."); diff --git a/dotnet/samples/GettingStarted/FoundryAgents/FoundryAgents_Step13_Plugins/Program.cs b/dotnet/samples/GettingStarted/FoundryAgents/FoundryAgents_Step13_Plugins/Program.cs index 15269ca9b8..b761c120db 100644 --- a/dotnet/samples/GettingStarted/FoundryAgents/FoundryAgents_Step13_Plugins/Program.cs +++ b/dotnet/samples/GettingStarted/FoundryAgents/FoundryAgents_Step13_Plugins/Program.cs @@ -42,7 +42,7 @@ services: serviceProvider); // Invoke the agent and output the text result. -AgentSession session = await agent.GetNewSessionAsync(); +AgentSession session = await agent.CreateSessionAsync(); Console.WriteLine(await agent.RunAsync("Tell me current time and weather in Seattle.", session)); // Cleanup by agent name removes the agent version created. diff --git a/dotnet/samples/GettingStarted/FoundryAgents/FoundryAgents_Step15_ComputerUse/Program.cs b/dotnet/samples/GettingStarted/FoundryAgents/FoundryAgents_Step15_ComputerUse/Program.cs index d7951635eb..e3294be059 100644 --- a/dotnet/samples/GettingStarted/FoundryAgents/FoundryAgents_Step15_ComputerUse/Program.cs +++ b/dotnet/samples/GettingStarted/FoundryAgents/FoundryAgents_Step15_ComputerUse/Program.cs @@ -83,7 +83,7 @@ private static async Task InvokeComputerUseAgentAsync(AIAgent agent) AllowBackgroundResponses = true, }; - AgentSession session = await agent.GetNewSessionAsync(); + AgentSession session = await agent.CreateSessionAsync(); ChatMessage message = new(ChatRole.User, [ new TextContent("I need you to help me search for 'OpenAI news'. Please type 'OpenAI news' and submit the search. Once you see search results, the task is complete."), diff --git a/dotnet/samples/GettingStarted/ModelContextProtocol/FoundryAgent_Hosted_MCP/Program.cs b/dotnet/samples/GettingStarted/ModelContextProtocol/FoundryAgent_Hosted_MCP/Program.cs index 4251f399d0..f6e762d2b4 100644 --- a/dotnet/samples/GettingStarted/ModelContextProtocol/FoundryAgent_Hosted_MCP/Program.cs +++ b/dotnet/samples/GettingStarted/ModelContextProtocol/FoundryAgent_Hosted_MCP/Program.cs @@ -42,7 +42,7 @@ }); // You can then invoke the agent like any other AIAgent. -AgentSession session = await agent.GetNewSessionAsync(); +AgentSession session = await agent.CreateSessionAsync(); Console.WriteLine(await agent.RunAsync("Please summarize the Azure AI Agent documentation related to MCP Tool calling?", session)); // Cleanup for sample purposes. @@ -75,7 +75,7 @@ }); // You can then invoke the agent like any other AIAgent. -var sessionWithRequiredApproval = await agentWithRequiredApproval.GetNewSessionAsync(); +var sessionWithRequiredApproval = await agentWithRequiredApproval.CreateSessionAsync(); var response = await agentWithRequiredApproval.RunAsync("Please summarize the Azure AI Agent documentation related to MCP Tool calling?", sessionWithRequiredApproval); var userInputRequests = response.UserInputRequests.ToList(); diff --git a/dotnet/samples/GettingStarted/ModelContextProtocol/ResponseAgent_Hosted_MCP/Program.cs b/dotnet/samples/GettingStarted/ModelContextProtocol/ResponseAgent_Hosted_MCP/Program.cs index c8edf00d03..0c4684bc36 100644 --- a/dotnet/samples/GettingStarted/ModelContextProtocol/ResponseAgent_Hosted_MCP/Program.cs +++ b/dotnet/samples/GettingStarted/ModelContextProtocol/ResponseAgent_Hosted_MCP/Program.cs @@ -37,7 +37,7 @@ tools: [mcpTool]); // You can then invoke the agent like any other AIAgent. -AgentSession session = await agent.GetNewSessionAsync(); +AgentSession session = await agent.CreateSessionAsync(); Console.WriteLine(await agent.RunAsync("Please summarize the Azure AI Agent documentation related to MCP Tool calling?", session)); // **** MCP Tool with Approval Required **** @@ -64,7 +64,7 @@ tools: [mcpToolWithApproval]); // You can then invoke the agent like any other AIAgent. -var sessionWithRequiredApproval = await agentWithRequiredApproval.GetNewSessionAsync(); +var sessionWithRequiredApproval = await agentWithRequiredApproval.CreateSessionAsync(); var response = await agentWithRequiredApproval.RunAsync("Please summarize the Azure AI Agent documentation related to MCP Tool calling?", sessionWithRequiredApproval); var userInputRequests = response.UserInputRequests.ToList(); diff --git a/dotnet/samples/GettingStarted/Workflows/Agents/CustomAgentExecutors/Program.cs b/dotnet/samples/GettingStarted/Workflows/Agents/CustomAgentExecutors/Program.cs index 9689b1c306..02fbdf3ecc 100644 --- a/dotnet/samples/GettingStarted/Workflows/Agents/CustomAgentExecutors/Program.cs +++ b/dotnet/samples/GettingStarted/Workflows/Agents/CustomAgentExecutors/Program.cs @@ -136,7 +136,7 @@ protected override RouteBuilder ConfigureRoutes(RouteBuilder routeBuilder) => public async ValueTask HandleAsync(string message, IWorkflowContext context, CancellationToken cancellationToken = default) { - this._session ??= await this._agent.GetNewSessionAsync(cancellationToken); + this._session ??= await this._agent.CreateSessionAsync(cancellationToken); var result = await this._agent.RunAsync(message, this._session, cancellationToken: cancellationToken); @@ -209,7 +209,7 @@ public FeedbackExecutor(string id, IChatClient chatClient) : base(id) public override async ValueTask HandleAsync(SloganResult message, IWorkflowContext context, CancellationToken cancellationToken = default) { - this._session ??= await this._agent.GetNewSessionAsync(cancellationToken); + this._session ??= await this._agent.CreateSessionAsync(cancellationToken); var sloganMessage = $""" Here is a slogan for the task '{message.Task}': diff --git a/dotnet/samples/GettingStarted/Workflows/Agents/WorkflowAsAnAgent/Program.cs b/dotnet/samples/GettingStarted/Workflows/Agents/WorkflowAsAnAgent/Program.cs index 908ed3b914..48436b7b8f 100644 --- a/dotnet/samples/GettingStarted/Workflows/Agents/WorkflowAsAnAgent/Program.cs +++ b/dotnet/samples/GettingStarted/Workflows/Agents/WorkflowAsAnAgent/Program.cs @@ -37,7 +37,7 @@ private static async Task Main() // Create the workflow and turn it into an agent var workflow = WorkflowFactory.BuildWorkflow(chatClient); var agent = workflow.AsAgent("workflow-agent", "Workflow Agent"); - var session = await agent.GetNewSessionAsync(); + var session = await agent.CreateSessionAsync(); // Start an interactive loop to interact with the workflow as if it were an agent while (true) diff --git a/dotnet/samples/GettingStarted/Workflows/Declarative/HostedWorkflow/Program.cs b/dotnet/samples/GettingStarted/Workflows/Declarative/HostedWorkflow/Program.cs index 96d728b487..b6011a1a71 100644 --- a/dotnet/samples/GettingStarted/Workflows/Declarative/HostedWorkflow/Program.cs +++ b/dotnet/samples/GettingStarted/Workflows/Declarative/HostedWorkflow/Program.cs @@ -47,7 +47,7 @@ public static async Task Main(string[] args) AIAgent agent = aiProjectClient.AsAIAgent(agentVersion); - AgentSession session = await agent.GetNewSessionAsync(); + AgentSession session = await agent.CreateSessionAsync(); ProjectConversation conversation = await aiProjectClient diff --git a/dotnet/samples/GettingStarted/Workflows/Observability/WorkflowAsAnAgent/Program.cs b/dotnet/samples/GettingStarted/Workflows/Observability/WorkflowAsAnAgent/Program.cs index 806fad421b..7d7d4d69fd 100644 --- a/dotnet/samples/GettingStarted/Workflows/Observability/WorkflowAsAnAgent/Program.cs +++ b/dotnet/samples/GettingStarted/Workflows/Observability/WorkflowAsAnAgent/Program.cs @@ -90,7 +90,7 @@ private static async Task Main() { EnableSensitiveData = true // enable sensitive data at the agent level such as prompts and responses }; - var session = await agent.GetNewSessionAsync(); + var session = await agent.CreateSessionAsync(); // Start an interactive loop to interact with the workflow as if it were an agent while (true) diff --git a/dotnet/samples/M365Agent/AFAgentApplication.cs b/dotnet/samples/M365Agent/AFAgentApplication.cs index 9b7d25abe4..4dea6c6e28 100644 --- a/dotnet/samples/M365Agent/AFAgentApplication.cs +++ b/dotnet/samples/M365Agent/AFAgentApplication.cs @@ -44,7 +44,7 @@ private async Task MessageActivityAsync(ITurnContext turnContext, ITurnState tur // Deserialize the conversation history into an AgentSession, or create a new one if none exists. AgentSession agentSession = sessionElementStart.ValueKind is not JsonValueKind.Undefined and not JsonValueKind.Null ? await this._agent.DeserializeSessionAsync(sessionElementStart, JsonUtilities.DefaultOptions, cancellationToken) - : await this._agent.GetNewSessionAsync(cancellationToken); + : await this._agent.CreateSessionAsync(cancellationToken); ChatMessage chatMessage = HandleUserInput(turnContext); diff --git a/dotnet/src/Microsoft.Agents.AI.A2A/A2AAgent.cs b/dotnet/src/Microsoft.Agents.AI.A2A/A2AAgent.cs index 1eb0f8449e..3ccc9f481e 100644 --- a/dotnet/src/Microsoft.Agents.AI.A2A/A2AAgent.cs +++ b/dotnet/src/Microsoft.Agents.AI.A2A/A2AAgent.cs @@ -54,7 +54,7 @@ public A2AAgent(A2AClient a2aClient, string? id = null, string? name = null, str } /// - public sealed override ValueTask GetNewSessionAsync(CancellationToken cancellationToken = default) + public sealed override ValueTask CreateSessionAsync(CancellationToken cancellationToken = default) => new(new A2AAgentSession()); /// @@ -62,7 +62,7 @@ public sealed override ValueTask GetNewSessionAsync(CancellationTo /// /// The context id to continue. /// A value task representing the asynchronous operation. The task result contains a new instance. - public ValueTask GetNewSessionAsync(string contextId) + public ValueTask CreateSessionAsync(string contextId) => new(new A2AAgentSession() { ContextId = contextId }); /// @@ -230,7 +230,7 @@ private async ValueTask GetA2ASessionAsync(AgentSession? sessio throw new InvalidOperationException("A session must be provided when AllowBackgroundResponses is enabled."); } - session ??= await this.GetNewSessionAsync(cancellationToken).ConfigureAwait(false); + session ??= await this.CreateSessionAsync(cancellationToken).ConfigureAwait(false); if (session is not A2AAgentSession typedSession) { diff --git a/dotnet/src/Microsoft.Agents.AI.Abstractions/AIAgent.cs b/dotnet/src/Microsoft.Agents.AI.Abstractions/AIAgent.cs index 9ec8d6b7e9..31f4993723 100644 --- a/dotnet/src/Microsoft.Agents.AI.Abstractions/AIAgent.cs +++ b/dotnet/src/Microsoft.Agents.AI.Abstractions/AIAgent.cs @@ -123,7 +123,7 @@ public abstract class AIAgent /// may be deferred until first use to optimize performance. /// /// - public abstract ValueTask GetNewSessionAsync(CancellationToken cancellationToken = default); + public abstract ValueTask CreateSessionAsync(CancellationToken cancellationToken = default); /// /// Deserializes an agent session from its JSON serialized representation. diff --git a/dotnet/src/Microsoft.Agents.AI.Abstractions/AgentSession.cs b/dotnet/src/Microsoft.Agents.AI.Abstractions/AgentSession.cs index b722582668..5bcea2239d 100644 --- a/dotnet/src/Microsoft.Agents.AI.Abstractions/AgentSession.cs +++ b/dotnet/src/Microsoft.Agents.AI.Abstractions/AgentSession.cs @@ -26,7 +26,7 @@ namespace Microsoft.Agents.AI; /// Chat history reduction, e.g. where messages needs to be summarized or truncated to reduce the size. /// /// An is always constructed by an so that the -/// can attach any necessary behaviors to the . See the +/// can attach any necessary behaviors to the . See the /// and methods for more information. /// /// @@ -42,7 +42,7 @@ namespace Microsoft.Agents.AI; /// /// /// -/// +/// /// public abstract class AgentSession { diff --git a/dotnet/src/Microsoft.Agents.AI.Abstractions/DelegatingAIAgent.cs b/dotnet/src/Microsoft.Agents.AI.Abstractions/DelegatingAIAgent.cs index 9e7bda3f28..99979871b1 100644 --- a/dotnet/src/Microsoft.Agents.AI.Abstractions/DelegatingAIAgent.cs +++ b/dotnet/src/Microsoft.Agents.AI.Abstractions/DelegatingAIAgent.cs @@ -74,7 +74,7 @@ protected DelegatingAIAgent(AIAgent innerAgent) } /// - public override ValueTask GetNewSessionAsync(CancellationToken cancellationToken = default) => this.InnerAgent.GetNewSessionAsync(cancellationToken); + public override ValueTask CreateSessionAsync(CancellationToken cancellationToken = default) => this.InnerAgent.CreateSessionAsync(cancellationToken); /// public override ValueTask DeserializeSessionAsync(JsonElement serializedSession, JsonSerializerOptions? jsonSerializerOptions = null, CancellationToken cancellationToken = default) diff --git a/dotnet/src/Microsoft.Agents.AI.CopilotStudio/CopilotStudioAgent.cs b/dotnet/src/Microsoft.Agents.AI.CopilotStudio/CopilotStudioAgent.cs index bf786a1712..378c36298b 100644 --- a/dotnet/src/Microsoft.Agents.AI.CopilotStudio/CopilotStudioAgent.cs +++ b/dotnet/src/Microsoft.Agents.AI.CopilotStudio/CopilotStudioAgent.cs @@ -42,7 +42,7 @@ public CopilotStudioAgent(CopilotClient client, ILoggerFactory? loggerFactory = } /// - public sealed override ValueTask GetNewSessionAsync(CancellationToken cancellationToken = default) + public sealed override ValueTask CreateSessionAsync(CancellationToken cancellationToken = default) => new(new CopilotStudioAgentSession()); /// @@ -50,7 +50,7 @@ public sealed override ValueTask GetNewSessionAsync(CancellationTo /// /// The conversation id to continue. /// A new instance. - public ValueTask GetNewSessionAsync(string conversationId) + public ValueTask CreateSessionAsync(string conversationId) => new(new CopilotStudioAgentSession() { ConversationId = conversationId }); /// @@ -68,7 +68,7 @@ protected override async Task RunCoreAsync( // Ensure that we have a valid session to work with. // If the session ID is null, we need to start a new conversation and set the session ID accordingly. - session ??= await this.GetNewSessionAsync(cancellationToken).ConfigureAwait(false); + session ??= await this.CreateSessionAsync(cancellationToken).ConfigureAwait(false); if (session is not CopilotStudioAgentSession typedSession) { throw new InvalidOperationException("The provided session is not compatible with the agent. Only sessions created by the agent can be used."); @@ -107,7 +107,7 @@ protected override async IAsyncEnumerable RunCoreStreamingA // Ensure that we have a valid session to work with. // If the session ID is null, we need to start a new conversation and set the session ID accordingly. - session ??= await this.GetNewSessionAsync(cancellationToken).ConfigureAwait(false); + session ??= await this.CreateSessionAsync(cancellationToken).ConfigureAwait(false); if (session is not CopilotStudioAgentSession typedSession) { throw new InvalidOperationException("The provided session is not compatible with the agent. Only sessions created by the agent can be used."); diff --git a/dotnet/src/Microsoft.Agents.AI.DurableTask/AgentEntity.cs b/dotnet/src/Microsoft.Agents.AI.DurableTask/AgentEntity.cs index 09c6df31ea..e87f17be68 100644 --- a/dotnet/src/Microsoft.Agents.AI.DurableTask/AgentEntity.cs +++ b/dotnet/src/Microsoft.Agents.AI.DurableTask/AgentEntity.cs @@ -67,7 +67,7 @@ public async Task Run(RunRequest request) // Start the agent response stream IAsyncEnumerable responseStream = agentWrapper.RunStreamingAsync( this.State.Data.ConversationHistory.SelectMany(e => e.Messages).Select(m => m.ToChatMessage()), - await agentWrapper.GetNewSessionAsync(cancellationToken).ConfigureAwait(false), + await agentWrapper.CreateSessionAsync(cancellationToken).ConfigureAwait(false), options: null, this._cancellationToken); diff --git a/dotnet/src/Microsoft.Agents.AI.DurableTask/DurableAIAgent.cs b/dotnet/src/Microsoft.Agents.AI.DurableTask/DurableAIAgent.cs index f944131b4e..a97652bd93 100644 --- a/dotnet/src/Microsoft.Agents.AI.DurableTask/DurableAIAgent.cs +++ b/dotnet/src/Microsoft.Agents.AI.DurableTask/DurableAIAgent.cs @@ -34,7 +34,7 @@ internal DurableAIAgent(TaskOrchestrationContext context, string agentName) /// /// The cancellation token. /// A value task that represents the asynchronous operation. The task result contains a new agent session. - public override ValueTask GetNewSessionAsync(CancellationToken cancellationToken = default) + public override ValueTask CreateSessionAsync(CancellationToken cancellationToken = default) { AgentSessionId sessionId = this._context.NewAgentSessionId(this._agentName); return ValueTask.FromResult(new DurableAgentSession(sessionId)); @@ -76,12 +76,12 @@ protected override async Task RunCoreAsync( throw new NotSupportedException("Cancellation is not supported for durable agents."); } - session ??= await this.GetNewSessionAsync(cancellationToken).ConfigureAwait(false); + session ??= await this.CreateSessionAsync(cancellationToken).ConfigureAwait(false); if (session is not DurableAgentSession durableSession) { throw new ArgumentException( "The provided session is not valid for a durable agent. " + - "Create a new session using GetNewSessionAsync or provide a session previously created by this agent.", + "Create a new session using CreateSessionAsync or provide a session previously created by this agent.", paramName: nameof(session)); } diff --git a/dotnet/src/Microsoft.Agents.AI.DurableTask/DurableAIAgentProxy.cs b/dotnet/src/Microsoft.Agents.AI.DurableTask/DurableAIAgentProxy.cs index d61bd6df77..b6d3fa4900 100644 --- a/dotnet/src/Microsoft.Agents.AI.DurableTask/DurableAIAgentProxy.cs +++ b/dotnet/src/Microsoft.Agents.AI.DurableTask/DurableAIAgentProxy.cs @@ -18,7 +18,7 @@ public override ValueTask DeserializeSessionAsync( return ValueTask.FromResult(DurableAgentSession.Deserialize(serializedSession, jsonSerializerOptions)); } - public override ValueTask GetNewSessionAsync(CancellationToken cancellationToken = default) + public override ValueTask CreateSessionAsync(CancellationToken cancellationToken = default) { return ValueTask.FromResult(new DurableAgentSession(AgentSessionId.WithRandomKey(this.Name!))); } @@ -29,12 +29,12 @@ protected override async Task RunCoreAsync( AgentRunOptions? options = null, CancellationToken cancellationToken = default) { - session ??= await this.GetNewSessionAsync(cancellationToken).ConfigureAwait(false); + session ??= await this.CreateSessionAsync(cancellationToken).ConfigureAwait(false); if (session is not DurableAgentSession durableSession) { throw new ArgumentException( "The provided session is not valid for a durable agent. " + - "Create a new session using GetNewSession or provide a session previously created by this agent.", + "Create a new session using CreateSessionAsync or provide a session previously created by this agent.", paramName: nameof(session)); } diff --git a/dotnet/src/Microsoft.Agents.AI.GitHub.Copilot/GitHubCopilotAgent.cs b/dotnet/src/Microsoft.Agents.AI.GitHub.Copilot/GitHubCopilotAgent.cs index 41236fcc55..e2771e21c4 100644 --- a/dotnet/src/Microsoft.Agents.AI.GitHub.Copilot/GitHubCopilotAgent.cs +++ b/dotnet/src/Microsoft.Agents.AI.GitHub.Copilot/GitHubCopilotAgent.cs @@ -86,7 +86,7 @@ public GitHubCopilotAgent( } /// - public sealed override ValueTask GetNewSessionAsync(CancellationToken cancellationToken = default) + public sealed override ValueTask CreateSessionAsync(CancellationToken cancellationToken = default) => new(new GitHubCopilotAgentSession()); /// @@ -94,7 +94,7 @@ public sealed override ValueTask GetNewSessionAsync(CancellationTo /// /// The session id to continue. /// A new instance. - public ValueTask GetNewSessionAsync(string sessionId) + public ValueTask CreateSessionAsync(string sessionId) => new(new GitHubCopilotAgentSession() { SessionId = sessionId }); /// @@ -122,7 +122,7 @@ protected override async IAsyncEnumerable RunCoreStreamingA _ = Throw.IfNull(messages); // Ensure we have a valid session - session ??= await this.GetNewSessionAsync(cancellationToken).ConfigureAwait(false); + session ??= await this.CreateSessionAsync(cancellationToken).ConfigureAwait(false); if (session is not GitHubCopilotAgentSession typedSession) { throw new InvalidOperationException( diff --git a/dotnet/src/Microsoft.Agents.AI.Hosting.AzureFunctions/README.md b/dotnet/src/Microsoft.Agents.AI.Hosting.AzureFunctions/README.md index 0506a0ea23..6cacc5adff 100644 --- a/dotnet/src/Microsoft.Agents.AI.Hosting.AzureFunctions/README.md +++ b/dotnet/src/Microsoft.Agents.AI.Hosting.AzureFunctions/README.md @@ -74,7 +74,7 @@ public static async Task SpamDetectionOrchestration( // Get the spam detection agent DurableAIAgent spamDetectionAgent = context.GetAgent("SpamDetectionAgent"); - AgentSession spamSession = await spamDetectionAgent.GetNewSessionAsync(); + AgentSession spamSession = await spamDetectionAgent.CreateSessionAsync(); // Step 1: Check if the email is spam AgentResponse spamDetectionResponse = await spamDetectionAgent.RunAsync( @@ -97,7 +97,7 @@ public static async Task SpamDetectionOrchestration( { // Generate and send response for legitimate email DurableAIAgent emailAssistantAgent = context.GetAgent("EmailAssistantAgent"); - AgentSession emailSession = await emailAssistantAgent.GetNewSessionAsync(); + AgentSession emailSession = await emailAssistantAgent.CreateSessionAsync(); AgentResponse emailAssistantResponse = await emailAssistantAgent.RunAsync( message: diff --git a/dotnet/src/Microsoft.Agents.AI.Hosting/Local/InMemoryAgentSessionStore.cs b/dotnet/src/Microsoft.Agents.AI.Hosting/Local/InMemoryAgentSessionStore.cs index ec1381f405..d66192c709 100644 --- a/dotnet/src/Microsoft.Agents.AI.Hosting/Local/InMemoryAgentSessionStore.cs +++ b/dotnet/src/Microsoft.Agents.AI.Hosting/Local/InMemoryAgentSessionStore.cs @@ -45,7 +45,7 @@ public override async ValueTask GetSessionAsync(AIAgent agent, str return sessionContent switch { - null => await agent.GetNewSessionAsync(cancellationToken).ConfigureAwait(false), + null => await agent.CreateSessionAsync(cancellationToken).ConfigureAwait(false), _ => await agent.DeserializeSessionAsync(sessionContent.Value, cancellationToken: cancellationToken).ConfigureAwait(false), }; } diff --git a/dotnet/src/Microsoft.Agents.AI.Hosting/NoopAgentSessionStore.cs b/dotnet/src/Microsoft.Agents.AI.Hosting/NoopAgentSessionStore.cs index c0736afda3..163c1ea867 100644 --- a/dotnet/src/Microsoft.Agents.AI.Hosting/NoopAgentSessionStore.cs +++ b/dotnet/src/Microsoft.Agents.AI.Hosting/NoopAgentSessionStore.cs @@ -20,6 +20,6 @@ public override ValueTask SaveSessionAsync(AIAgent agent, string conversationId, /// public override ValueTask GetSessionAsync(AIAgent agent, string conversationId, CancellationToken cancellationToken = default) { - return agent.GetNewSessionAsync(cancellationToken); + return agent.CreateSessionAsync(cancellationToken); } } diff --git a/dotnet/src/Microsoft.Agents.AI.Purview/PurviewAgent.cs b/dotnet/src/Microsoft.Agents.AI.Purview/PurviewAgent.cs index 336be0e108..a08d978fa8 100644 --- a/dotnet/src/Microsoft.Agents.AI.Purview/PurviewAgent.cs +++ b/dotnet/src/Microsoft.Agents.AI.Purview/PurviewAgent.cs @@ -36,9 +36,9 @@ public override ValueTask DeserializeSessionAsync(JsonElement seri } /// - public override ValueTask GetNewSessionAsync(CancellationToken cancellationToken = default) + public override ValueTask CreateSessionAsync(CancellationToken cancellationToken = default) { - return this._innerAgent.GetNewSessionAsync(cancellationToken); + return this._innerAgent.CreateSessionAsync(cancellationToken); } /// diff --git a/dotnet/src/Microsoft.Agents.AI.Workflows/Specialized/AIAgentHostExecutor.cs b/dotnet/src/Microsoft.Agents.AI.Workflows/Specialized/AIAgentHostExecutor.cs index f53a6f076b..3562747b7c 100644 --- a/dotnet/src/Microsoft.Agents.AI.Workflows/Specialized/AIAgentHostExecutor.cs +++ b/dotnet/src/Microsoft.Agents.AI.Workflows/Specialized/AIAgentHostExecutor.cs @@ -93,7 +93,7 @@ public bool ShouldEmitStreamingEvents(bool? emitEvents) => emitEvents ?? this._options.EmitAgentUpdateEvents ?? false; private async ValueTask EnsureSessionAsync(IWorkflowContext context, CancellationToken cancellationToken) => - this._session ??= await this._agent.GetNewSessionAsync(cancellationToken).ConfigureAwait(false); + this._session ??= await this._agent.CreateSessionAsync(cancellationToken).ConfigureAwait(false); private const string UserInputRequestStateKey = nameof(_userInputHandler); private const string FunctionCallRequestStateKey = nameof(_functionCallHandler); diff --git a/dotnet/src/Microsoft.Agents.AI.Workflows/WorkflowHostAgent.cs b/dotnet/src/Microsoft.Agents.AI.Workflows/WorkflowHostAgent.cs index 3bd1059ce8..86c725bca1 100644 --- a/dotnet/src/Microsoft.Agents.AI.Workflows/WorkflowHostAgent.cs +++ b/dotnet/src/Microsoft.Agents.AI.Workflows/WorkflowHostAgent.cs @@ -65,7 +65,7 @@ private async ValueTask ValidateWorkflowAsync() protocol.ThrowIfNotChatProtocol(allowCatchAll: true); } - public override ValueTask GetNewSessionAsync(CancellationToken cancellationToken = default) + public override ValueTask CreateSessionAsync(CancellationToken cancellationToken = default) => new(new WorkflowSession(this._workflow, this.GenerateNewId(), this._executionEnvironment, this._checkpointManager, this._includeExceptionDetails, this._includeWorkflowOutputsInResponse)); public override ValueTask DeserializeSessionAsync(JsonElement serializedSession, JsonSerializerOptions? jsonSerializerOptions = null, CancellationToken cancellationToken = default) @@ -73,7 +73,7 @@ public override ValueTask DeserializeSessionAsync(JsonElement seri private async ValueTask UpdateSessionAsync(IEnumerable messages, AgentSession? session = null, CancellationToken cancellationToken = default) { - session ??= await this.GetNewSessionAsync(cancellationToken).ConfigureAwait(false); + session ??= await this.CreateSessionAsync(cancellationToken).ConfigureAwait(false); if (session is not WorkflowSession workflowSession) { diff --git a/dotnet/src/Microsoft.Agents.AI/ChatClient/ChatClientAgent.cs b/dotnet/src/Microsoft.Agents.AI/ChatClient/ChatClientAgent.cs index 937a6d0f0b..504928d2d6 100644 --- a/dotnet/src/Microsoft.Agents.AI/ChatClient/ChatClientAgent.cs +++ b/dotnet/src/Microsoft.Agents.AI/ChatClient/ChatClientAgent.cs @@ -302,7 +302,7 @@ protected override async IAsyncEnumerable RunCoreStreamingA : this.ChatClient.GetService(serviceType, serviceKey)); /// - public override async ValueTask GetNewSessionAsync(CancellationToken cancellationToken = default) + public override async ValueTask CreateSessionAsync(CancellationToken cancellationToken = default) { ChatHistoryProvider? chatHistoryProvider = this._agentOptions?.ChatHistoryProviderFactory is not null ? await this._agentOptions.ChatHistoryProviderFactory.Invoke(new() { SerializedState = default, JsonSerializerOptions = null }, cancellationToken).ConfigureAwait(false) @@ -337,7 +337,7 @@ public override async ValueTask GetNewSessionAsync(CancellationTok /// instances that support server-side conversation storage through their underlying . /// /// - public async ValueTask GetNewSessionAsync(string conversationId, CancellationToken cancellationToken = default) + public async ValueTask CreateSessionAsync(string conversationId, CancellationToken cancellationToken = default) { AIContextProvider? contextProvider = this._agentOptions?.AIContextProviderFactory is not null ? await this._agentOptions.AIContextProviderFactory.Invoke(new() { SerializedState = default, JsonSerializerOptions = null }, cancellationToken).ConfigureAwait(false) @@ -365,14 +365,14 @@ public async ValueTask GetNewSessionAsync(string conversationId, C /// with a may not be compatible with these services. /// /// - /// Where a service requires server-side conversation storage, use . + /// Where a service requires server-side conversation storage, use . /// /// /// If the agent detects, during the first run, that the underlying AI service requires server-side conversation storage, /// the session will throw an exception to indicate that it cannot continue using the provided . /// /// - public async ValueTask GetNewSessionAsync(ChatHistoryProvider chatHistoryProvider, CancellationToken cancellationToken = default) + public async ValueTask CreateSessionAsync(ChatHistoryProvider chatHistoryProvider, CancellationToken cancellationToken = default) { AIContextProvider? contextProvider = this._agentOptions?.AIContextProviderFactory is not null ? await this._agentOptions.AIContextProviderFactory.Invoke(new() { SerializedState = default, JsonSerializerOptions = null }, cancellationToken).ConfigureAwait(false) @@ -689,7 +689,7 @@ private async Task throw new InvalidOperationException("A session must be provided when continuing a background response with a continuation token."); } - session ??= await this.GetNewSessionAsync(cancellationToken).ConfigureAwait(false); + session ??= await this.CreateSessionAsync(cancellationToken).ConfigureAwait(false); if (session is not ChatClientAgentSession typedSession) { throw new InvalidOperationException("The provided session is not compatible with the agent. Only sessions created by the agent can be used."); diff --git a/dotnet/tests/AgentConformance.IntegrationTests/ChatClientAgentRunStreamingTests.cs b/dotnet/tests/AgentConformance.IntegrationTests/ChatClientAgentRunStreamingTests.cs index a32fa3e0ea..aa7d09a86d 100644 --- a/dotnet/tests/AgentConformance.IntegrationTests/ChatClientAgentRunStreamingTests.cs +++ b/dotnet/tests/AgentConformance.IntegrationTests/ChatClientAgentRunStreamingTests.cs @@ -22,7 +22,7 @@ public virtual async Task RunWithInstructionsAndNoMessageReturnsExpectedResultAs { // Arrange var agent = await this.Fixture.CreateChatClientAgentAsync(instructions: "Always respond with 'Computer says no', even if there was no user input."); - var session = await agent.GetNewSessionAsync(); + var session = await agent.CreateSessionAsync(); await using var agentCleanup = new AgentCleanup(agent, this.Fixture); await using var sessionCleanup = new SessionCleanup(session, this.Fixture); @@ -53,7 +53,7 @@ public virtual async Task RunWithFunctionsInvokesFunctionsAndReturnsExpectedResu AIFunctionFactory.Create(MenuPlugin.GetSpecials), AIFunctionFactory.Create(MenuPlugin.GetItemPrice) ]); - var session = await agent.GetNewSessionAsync(); + var session = await agent.CreateSessionAsync(); foreach (var questionAndAnswer in questionsAndAnswers) { diff --git a/dotnet/tests/AgentConformance.IntegrationTests/ChatClientAgentRunTests.cs b/dotnet/tests/AgentConformance.IntegrationTests/ChatClientAgentRunTests.cs index be51b9683d..8b88775615 100644 --- a/dotnet/tests/AgentConformance.IntegrationTests/ChatClientAgentRunTests.cs +++ b/dotnet/tests/AgentConformance.IntegrationTests/ChatClientAgentRunTests.cs @@ -21,7 +21,7 @@ public virtual async Task RunWithInstructionsAndNoMessageReturnsExpectedResultAs { // Arrange var agent = await this.Fixture.CreateChatClientAgentAsync(instructions: "ALWAYS RESPOND WITH 'Computer says no', even if there was no user input."); - var session = await agent.GetNewSessionAsync(); + var session = await agent.CreateSessionAsync(); await using var agentCleanup = new AgentCleanup(agent, this.Fixture); await using var sessionCleanup = new SessionCleanup(session, this.Fixture); @@ -53,7 +53,7 @@ public virtual async Task RunWithFunctionsInvokesFunctionsAndReturnsExpectedResu AIFunctionFactory.Create(MenuPlugin.GetSpecials), AIFunctionFactory.Create(MenuPlugin.GetItemPrice) ]); - var session = await agent.GetNewSessionAsync(); + var session = await agent.CreateSessionAsync(); foreach (var questionAndAnswer in questionsAndAnswers) { diff --git a/dotnet/tests/AgentConformance.IntegrationTests/RunStreamingTests.cs b/dotnet/tests/AgentConformance.IntegrationTests/RunStreamingTests.cs index 2290e20cb4..f9cc732175 100644 --- a/dotnet/tests/AgentConformance.IntegrationTests/RunStreamingTests.cs +++ b/dotnet/tests/AgentConformance.IntegrationTests/RunStreamingTests.cs @@ -24,7 +24,7 @@ public virtual async Task RunWithNoMessageDoesNotFailAsync() { // Arrange var agent = this.Fixture.Agent; - var session = await agent.GetNewSessionAsync(); + var session = await agent.CreateSessionAsync(); await using var cleanup = new SessionCleanup(session, this.Fixture); // Act @@ -36,7 +36,7 @@ public virtual async Task RunWithStringReturnsExpectedResultAsync() { // Arrange var agent = this.Fixture.Agent; - var session = await agent.GetNewSessionAsync(); + var session = await agent.CreateSessionAsync(); await using var cleanup = new SessionCleanup(session, this.Fixture); // Act @@ -52,7 +52,7 @@ public virtual async Task RunWithChatMessageReturnsExpectedResultAsync() { // Arrange var agent = this.Fixture.Agent; - var session = await agent.GetNewSessionAsync(); + var session = await agent.CreateSessionAsync(); await using var cleanup = new SessionCleanup(session, this.Fixture); // Act @@ -68,7 +68,7 @@ public virtual async Task RunWithChatMessagesReturnsExpectedResultAsync() { // Arrange var agent = this.Fixture.Agent; - var session = await agent.GetNewSessionAsync(); + var session = await agent.CreateSessionAsync(); await using var cleanup = new SessionCleanup(session, this.Fixture); // Act @@ -92,7 +92,7 @@ public virtual async Task SessionMaintainsHistoryAsync() const string Q1 = "What is the capital of France."; const string Q2 = "And Austria?"; var agent = this.Fixture.Agent; - var session = await agent.GetNewSessionAsync(); + var session = await agent.CreateSessionAsync(); await using var cleanup = new SessionCleanup(session, this.Fixture); // Act diff --git a/dotnet/tests/AgentConformance.IntegrationTests/RunTests.cs b/dotnet/tests/AgentConformance.IntegrationTests/RunTests.cs index be1fa0f2f3..302784a1a8 100644 --- a/dotnet/tests/AgentConformance.IntegrationTests/RunTests.cs +++ b/dotnet/tests/AgentConformance.IntegrationTests/RunTests.cs @@ -24,7 +24,7 @@ public virtual async Task RunWithNoMessageDoesNotFailAsync() { // Arrange var agent = this.Fixture.Agent; - var session = await agent.GetNewSessionAsync(); + var session = await agent.CreateSessionAsync(); await using var cleanup = new SessionCleanup(session, this.Fixture); // Act @@ -39,7 +39,7 @@ public virtual async Task RunWithStringReturnsExpectedResultAsync() { // Arrange var agent = this.Fixture.Agent; - var session = await agent.GetNewSessionAsync(); + var session = await agent.CreateSessionAsync(); await using var cleanup = new SessionCleanup(session, this.Fixture); // Act @@ -57,7 +57,7 @@ public virtual async Task RunWithChatMessageReturnsExpectedResultAsync() { // Arrange var agent = this.Fixture.Agent; - var session = await agent.GetNewSessionAsync(); + var session = await agent.CreateSessionAsync(); await using var cleanup = new SessionCleanup(session, this.Fixture); // Act @@ -74,7 +74,7 @@ public virtual async Task RunWithChatMessagesReturnsExpectedResultAsync() { // Arrange var agent = this.Fixture.Agent; - var session = await agent.GetNewSessionAsync(); + var session = await agent.CreateSessionAsync(); await using var cleanup = new SessionCleanup(session, this.Fixture); // Act @@ -99,7 +99,7 @@ public virtual async Task SessionMaintainsHistoryAsync() const string Q1 = "What is the capital of France."; const string Q2 = "And Austria?"; var agent = this.Fixture.Agent; - var session = await agent.GetNewSessionAsync(); + var session = await agent.CreateSessionAsync(); await using var cleanup = new SessionCleanup(session, this.Fixture); // Act diff --git a/dotnet/tests/Microsoft.Agents.AI.A2A.UnitTests/A2AAgentTests.cs b/dotnet/tests/Microsoft.Agents.AI.A2A.UnitTests/A2AAgentTests.cs index a903973806..d6e736a528 100644 --- a/dotnet/tests/Microsoft.Agents.AI.A2A.UnitTests/A2AAgentTests.cs +++ b/dotnet/tests/Microsoft.Agents.AI.A2A.UnitTests/A2AAgentTests.cs @@ -148,7 +148,7 @@ public async Task RunAsync_WithNewSession_UpdatesSessionConversationIdAsync() new(ChatRole.User, "Test message") }; - var session = await this._agent.GetNewSessionAsync(); + var session = await this._agent.CreateSessionAsync(); // Act await this._agent.RunAsync(inputMessages, session); @@ -168,7 +168,7 @@ public async Task RunAsync_WithExistingSession_SetConversationIdToMessageAsync() new(ChatRole.User, "Test message") }; - var session = await this._agent.GetNewSessionAsync(); + var session = await this._agent.CreateSessionAsync(); var a2aSession = (A2AAgentSession)session; a2aSession.ContextId = "existing-context-id"; @@ -201,7 +201,7 @@ public async Task RunAsync_WithSessionHavingDifferentContextId_ThrowsInvalidOper ContextId = "different-context" }; - var session = await this._agent.GetNewSessionAsync(); + var session = await this._agent.CreateSessionAsync(); var a2aSession = (A2AAgentSession)session; a2aSession.ContextId = "existing-context-id"; @@ -272,7 +272,7 @@ public async Task RunStreamingAsync_WithSession_UpdatesSessionConversationIdAsyn ContextId = "new-stream-context" }; - var session = await this._agent.GetNewSessionAsync(); + var session = await this._agent.CreateSessionAsync(); // Act await foreach (var _ in this._agent.RunStreamingAsync(inputMessages, session)) @@ -296,7 +296,7 @@ public async Task RunStreamingAsync_WithExistingSession_SetConversationIdToMessa this._handler.StreamingResponseToReturn = new AgentMessage(); - var session = await this._agent.GetNewSessionAsync(); + var session = await this._agent.CreateSessionAsync(); var a2aSession = (A2AAgentSession)session; a2aSession.ContextId = "existing-context-id"; @@ -316,7 +316,7 @@ public async Task RunStreamingAsync_WithExistingSession_SetConversationIdToMessa public async Task RunStreamingAsync_WithSessionHavingDifferentContextId_ThrowsInvalidOperationExceptionAsync() { // Arrange - var session = await this._agent.GetNewSessionAsync(); + var session = await this._agent.CreateSessionAsync(); var a2aSession = (A2AAgentSession)session; a2aSession.ContextId = "existing-context-id"; @@ -440,7 +440,7 @@ public async Task RunAsync_WithTaskInSessionAndMessage_AddTaskAsReferencesToMess Parts = [new TextPart { Text = "Response to task" }] }; - var session = (A2AAgentSession)await this._agent.GetNewSessionAsync(); + var session = (A2AAgentSession)await this._agent.CreateSessionAsync(); session.TaskId = "task-123"; var inputMessage = new ChatMessage(ChatRole.User, "Please make the background transparent"); @@ -466,7 +466,7 @@ public async Task RunAsync_WithAgentTask_UpdatesSessionTaskIdAsync() Status = new() { State = TaskState.Submitted } }; - var session = await this._agent.GetNewSessionAsync(); + var session = await this._agent.CreateSessionAsync(); // Act await this._agent.RunAsync("Start a task", session); @@ -492,7 +492,7 @@ public async Task RunAsync_WithAgentTaskResponse_ReturnsTaskResponseCorrectlyAsy } }; - var session = await this._agent.GetNewSessionAsync(); + var session = await this._agent.CreateSessionAsync(); // Act var result = await this._agent.RunAsync("Start a long-running task", session); @@ -586,7 +586,7 @@ public async Task RunStreamingAsync_WithTaskInSessionAndMessage_AddTaskAsReferen Parts = [new TextPart { Text = "Response to task" }] }; - var session = (A2AAgentSession)await this._agent.GetNewSessionAsync(); + var session = (A2AAgentSession)await this._agent.CreateSessionAsync(); session.TaskId = "task-123"; // Act @@ -613,7 +613,7 @@ public async Task RunStreamingAsync_WithAgentTask_UpdatesSessionTaskIdAsync() Status = new() { State = TaskState.Submitted } }; - var session = await this._agent.GetNewSessionAsync(); + var session = await this._agent.CreateSessionAsync(); // Act await foreach (var _ in this._agent.RunStreamingAsync("Start a task", session)) @@ -686,7 +686,7 @@ public async Task RunStreamingAsync_WithAgentTask_YieldsResponseUpdateAsync() ] }; - var session = await this._agent.GetNewSessionAsync(); + var session = await this._agent.CreateSessionAsync(); // Act var updates = new List(); @@ -725,7 +725,7 @@ public async Task RunStreamingAsync_WithTaskStatusUpdateEvent_YieldsResponseUpda Status = new() { State = TaskState.Working } }; - var session = await this._agent.GetNewSessionAsync(); + var session = await this._agent.CreateSessionAsync(); // Act var updates = new List(); @@ -768,7 +768,7 @@ public async Task RunStreamingAsync_WithTaskArtifactUpdateEvent_YieldsResponseUp } }; - var session = await this._agent.GetNewSessionAsync(); + var session = await this._agent.CreateSessionAsync(); // Act var updates = new List(); diff --git a/dotnet/tests/Microsoft.Agents.AI.AGUI.UnitTests/AGUIChatClientTests.cs b/dotnet/tests/Microsoft.Agents.AI.AGUI.UnitTests/AGUIChatClientTests.cs index 260e6483dd..decfb93a31 100644 --- a/dotnet/tests/Microsoft.Agents.AI.AGUI.UnitTests/AGUIChatClientTests.cs +++ b/dotnet/tests/Microsoft.Agents.AI.AGUI.UnitTests/AGUIChatClientTests.cs @@ -228,7 +228,7 @@ public async Task RunStreamingAsync_ReturnsStreamingUpdates_AfterCompletionAsync var chatClient = new AGUIChatClient(httpClient, "http://localhost/agent", null, AGUIJsonSerializerContext.Default.Options); AIAgent agent = chatClient.AsAIAgent(instructions: null, name: "agent1", description: "Test agent", tools: []); - AgentSession session = await agent.GetNewSessionAsync(); + AgentSession session = await agent.CreateSessionAsync(); List messages = [new ChatMessage(ChatRole.User, "Hello")]; // Act @@ -250,7 +250,7 @@ public async Task DeserializeSession_WithValidState_ReturnsChatClientAgentSessio using var httpClient = new HttpClient(); var chatClient = new AGUIChatClient(httpClient, "http://localhost/agent", null, AGUIJsonSerializerContext.Default.Options); AIAgent agent = chatClient.AsAIAgent(instructions: null, name: "agent1", description: "Test agent", tools: []); - AgentSession originalSession = await agent.GetNewSessionAsync(); + AgentSession originalSession = await agent.CreateSessionAsync(); JsonElement serialized = originalSession.Serialize(); // Act @@ -487,7 +487,7 @@ public async Task RunStreamingAsync_UpdatesSessionWithToolMessages_AfterCompleti var chatClient = new AGUIChatClient(httpClient, "http://localhost/agent", null, AGUIJsonSerializerContext.Default.Options); AIAgent agent = chatClient.AsAIAgent(instructions: null, name: "agent1", description: "Test agent", tools: [testTool]); - AgentSession session = await agent.GetNewSessionAsync(); + AgentSession session = await agent.CreateSessionAsync(); List messages = [new ChatMessage(ChatRole.User, "Test")]; // Act diff --git a/dotnet/tests/Microsoft.Agents.AI.Abstractions.UnitTests/AIAgentTests.cs b/dotnet/tests/Microsoft.Agents.AI.Abstractions.UnitTests/AIAgentTests.cs index 4b872f0da1..17445eaffa 100644 --- a/dotnet/tests/Microsoft.Agents.AI.Abstractions.UnitTests/AIAgentTests.cs +++ b/dotnet/tests/Microsoft.Agents.AI.Abstractions.UnitTests/AIAgentTests.cs @@ -378,7 +378,7 @@ public MockAgent(string? id = null) protected override string? IdCore { get; } - public override async ValueTask GetNewSessionAsync(CancellationToken cancellationToken = default) + public override async ValueTask CreateSessionAsync(CancellationToken cancellationToken = default) => throw new NotImplementedException(); public override async ValueTask DeserializeSessionAsync(JsonElement serializedSession, JsonSerializerOptions? jsonSerializerOptions = null, CancellationToken cancellationToken = default) diff --git a/dotnet/tests/Microsoft.Agents.AI.Abstractions.UnitTests/DelegatingAIAgentTests.cs b/dotnet/tests/Microsoft.Agents.AI.Abstractions.UnitTests/DelegatingAIAgentTests.cs index 5be491213b..6320d9c900 100644 --- a/dotnet/tests/Microsoft.Agents.AI.Abstractions.UnitTests/DelegatingAIAgentTests.cs +++ b/dotnet/tests/Microsoft.Agents.AI.Abstractions.UnitTests/DelegatingAIAgentTests.cs @@ -35,7 +35,7 @@ public DelegatingAIAgentTests() this._innerAgentMock.Protected().SetupGet("IdCore").Returns("test-agent-id"); this._innerAgentMock.Setup(x => x.Name).Returns("Test Agent"); this._innerAgentMock.Setup(x => x.Description).Returns("Test Description"); - this._innerAgentMock.Setup(x => x.GetNewSessionAsync()).ReturnsAsync(this._testSession); + this._innerAgentMock.Setup(x => x.CreateSessionAsync()).ReturnsAsync(this._testSession); this._innerAgentMock .Protected() @@ -132,17 +132,17 @@ public void Description_DelegatesToInnerAgent() #region Method Delegation Tests /// - /// Verify that GetNewSessionAsync delegates to inner agent. + /// Verify that CreateSessionAsync delegates to inner agent. /// [Fact] - public async Task GetNewSessionAsync_DelegatesToInnerAgentAsync() + public async Task CreateSessionAsync_DelegatesToInnerAgentAsync() { // Act - var session = await this._delegatingAgent.GetNewSessionAsync(); + var session = await this._delegatingAgent.CreateSessionAsync(); // Assert Assert.Same(this._testSession, session); - this._innerAgentMock.Verify(x => x.GetNewSessionAsync(), Times.Once); + this._innerAgentMock.Verify(x => x.CreateSessionAsync(), Times.Once); } /// 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 c26be5822c..d5072a8f5f 100644 --- a/dotnet/tests/Microsoft.Agents.AI.Anthropic.UnitTests/Extensions/AnthropicBetaServiceExtensionsTests.cs +++ b/dotnet/tests/Microsoft.Agents.AI.Anthropic.UnitTests/Extensions/AnthropicBetaServiceExtensionsTests.cs @@ -252,7 +252,7 @@ public async Task CreateAIAgent_WithExplicitMaxTokens_UsesProvidedValueAsync() defaultMaxTokens: 8192); // Invoke the agent to trigger the request - var session = await agent.GetNewSessionAsync(); + var session = await agent.CreateSessionAsync(); try { await agent.RunAsync("Test message", session); 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 4a61a699fc..10cbd6e369 100644 --- a/dotnet/tests/Microsoft.Agents.AI.Anthropic.UnitTests/Extensions/AnthropicClientExtensionsTests.cs +++ b/dotnet/tests/Microsoft.Agents.AI.Anthropic.UnitTests/Extensions/AnthropicClientExtensionsTests.cs @@ -319,7 +319,7 @@ public async Task CreateAIAgent_WithExplicitMaxTokens_UsesProvidedValueAsync() defaultMaxTokens: 8192); // Invoke the agent to trigger the request - var session = await agent.GetNewSessionAsync(); + var session = await agent.CreateSessionAsync(); try { await agent.RunAsync("Test message", session); diff --git a/dotnet/tests/Microsoft.Agents.AI.AzureAI.UnitTests/AzureAIProjectChatClientTests.cs b/dotnet/tests/Microsoft.Agents.AI.AzureAI.UnitTests/AzureAIProjectChatClientTests.cs index 483b81fa1d..9cc340ef5e 100644 --- a/dotnet/tests/Microsoft.Agents.AI.AzureAI.UnitTests/AzureAIProjectChatClientTests.cs +++ b/dotnet/tests/Microsoft.Agents.AI.AzureAI.UnitTests/AzureAIProjectChatClientTests.cs @@ -53,7 +53,7 @@ public async Task ChatClient_UsesDefaultConversationIdAsync() }); // Act - var session = await agent.GetNewSessionAsync(); + var session = await agent.CreateSessionAsync(); await agent.RunAsync("Hello", session); Assert.True(requestTriggered); @@ -102,7 +102,7 @@ public async Task ChatClient_UsesPerRequestConversationId_WhenNoDefaultConversat }); // Act - var session = await agent.GetNewSessionAsync(); + var session = await agent.CreateSessionAsync(); await agent.RunAsync("Hello", session, options: new ChatClientAgentRunOptions() { ChatOptions = new() { ConversationId = "conv_12345" } }); Assert.True(requestTriggered); @@ -151,7 +151,7 @@ public async Task ChatClient_UsesPerRequestConversationId_EvenWhenDefaultConvers }); // Act - var session = await agent.GetNewSessionAsync(); + var session = await agent.CreateSessionAsync(); await agent.RunAsync("Hello", session, options: new ChatClientAgentRunOptions() { ChatOptions = new() { ConversationId = "conv_12345" } }); Assert.True(requestTriggered); @@ -200,7 +200,7 @@ public async Task ChatClient_UsesPreviousResponseId_WhenConversationIsNotPrefixe }); // Act - var session = await agent.GetNewSessionAsync(); + var session = await agent.CreateSessionAsync(); await agent.RunAsync("Hello", session, options: new ChatClientAgentRunOptions() { ChatOptions = new() { ConversationId = "resp_0888a" } }); Assert.True(requestTriggered); diff --git a/dotnet/tests/Microsoft.Agents.AI.Declarative.UnitTests/AggregatorPromptAgentFactoryTests.cs b/dotnet/tests/Microsoft.Agents.AI.Declarative.UnitTests/AggregatorPromptAgentFactoryTests.cs index 2059eceeb6..930557ab79 100644 --- a/dotnet/tests/Microsoft.Agents.AI.Declarative.UnitTests/AggregatorPromptAgentFactoryTests.cs +++ b/dotnet/tests/Microsoft.Agents.AI.Declarative.UnitTests/AggregatorPromptAgentFactoryTests.cs @@ -71,7 +71,7 @@ public override ValueTask DeserializeSessionAsync(JsonElement seri throw new NotImplementedException(); } - public override ValueTask GetNewSessionAsync(CancellationToken cancellationToken = default) + public override ValueTask CreateSessionAsync(CancellationToken cancellationToken = default) { throw new NotImplementedException(); } diff --git a/dotnet/tests/Microsoft.Agents.AI.DurableTask.IntegrationTests/AgentEntityTests.cs b/dotnet/tests/Microsoft.Agents.AI.DurableTask.IntegrationTests/AgentEntityTests.cs index 87774d9223..fe20b2e843 100644 --- a/dotnet/tests/Microsoft.Agents.AI.DurableTask.IntegrationTests/AgentEntityTests.cs +++ b/dotnet/tests/Microsoft.Agents.AI.DurableTask.IntegrationTests/AgentEntityTests.cs @@ -51,7 +51,7 @@ public async Task EntityNamePrefixAsync() // A proxy agent is needed to call the hosted test agent AIAgent simpleAgentProxy = simpleAgent.AsDurableAgentProxy(testHelper.Services); - AgentSession session = await simpleAgentProxy.GetNewSessionAsync(this.TestTimeoutToken); + AgentSession session = await simpleAgentProxy.CreateSessionAsync(this.TestTimeoutToken); DurableTaskClient client = testHelper.GetClient(); @@ -98,7 +98,7 @@ public async Task RunAgentMethodNamesAllWorkAsync(string runAgentMethodName) // A proxy agent is needed to call the hosted test agent AIAgent simpleAgentProxy = simpleAgent.AsDurableAgentProxy(testHelper.Services); - AgentSession session = await simpleAgentProxy.GetNewSessionAsync(this.TestTimeoutToken); + AgentSession session = await simpleAgentProxy.CreateSessionAsync(this.TestTimeoutToken); DurableTaskClient client = testHelper.GetClient(); @@ -184,7 +184,7 @@ private sealed class TestOrchestrator : TaskOrchestrator public override async Task RunAsync(TaskOrchestrationContext context, string input) { DurableAIAgent writer = context.GetAgent("TestAgent"); - AgentSession writerSession = await writer.GetNewSessionAsync(); + AgentSession writerSession = await writer.CreateSessionAsync(); await writer.RunAsync( message: context.GetInput()!, diff --git a/dotnet/tests/Microsoft.Agents.AI.DurableTask.IntegrationTests/ExternalClientTests.cs b/dotnet/tests/Microsoft.Agents.AI.DurableTask.IntegrationTests/ExternalClientTests.cs index 2683047acb..d48e8c0c28 100644 --- a/dotnet/tests/Microsoft.Agents.AI.DurableTask.IntegrationTests/ExternalClientTests.cs +++ b/dotnet/tests/Microsoft.Agents.AI.DurableTask.IntegrationTests/ExternalClientTests.cs @@ -51,7 +51,7 @@ public async Task SimplePromptAsync() AIAgent simpleAgentProxy = simpleAgent.AsDurableAgentProxy(testHelper.Services); // Act: send a prompt to the agent and wait for a response - AgentSession session = await simpleAgentProxy.GetNewSessionAsync(this.TestTimeoutToken); + AgentSession session = await simpleAgentProxy.CreateSessionAsync(this.TestTimeoutToken); await simpleAgentProxy.RunAsync( message: "Hello!", session, @@ -156,7 +156,7 @@ async Task RunWorkflowAsync(TaskOrchestrationContext context, string nam { // 1. Get agent and create a session DurableAIAgent agent = context.GetAgent("SimpleAgent"); - AgentSession session = await agent.GetNewSessionAsync(this.TestTimeoutToken); + AgentSession session = await agent.CreateSessionAsync(this.TestTimeoutToken); // 2. Call an agent and tell it my name await agent.RunAsync($"My name is {name}.", session); @@ -194,7 +194,7 @@ async Task RunWorkflowAsync(TaskOrchestrationContext context, string nam AIAgent workflowManagerAgentProxy = testHelper.Services.GetDurableAgentProxy("WorkflowAgent"); // Act: send a prompt to the agent - AgentSession session = await workflowManagerAgentProxy.GetNewSessionAsync(this.TestTimeoutToken); + AgentSession session = await workflowManagerAgentProxy.CreateSessionAsync(this.TestTimeoutToken); await workflowManagerAgentProxy.RunAsync( message: "Start a greeting workflow for \"John Doe\".", session, diff --git a/dotnet/tests/Microsoft.Agents.AI.DurableTask.IntegrationTests/TimeToLiveTests.cs b/dotnet/tests/Microsoft.Agents.AI.DurableTask.IntegrationTests/TimeToLiveTests.cs index 306daa5682..f9f008c1c2 100644 --- a/dotnet/tests/Microsoft.Agents.AI.DurableTask.IntegrationTests/TimeToLiveTests.cs +++ b/dotnet/tests/Microsoft.Agents.AI.DurableTask.IntegrationTests/TimeToLiveTests.cs @@ -55,7 +55,7 @@ public async Task EntityExpiresAfterTTLAsync() }); AIAgent agentProxy = simpleAgent.AsDurableAgentProxy(testHelper.Services); - AgentSession session = await agentProxy.GetNewSessionAsync(this.TestTimeoutToken); + AgentSession session = await agentProxy.CreateSessionAsync(this.TestTimeoutToken); DurableTaskClient client = testHelper.GetClient(); AgentSessionId sessionId = session.GetService(); @@ -120,7 +120,7 @@ public async Task EntityTTLResetsOnInteractionAsync() }); AIAgent agentProxy = simpleAgent.AsDurableAgentProxy(testHelper.Services); - AgentSession session = await agentProxy.GetNewSessionAsync(this.TestTimeoutToken); + AgentSession session = await agentProxy.CreateSessionAsync(this.TestTimeoutToken); DurableTaskClient client = testHelper.GetClient(); AgentSessionId sessionId = session.GetService(); diff --git a/dotnet/tests/Microsoft.Agents.AI.GitHub.Copilot.IntegrationTests/GitHubCopilotAgentTests.cs b/dotnet/tests/Microsoft.Agents.AI.GitHub.Copilot.IntegrationTests/GitHubCopilotAgentTests.cs index 985439bc46..855e9b4037 100644 --- a/dotnet/tests/Microsoft.Agents.AI.GitHub.Copilot.IntegrationTests/GitHubCopilotAgentTests.cs +++ b/dotnet/tests/Microsoft.Agents.AI.GitHub.Copilot.IntegrationTests/GitHubCopilotAgentTests.cs @@ -96,7 +96,7 @@ public async Task RunAsync_WithSession_MaintainsContextAsync() client, instructions: "You are a helpful assistant. Keep your answers short."); - AgentSession session = await agent.GetNewSessionAsync(); + AgentSession session = await agent.CreateSessionAsync(); // Act - First turn AgentResponse response1 = await agent.RunAsync("My name is Alice.", session); @@ -123,7 +123,7 @@ public async Task RunAsync_WithSessionResume_ContinuesConversationAsync() client1, instructions: "You are a helpful assistant. Keep your answers short."); - AgentSession session1 = await agent1.GetNewSessionAsync(); + AgentSession session1 = await agent1.CreateSessionAsync(); await agent1.RunAsync("Remember this number: 42.", session1); sessionId = ((GitHubCopilotAgentSession)session1).SessionId; @@ -137,7 +137,7 @@ public async Task RunAsync_WithSessionResume_ContinuesConversationAsync() client2, instructions: "You are a helpful assistant. Keep your answers short."); - AgentSession session2 = await agent2.GetNewSessionAsync(sessionId); + AgentSession session2 = await agent2.CreateSessionAsync(sessionId); AgentResponse response = await agent2.RunAsync("What number did I ask you to remember?", session2); // Assert diff --git a/dotnet/tests/Microsoft.Agents.AI.GitHub.Copilot.UnitTests/GitHubCopilotAgentTests.cs b/dotnet/tests/Microsoft.Agents.AI.GitHub.Copilot.UnitTests/GitHubCopilotAgentTests.cs index 797325e93f..e80990de1b 100644 --- a/dotnet/tests/Microsoft.Agents.AI.GitHub.Copilot.UnitTests/GitHubCopilotAgentTests.cs +++ b/dotnet/tests/Microsoft.Agents.AI.GitHub.Copilot.UnitTests/GitHubCopilotAgentTests.cs @@ -55,14 +55,14 @@ public void Constructor_WithDefaultParameters_UsesBaseProperties() } [Fact] - public async Task GetNewSessionAsync_ReturnsGitHubCopilotAgentSessionAsync() + public async Task CreateSessionAsync_ReturnsGitHubCopilotAgentSessionAsync() { // Arrange CopilotClient copilotClient = new(new CopilotClientOptions { AutoStart = false }); var agent = new GitHubCopilotAgent(copilotClient, ownsClient: false, tools: null); // Act - var session = await agent.GetNewSessionAsync(); + var session = await agent.CreateSessionAsync(); // Assert Assert.NotNull(session); @@ -70,7 +70,7 @@ public async Task GetNewSessionAsync_ReturnsGitHubCopilotAgentSessionAsync() } [Fact] - public async Task GetNewSessionAsync_WithSessionId_ReturnsSessionWithSessionIdAsync() + public async Task CreateSessionAsync_WithSessionId_ReturnsSessionWithSessionIdAsync() { // Arrange CopilotClient copilotClient = new(new CopilotClientOptions { AutoStart = false }); @@ -78,7 +78,7 @@ public async Task GetNewSessionAsync_WithSessionId_ReturnsSessionWithSessionIdAs const string TestSessionId = "test-session-id"; // Act - var session = await agent.GetNewSessionAsync(TestSessionId); + var session = await agent.CreateSessionAsync(TestSessionId); // Assert Assert.NotNull(session); diff --git a/dotnet/tests/Microsoft.Agents.AI.Hosting.A2A.UnitTests/AIAgentExtensionsTests.cs b/dotnet/tests/Microsoft.Agents.AI.Hosting.A2A.UnitTests/AIAgentExtensionsTests.cs index 4b9cbce2c4..f98dc84c81 100644 --- a/dotnet/tests/Microsoft.Agents.AI.Hosting.A2A.UnitTests/AIAgentExtensionsTests.cs +++ b/dotnet/tests/Microsoft.Agents.AI.Hosting.A2A.UnitTests/AIAgentExtensionsTests.cs @@ -175,7 +175,7 @@ private static Mock CreateAgentMock(Action optionsCal { Mock agentMock = new() { CallBase = true }; agentMock.SetupGet(x => x.Name).Returns("TestAgent"); - agentMock.Setup(x => x.GetNewSessionAsync()).ReturnsAsync(new TestAgentSession()); + agentMock.Setup(x => x.CreateSessionAsync()).ReturnsAsync(new TestAgentSession()); agentMock .Protected() .Setup>("RunCoreAsync", @@ -194,7 +194,7 @@ private static Mock CreateAgentMockWithResponse(AgentResponse response) { Mock agentMock = new() { CallBase = true }; agentMock.SetupGet(x => x.Name).Returns("TestAgent"); - agentMock.Setup(x => x.GetNewSessionAsync()).ReturnsAsync(new TestAgentSession()); + agentMock.Setup(x => x.CreateSessionAsync()).ReturnsAsync(new TestAgentSession()); agentMock .Protected() .Setup>("RunCoreAsync", 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 da139ea1a7..aee568204e 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 @@ -31,7 +31,7 @@ public async Task ClientReceivesStreamedAssistantMessageAsync() await this.SetupTestServerAsync(); var chatClient = new AGUIChatClient(this._client!, "", null); AIAgent agent = chatClient.AsAIAgent(instructions: null, name: "assistant", description: "Sample assistant", tools: []); - ChatClientAgentSession? session = (ChatClientAgentSession)await agent.GetNewSessionAsync(); + ChatClientAgentSession? session = (ChatClientAgentSession)await agent.CreateSessionAsync(); ChatMessage userMessage = new(ChatRole.User, "hello"); List updates = []; @@ -62,7 +62,7 @@ public async Task ClientReceivesRunLifecycleEventsAsync() await this.SetupTestServerAsync(); var chatClient = new AGUIChatClient(this._client!, "", null); AIAgent agent = chatClient.AsAIAgent(instructions: null, name: "assistant", description: "Sample assistant", tools: []); - ChatClientAgentSession? session = (ChatClientAgentSession)await agent.GetNewSessionAsync(); + ChatClientAgentSession? session = (ChatClientAgentSession)await agent.CreateSessionAsync(); ChatMessage userMessage = new(ChatRole.User, "test"); List updates = []; @@ -106,7 +106,7 @@ public async Task RunAsyncAggregatesStreamingUpdatesAsync() await this.SetupTestServerAsync(); var chatClient = new AGUIChatClient(this._client!, "", null); AIAgent agent = chatClient.AsAIAgent(instructions: null, name: "assistant", description: "Sample assistant", tools: []); - ChatClientAgentSession? session = (ChatClientAgentSession)await agent.GetNewSessionAsync(); + ChatClientAgentSession? session = (ChatClientAgentSession)await agent.CreateSessionAsync(); ChatMessage userMessage = new(ChatRole.User, "hello"); // Act @@ -125,7 +125,7 @@ public async Task MultiTurnConversationPreservesAllMessagesInSessionAsync() await this.SetupTestServerAsync(); var chatClient = new AGUIChatClient(this._client!, "", null); AIAgent agent = chatClient.AsAIAgent(instructions: null, name: "assistant", description: "Sample assistant", tools: []); - ChatClientAgentSession chatClientSession = (ChatClientAgentSession)await agent.GetNewSessionAsync(); + ChatClientAgentSession chatClientSession = (ChatClientAgentSession)await agent.CreateSessionAsync(); ChatMessage firstUserMessage = new(ChatRole.User, "First question"); // Act - First turn @@ -169,7 +169,7 @@ public async Task AgentSendsMultipleMessagesInOneTurnAsync() await this.SetupTestServerAsync(useMultiMessageAgent: true); var chatClient = new AGUIChatClient(this._client!, "", null); AIAgent agent = chatClient.AsAIAgent(instructions: null, name: "assistant", description: "Sample assistant", tools: []); - ChatClientAgentSession chatClientSession = (ChatClientAgentSession)await agent.GetNewSessionAsync(); + ChatClientAgentSession chatClientSession = (ChatClientAgentSession)await agent.CreateSessionAsync(); ChatMessage userMessage = new(ChatRole.User, "Tell me a story"); List updates = []; @@ -201,7 +201,7 @@ public async Task UserSendsMultipleMessagesAtOnceAsync() await this.SetupTestServerAsync(); var chatClient = new AGUIChatClient(this._client!, "", null); AIAgent agent = chatClient.AsAIAgent(instructions: null, name: "assistant", description: "Sample assistant", tools: []); - ChatClientAgentSession chatClientSession = (ChatClientAgentSession)await agent.GetNewSessionAsync(); + ChatClientAgentSession chatClientSession = (ChatClientAgentSession)await agent.CreateSessionAsync(); // Multiple user messages sent in one turn ChatMessage[] userMessages = @@ -280,7 +280,7 @@ internal sealed class FakeChatClientAgent : AIAgent public override string? Description => "A fake agent for testing"; - public override ValueTask GetNewSessionAsync(CancellationToken cancellationToken = default) => + public override ValueTask CreateSessionAsync(CancellationToken cancellationToken = default) => new(new FakeInMemoryAgentSession()); public override ValueTask DeserializeSessionAsync(JsonElement serializedSession, JsonSerializerOptions? jsonSerializerOptions = null, CancellationToken cancellationToken = default) => @@ -344,7 +344,7 @@ internal sealed class FakeMultiMessageAgent : AIAgent public override string? Description => "A fake agent that sends multiple messages for testing"; - public override ValueTask GetNewSessionAsync(CancellationToken cancellationToken = default) => + public override ValueTask CreateSessionAsync(CancellationToken cancellationToken = default) => new(new FakeInMemoryAgentSession()); public override ValueTask DeserializeSessionAsync(JsonElement serializedSession, JsonSerializerOptions? jsonSerializerOptions = null, CancellationToken cancellationToken = default) => diff --git a/dotnet/tests/Microsoft.Agents.AI.Hosting.AGUI.AspNetCore.IntegrationTests/ForwardedPropertiesTests.cs b/dotnet/tests/Microsoft.Agents.AI.Hosting.AGUI.AspNetCore.IntegrationTests/ForwardedPropertiesTests.cs index d66a63b854..92c83e06f5 100644 --- a/dotnet/tests/Microsoft.Agents.AI.Hosting.AGUI.AspNetCore.IntegrationTests/ForwardedPropertiesTests.cs +++ b/dotnet/tests/Microsoft.Agents.AI.Hosting.AGUI.AspNetCore.IntegrationTests/ForwardedPropertiesTests.cs @@ -334,7 +334,7 @@ protected override async IAsyncEnumerable RunCoreStreamingA await Task.CompletedTask; } - public override ValueTask GetNewSessionAsync(CancellationToken cancellationToken = default) => + public override ValueTask CreateSessionAsync(CancellationToken cancellationToken = default) => new(new FakeInMemoryAgentSession()); public override ValueTask DeserializeSessionAsync(JsonElement serializedSession, JsonSerializerOptions? jsonSerializerOptions = null, CancellationToken cancellationToken = default) => 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 b80931db23..2d8742e930 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 @@ -34,7 +34,7 @@ public async Task StateSnapshot_IsReturnedAsDataContent_WithCorrectMediaTypeAsyn await this.SetupTestServerAsync(fakeAgent); var chatClient = new AGUIChatClient(this._client!, "", null); AIAgent agent = chatClient.AsAIAgent(instructions: null, name: "assistant", description: "Sample assistant", tools: []); - ChatClientAgentSession? session = (ChatClientAgentSession)await agent.GetNewSessionAsync(); + ChatClientAgentSession? session = (ChatClientAgentSession)await agent.CreateSessionAsync(); string stateJson = JsonSerializer.Serialize(initialState); byte[] stateBytes = System.Text.Encoding.UTF8.GetBytes(stateJson); @@ -77,7 +77,7 @@ public async Task StateSnapshot_HasCorrectAdditionalPropertiesAsync() await this.SetupTestServerAsync(fakeAgent); var chatClient = new AGUIChatClient(this._client!, "", null); AIAgent agent = chatClient.AsAIAgent(instructions: null, name: "assistant", description: "Sample assistant", tools: []); - ChatClientAgentSession? session = (ChatClientAgentSession)await agent.GetNewSessionAsync(); + ChatClientAgentSession? session = (ChatClientAgentSession)await agent.CreateSessionAsync(); string stateJson = JsonSerializer.Serialize(initialState); byte[] stateBytes = System.Text.Encoding.UTF8.GetBytes(stateJson); @@ -119,7 +119,7 @@ public async Task ComplexState_WithNestedObjectsAndArrays_RoundTripsCorrectlyAsy await this.SetupTestServerAsync(fakeAgent); var chatClient = new AGUIChatClient(this._client!, "", null); AIAgent agent = chatClient.AsAIAgent(instructions: null, name: "assistant", description: "Sample assistant", tools: []); - ChatClientAgentSession? session = (ChatClientAgentSession)await agent.GetNewSessionAsync(); + ChatClientAgentSession? session = (ChatClientAgentSession)await agent.CreateSessionAsync(); string stateJson = JsonSerializer.Serialize(complexState); byte[] stateBytes = System.Text.Encoding.UTF8.GetBytes(stateJson); @@ -159,7 +159,7 @@ public async Task StateSnapshot_CanBeUsedInSubsequentRequest_ForStateRoundTripAs await this.SetupTestServerAsync(fakeAgent); var chatClient = new AGUIChatClient(this._client!, "", null); AIAgent agent = chatClient.AsAIAgent(instructions: null, name: "assistant", description: "Sample assistant", tools: []); - ChatClientAgentSession? session = (ChatClientAgentSession)await agent.GetNewSessionAsync(); + ChatClientAgentSession? session = (ChatClientAgentSession)await agent.CreateSessionAsync(); string stateJson = JsonSerializer.Serialize(initialState); byte[] stateBytes = System.Text.Encoding.UTF8.GetBytes(stateJson); @@ -210,7 +210,7 @@ public async Task WithoutState_AgentBehavesNormally_NoStateSnapshotReturnedAsync await this.SetupTestServerAsync(fakeAgent); var chatClient = new AGUIChatClient(this._client!, "", null); AIAgent agent = chatClient.AsAIAgent(instructions: null, name: "assistant", description: "Sample assistant", tools: []); - ChatClientAgentSession? session = (ChatClientAgentSession)await agent.GetNewSessionAsync(); + ChatClientAgentSession? session = (ChatClientAgentSession)await agent.CreateSessionAsync(); ChatMessage userMessage = new(ChatRole.User, "hello"); @@ -243,7 +243,7 @@ public async Task EmptyState_DoesNotTriggerStateHandlingAsync() await this.SetupTestServerAsync(fakeAgent); var chatClient = new AGUIChatClient(this._client!, "", null); AIAgent agent = chatClient.AsAIAgent(instructions: null, name: "assistant", description: "Sample assistant", tools: []); - ChatClientAgentSession? session = (ChatClientAgentSession)await agent.GetNewSessionAsync(); + ChatClientAgentSession? session = (ChatClientAgentSession)await agent.CreateSessionAsync(); string stateJson = JsonSerializer.Serialize(emptyState); byte[] stateBytes = System.Text.Encoding.UTF8.GetBytes(stateJson); @@ -280,7 +280,7 @@ public async Task NonStreamingRunAsync_WithState_ReturnsStateInResponseAsync() await this.SetupTestServerAsync(fakeAgent); var chatClient = new AGUIChatClient(this._client!, "", null); AIAgent agent = chatClient.AsAIAgent(instructions: null, name: "assistant", description: "Sample assistant", tools: []); - ChatClientAgentSession? session = (ChatClientAgentSession)await agent.GetNewSessionAsync(); + ChatClientAgentSession? session = (ChatClientAgentSession)await agent.CreateSessionAsync(); string stateJson = JsonSerializer.Serialize(initialState); byte[] stateBytes = System.Text.Encoding.UTF8.GetBytes(stateJson); @@ -417,7 +417,7 @@ stateObj is JsonElement state && await Task.CompletedTask; } - public override ValueTask GetNewSessionAsync(CancellationToken cancellationToken = default) => + public override ValueTask CreateSessionAsync(CancellationToken cancellationToken = default) => new(new FakeInMemoryAgentSession()); public override ValueTask DeserializeSessionAsync(JsonElement serializedSession, JsonSerializerOptions? jsonSerializerOptions = null, CancellationToken cancellationToken = default) => 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 2257d0920b..d512af28cd 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 @@ -45,7 +45,7 @@ public async Task ServerTriggersSingleFunctionCallAsync() await this.SetupTestServerAsync(serverTools: [serverTool]); var chatClient = new AGUIChatClient(this._client!, "", null); AIAgent agent = chatClient.AsAIAgent(instructions: null, name: "assistant", description: "Test assistant", tools: []); - AgentSession session = await agent.GetNewSessionAsync(); + AgentSession session = await agent.CreateSessionAsync(); ChatMessage userMessage = new(ChatRole.User, "Call the server function"); List updates = []; @@ -93,7 +93,7 @@ public async Task ServerTriggersMultipleFunctionCallsAsync() await this.SetupTestServerAsync(serverTools: [getWeatherTool, getTimeTool]); var chatClient = new AGUIChatClient(this._client!, "", null); AIAgent agent = chatClient.AsAIAgent(instructions: null, name: "assistant", description: "Test assistant", tools: []); - AgentSession session = await agent.GetNewSessionAsync(); + AgentSession session = await agent.CreateSessionAsync(); ChatMessage userMessage = new(ChatRole.User, "What's the weather and time?"); List updates = []; @@ -134,7 +134,7 @@ public async Task ClientTriggersSingleFunctionCallAsync() await this.SetupTestServerAsync(); var chatClient = new AGUIChatClient(this._client!, "", null); AIAgent agent = chatClient.AsAIAgent(instructions: null, name: "assistant", description: "Test assistant", tools: [clientTool]); - AgentSession session = await agent.GetNewSessionAsync(); + AgentSession session = await agent.CreateSessionAsync(); ChatMessage userMessage = new(ChatRole.User, "Call the client function"); List updates = []; @@ -182,7 +182,7 @@ public async Task ClientTriggersMultipleFunctionCallsAsync() await this.SetupTestServerAsync(); var chatClient = new AGUIChatClient(this._client!, "", null); AIAgent agent = chatClient.AsAIAgent(instructions: null, name: "assistant", description: "Test assistant", tools: [calculateTool, formatTool]); - AgentSession session = await agent.GetNewSessionAsync(); + AgentSession session = await agent.CreateSessionAsync(); ChatMessage userMessage = new(ChatRole.User, "Calculate 5 + 3 and format 'hello'"); List updates = []; @@ -233,7 +233,7 @@ public async Task ServerAndClientTriggerFunctionCallsSimultaneouslyAsync() await this.SetupTestServerAsync(serverTools: [serverTool]); var chatClient = new AGUIChatClient(this._client!, "", null); AIAgent agent = chatClient.AsAIAgent(instructions: null, name: "assistant", description: "Test assistant", tools: [clientTool]); - AgentSession session = await agent.GetNewSessionAsync(); + AgentSession session = await agent.CreateSessionAsync(); ChatMessage userMessage = new(ChatRole.User, "Get both server and client data"); List updates = []; @@ -298,7 +298,7 @@ public async Task FunctionCallsPreserveCallIdAndNameAsync() await this.SetupTestServerAsync(serverTools: [testTool]); var chatClient = new AGUIChatClient(this._client!, "", null); AIAgent agent = chatClient.AsAIAgent(instructions: null, name: "assistant", description: "Test assistant", tools: []); - AgentSession session = await agent.GetNewSessionAsync(); + AgentSession session = await agent.CreateSessionAsync(); ChatMessage userMessage = new(ChatRole.User, "Call the test function"); List updates = []; @@ -342,7 +342,7 @@ public async Task ParallelFunctionCallsFromServerAreHandledCorrectlyAsync() await this.SetupTestServerAsync(serverTools: [func1, func2], triggerParallelCalls: true); var chatClient = new AGUIChatClient(this._client!, "", null); AIAgent agent = chatClient.AsAIAgent(instructions: null, name: "assistant", description: "Test assistant", tools: []); - AgentSession session = await agent.GetNewSessionAsync(); + AgentSession session = await agent.CreateSessionAsync(); ChatMessage userMessage = new(ChatRole.User, "Call both functions in parallel"); List updates = []; @@ -428,7 +428,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.AsAIAgent(instructions: null, name: "assistant", description: "Test assistant", tools: []); - AgentSession session = await agent.GetNewSessionAsync(); + AgentSession session = await agent.CreateSessionAsync(); ChatMessage userMessage = new(ChatRole.User, "Get server forecast for Seattle for 5 days"); List updates = []; @@ -474,7 +474,7 @@ public async Task ClientToolCallWithCustomArgumentsAsync() await this.SetupTestServerAsync(); var chatClient = new AGUIChatClient(this._client!, "", null, ClientJsonContext.Default.Options); AIAgent agent = chatClient.AsAIAgent(instructions: null, name: "assistant", description: "Test assistant", tools: [clientTool]); - AgentSession session = await agent.GetNewSessionAsync(); + AgentSession session = await agent.CreateSessionAsync(); ChatMessage userMessage = new(ChatRole.User, "Get client forecast for Portland with hourly data"); List updates = []; diff --git a/dotnet/tests/Microsoft.Agents.AI.Hosting.AGUI.AspNetCore.UnitTests/AGUIEndpointRouteBuilderExtensionsTests.cs b/dotnet/tests/Microsoft.Agents.AI.Hosting.AGUI.AspNetCore.UnitTests/AGUIEndpointRouteBuilderExtensionsTests.cs index 50972d3aa6..544002f34b 100644 --- a/dotnet/tests/Microsoft.Agents.AI.Hosting.AGUI.AspNetCore.UnitTests/AGUIEndpointRouteBuilderExtensionsTests.cs +++ b/dotnet/tests/Microsoft.Agents.AI.Hosting.AGUI.AspNetCore.UnitTests/AGUIEndpointRouteBuilderExtensionsTests.cs @@ -425,7 +425,7 @@ private sealed class MultiResponseAgent : AIAgent public override string? Description => "Agent that produces multiple text chunks"; - public override ValueTask GetNewSessionAsync(CancellationToken cancellationToken = default) => + public override ValueTask CreateSessionAsync(CancellationToken cancellationToken = default) => new(new TestInMemoryAgentSession()); public override ValueTask DeserializeSessionAsync(JsonElement serializedSession, JsonSerializerOptions? jsonSerializerOptions = null, CancellationToken cancellationToken = default) => @@ -515,7 +515,7 @@ private sealed class TestAgent : AIAgent public override string? Description => "Test agent"; - public override ValueTask GetNewSessionAsync(CancellationToken cancellationToken = default) => + public override ValueTask CreateSessionAsync(CancellationToken cancellationToken = default) => new(new TestInMemoryAgentSession()); public override ValueTask DeserializeSessionAsync(JsonElement serializedSession, JsonSerializerOptions? jsonSerializerOptions = null, CancellationToken cancellationToken = default) => diff --git a/dotnet/tests/Microsoft.Agents.AI.Hosting.AzureFunctions.UnitTests/TestAgent.cs b/dotnet/tests/Microsoft.Agents.AI.Hosting.AzureFunctions.UnitTests/TestAgent.cs index fd5753ed7e..a597b26304 100644 --- a/dotnet/tests/Microsoft.Agents.AI.Hosting.AzureFunctions.UnitTests/TestAgent.cs +++ b/dotnet/tests/Microsoft.Agents.AI.Hosting.AzureFunctions.UnitTests/TestAgent.cs @@ -11,7 +11,7 @@ internal sealed class TestAgent(string name, string description) : AIAgent public override string? Description => description; - public override ValueTask GetNewSessionAsync(CancellationToken cancellationToken = default) => new(new DummyAgentSession()); + public override ValueTask CreateSessionAsync(CancellationToken cancellationToken = default) => new(new DummyAgentSession()); public override ValueTask DeserializeSessionAsync( JsonElement serializedSession, diff --git a/dotnet/tests/Microsoft.Agents.AI.UnitTests/AgentExtensionsTests.cs b/dotnet/tests/Microsoft.Agents.AI.UnitTests/AgentExtensionsTests.cs index eea65444b8..569d2c421d 100644 --- a/dotnet/tests/Microsoft.Agents.AI.UnitTests/AgentExtensionsTests.cs +++ b/dotnet/tests/Microsoft.Agents.AI.UnitTests/AgentExtensionsTests.cs @@ -382,7 +382,7 @@ public TestAgent(string? name, string? description, Exception exceptionToThrow) this._exceptionToThrow = exceptionToThrow; } - public override ValueTask GetNewSessionAsync(CancellationToken cancellationToken = default) + public override ValueTask CreateSessionAsync(CancellationToken cancellationToken = default) => throw new NotImplementedException(); public override ValueTask DeserializeSessionAsync(JsonElement serializedSession, JsonSerializerOptions? jsonSerializerOptions = null, CancellationToken cancellationToken = default) diff --git a/dotnet/tests/Microsoft.Agents.AI.UnitTests/ChatClient/ChatClientAgentTests.cs b/dotnet/tests/Microsoft.Agents.AI.UnitTests/ChatClient/ChatClientAgentTests.cs index 6c2be9689a..e1ff5f8cbd 100644 --- a/dotnet/tests/Microsoft.Agents.AI.UnitTests/ChatClient/ChatClientAgentTests.cs +++ b/dotnet/tests/Microsoft.Agents.AI.UnitTests/ChatClient/ChatClientAgentTests.cs @@ -241,8 +241,8 @@ public async Task RunAsyncRetrievesMessagesFromSessionWhenSessionHasChatHistoryP ChatClientAgent agent = new(mockService.Object, options: new() { ChatOptions = new() { Instructions = "test instructions" } }); - // Create a session using the agent's GetNewSessionAsync method - var session = await agent.GetNewSessionAsync(); + // Create a session using the agent's CreateSessionAsync method + var session = await agent.CreateSessionAsync(); // Act await agent.RunAsync([new(ChatRole.User, "new message")], session: session); @@ -356,7 +356,7 @@ public async Task RunAsyncInvokesAIContextProviderAndUsesResultAsync() ChatClientAgent agent = new(mockService.Object, options: new() { AIContextProviderFactory = (_, _) => new(mockProvider.Object), ChatOptions = new() { Instructions = "base instructions", Tools = [AIFunctionFactory.Create(() => { }, "base function")] } }); // Act - var session = await agent.GetNewSessionAsync() as ChatClientAgentSession; + var session = await agent.CreateSessionAsync() as ChatClientAgentSession; await agent.RunAsync(requestMessages, session); // Assert @@ -1296,7 +1296,7 @@ public async Task RunStreamingAsyncUsesChatHistoryProviderWhenNoConversationIdRe }); // Act - ChatClientAgentSession? session = await agent.GetNewSessionAsync() as ChatClientAgentSession; + ChatClientAgentSession? session = await agent.CreateSessionAsync() as ChatClientAgentSession; await agent.RunStreamingAsync([new(ChatRole.User, "test")], session).ToListAsync(); // Assert @@ -1334,7 +1334,7 @@ public async Task RunStreamingAsyncThrowsWhenChatHistoryProviderFactoryProvidedA }); // Act & Assert - ChatClientAgentSession? session = await agent.GetNewSessionAsync() as ChatClientAgentSession; + ChatClientAgentSession? session = await agent.CreateSessionAsync() as ChatClientAgentSession; var exception = await Assert.ThrowsAsync(async () => await agent.RunStreamingAsync([new(ChatRole.User, "test")], session).ToListAsync()); Assert.Equal("Only the ConversationId or ChatHistoryProvider may be set, but not both and switching from one to another is not supported.", exception.Message); } @@ -1391,7 +1391,7 @@ public async Task RunStreamingAsyncInvokesAIContextProviderAndUsesResultAsync() }); // Act - var session = await agent.GetNewSessionAsync() as ChatClientAgentSession; + var session = await agent.CreateSessionAsync() as ChatClientAgentSession; var updates = agent.RunStreamingAsync(requestMessages, session); _ = await updates.ToAgentResponseAsync(); diff --git a/dotnet/tests/Microsoft.Agents.AI.UnitTests/ChatClient/ChatClientAgent_ChatHistoryManagementTests.cs b/dotnet/tests/Microsoft.Agents.AI.UnitTests/ChatClient/ChatClientAgent_ChatHistoryManagementTests.cs index e2b7313e7f..a854a76622 100644 --- a/dotnet/tests/Microsoft.Agents.AI.UnitTests/ChatClient/ChatClientAgent_ChatHistoryManagementTests.cs +++ b/dotnet/tests/Microsoft.Agents.AI.UnitTests/ChatClient/ChatClientAgent_ChatHistoryManagementTests.cs @@ -158,7 +158,7 @@ public async Task RunAsync_UsesDefaultInMemoryChatHistoryProvider_WhenNoConversa }); // Act - ChatClientAgentSession? session = await agent.GetNewSessionAsync() as ChatClientAgentSession; + ChatClientAgentSession? session = await agent.CreateSessionAsync() as ChatClientAgentSession; await agent.RunAsync([new(ChatRole.User, "test")], session); // Assert @@ -200,7 +200,7 @@ public async Task RunAsync_UsesChatHistoryProviderFactory_WhenProvidedAndNoConve }); // Act - ChatClientAgentSession? session = await agent.GetNewSessionAsync() as ChatClientAgentSession; + ChatClientAgentSession? session = await agent.CreateSessionAsync() as ChatClientAgentSession; await agent.RunAsync([new(ChatRole.User, "test")], session); // Assert @@ -248,7 +248,7 @@ public async Task RunAsync_NotifiesChatHistoryProvider_OnFailureAsync() }); // Act - ChatClientAgentSession? session = await agent.GetNewSessionAsync() as ChatClientAgentSession; + ChatClientAgentSession? session = await agent.CreateSessionAsync() as ChatClientAgentSession; await Assert.ThrowsAsync(() => agent.RunAsync([new(ChatRole.User, "test")], session)); // Assert @@ -282,7 +282,7 @@ public async Task RunAsync_Throws_WhenChatHistoryProviderFactoryProvidedAndConve }); // Act & Assert - ChatClientAgentSession? session = await agent.GetNewSessionAsync() as ChatClientAgentSession; + ChatClientAgentSession? session = await agent.CreateSessionAsync() as ChatClientAgentSession; InvalidOperationException exception = await Assert.ThrowsAsync(() => agent.RunAsync([new(ChatRole.User, "test")], session)); Assert.Equal("Only the ConversationId or ChatHistoryProvider may be set, but not both and switching from one to another is not supported.", exception.Message); } @@ -335,7 +335,7 @@ public async Task RunAsync_UsesOverrideChatHistoryProvider_WhenProvidedViaAdditi }); // Act - ChatClientAgentSession? session = await agent.GetNewSessionAsync() as ChatClientAgentSession; + ChatClientAgentSession? session = await agent.CreateSessionAsync() as ChatClientAgentSession; AdditionalPropertiesDictionary additionalProperties = new(); additionalProperties.Add(mockOverrideChatHistoryProvider.Object); await agent.RunAsync([new(ChatRole.User, "test")], session, options: new AgentRunOptions { AdditionalProperties = additionalProperties }); diff --git a/dotnet/tests/Microsoft.Agents.AI.UnitTests/ChatClient/ChatClientAgent_GetNewSessionTests.cs b/dotnet/tests/Microsoft.Agents.AI.UnitTests/ChatClient/ChatClientAgent_CreateSessionTests.cs similarity index 83% rename from dotnet/tests/Microsoft.Agents.AI.UnitTests/ChatClient/ChatClientAgent_GetNewSessionTests.cs rename to dotnet/tests/Microsoft.Agents.AI.UnitTests/ChatClient/ChatClientAgent_CreateSessionTests.cs index c48b303fa2..86220a6462 100644 --- a/dotnet/tests/Microsoft.Agents.AI.UnitTests/ChatClient/ChatClientAgent_GetNewSessionTests.cs +++ b/dotnet/tests/Microsoft.Agents.AI.UnitTests/ChatClient/ChatClientAgent_CreateSessionTests.cs @@ -7,12 +7,12 @@ namespace Microsoft.Agents.AI.UnitTests; /// -/// Contains unit tests for the ChatClientAgent.GetNewSessionAsync methods. +/// Contains unit tests for the ChatClientAgent.CreateSessionAsync methods. /// -public class ChatClientAgent_GetNewSessionTests +public class ChatClientAgent_CreateSessionTests { [Fact] - public async Task GetNewSession_UsesAIContextProviderFactory_IfProvidedAsync() + public async Task CreateSession_UsesAIContextProviderFactory_IfProvidedAsync() { // Arrange var mockChatClient = new Mock(); @@ -29,7 +29,7 @@ public async Task GetNewSession_UsesAIContextProviderFactory_IfProvidedAsync() }); // Act - var session = await agent.GetNewSessionAsync(); + var session = await agent.CreateSessionAsync(); // Assert Assert.True(factoryCalled, "AIContextProviderFactory was not called."); @@ -39,7 +39,7 @@ public async Task GetNewSession_UsesAIContextProviderFactory_IfProvidedAsync() } [Fact] - public async Task GetNewSession_UsesChatHistoryProviderFactory_IfProvidedAsync() + public async Task CreateSession_UsesChatHistoryProviderFactory_IfProvidedAsync() { // Arrange var mockChatClient = new Mock(); @@ -56,7 +56,7 @@ public async Task GetNewSession_UsesChatHistoryProviderFactory_IfProvidedAsync() }); // Act - var session = await agent.GetNewSessionAsync(); + var session = await agent.CreateSessionAsync(); // Assert Assert.True(factoryCalled, "ChatHistoryProviderFactory was not called."); @@ -66,7 +66,7 @@ public async Task GetNewSession_UsesChatHistoryProviderFactory_IfProvidedAsync() } [Fact] - public async Task GetNewSession_UsesChatHistoryProvider_FromTypedOverloadAsync() + public async Task CreateSession_UsesChatHistoryProvider_FromTypedOverloadAsync() { // Arrange var mockChatClient = new Mock(); @@ -74,7 +74,7 @@ public async Task GetNewSession_UsesChatHistoryProvider_FromTypedOverloadAsync() var agent = new ChatClientAgent(mockChatClient.Object); // Act - var session = await agent.GetNewSessionAsync(mockChatHistoryProvider.Object); + var session = await agent.CreateSessionAsync(mockChatHistoryProvider.Object); // Assert Assert.IsType(session); @@ -83,7 +83,7 @@ public async Task GetNewSession_UsesChatHistoryProvider_FromTypedOverloadAsync() } [Fact] - public async Task GetNewSession_UsesConversationId_FromTypedOverloadAsync() + public async Task CreateSession_UsesConversationId_FromTypedOverloadAsync() { // Arrange var mockChatClient = new Mock(); @@ -91,7 +91,7 @@ public async Task GetNewSession_UsesConversationId_FromTypedOverloadAsync() var agent = new ChatClientAgent(mockChatClient.Object); // Act - var session = await agent.GetNewSessionAsync(TestConversationId); + var session = await agent.CreateSessionAsync(TestConversationId); // Assert Assert.IsType(session); diff --git a/dotnet/tests/Microsoft.Agents.AI.UnitTests/ChatClient/ChatClientAgent_RunWithCustomOptionsTests.cs b/dotnet/tests/Microsoft.Agents.AI.UnitTests/ChatClient/ChatClientAgent_RunWithCustomOptionsTests.cs index cff5b6ba78..7a71871b02 100644 --- a/dotnet/tests/Microsoft.Agents.AI.UnitTests/ChatClient/ChatClientAgent_RunWithCustomOptionsTests.cs +++ b/dotnet/tests/Microsoft.Agents.AI.UnitTests/ChatClient/ChatClientAgent_RunWithCustomOptionsTests.cs @@ -30,7 +30,7 @@ public async Task RunAsync_WithSessionAndOptions_CallsBaseMethodAsync() It.IsAny())).ReturnsAsync(new ChatResponse([new(ChatRole.Assistant, "Response")])); ChatClientAgent agent = new(mockChatClient.Object); - AgentSession session = await agent.GetNewSessionAsync(); + AgentSession session = await agent.CreateSessionAsync(); ChatClientAgentRunOptions options = new(); // Act @@ -59,7 +59,7 @@ public async Task RunAsync_WithStringMessageAndOptions_CallsBaseMethodAsync() It.IsAny())).ReturnsAsync(new ChatResponse([new(ChatRole.Assistant, "Response")])); ChatClientAgent agent = new(mockChatClient.Object); - AgentSession session = await agent.GetNewSessionAsync(); + AgentSession session = await agent.CreateSessionAsync(); ChatClientAgentRunOptions options = new(); // Act @@ -88,7 +88,7 @@ public async Task RunAsync_WithChatMessageAndOptions_CallsBaseMethodAsync() It.IsAny())).ReturnsAsync(new ChatResponse([new(ChatRole.Assistant, "Response")])); ChatClientAgent agent = new(mockChatClient.Object); - AgentSession session = await agent.GetNewSessionAsync(); + AgentSession session = await agent.CreateSessionAsync(); ChatMessage message = new(ChatRole.User, "Test message"); ChatClientAgentRunOptions options = new(); @@ -118,7 +118,7 @@ public async Task RunAsync_WithMessagesCollectionAndOptions_CallsBaseMethodAsync It.IsAny())).ReturnsAsync(new ChatResponse([new(ChatRole.Assistant, "Response")])); ChatClientAgent agent = new(mockChatClient.Object); - AgentSession session = await agent.GetNewSessionAsync(); + AgentSession session = await agent.CreateSessionAsync(); IEnumerable messages = [new(ChatRole.User, "Message 1"), new(ChatRole.User, "Message 2")]; ChatClientAgentRunOptions options = new(); @@ -179,7 +179,7 @@ public async Task RunStreamingAsync_WithSessionAndOptions_CallsBaseMethodAsync() It.IsAny())).Returns(GetAsyncUpdatesAsync()); ChatClientAgent agent = new(mockChatClient.Object); - AgentSession session = await agent.GetNewSessionAsync(); + AgentSession session = await agent.CreateSessionAsync(); ChatClientAgentRunOptions options = new(); // Act @@ -211,7 +211,7 @@ public async Task RunStreamingAsync_WithStringMessageAndOptions_CallsBaseMethodA It.IsAny())).Returns(GetAsyncUpdatesAsync()); ChatClientAgent agent = new(mockChatClient.Object); - AgentSession session = await agent.GetNewSessionAsync(); + AgentSession session = await agent.CreateSessionAsync(); ChatClientAgentRunOptions options = new(); // Act @@ -243,7 +243,7 @@ public async Task RunStreamingAsync_WithChatMessageAndOptions_CallsBaseMethodAsy It.IsAny())).Returns(GetAsyncUpdatesAsync()); ChatClientAgent agent = new(mockChatClient.Object); - AgentSession session = await agent.GetNewSessionAsync(); + AgentSession session = await agent.CreateSessionAsync(); ChatMessage message = new(ChatRole.User, "Test message"); ChatClientAgentRunOptions options = new(); @@ -276,7 +276,7 @@ public async Task RunStreamingAsync_WithMessagesCollectionAndOptions_CallsBaseMe It.IsAny())).Returns(GetAsyncUpdatesAsync()); ChatClientAgent agent = new(mockChatClient.Object); - AgentSession session = await agent.GetNewSessionAsync(); + AgentSession session = await agent.CreateSessionAsync(); IEnumerable messages = [new ChatMessage(ChatRole.User, "Message 1"), new ChatMessage(ChatRole.User, "Message 2")]; ChatClientAgentRunOptions options = new(); @@ -324,7 +324,7 @@ public async Task RunAsyncOfT_WithSessionAndOptions_CallsBaseMethodAsync() It.IsAny())).ReturnsAsync(new ChatResponse([new(ChatRole.Assistant, """{"id":2, "fullName":"Tigger", "species":"Tiger"}""")])); ChatClientAgent agent = new(mockChatClient.Object); - AgentSession session = await agent.GetNewSessionAsync(); + AgentSession session = await agent.CreateSessionAsync(); ChatClientAgentRunOptions options = new(); // Act @@ -354,7 +354,7 @@ public async Task RunAsyncOfT_WithStringMessageAndOptions_CallsBaseMethodAsync() It.IsAny())).ReturnsAsync(new ChatResponse([new(ChatRole.Assistant, """{"id":2, "fullName":"Tigger", "species":"Tiger"}""")])); ChatClientAgent agent = new(mockChatClient.Object); - AgentSession session = await agent.GetNewSessionAsync(); + AgentSession session = await agent.CreateSessionAsync(); ChatClientAgentRunOptions options = new(); // Act @@ -384,7 +384,7 @@ public async Task RunAsyncOfT_WithChatMessageAndOptions_CallsBaseMethodAsync() It.IsAny())).ReturnsAsync(new ChatResponse([new(ChatRole.Assistant, """{"id":2, "fullName":"Tigger", "species":"Tiger"}""")])); ChatClientAgent agent = new(mockChatClient.Object); - AgentSession session = await agent.GetNewSessionAsync(); + AgentSession session = await agent.CreateSessionAsync(); ChatMessage message = new(ChatRole.User, "Test message"); ChatClientAgentRunOptions options = new(); @@ -415,7 +415,7 @@ public async Task RunAsyncOfT_WithMessagesCollectionAndOptions_CallsBaseMethodAs It.IsAny())).ReturnsAsync(new ChatResponse([new(ChatRole.Assistant, """{"id":2, "fullName":"Tigger", "species":"Tiger"}""")])); ChatClientAgent agent = new(mockChatClient.Object); - AgentSession session = await agent.GetNewSessionAsync(); + AgentSession session = await agent.CreateSessionAsync(); IEnumerable messages = [new(ChatRole.User, "Message 1"), new(ChatRole.User, "Message 2")]; ChatClientAgentRunOptions options = new(); diff --git a/dotnet/tests/Microsoft.Agents.AI.UnitTests/TestAIAgent.cs b/dotnet/tests/Microsoft.Agents.AI.UnitTests/TestAIAgent.cs index 0ef255155a..cadc7bdc38 100644 --- a/dotnet/tests/Microsoft.Agents.AI.UnitTests/TestAIAgent.cs +++ b/dotnet/tests/Microsoft.Agents.AI.UnitTests/TestAIAgent.cs @@ -14,8 +14,8 @@ internal sealed class TestAIAgent : AIAgent public Func? NameFunc; public Func? DescriptionFunc; - public Func DeserializeSessionFunc = delegate { throw new NotSupportedException(); }; - public Func GetNewSessionFunc = delegate { throw new NotSupportedException(); }; + public readonly Func DeserializeSessionFunc = delegate { throw new NotSupportedException(); }; + public readonly Func CreateSessionFunc = delegate { throw new NotSupportedException(); }; public Func, AgentSession?, AgentRunOptions?, CancellationToken, Task> RunAsyncFunc = delegate { throw new NotSupportedException(); }; public Func, AgentSession?, AgentRunOptions?, CancellationToken, IAsyncEnumerable> RunStreamingAsyncFunc = delegate { throw new NotSupportedException(); }; public Func? GetServiceFunc; @@ -27,8 +27,8 @@ internal sealed class TestAIAgent : AIAgent public override ValueTask DeserializeSessionAsync(JsonElement serializedSession, JsonSerializerOptions? jsonSerializerOptions = null, CancellationToken cancellationToken = default) => new(this.DeserializeSessionFunc(serializedSession, jsonSerializerOptions)); - public override ValueTask GetNewSessionAsync(CancellationToken cancellationToken = default) => - new(this.GetNewSessionFunc()); + public override ValueTask CreateSessionAsync(CancellationToken cancellationToken = default) => + new(this.CreateSessionFunc()); protected override Task RunCoreAsync(IEnumerable messages, AgentSession? session = null, AgentRunOptions? options = null, CancellationToken cancellationToken = default) => this.RunAsyncFunc(messages, session, options, cancellationToken); diff --git a/dotnet/tests/Microsoft.Agents.AI.Workflows.UnitTests/AgentWorkflowBuilderTests.cs b/dotnet/tests/Microsoft.Agents.AI.Workflows.UnitTests/AgentWorkflowBuilderTests.cs index ac0899e413..59636d519d 100644 --- a/dotnet/tests/Microsoft.Agents.AI.Workflows.UnitTests/AgentWorkflowBuilderTests.cs +++ b/dotnet/tests/Microsoft.Agents.AI.Workflows.UnitTests/AgentWorkflowBuilderTests.cs @@ -135,7 +135,7 @@ private class DoubleEchoAgent(string name) : AIAgent { public override string Name => name; - public override ValueTask GetNewSessionAsync(CancellationToken cancellationToken = default) + public override ValueTask CreateSessionAsync(CancellationToken cancellationToken = default) => new(new DoubleEchoAgentSession()); public override ValueTask DeserializeSessionAsync(JsonElement serializedSession, JsonSerializerOptions? jsonSerializerOptions = null, CancellationToken cancellationToken = default) diff --git a/dotnet/tests/Microsoft.Agents.AI.Workflows.UnitTests/InProcessExecutionTests.cs b/dotnet/tests/Microsoft.Agents.AI.Workflows.UnitTests/InProcessExecutionTests.cs index b03660d20c..bb7dbf2dda 100644 --- a/dotnet/tests/Microsoft.Agents.AI.Workflows.UnitTests/InProcessExecutionTests.cs +++ b/dotnet/tests/Microsoft.Agents.AI.Workflows.UnitTests/InProcessExecutionTests.cs @@ -144,7 +144,7 @@ public SimpleTestAgent(string name) public override string Name { get; } - public override ValueTask GetNewSessionAsync(CancellationToken cancellationToken = default) => new(new SimpleTestAgentSession()); + public override ValueTask CreateSessionAsync(CancellationToken cancellationToken = default) => new(new SimpleTestAgentSession()); public override ValueTask DeserializeSessionAsync(System.Text.Json.JsonElement serializedSession, System.Text.Json.JsonSerializerOptions? jsonSerializerOptions = null, CancellationToken cancellationToken = default) => new(new SimpleTestAgentSession()); diff --git a/dotnet/tests/Microsoft.Agents.AI.Workflows.UnitTests/RepresentationTests.cs b/dotnet/tests/Microsoft.Agents.AI.Workflows.UnitTests/RepresentationTests.cs index 0ebc58a395..c6f48b2724 100644 --- a/dotnet/tests/Microsoft.Agents.AI.Workflows.UnitTests/RepresentationTests.cs +++ b/dotnet/tests/Microsoft.Agents.AI.Workflows.UnitTests/RepresentationTests.cs @@ -24,7 +24,7 @@ private sealed class TestExecutor() : Executor("TestExecutor") private sealed class TestAgent : AIAgent { - public override ValueTask GetNewSessionAsync(CancellationToken cancellationToken = default) + public override ValueTask CreateSessionAsync(CancellationToken cancellationToken = default) => throw new NotImplementedException(); public override ValueTask DeserializeSessionAsync(JsonElement serializedSession, JsonSerializerOptions? jsonSerializerOptions = null, CancellationToken cancellationToken = default) diff --git a/dotnet/tests/Microsoft.Agents.AI.Workflows.UnitTests/RoleCheckAgent.cs b/dotnet/tests/Microsoft.Agents.AI.Workflows.UnitTests/RoleCheckAgent.cs index 732175c8b6..611ae3caa2 100644 --- a/dotnet/tests/Microsoft.Agents.AI.Workflows.UnitTests/RoleCheckAgent.cs +++ b/dotnet/tests/Microsoft.Agents.AI.Workflows.UnitTests/RoleCheckAgent.cs @@ -19,7 +19,7 @@ internal sealed class RoleCheckAgent(bool allowOtherAssistantRoles, string? id = public override ValueTask DeserializeSessionAsync(JsonElement serializedSession, JsonSerializerOptions? jsonSerializerOptions = null, CancellationToken cancellationToken = default) => new(new RoleCheckAgentSession()); - public override ValueTask GetNewSessionAsync(CancellationToken cancellationToken = default) => new(new RoleCheckAgentSession()); + public override ValueTask CreateSessionAsync(CancellationToken cancellationToken = default) => new(new RoleCheckAgentSession()); protected override Task RunCoreAsync(IEnumerable messages, AgentSession? session = null, AgentRunOptions? options = null, CancellationToken cancellationToken = default) => this.RunStreamingAsync(messages, session, options, cancellationToken).ToAgentResponseAsync(cancellationToken); diff --git a/dotnet/tests/Microsoft.Agents.AI.Workflows.UnitTests/Sample/06_GroupChat_Workflow.cs b/dotnet/tests/Microsoft.Agents.AI.Workflows.UnitTests/Sample/06_GroupChat_Workflow.cs index fd19797a56..7941dd6b7a 100644 --- a/dotnet/tests/Microsoft.Agents.AI.Workflows.UnitTests/Sample/06_GroupChat_Workflow.cs +++ b/dotnet/tests/Microsoft.Agents.AI.Workflows.UnitTests/Sample/06_GroupChat_Workflow.cs @@ -60,7 +60,7 @@ internal sealed class HelloAgent(string id = nameof(HelloAgent)) : AIAgent protected override string? IdCore => id; public override string? Name => id; - public override ValueTask GetNewSessionAsync(CancellationToken cancellationToken = default) + public override ValueTask CreateSessionAsync(CancellationToken cancellationToken = default) => new(new HelloAgentSession()); public override ValueTask DeserializeSessionAsync(JsonElement serializedSession, JsonSerializerOptions? jsonSerializerOptions = null, CancellationToken cancellationToken = default) diff --git a/dotnet/tests/Microsoft.Agents.AI.Workflows.UnitTests/Sample/07_GroupChat_Workflow_HostAsAgent.cs b/dotnet/tests/Microsoft.Agents.AI.Workflows.UnitTests/Sample/07_GroupChat_Workflow_HostAsAgent.cs index 215bd52119..950ce70806 100644 --- a/dotnet/tests/Microsoft.Agents.AI.Workflows.UnitTests/Sample/07_GroupChat_Workflow_HostAsAgent.cs +++ b/dotnet/tests/Microsoft.Agents.AI.Workflows.UnitTests/Sample/07_GroupChat_Workflow_HostAsAgent.cs @@ -19,7 +19,7 @@ public static async ValueTask RunAsync(TextWriter writer, IWorkflowExecutionEnvi for (int i = 0; i < numIterations; i++) { - AgentSession session = await agent.GetNewSessionAsync(); + AgentSession session = await agent.CreateSessionAsync(); await foreach (AgentResponseUpdate update in agent.RunStreamingAsync(session).ConfigureAwait(false)) { if (update.RawRepresentation is WorkflowEvent) diff --git a/dotnet/tests/Microsoft.Agents.AI.Workflows.UnitTests/Sample/10_Sequential_HostAsAgent.cs b/dotnet/tests/Microsoft.Agents.AI.Workflows.UnitTests/Sample/10_Sequential_HostAsAgent.cs index 280eb8c0d4..7dd454ed59 100644 --- a/dotnet/tests/Microsoft.Agents.AI.Workflows.UnitTests/Sample/10_Sequential_HostAsAgent.cs +++ b/dotnet/tests/Microsoft.Agents.AI.Workflows.UnitTests/Sample/10_Sequential_HostAsAgent.cs @@ -21,7 +21,7 @@ public static async ValueTask RunAsync(TextWriter writer, IWorkflowExecutionEnvi { AIAgent hostAgent = WorkflowInstance.AsAgent("echo-workflow", "EchoW", executionEnvironment: executionEnvironment); - AgentSession session = await hostAgent.GetNewSessionAsync(); + AgentSession session = await hostAgent.CreateSessionAsync(); foreach (string input in inputs) { AgentResponse response; diff --git a/dotnet/tests/Microsoft.Agents.AI.Workflows.UnitTests/Sample/11_Concurrent_HostAsAgent.cs b/dotnet/tests/Microsoft.Agents.AI.Workflows.UnitTests/Sample/11_Concurrent_HostAsAgent.cs index cf2566de8d..71b5692d2b 100644 --- a/dotnet/tests/Microsoft.Agents.AI.Workflows.UnitTests/Sample/11_Concurrent_HostAsAgent.cs +++ b/dotnet/tests/Microsoft.Agents.AI.Workflows.UnitTests/Sample/11_Concurrent_HostAsAgent.cs @@ -33,7 +33,7 @@ public static async ValueTask RunAsync(TextWriter writer, IWorkflowExecutionEnvi { AIAgent hostAgent = WorkflowInstance.AsAgent("echo-workflow", "EchoW", executionEnvironment: executionEnvironment); - AgentSession session = await hostAgent.GetNewSessionAsync(); + AgentSession session = await hostAgent.CreateSessionAsync(); foreach (string input in inputs) { AgentResponse response; diff --git a/dotnet/tests/Microsoft.Agents.AI.Workflows.UnitTests/Sample/12_HandOff_HostAsAgent.cs b/dotnet/tests/Microsoft.Agents.AI.Workflows.UnitTests/Sample/12_HandOff_HostAsAgent.cs index 7e4ccac59f..e73873ca90 100644 --- a/dotnet/tests/Microsoft.Agents.AI.Workflows.UnitTests/Sample/12_HandOff_HostAsAgent.cs +++ b/dotnet/tests/Microsoft.Agents.AI.Workflows.UnitTests/Sample/12_HandOff_HostAsAgent.cs @@ -69,7 +69,7 @@ public static async ValueTask RunAsync(TextWriter writer, IWorkflowExecutionEnvi { AIAgent hostAgent = WorkflowInstance.AsAgent("echo-workflow", "EchoW", executionEnvironment: executionEnvironment); - AgentSession session = await hostAgent.GetNewSessionAsync(); + AgentSession session = await hostAgent.CreateSessionAsync(); foreach (string input in inputs) { AgentResponse response; diff --git a/dotnet/tests/Microsoft.Agents.AI.Workflows.UnitTests/Sample/13_Subworkflow_Checkpointing.cs b/dotnet/tests/Microsoft.Agents.AI.Workflows.UnitTests/Sample/13_Subworkflow_Checkpointing.cs index f04af720c6..368eb46067 100644 --- a/dotnet/tests/Microsoft.Agents.AI.Workflows.UnitTests/Sample/13_Subworkflow_Checkpointing.cs +++ b/dotnet/tests/Microsoft.Agents.AI.Workflows.UnitTests/Sample/13_Subworkflow_Checkpointing.cs @@ -32,7 +32,7 @@ public static async ValueTask RunAsAgentAsync(TextWriter writer, s { AIAgent hostAgent = WorkflowInstance.AsAgent("echo-workflow", "EchoW", executionEnvironment: environment, includeWorkflowOutputsInResponse: true); - session ??= await hostAgent.GetNewSessionAsync(); + session ??= await hostAgent.CreateSessionAsync(); AgentResponse response; ResponseContinuationToken? continuationToken = null; do diff --git a/dotnet/tests/Microsoft.Agents.AI.Workflows.UnitTests/TestEchoAgent.cs b/dotnet/tests/Microsoft.Agents.AI.Workflows.UnitTests/TestEchoAgent.cs index f9a4309f86..e6592605f1 100644 --- a/dotnet/tests/Microsoft.Agents.AI.Workflows.UnitTests/TestEchoAgent.cs +++ b/dotnet/tests/Microsoft.Agents.AI.Workflows.UnitTests/TestEchoAgent.cs @@ -18,10 +18,10 @@ internal class TestEchoAgent(string? id = null, string? name = null, string? pre public override async ValueTask DeserializeSessionAsync(JsonElement serializedSession, JsonSerializerOptions? jsonSerializerOptions = null, CancellationToken cancellationToken = default) { - return serializedSession.Deserialize(jsonSerializerOptions) ?? await this.GetNewSessionAsync(cancellationToken); + return serializedSession.Deserialize(jsonSerializerOptions) ?? await this.CreateSessionAsync(cancellationToken); } - public override ValueTask GetNewSessionAsync(CancellationToken cancellationToken = default) => + public override ValueTask CreateSessionAsync(CancellationToken cancellationToken = default) => new(new EchoAgentSession()); private static ChatMessage UpdateSession(ChatMessage message, InMemoryAgentSession? session = null) diff --git a/dotnet/tests/Microsoft.Agents.AI.Workflows.UnitTests/TestReplayAgent.cs b/dotnet/tests/Microsoft.Agents.AI.Workflows.UnitTests/TestReplayAgent.cs index 82358e1198..c79e0f3a8c 100644 --- a/dotnet/tests/Microsoft.Agents.AI.Workflows.UnitTests/TestReplayAgent.cs +++ b/dotnet/tests/Microsoft.Agents.AI.Workflows.UnitTests/TestReplayAgent.cs @@ -45,7 +45,7 @@ static ChatMessage ToMessage(string text) return result; } - public override ValueTask GetNewSessionAsync(CancellationToken cancellationToken = default) + public override ValueTask CreateSessionAsync(CancellationToken cancellationToken = default) => new(new ReplayAgentSession()); public override ValueTask DeserializeSessionAsync(JsonElement serializedSession, JsonSerializerOptions? jsonSerializerOptions = null, CancellationToken cancellationToken = default) diff --git a/dotnet/tests/Microsoft.Agents.AI.Workflows.UnitTests/TestRequestAgent.cs b/dotnet/tests/Microsoft.Agents.AI.Workflows.UnitTests/TestRequestAgent.cs index 226f26ad6c..447c7f5e89 100644 --- a/dotnet/tests/Microsoft.Agents.AI.Workflows.UnitTests/TestRequestAgent.cs +++ b/dotnet/tests/Microsoft.Agents.AI.Workflows.UnitTests/TestRequestAgent.cs @@ -29,7 +29,7 @@ internal sealed class TestRequestAgent(TestAgentRequestType requestType, int unp protected override string? IdCore => id; public override string? Name => name; - public override ValueTask GetNewSessionAsync(CancellationToken cancellationToken) + public override ValueTask CreateSessionAsync(CancellationToken cancellationToken) => new(requestType switch { TestAgentRequestType.FunctionCall => new TestRequestAgentSession(), @@ -73,7 +73,7 @@ private async IAsyncEnumerable RunStreamingAsync traSessin = ConvertSession(session); if (traSessin.HasSentRequests) diff --git a/dotnet/tests/Microsoft.Agents.AI.Workflows.UnitTests/WorkflowHostSmokeTests.cs b/dotnet/tests/Microsoft.Agents.AI.Workflows.UnitTests/WorkflowHostSmokeTests.cs index 8c8a543d2c..7bab74c31d 100644 --- a/dotnet/tests/Microsoft.Agents.AI.Workflows.UnitTests/WorkflowHostSmokeTests.cs +++ b/dotnet/tests/Microsoft.Agents.AI.Workflows.UnitTests/WorkflowHostSmokeTests.cs @@ -46,7 +46,7 @@ public override ValueTask DeserializeSessionAsync(JsonElement seri return new(new Session(serializedSession, jsonSerializerOptions)); } - public override ValueTask GetNewSessionAsync(CancellationToken cancellationToken = default) + public override ValueTask CreateSessionAsync(CancellationToken cancellationToken = default) { return new(new Session()); }