Skip to main content
This is the simplest possible AutoGen example. It creates a single assistant agent that responds to a task.

What You’ll Learn

  • How to create an OpenAI model client
  • How to create an AssistantAgent
  • How to run a simple task

Prerequisites

1

Install AutoGen

2

Set your OpenAI API key

Code Example

Create a file called hello_world.py with the following code:

Run the Example

Expected Output

You should see output similar to:

How It Works

  1. Model Client: Creates an OpenAIChatCompletionClient configured to use GPT-4o
  2. Assistant Agent: Creates an AssistantAgent that uses the model client to generate responses
  3. Run Task: Executes the task and returns a TaskResult containing the agent’s response
  4. 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