AutoGen is a framework from Microsoft Research for building multi-agent applications where LLM-backed agents can converse with each other, execute code, and involve human participants in the loop. It is designed for workflows where a single agent is insufficient: research pipelines, code generation and execution cycles, collaborative document drafting, and any task where breaking work into specialist roles improves the result.
The Core Abstraction: ConversableAgent
Everything in AutoGen is a ConversableAgent. It can send messages, receive messages, and optionally execute code. Specializations of ConversableAgent handle the two most common roles:
AssistantAgent is backed by an LLM. It receives messages, reasons about them, and produces text responses or code. By default it uses GPT-4 but can be configured with any model.
UserProxyAgent represents either a human or a code executor. When configured as a code executor (the common case), it extracts code blocks from the assistant's messages and runs them in a sandboxed environment. The result is returned to the assistant, which can then reason about the output and produce the next step.
A minimal two-agent setup:
import autogen
config_list = [{"model": "gpt-4o", "api_key": "YOUR_KEY"}]
assistant = autogen.AssistantAgent(
name="assistant",
llm_config={"config_list": config_list},
)
user_proxy = autogen.UserProxyAgent(
name="user_proxy",
human_input_mode="NEVER",
max_consecutive_auto_reply=10,
code_execution_config={"work_dir": "coding", "use_docker": False},
)
user_proxy.initiate_chat(
assistant,
message="Plot a chart of Apple stock price for the last 30 days and save it as a PNG."
)
The assistant generates Python code to fetch the data and plot the chart. The user_proxy executes it. If it errors, the assistant sees the error and generates corrected code. This loop continues until the task is complete or the max reply limit is reached.
GroupChat: Coordinating Multiple Agents
GroupChat coordinates conversations among three or more agents. A GroupChatManager selects which agent speaks next based on the conversation history. This enables multi-specialist workflows:
planner = autogen.AssistantAgent(name="planner", ...)
coder = autogen.AssistantAgent(name="coder", ...)
reviewer = autogen.AssistantAgent(name="reviewer", ...)
user_proxy = autogen.UserProxyAgent(name="user_proxy", ...)
groupchat = autogen.GroupChat(
agents=[user_proxy, planner, coder, reviewer],
messages=[],
max_round=20
)
manager = autogen.GroupChatManager(groupchat=groupchat, llm_config={"config_list": config_list})
user_proxy.initiate_chat(manager, message="Build a REST API for user authentication in FastAPI.")
The planner designs the approach, the coder implements it, the reviewer critiques it, and the coder revises based on feedback. Each agent has a system prompt that defines its role and constraints.