.NET: [BREAKING] Rename GetNewSession to CreateSession (#3501)

* Rename GetNewSession to CreateSession

* Address copilot feedback

* Suppress warning

* Suppress warning

* Fix further warnings.
This commit is contained in:
westey
2026-02-03 11:33:50 +00:00
committed by GitHub
parent 405bd6fb4b
commit 6fdf6111e6
132 changed files with 277 additions and 261 deletions
@@ -47,14 +47,14 @@ AIAgent agent = new AzureOpenAIClient(
});
// 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));
@@ -40,7 +40,7 @@ AIAgent agent = new AzureOpenAIClient(
: 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>()!;
@@ -60,5 +60,5 @@ AgentSession restoredSession = await agent.DeserializeSessionAsync(serializedSes
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));
@@ -37,7 +37,7 @@ AIAgent agent = chatClient.AsAIAgent(new ChatClientAgentOptions()
});
// 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 @@ Console.WriteLine("\n>> Use new session with previously created memories\n");
// 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;