Learning Objectives
- Understand the AG2 / AutoGen split and what it means for developers
- Identify AG2's core concepts: conversable agents, group chat, and code execution
- Compare AG2 vs. CrewAI and LangGraph for different multi-agent use cases
What Is AG2?
AG2 ("The Open-Source AgentOS") is a community-governed multi-agent framework originally created by Microsoft Research as AutoGen in September 2023. AutoGen became one of the most cited AI agent papers of the year, pioneering the idea that complex AI tasks are best accomplished through multi-agent conversations — AI agents that talk to each other, critique each other's work, and converge on better solutions through dialogue.
In November 2024, the original creators forked the project as AG2 at ag2.ai, moving to independent, community-driven governance. The project retains AutoGen's core architecture while continuing active development under the AG2 banner.
⚠️Warning
The AutoGen Split: There are now two lineages. AG2 (at ag2.ai) is the community fork continuing the original vision. Meanwhile, Microsoft retired AutoGen in early 2026, placing it in maintenance mode (bug fixes only, no new features) alongside Semantic Kernel. Microsoft now directs developers to its new Microsoft Agent Framework for enterprise agent orchestration. If you're starting a new project, AG2 is the active open-source option; Microsoft Agent Framework is the enterprise-managed option.
✅Tip
Try AG2: Open source at ag2.ai; pip install ag2; AG2 Studio provides a no-code interface; Apache 2.0 license
Core Concepts
Conversable Agents
AG2's fundamental building block is the ConversableAgent — an agent that can send and receive messages in a conversation:
from ag2 import AssistantAgent, UserProxyAgent
config_list = [{"model": "gpt-4o", "api_key": "your-key"}]
assistant = AssistantAgent(
name="Assistant",
llm_config={"config_list": config_list},
system_message="You are a helpful AI assistant."
)
user_proxy = UserProxyAgent(
name="User",
human_input_mode="NEVER", # or "ALWAYS" or "TERMINATE"
max_consecutive_auto_reply=10,
code_execution_config={"work_dir": "./workspace"}
)
user_proxy.initiate_chat(assistant, message="Analyze the sales data in sales.csv and plot a bar chart")
The UserProxyAgent acts as the human interface and code executor — it runs any code the AssistantAgent produces in a sandboxed working directory and returns the output to continue the conversation.
Conversation Patterns
AG2 implements several conversation patterns:
- Two-agent chat: Human proxy + AI assistant; iterative task completion with code execution
- Group chat: Multiple agents participate in a shared conversation; a GroupChatManager decides who speaks next
- Nested chat: Agent conversations that call other agent conversations as tools
Code Execution — AG2's Signature Feature
AG2's code execution loop is its most distinctive capability:
- AssistantAgent writes Python code to solve a task
- UserProxyAgent executes the code in a Docker container or local sandbox
- Output (success, error, result) is sent back to AssistantAgent
- AssistantAgent debugs, corrects, and improves the code based on the output
- Loop continues until the task is complete or the conversation terminates
This self-correcting code loop means AG2 can tackle data analysis, visualization, file processing, and API interaction tasks autonomously.
💡Key Concept
Why conversation-based multi-agent works: The original Microsoft Research insight was that LLMs improve significantly when they receive feedback — including feedback from other LLMs. An agent that writes code and then receives the execution output as feedback produces better code than one that writes without feedback. Similarly, an agent that has its analysis critiqued by a "Critic" agent produces more thorough analysis. AG2's conversation model enables these feedback loops naturally.
Group Chat — Multi-Agent Collaboration
For complex tasks requiring multiple perspectives:
from ag2 import AssistantAgent, UserProxyAgent, GroupChat, GroupChatManager
research_agent = AssistantAgent(name="Researcher", ...)
analyst_agent = AssistantAgent(name="Analyst", ...)
critic_agent = AssistantAgent(name="Critic", ...)
group_chat = GroupChat(
agents=[user_proxy, research_agent, analyst_agent, critic_agent],
messages=[],
max_round=12
)
manager = GroupChatManager(groupchat=group_chat, llm_config={"config_list": config_list})
user_proxy.initiate_chat(manager, message="Analyze market trends for EV adoption in 2025-2026")
The GroupChatManager uses an LLM to decide which agent should respond next — researchers gather facts, analysts draw conclusions, critics identify weaknesses.
AG2 Studio — No-Code Interface
AG2 Studio provides a web interface for building multi-agent workflows without code:
- Visual workflow builder for agent configurations
- Upload files and watch agents process them
- Debug agent conversations step-by-step
- Build reusable agent templates
Comparison: Multi-Agent Frameworks
| Feature | AG2 | CrewAI | LangGraph |
|---|---|---|---|
| Primary strength | Code generation + execution; conversation | Role-based task delegation; enterprise Flows | Stateful agent graphs; durable execution |
| Code execution | Native; sandbox; auto-correction loop | Via tools | Via tools |
| Human-in-the-loop | First-class feature (ALWAYS/NEVER/TERMINATE) | Limited | Checkpoint-based |
| Enterprise backing | Community-governed (Apache 2.0) | CrewAI Inc. (Enterprise AMP Suite) | LangChain Inc. (LangSmith platform) |
| Syntax | Class-based, verbose | Simpler; role-focused | Complex; graph-based |
Pricing
AG2 is free and open source (Apache 2.0 license). Costs are LLM API usage only.
Strengths
- Active community governance: Independent from any single vendor; community-driven roadmap at ag2.ai
- Code execution loop: Best-in-class code writing, execution, and self-correction among open-source frameworks
- Human-in-the-loop: Granular control over when humans are consulted (
ALWAYS,NEVER,TERMINATE) - Group chat flexibility: Manager-directed multi-agent conversations are powerful and expressive
- Docker isolation: Code execution in Docker containers provides safe sandboxing
- Research foundation: Built on one of the most cited AI agent papers; rigorous academic grounding
Limitations & Considerations
- Ecosystem fragmentation: The AutoGen/AG2 split means some tutorials, blog posts, and Stack Overflow answers reference the old
pyautogenpackage — verify you're using the correct import (ag2) - LLM API costs: Multi-turn conversations consume many tokens — costs can escalate quickly on complex tasks
- Conversation loops: Agents can get stuck in unproductive loops — requires careful max-conversation limits
- Less intuitive than CrewAI: For role-based task workflows, CrewAI's syntax is more readable
- Microsoft ecosystem: Azure OpenAI integration was a strength of the original AutoGen; AG2 maintains it but the Microsoft Agent Framework is now Microsoft's preferred enterprise path
Best Use Cases
| Task | Why AG2 |
|---|---|
| Code generation and execution tasks | Self-correcting code loop with sandbox execution |
| Data analysis with code | Write pandas code, execute, debug, visualize, iterate |
| Research with critique | Researcher + Critic + Synthesizer group chat |
| Human-in-the-loop approval workflows | Insert human review at specific conversation points |
| Academic and research applications | Rigorous research foundation; reproducible experiments |
When to choose alternatives:
- Simpler role-based pipelines → CrewAI
- Complex stateful graph workflows → LangGraph
- Enterprise Microsoft ecosystem → Microsoft Agent Framework
- Visual no-code automation → n8n or Make
Getting Started
pip install ag2
from ag2 import AssistantAgent, UserProxyAgent
config_list = [{"model": "gpt-4o", "api_key": "YOUR_KEY"}]
assistant = AssistantAgent("assistant", llm_config={"config_list": config_list})
user_proxy = UserProxyAgent("user", human_input_mode="NEVER",
code_execution_config={"work_dir": "."})
user_proxy.initiate_chat(assistant,
message="Write a Python script that fetches the top 5 tech news headlines using a web API and prints them formatted nicely")
Watch the agents exchange messages — the assistant writes code, the proxy executes it and returns output, the assistant debugs and improves.
✅Tip
For code automation tasks: AG2's code execution loop is genuinely impressive for tasks where you can describe the goal and let the agent figure out the implementation. Start with a clear specification: "Write a script that [does specific thing] using [specific library] and produces [specific output]." The more precise the spec, the less iteration the agents need. Use work_dir to specify where files should be created and use code_execution_config={"use_docker": True} for safe sandboxing.
Key Takeaways
- AG2 (formerly AutoGen) is the community-governed successor to Microsoft Research's pioneering multi-agent framework, with a signature code execution loop that writes, runs, and iterates code automatically
- Microsoft retired AutoGen in early 2026 in favor of the Microsoft Agent Framework; the open-source community continues active development under AG2
- The human-in-the-loop feature (ALWAYS/NEVER/TERMINATE modes) is one of the most granular human oversight implementations in any agent framework
- GroupChat allows multiple specialized agents to collaborate in a shared conversation, directed by a manager agent
- Free and open source (Apache 2.0); costs are LLM API calls only