What Is AutoGen?
AutoGen (developed by Microsoft Research) is a framework for building multi-agent AI systems where agents communicate with each other through structured conversations. Unlike CrewAI (role-based tasks) or LangGraph (state machines), AutoGen's core abstraction is the ConversableAgent — an agent that can send and receive messages from other agents and humans.
This conversational model is powerful because:
- Agent interactions are auditable — you can read the full conversation
- Human participation is a first-class feature at any point
- Agents can critique and correct each other's work through dialogue
- The system naturally handles multi-turn problem solving
Installation
pip install pyautogen # Core AutoGen
pip install pyautogen[openai] # With OpenAI support
AutoGen works with any OpenAI-compatible API, including Azure OpenAI, Anthropic (via proxy), local models (Ollama), and more.
Core Agent Types
| Agent Type | Description |
|---|---|
ConversableAgent | Base agent — can send/receive messages, call tools |
AssistantAgent | Pre-configured LLM agent for task completion |
UserProxyAgent | Represents a human; can execute code and request human input |
GroupChatManager | Manages turn-taking in multi-agent group chats |
import autogen
# LLM configuration
config_list = [
{
"model": "claude-sonnet-4-6",
"api_key": "your-api-key",
"base_url": "https://api.anthropic.com/v1",
"api_type": "anthropic",
}
]
llm_config = {
"config_list": config_list,
"temperature": 0,
"timeout": 120,
}
# -------------------------------------------------------
# AGENT 1: The Assistant (LLM-powered)
# -------------------------------------------------------
assistant = autogen.AssistantAgent(
name="DataScientist",
system_message=(
"You are an expert data scientist. When given a task, "
"write clean, well-commented Python code to solve it. "
"Always include error handling and print results. "
"If code execution reveals an error, debug and fix it."
),
llm_config=llm_config,
)
# -------------------------------------------------------
# AGENT 2: The UserProxy (executes code, optionally involves human)
# -------------------------------------------------------
user_proxy = autogen.UserProxyAgent(
name="CodeRunner",
human_input_mode="NEVER", # run fully autonomously
# human_input_mode="TERMINATE", # ask human only before terminating
# human_input_mode="ALWAYS", # ask human every turn
max_consecutive_auto_reply=10,
is_termination_msg=lambda msg: "TASK_COMPLETE" in msg.get("content", ""),
code_execution_config={
"work_dir": "/tmp/autogen_workspace",
"use_docker": False, # set True for sandboxed execution
},
system_message="Execute code provided by DataScientist. Report results accurately.",
)
# -------------------------------------------------------
# Start the conversation
# -------------------------------------------------------
user_proxy.initiate_chat(
assistant,
message=(
"Analyze the Iris dataset: load it from sklearn, compute summary statistics, "
"find correlations between features, and identify which features best "
"distinguish the three species. Print all findings."
),
)Group Chat — Multiple Agents Conversing
For tasks that benefit from multiple expert perspectives, AutoGen's GroupChat lets several agents converse in a shared channel, with a GroupChatManager orchestrating turn-taking:
import autogen
llm_config = {"config_list": config_list, "temperature": 0}
# -------------------------------------------------------
# Define specialized agents
# -------------------------------------------------------
product_manager = autogen.AssistantAgent(
name="ProductManager",
system_message=(
"You are a product manager. You understand user needs, "
"prioritize features, and define requirements. "
"When the technical solution is ready, say 'APPROVED' to end discussion."
),
llm_config=llm_config,
)
backend_dev = autogen.AssistantAgent(
name="BackendDev",
system_message=(
"You are a senior backend engineer specializing in Python APIs. "
"You propose technical solutions, write server-side code, "
"and raise concerns about scalability and security."
),
llm_config=llm_config,
)
frontend_dev = autogen.AssistantAgent(
name="FrontendDev",
system_message=(
"You are a frontend engineer specializing in React. "
"You design UI/UX, write component code, "
"and ensure the API contract suits the frontend needs."
),
llm_config=llm_config,
)
qa_engineer = autogen.AssistantAgent(
name="QAEngineer",
system_message=(
"You are a QA engineer. You review all proposed code and designs, "
"identify edge cases and potential bugs, and suggest test cases."
),
llm_config=llm_config,
)
# UserProxy coordinates and can execute code
coordinator = autogen.UserProxyAgent(
name="Coordinator",
human_input_mode="NEVER",
max_consecutive_auto_reply=0,
is_termination_msg=lambda msg: "APPROVED" in msg.get("content", ""),
code_execution_config={"work_dir": "/tmp/autogen_workspace", "use_docker": False},
)
# -------------------------------------------------------
# Set up group chat
# -------------------------------------------------------
group_chat = autogen.GroupChat(
agents=[coordinator, product_manager, backend_dev, frontend_dev, qa_engineer],
messages=[],
max_round=20,
speaker_selection_method="auto", # let the manager decide who speaks next
)
manager = autogen.GroupChatManager(
groupchat=group_chat,
llm_config=llm_config,
)
# -------------------------------------------------------
# Initiate the group discussion
# -------------------------------------------------------
coordinator.initiate_chat(
manager,
message=(
"Design and implement a simple REST API endpoint for user authentication "
"(POST /auth/login) that accepts email and password, validates credentials "
"against a mock database, and returns a JWT token. "
"Include the frontend form component and test cases."
),
)Nested Chat — Agents Delegating to Sub-Agents
AutoGen supports nested chats where an agent can spin up a sub-conversation to complete part of its task:
# A writer agent that uses a nested chat with a critic for self-revision
writer = autogen.AssistantAgent(
name="Writer",
system_message=(
"You write technical blog posts. After writing, "
"you will consult with a critic to improve the draft."
),
llm_config=llm_config,
)
critic = autogen.AssistantAgent(
name="Critic",
system_message=(
"You are a harsh but fair technical editor. "
"Review the blog post draft and provide specific, actionable feedback "
"on clarity, accuracy, and structure. Rate it 1-10."
),
llm_config=llm_config,
)
user = autogen.UserProxyAgent(
name="User",
human_input_mode="NEVER",
is_termination_msg=lambda x: x.get("content", "").find("TERMINATE") >= 0,
code_execution_config=False,
)
# Register a nested chat: when user talks to writer,
# writer automatically consults critic before finalizing
writer.register_nested_chats(
[{"recipient": critic, "message": "Please review this draft: {last_message}", "max_turns": 2}],
trigger=user,
)
user.initiate_chat(
writer,
message="Write a 300-word intro to vector databases for a developer audience.",
)When to Use AutoGen
AutoGen excels when:
- Dialogue is the workflow — agents need to debate, critique, and refine through conversation
- Code generation + execution — the write-test-fix cycle maps naturally to two-agent patterns
- Human supervision at variable granularity — you can change
human_input_modewithout restructuring your system - Research tasks where multiple expert perspectives add value
AutoGen vs LangGraph vs CrewAI
| Scenario | Best Choice |
|---|---|
| Conversational multi-agent with code execution | AutoGen |
| Complex conditional workflows with cycles | LangGraph |
| Role-based task crews with clear deliverables | CrewAI |
| Maximum observability and control | LangGraph |
| Quickest to get running | AutoGen / CrewAI |
Knowledge check
Which AutoGen human_input_mode is best for a production system that runs overnight batch jobs?
Summary
AutoGen's conversational paradigm makes multi-agent collaboration feel natural:
- ConversableAgent is the universal building block — everything is a message
- UserProxyAgent bridges humans and code execution
- GroupChat enables multi-agent round-table discussion with automatic speaker selection
- Nested chats let agents delegate sub-tasks to specialized peer conversations
human_input_modegives you a dial from fully autonomous to fully supervised
In the next chapter, we'll explore MCP (Model Context Protocol) — Anthropic's open standard for giving agents access to tools, resources, and context in a secure, standardized way.