What is AutoGen?
AutoGen is an open-source framework by Microsoft for building multi-agent AI applications. It enables the creation of agents that can collaborate, converse, and solve complex tasks through autonomous or human-in-the-loop workflows. With AutoGen v0.4, the framework features a completely redesigned architecture for production-ready agentic systems.
"AutoGen enables next-gen LLM applications via multi-agent conversation. It simplifies the orchestration, automation, and optimization of complex LLM workflows."
Multi-Agent
Collaborative AI
Conversations
Agent chat patterns
Code Execution
Safe sandboxes
Human-in-Loop
Control & feedback
AutoGen v0.4 Architecture
AutoGen v0.4 introduces a layered, modular architecture designed for scalability and flexibility:
AutoGen Core
Low-level, event-driven framework based on the actor model. Provides building blocks for agents, messages, and routing. Ideal for highly customized and distributed systems.
AutoGen AgentChat
High-level, task-driven API built on Core. Offers group chat, code execution, and pre-built agents. Perfect for rapid prototyping of interactive applications.
Extensions Layer
Advanced runtimes, tools, and ecosystem integrations. Supports community-developed extensions for custom models (Hugging Face, Ollama), tools, and memory systems.
Built-in Agent Types
AssistantAgent
AI-powered agent backed by an LLM. Can generate code, use tools, and reason about tasks.
UserProxyAgent
Represents human user. Can execute code, provide feedback, or be fully automated.
GroupChatManager
Orchestrates multi-agent conversations. Decides which agent speaks next based on context.
CodeExecutorAgent
Executes code in sandboxed environments. Supports Docker and local execution.
Quick Start: Two-Agent Chat
Create a simple conversation between an AI assistant and a user proxy:
# Install AutoGen
# pip install autogen-agentchat
from autogen import AssistantAgent, UserProxyAgent
import os
# Configure LLM
llm_config = {
"config_list": [{
"model": "gpt-4o-mini",
"api_key": os.getenv("OPENAI_API_KEY")
}]
}
# Create assistant agent
assistant = AssistantAgent(
name="assistant",
llm_config=llm_config,
system_message="You are a helpful AI assistant."
)
# Create user proxy (can execute code)
user_proxy = UserProxyAgent(
name="user",
human_input_mode="TERMINATE", # or "ALWAYS" for human approval
code_execution_config={"use_docker": False}
)
# Start conversation
user_proxy.initiate_chat(
assistant,
message="Write a Python function to calculate factorial."
)
Expected Output
user (to assistant): Write a Python function to calculate factorial. assistant (to user): Here's a Python function to calculate factorial: ```python def factorial(n): if n == 0 or n == 1: return 1 return n * factorial(n - 1) ``` user (to assistant): [Code executed successfully] Output: factorial(5) = 120
Example: Group Chat
Create a multi-agent team that collaborates to solve problems:
from autogen import AssistantAgent, UserProxyAgent, GroupChat, GroupChatManager
# Create specialized agents
planner = AssistantAgent(
name="planner",
system_message="You break down tasks into steps. Don't write code.",
llm_config=llm_config
)
coder = AssistantAgent(
name="coder",
system_message="You write Python code based on plans.",
llm_config=llm_config
)
reviewer = AssistantAgent(
name="reviewer",
system_message="You review code for bugs and improvements.",
llm_config=llm_config
)
executor = UserProxyAgent(
name="executor",
human_input_mode="NEVER",
code_execution_config={"use_docker": False}
)
# Create group chat
group_chat = GroupChat(
agents=[planner, coder, reviewer, executor],
messages=[],
max_round=10
)
# Manager orchestrates the conversation
manager = GroupChatManager(groupchat=group_chat, llm_config=llm_config)
# Start the team
executor.initiate_chat(manager, message="Build a REST API endpoint for user registration.")
Example: Function Calling / Tools
Register custom functions that agents can call:
from autogen import AssistantAgent, UserProxyAgent, register_function
# Define a tool function
def get_weather(city: str) -> str:
"""Get weather for a city."""
# In production, call real API
return f"Weather in {city}: 22°C, Sunny"
def search_web(query: str) -> str:
"""Search the web for information."""
return f"Search results for '{query}': [result 1, result 2]"
# Create agents
assistant = AssistantAgent(name="assistant", llm_config=llm_config)
user = UserProxyAgent(name="user", human_input_mode="NEVER")
# Register functions for both agents
register_function(
get_weather,
caller=assistant, # Agent that suggests tool calls
executor=user, # Agent that executes tools
description="Get current weather for a city"
)
register_function(
search_web,
caller=assistant,
executor=user,
description="Search the web for information"
)
# The assistant will now use these tools
user.initiate_chat(assistant, message="What's the weather in London?")
Conversation Patterns
1:1 Chat
Simple two-agent conversation with back-and-forth messaging.
Group Chat
Multiple agents collaborate with a manager orchestrating turns.
Hierarchical Chat
Nested groups with supervisors managing sub-teams.
Sequential Chat
Chain of agents where output of one becomes input to next.
Nested Chat
Agent can spawn sub-conversations to handle sub-tasks.
FSM Chat
Finite state machine-based transitions between agents.
AutoGen vs Other Frameworks
| Aspect | AutoGen | CrewAI | LangGraph |
|---|---|---|---|
| Paradigm | Conversations | Roles & tasks | State graphs |
| Backed By | Microsoft | CrewAI Inc | LangChain |
| Code Execution | Built-in (Docker) | Limited | Via tools |
| Human-in-Loop | Native support | Basic | Interrupt nodes |
| Best For | Collaborative coding | Role-based teams | Complex workflows |
AutoGen Studio
Low-Code Agent Builder
AutoGen Studio provides a visual interface for building, testing, and deploying multi-agent applications without writing code. Features include real-time updates, message flow visualization, and deployment as APIs or Docker containers.
Key Features (v0.4)
Async Messaging
Event-driven and request/response patterns for scalable workflows.
Observability
Built-in tracing and debugging with OpenTelemetry support.
Cross-Language
Interoperability between Python and .NET agents.
Learning Agents
Agents can remember teachings and improve over time.