From 12e44161a40be78cfc25f693d32e1823809729ca Mon Sep 17 00:00:00 2001 From: akumbom Date: Tue, 16 Jun 2026 15:30:20 +0100 Subject: [PATCH] Fix(lesson 04): Migrated from AgentThread to AgentSession for context management --- .../code_samples/04-dotnet-agent-framework.cs | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/04-tool-use/code_samples/04-dotnet-agent-framework.cs b/04-tool-use/code_samples/04-dotnet-agent-framework.cs index 11dc372728..e269136a9a 100755 --- a/04-tool-use/code_samples/04-dotnet-agent-framework.cs +++ b/04-tool-use/code_samples/04-dotnet-agent-framework.cs @@ -224,7 +224,7 @@ Always mention which tools you used so users understand the agent's capabilities AIAgent agent = openAIClient .GetChatClient(github_model_id) .AsIChatClient() - .CreateAIAgent( + .AsAIAgent( name: AGENT_NAME, instructions: AGENT_INSTRUCTIONS, tools: [ @@ -235,8 +235,9 @@ Always mention which tools you used so users understand the agent's capabilities ] ); -// Create Conversation Thread -AgentThread thread = agent.GetNewThread(); +// Create Conversation Session +AgentSession session = await agent.CreateSessionAsync(); + // ============================================================================ // DEMONSTRATION 1: Tool Selection - Agent picks the right tool @@ -246,7 +247,7 @@ Always mention which tools you used so users understand the agent's capabilities Console.WriteLine("User: What's the weather like in Tokyo?\n"); Console.WriteLine("Agent Response:"); -await foreach (var update in agent.RunStreamingAsync("What's the weather like in Tokyo?", thread)) +await foreach (var update in agent.RunStreamingAsync("What's the weather like in Tokyo?", session)) { await Task.Delay(10); Console.Write(update); @@ -261,7 +262,7 @@ Always mention which tools you used so users understand the agent's capabilities Console.WriteLine("User: How much would a 5-day luxury trip to Rome cost?\n"); Console.WriteLine("Agent Response:"); -await foreach (var update in agent.RunStreamingAsync("How much would a 5-day luxury trip to Rome cost?", thread)) +await foreach (var update in agent.RunStreamingAsync("How much would a 5-day luxury trip to Rome cost?", session)) { await Task.Delay(10); Console.Write(update); @@ -278,7 +279,7 @@ Always mention which tools you used so users understand the agent's capabilities await foreach (var update in agent.RunStreamingAsync( "Plan me a complete trip - suggest a destination and give me all the details including weather and costs for a 3-day moderate budget trip.", - thread)) + session)) { await Task.Delay(10); Console.Write(update);