Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion dotnet/samples/A2AClientServer/A2AClient/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion dotnet/samples/AGUIClientServer/AGUIClient/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<ChatMessage> messages = [new(ChatRole.System, "You are a helpful assistant.")];
try
{
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public sealed record TextResponse(string Text);
public static async Task<string> RunOrchestrationAsync([OrchestrationTrigger] TaskOrchestrationContext context)
{
DurableAIAgent writer = context.GetAgent("WriterAgent");
AgentSession writerSession = await writer.GetNewSessionAsync();
AgentSession writerSession = await writer.CreateSessionAsync();

AgentResponse<TextResponse> initial = await writer.RunAsync<TextResponse>(
message: "Write a concise inspirational sentence about learning.",
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public static async Task<string> 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<DetectionResult> spamDetectionResponse = await spamDetectionAgent.RunAsync<DetectionResult>(
Expand All @@ -43,7 +43,7 @@ public static async Task<string> 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<EmailResponse> emailAssistantResponse = await emailAssistantAgent.RunAsync<EmailResponse>(
message:
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public static async Task<object> 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}");
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public static async Task<object> 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}");
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ public async Task<IActionResult> 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<AgentSessionId>().ToString();

this._logger.LogInformation("Creating new agent session: {AgentSessionId}", agentSessionId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@
Console.WriteLine();

// Create a session for the conversation
AgentSession session = await agentProxy.GetNewSessionAsync();
AgentSession session = await agentProxy.CreateSessionAsync();

while (true)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ when given an improved sentence you polish it further.
static async Task<string> RunOrchestratorAsync(TaskOrchestrationContext context)
{
DurableAIAgent writer = context.GetAgent("WriterAgent");
AgentSession writerSession = await writer.GetNewSessionAsync();
AgentSession writerSession = await writer.CreateSessionAsync();

AgentResponse<TextResponse> initial = await writer.RunAsync<TextResponse>(
message: "Write a concise inspirational sentence about learning.",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ static async Task<string> 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<DetectionResult> spamDetectionResponse = await spamDetectionAgent.RunAsync<DetectionResult>(
Expand All @@ -78,7 +78,7 @@ static async Task<string> 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<EmailResponse> emailAssistantResponse = await emailAssistantAgent.RunAsync<EmailResponse>(
message:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ static async Task<object> 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}");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ static async Task<object> 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}");
Expand Down Expand Up @@ -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) =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<AgentSessionId>();
string conversationId = sessionId.ToString();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
name: "agui-client",
description: "AG-UI Client Agent");

AgentSession session = await agent.GetNewSessionAsync();
AgentSession session = await agent.CreateSessionAsync();
List<ChatMessage> messages =
[
new(ChatRole.System, "You are a helpful assistant.")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
name: "agui-client",
description: "AG-UI Client Agent");

AgentSession session = await agent.GetNewSessionAsync();
AgentSession session = await agent.CreateSessionAsync();
List<ChatMessage> messages =
[
new(ChatRole.System, "You are a helpful assistant.")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<ChatMessage> messages =
[
new(ChatRole.System, "You are a helpful assistant.")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
};
StatefulAgent<AgentState> agent = new(baseAgent, jsonOptions, new AgentState());

AgentSession session = await agent.GetNewSessionAsync();
AgentSession session = await agent.CreateSessionAsync();
List<ChatMessage> messages =
[
new(ChatRole.System, "You are a helpful recipe assistant.")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ static async Task<string> 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);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ internal sealed class UpperCaseParrotAgent : AIAgent
{
public override string? Name => "UpperCaseParrotAgent";

public override ValueTask<AgentSession> GetNewSessionAsync(CancellationToken cancellationToken = default)
public override ValueTask<AgentSession> CreateSessionAsync(CancellationToken cancellationToken = default)
=> new(new CustomAgentSession());

public override ValueTask<AgentSession> DeserializeSessionAsync(JsonElement serializedSession, JsonSerializerOptions? jsonSerializerOptions = null, CancellationToken cancellationToken = default)
Expand All @@ -37,7 +37,7 @@ public override ValueTask<AgentSession> DeserializeSessionAsync(JsonElement seri
protected override async Task<AgentResponse> RunCoreAsync(IEnumerable<ChatMessage> 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)
{
Expand Down Expand Up @@ -69,7 +69,7 @@ protected override async Task<AgentResponse> RunCoreAsync(IEnumerable<ChatMessag
protected override async IAsyncEnumerable<AgentResponseUpdate> RunCoreStreamingAsync(IEnumerable<ChatMessage> 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)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Original file line number Diff line number Diff line change
Expand Up @@ -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<Mem0Provider>()!;
Expand All @@ -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));
Original file line number Diff line number Diff line change
Expand Up @@ -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");

Expand Down Expand Up @@ -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<UserInfoMemory>() is UserInfoMemory newSessionMemory)
{
newSessionMemory.UserInfo = userInfo;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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");

Expand Down
Loading
Loading