What You’ll Learn
- How to create an OpenAI model client
- How to create an AssistantAgent
- How to run a simple task
Prerequisites
Code Example
Create a file calledhello_world.py with the following code:
Run the Example
Expected Output
You should see output similar to:How It Works
- Model Client: Creates an
OpenAIChatCompletionClientconfigured to use GPT-4o - Assistant Agent: Creates an
AssistantAgentthat uses the model client to generate responses - Run Task: Executes the task and returns a
TaskResultcontaining the agent’s response - Cleanup: Closes the model client to release resources
Key Concepts
AssistantAgent
A general-purpose agent that uses an LLM to respond to tasks and messages.
Model Client
Handles communication with the LLM provider (OpenAI, Azure, etc.).
Task
A string prompt that tells the agent what to do.
TaskResult
Contains the messages generated during task execution.
Next Steps
Two Agent Chat
Learn how to create conversations between multiple agents
Tool Calling
Add tools to give your agents new capabilities