Skip to content

Commit 0a39199

Browse files
authored
Merge pull request #588 from marietta-a/fix/02-dotnet-agent-framework
Fix(lesson 02): Replaced deprecated AgentThread with AgentSession for context management
2 parents 88f17bb + 31bb0a0 commit 0a39199

1 file changed

Lines changed: 9 additions & 9 deletions

File tree

02-explore-agentic-frameworks/code_samples/02-dotnet-agent-framework.cs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -93,23 +93,23 @@ What kind of trip would you like me to help you plan today?"
9393
AIAgent agent = openAIClient
9494
.GetChatClient(github_model_id)
9595
.AsIChatClient()
96-
.CreateAIAgent(
96+
.AsAIAgent(
9797
name: AGENT_NAME,
9898
instructions: AGENT_INSTRUCTIONS,
9999
tools: [AIFunctionFactory.Create(GetRandomDestination)]
100100
);
101101

102-
// Create New Conversation Thread for Context Management
103-
// Initialize a new conversation thread to maintain context across multiple interactions
104-
// Threads enable the agent to remember previous exchanges and maintain conversational state
102+
// Create New Session for Context Management.
103+
// Initialize a new conversation session to maintain context across multiple interactions
104+
// Sessions enable the agent to remember previous exchanges and maintain conversational state
105105
// This is essential for multi-turn conversations and contextual understanding
106-
AgentThread thread = agent.GetNewThread();
106+
AgentSession session = await agent.CreateSessionAsync();
107107

108108
// Execute Agent: First Travel Planning Request
109109
// Run the agent with an initial request that will likely trigger the random destination tool
110110
// The agent will analyze the request, use the GetRandomDestination tool, and create an itinerary
111-
// Using the thread parameter maintains conversation context for subsequent interactions
112-
await foreach (var update in agent.RunStreamingAsync("Plan me a day trip", thread))
111+
// Using the session parameter maintains conversation context for subsequent interactions
112+
await foreach (var update in agent.RunStreamingAsync("Plan me a day trip", session))
113113
{
114114
await Task.Delay(10);
115115
Console.Write(update);
@@ -120,8 +120,8 @@ What kind of trip would you like me to help you plan today?"
120120
// Execute Agent: Follow-up Request with Context Awareness
121121
// Demonstrate contextual conversation by referencing the previous response
122122
// The agent remembers the previous destination suggestion and will provide an alternative
123-
// This showcases the power of conversation threads and contextual understanding in .NET agents
124-
await foreach (var update in agent.RunStreamingAsync("I don't like that destination. Plan me another vacation.", thread))
123+
// This showcases the power of conversation sessions and contextual understanding in .NET agents
124+
await foreach (var update in agent.RunStreamingAsync("I don't like that destination. Plan me another vacation.", session))
125125
{
126126
await Task.Delay(10);
127127
Console.Write(update);

0 commit comments

Comments
 (0)