Skip to content

Fix(lesson 04): Replaced deprecated AgentThread with AgentSession for context management#590

Open
marietta-a wants to merge 1 commit into
microsoft:mainfrom
marietta-a:fix/04-dotnet-agent-framework
Open

Fix(lesson 04): Replaced deprecated AgentThread with AgentSession for context management#590
marietta-a wants to merge 1 commit into
microsoft:mainfrom
marietta-a:fix/04-dotnet-agent-framework

Conversation

@marietta-a

Copy link
Copy Markdown

Description

Fixes CS1061 and CS0246 compilation errors in 04-dotnet-agent-framework.cs by updating to the correct agent API methods and types.

Addresses: #587


Root Cause

During the creation of an agent with outdated methods, the code generated:

error CS1061: 'IChatClient' does not contain a definition for 'CreateAIAgent' ...
error CS0246: The type or namespace name 'AgentThread' could not be found ...
error CS1061: 'AIAgent' does not contain a definition for 'GetNewThread' ...
  • The extension method .CreateAIAgent(...) is not defined for IChatClient. The supported method is .AsAIAgent(...).
  • AgentThread is not part of the current framework; the correct type is AgentSession.
  • GetNewThread() has been replaced by CreateSessionAsync() for session management.

Reference: Multi-turn Conversations, C#

Changes

  • Replaced .CreateAIAgent(...) with .AsAIAgent(...)
  • Replaced AgentThread with AgentSession
  • Replaced .GetNewThread() with .CreateSessionAsync()
  • Updated inline comments to reflect the correct agent/session workflow

Testing

Verified code compiles and runs without errors on:

  • OS: Windows 11, macOS Tahoe 26.2
  • .NET SDK: 10.0.301
  • Microsoft.Extensions.AI@10.*
  • Microsoft.Extensions.AI.OpenAI@10.-
  • Microsoft.Agents.AI.OpenAI@1.-

This PR ensures the lesson‑04 sample aligns with the current APIs and demonstrates proper multi-turn conversation handling.

Copilot AI review requested due to automatic review settings June 16, 2026 14:34

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.

@github-actions

Copy link
Copy Markdown
Contributor

👋 Thanks for contributing @marietta-a! We will review the pull request and get back to you soon.

@github-actions github-actions Bot requested a review from koreyspace June 16, 2026 14:34
@marietta-a marietta-a changed the title Fix(lesson 04): Switch from AgentThread to AgentSession for context management Fix(lesson 04): Replaced deprecated AgentThread with AgentSession for context management Jun 17, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants