Files
agent-framework/dotnet/samples/GettingStarted/AgentWithOpenAI/Agent_OpenAI_Step03_CreateFromChatClient
T
westey a3a9147e61 .NET: [BREAKING] Rename AgentThread to AgentSession (#3430)
* Rename AgentThread to AgentSession

* Add more renames

* Update readme files

* Revert nullable variable change and further fixes.

* Revert change in header name

* Fix some comments and tests

* Update changelog.

* Address PR feedback.

* Fixing code review comments.

* Fix new errors after merging latest code.
a3a9147e61 ยท 2026-01-26 16:30:25 +00:00
History
..

Creating an Agent from a ChatClient

This sample demonstrates how to create an AI agent directly from an OpenAI.Chat.ChatClient instance using the OpenAIChatClientAgent class.

What This Sample Shows

  • Direct ChatClient Creation: Shows how to create an OpenAI.Chat.ChatClient from OpenAI.OpenAIClient and then use it to instantiate an agent
  • OpenAIChatClientAgent: Demonstrates using the OpenAI SDK primitives instead of the ones from Microsoft.Extensions.AI and Microsoft.Agents.AI abstractions
  • Full Agent Capabilities: Shows both regular and streaming invocation of the agent

Running the Sample

  1. Set the required environment variables:

    set OPENAI_API_KEY=your_api_key_here
    set OPENAI_MODEL=gpt-4o-mini
    
  2. Run the sample:

    dotnet run