Skip to main content

Quickstart

This guide will get you up and running with AutoGen in under 5 minutes. You’ll create a simple agent that can use tools to answer questions.

Prerequisites

Before you begin, ensure you have:
  • Python 3.10 or later installed
  • An OpenAI API key (or another supported LLM provider)
Don’t have an OpenAI API key? Get one at platform.openai.com. You can also use other providers like Azure OpenAI, Anthropic, or local models.

Installation

1

Install AutoGen packages

Install both AgentChat and the OpenAI extension:
This installs:
  • autogen-agentchat: High-level API for building agents
  • autogen-ext[openai]: OpenAI model client extension
2

Set your API key

Export your OpenAI API key as an environment variable:
3

Verify installation

Check that packages are installed correctly:

Hello World: Your First Agent

Let’s create a simple assistant agent that responds to a task.
1

Create a Python file

Create a new file called hello_agent.py:
hello_agent.py
2

Run your agent

Execute the script:
You should see output similar to:
The agent uses OpenAI’s GPT-4o model by default. You can change this to gpt-4o-mini for faster/cheaper responses or gpt-4 for maximum quality.

Adding Tools to Your Agent

Now let’s make it more interesting by giving the agent access to a tool. We’ll create a weather agent that can look up weather information.
1

Define a tool function

Create a new file called weather_agent.py:
weather_agent.py
2

Run the weather agent

Execute the script:
You’ll see the agent:
  1. Receive your question
  2. Call the get_weather tool with city="New York"
  3. Get the tool result
  4. Formulate a natural language response
Output:
AutoGen automatically:
  • Converts your Python function into a tool schema
  • Passes it to the LLM via function calling
  • Executes the function when the model requests it
  • Returns results back to the model for final response generation

Understanding the Code

Let’s break down the key components:

Model Client

The model client connects to your LLM provider. AutoGen supports many providers through extensions:
  • OpenAIChatCompletionClient for OpenAI
  • AzureOpenAIChatCompletionClient for Azure OpenAI
  • AnthropicClient for Claude
  • And more…

Assistant Agent

The AssistantAgent is a pre-configured agent type that:
  • Uses an LLM to process messages
  • Can call tools when needed
  • Reflects on tool results when reflect_on_tool_use=True
  • Follows instructions in the system_message

Running the Agent

The run() method executes the agent and returns a TaskResult with:
  • All messages exchanged
  • The final stop reason
  • Usage statistics
For streaming output, use run_stream() with the Console helper:

Next Steps

Congratulations! You’ve created your first AutoGen agent. Here’s what to explore next:

Core Concepts

Understand agents, teams, tools, and the architecture

Multi-Agent Teams

Create teams of agents that collaborate on complex tasks

Advanced Tools

Integrate MCP servers, code execution, and custom tools

Example Gallery

Browse complete examples and use cases

Common Next Tasks

Use a Different Model Provider

Switch to Azure OpenAI:
Or use Anthropic Claude:

Add Multiple Tools

Agents can use multiple tools:

Create a Multi-Agent Team

Combine multiple agents:
Teams are covered in detail in the AgentChat documentation.

Troubleshooting

Make sure you installed both packages:
If using a virtual environment, ensure it’s activated.
Verify your API key is set correctly:
Or pass it explicitly:
AutoGen uses async/await throughout. If running in a Jupyter notebook, you can use await directly:
In a Python script, wrap in asyncio.run():
If you hit rate limits:
  • Use a smaller/cheaper model like gpt-4o-mini
  • Add delays between requests
  • Check your OpenAI usage limits

Getting Help

If you run into issues:
Ready to learn more? Continue to Core Concepts to understand how AutoGen works under the hood.