Quick Start
Get up and running with AG2 in just 3 minutes! This guide will help you set up your environment and build your very first agent workflow.
Prerequisites
Make sure you've installed AG2 before continuing. Need just 30 seconds: pip install "ag2[openai]"
Set Up Your Environment#
Python Version
AG2 requires Python version >= 3.10, < 3.14. We recommend using a virtual environment for your project to keep your packages contained. See venv.
Set Your API Key
Make sure to set your LLM API key as an environment variable:
Build Your First Agent Workflow#
Let's build a poetic AI assistant that responds in rhymes using AG2 and OpenAI's gpt-5-nano model.
Create a Python script called first_agent.py, and paste the following code into it:
import os
from autogen import ConversableAgent, LLMConfig
# 1. Define our LLM configuration for OpenAI's gpt-5-nano
# uses the OPENAI_API_KEY environment variable
llm_config = LLMConfig(
{"api_type": "openai", "model": "gpt-5-nano", "api_key": os.environ["OPENAI_API_KEY"]}
)
# 2. Create our LLM agent
my_agent = ConversableAgent(
name="helpful_agent",
system_message="You are a poetic AI assistant, respond in rhyme.",
llm_config=llm_config,
)
# 3. Run the agent with a prompt and process the response
response = my_agent.run(
message="In one sentence, what's the big deal about AI?",
max_turns=3,
user_input=True,
)
response.process()
Why run() then process()?
run() prepares the conversation, process() executes it. This two-step pattern gives you a chance to inspect or modify the workflow before it runs.
Run Your Example#
In your terminal, run:
If everything is set up correctly, the agent will reply to your initial message in rhyme, then prompt you for a response. You can either:
- Type a reply — and the agent will respond in rhyme to your message
- Press Enter — to send an empty message to the agent, and see how it creatively responds
- Type exit — to end the conversation
The interaction continues for up to 3 turns (or until you exit).
Example Output#
user (to helpful_agent):
In one sentence, what's the big deal about AI?
--------------------------------------------------------------------------------
>>>>>>>> USING AUTO REPLY...
helpful_agent (to user):
AI transforms our world, enhancing life's parade,
With insights and solutions, it helps plans cascade.
--------------------------------------------------------------------------------
Replying as user. Provide feedback to helpful_agent. Press enter to skip and use auto-reply, or type 'exit' to end the conversation:
Try it without installing
Want to see AG2 in action right away? The AG2 Playground lets you run multi-agent workflows live in your browser — no setup required.
What's Next?#
Now that you've built your first agent, here's where to go:
- Overview — Understand the core building blocks of AG2
- LLM Configuration — Configure different model providers (Gemini, Anthropic, etc.)
- Introducing Group Chat — Make multiple agents collaborate together