What is AutoGen?
AutoGen's conversation-centric approach to multi-agent AI, how it differs from LangChain, the two core agent types, and a minimal working example.
What is AutoGen?
AutoGen is a framework from Microsoft Research for building multi-agent AI systems where agents communicate with each other through conversations. Rather than wiring up function chains or graph edges, AutoGen models agent interaction as a back-and-forth message thread — the same mental model you already have for a group chat.
The insight behind AutoGen is simple but powerful: conversations are the universal interface. Humans coordinate through conversation. LLMs were trained on conversation. So instead of inventing a new abstraction, AutoGen leans into it.
The Problem AutoGen Solves
Before AutoGen, building a system where one AI agent writes code and another reviews it required:
- Custom message routing logic
- State management across function calls
- Fragile prompt engineering to make agents "talk" to each other
- Manual orchestration of who speaks when
AutoGen replaces all of this with a conversation loop. Each agent sends and receives messages. The framework handles turn-taking, history tracking, and termination.
AutoGen vs LangChain: A Conceptual Comparison
LangChain and AutoGen solve different problems, even though they both involve LLMs.
| Dimension | LangChain | AutoGen | |---|---|---| | Primary abstraction | Chains (data pipelines) | Conversations (message threads) | | Agent interaction | Function calls and tool invocations | Message exchange between agents | | State management | Chain variables, memory objects | Conversation history (list of messages) | | Multi-agent support | LangGraph extension required | Built-in from day one | | Best for | ETL-style LLM pipelines, RAG | Collaborative agent workflows | | Code execution | Requires manual setup | First-class UserProxyAgent feature | | Human-in-the-loop | Via callbacks | Via human_input_mode parameter |
LangChain is excellent when you have a deterministic pipeline: retrieve documents, summarise them, format the output. The data flows forward through stages.
AutoGen is excellent when you need agents to iterate together: an assistant proposes a solution, another agent tests it, the assistant revises based on feedback. The flow is conversational and non-linear.
The Two Core Agent Types
AutoGen v0.2 has two foundational agent classes. Everything else is built on top of them.
1. AssistantAgent
An LLM-backed agent that generates responses. This is the "thinking" agent — it reads the conversation history and produces the next message.
from autogen import AssistantAgent
assistant = AssistantAgent(
name="assistant",
llm_config={
"config_list": [
{
"model": "gpt-4o",
"api_key": "YOUR_API_KEY",
}
]
},
system_message="""You are a helpful Python programming assistant.
When asked to write code, produce clean, well-commented Python.
Reply TERMINATE when the task is complete.""",
)Key properties:
name: identifier used in conversation history and logsllm_config: model configuration including provider, model, and API keysystem_message: the agent's persona and instructions
2. UserProxyAgent
Represents the human (or automation) side of the conversation. It can execute code, run tools, and pass results back. It does not call an LLM by default.
from autogen import UserProxyAgent
user_proxy = UserProxyAgent(
name="user_proxy",
human_input_mode="NEVER", # fully automated — never ask for input
max_consecutive_auto_reply=10, # safety limit on automated replies
is_termination_msg=lambda msg: "TERMINATE" in msg.get("content", ""),
code_execution_config={
"work_dir": "coding_workspace",
"use_docker": False, # run code locally (set True for Docker sandbox)
},
)Key properties:
human_input_mode:"NEVER","TERMINATE", or"ALWAYS"— controls when the agent pauses to ask a real humanis_termination_msg: a function that decides when the conversation should stopcode_execution_config: configures whether and where code execution happens
Minimal Two-Agent Example
Here is the smallest complete AutoGen program. An assistant and a user proxy have a conversation about a Python task.
import autogen
# 1. Configure the LLM
llm_config = {
"config_list": [
{
"model": "gpt-4o-mini",
"api_key": "YOUR_OPENAI_API_KEY",
}
],
"temperature": 0,
}
# 2. Create the assistant agent (LLM-backed)
assistant = autogen.AssistantAgent(
name="assistant",
llm_config=llm_config,
system_message="""You are a helpful Python tutor.
Write clear Python code with explanations.
End your final response with TERMINATE.""",
)
# 3. Create the user proxy (executes code, represents the human)
user_proxy = autogen.UserProxyAgent(
name="user_proxy",
human_input_mode="NEVER",
max_consecutive_auto_reply=5,
is_termination_msg=lambda msg: "TERMINATE" in msg.get("content", ""),
code_execution_config={"work_dir": "workspace", "use_docker": False},
)
# 4. Start the conversation
user_proxy.initiate_chat(
assistant,
message="Write a Python function that reverses a string and include a test.",
)When you run this:
user_proxysends the task message toassistantassistantcalls the LLM and generates Python codeuser_proxysees a code block in the response and executes ituser_proxysends the execution result back toassistantassistantsees the result and replies "TERMINATE" if all is gooduser_proxy.is_termination_msgtriggers and the conversation ends
Reading the Conversation History
After initiate_chat completes, you can inspect what happened:
# All messages in order
messages = user_proxy.chat_messages[assistant]
for msg in messages:
role = msg["role"] # "user" or "assistant"
name = msg.get("name") # agent name
content = msg["content"]
print(f"[{name or role}]: {content[:100]}...")The conversation history is a plain list of dicts — easy to log, serialize, or feed into another system.
When to Use AutoGen
AutoGen fits well when:
- You need iterative refinement — an agent produces output, another critiques it, the first revises
- You want code generation + execution in the same loop
- You have multiple specialists that each own a domain (researcher, coder, reviewer)
- You want human approval at certain checkpoints without rewriting the whole workflow
AutoGen is less suited when:
- Your pipeline is strictly linear (use LangChain or a simple script)
- You need fine-grained state machines with explicit transitions (use LangGraph)
- You need real-time streaming output per token (AutoGen's streaming support is limited in v0.2)
AutoGen v0.2 vs v0.4: API Changes
AutoGen went through a major rewrite between v0.2 and v0.4. Most tutorials and documentation online target v0.2. Here are the critical differences:
| Feature | v0.2 | v0.4 |
|---|---|---|
| Package name | pyautogen or autogen-agentchat | autogen-agentchat (new) |
| Agent base class | ConversableAgent | BaseChatAgent |
| LLM config | Dict with config_list | ChatCompletionClient objects |
| Group chat | GroupChat + GroupChatManager | RoundRobinGroupChat, SelectorGroupChat |
| Tool registration | @register_for_llm decorator | FunctionTool class |
| Async support | Limited | First-class asyncio throughout |
| Termination | is_termination_msg function | TextMentionTermination condition objects |
Which version should you learn? As of mid-2026, v0.4 is the actively maintained branch. However, the majority of production systems you will encounter were built on v0.2, and the conceptual model is the same. This course primarily uses v0.2 idioms since they are more widely deployed, and calls out v0.4 equivalents where relevant.
Installing v0.2
pip install pyautogen==0.2.38Installing v0.4
pip install autogen-agentchat autogen-ext[openai]v0.4 Equivalent of the Minimal Example
import asyncio
from autogen_agentchat.agents import AssistantAgent, UserProxyAgent
from autogen_agentchat.conditions import TextMentionTermination
from autogen_agentchat.teams import RoundRobinGroupChat
from autogen_ext.models.openai import OpenAIChatCompletionClient
async def main():
model_client = OpenAIChatCompletionClient(model="gpt-4o-mini")
assistant = AssistantAgent(
name="assistant",
model_client=model_client,
system_message="You are a helpful Python tutor. End with TERMINATE when done.",
)
user_proxy = UserProxyAgent(name="user_proxy")
termination = TextMentionTermination("TERMINATE")
team = RoundRobinGroupChat([assistant, user_proxy], termination_condition=termination)
result = await team.run(task="Write a Python function that reverses a string.")
print(result.messages)
asyncio.run(main())Notice that v0.4 uses asyncio, replaces GroupChat with typed team classes, and separates the model client from the agent config.
Summary
- AutoGen treats conversations as the primary primitive for multi-agent coordination
- The two core agents are
AssistantAgent(LLM-backed) andUserProxyAgent(executor/human proxy) - A conversation starts with
initiate_chatand ends when a termination condition is met - v0.2 is widely deployed; v0.4 adds async and typed team classes
- AutoGen is the right tool for iterative, collaborative agent workflows — not linear pipelines
In the next lesson, we go deeper into why conversations are such a powerful primitive for multi-agent systems.
Found this helpful?
Leave a comment
Have a question, correction, or just found this helpful? Leave a note below.