AutoGen¶
What it is¶
AutoGen is an open-source framework from Microsoft Research that enables the development of LLM applications using multiple agents that can converse with each other to solve tasks. It supports human participation and code execution.
What problem it solves¶
It enables complex workflows that require multiple turns of conversation, code generation and execution, and human-in-the-loop feedback. It automates the "chat" between agents to reach a goal.
Where it fits in the stack¶
Framework / Multi-Agent Orchestrator
Typical use cases¶
- Software Engineering: An assistant agent writing code and a proxy agent executing it to fix bugs.
- Group Chat: Multiple specialized agents (e.g., Coder, Critic, Manager) discussing a problem.
- Interactive Apps: Agents that can ask humans for clarification or approval.
Strengths¶
- Customizability: Agents are highly configurable in terms of their behavior and tools.
- Code Execution: Built-in support for running generated code in Docker or local environments.
- Conversational Patterns: Supports diverse conversation patterns like group chat, nested chat, and sequential chat.
Technical Architecture: Conversational Patterns¶
AutoGen orchestrates agents through several established patterns: - Sequential Chat: A linear chain where one agent's output becomes another's input. - Group Chat: A multi-agent environment where a "GroupChatManager" decides which agent speaks next. - Nested Chat: An agent can "nest" a whole conversation as a tool or a sub-task, effectively creating hierarchical reasoning. - StateFlow: Using custom logic to transition between agents based on finite state machines (FSM).
Advanced Configuration: StateFlow and Transitions¶
For complex logic that isn't purely conversational, AutoGen allows for explicit state machine transitions.
1. FSM-based StateFlow¶
Define a transition graph where the next speaker is determined by the current state and specific transition rules.
from autogen import GroupChat, GroupChatManager
# Define agents
planner = AssistantAgent("planner", ...)
executor = AssistantAgent("executor", ...)
reviewer = AssistantAgent("reviewer", ...)
# Define transitions
graph_dict = {
planner: [executor],
executor: [reviewer, planner], # If executor fails, go back to planner
reviewer: [planner, None] # None represents task completion
}
groupchat = GroupChat(
agents=[planner, executor, reviewer],
messages=[],
max_round=20,
allowed_or_disallowed_speaker_transitions=graph_dict,
speaker_transitions_type="allowed"
)
manager = GroupChatManager(groupchat=groupchat, llm_config=llm_config)
2. Custom Speaker Selection¶
Beyond round-robin or random selection, you can provide a custom function to determine the next speaker.
def custom_speaker_selection(last_speaker, groupchat):
# Custom logic to inspect message history and decide
if "ERROR" in groupchat.messages[-1]["content"]:
return planner
return groupchat.next_agent(last_speaker)
groupchat = GroupChat(
agents=[planner, executor, reviewer],
messages=[],
speaker_selection_method=custom_speaker_selection
)
Code Execution Safety Patterns¶
Running arbitrary code generated by LLMs requires robust sandboxing.
- Docker Execution: The recommended pattern for production, isolating the execution environment.
- Local Execution: Only for trusted environments; uses a command-line interface with optional timeout and working directory restrictions.
- User Confirmation: The
UserProxyAgentcan be configured to request human approval (human_input_mode="ALWAYS") before any code is executed.
Limitations¶
- Overhead: Can be complex to set up and manage for simpler multi-agent tasks.
- Cost: Like most multi-agent frameworks, it can lead to high token consumption.
When to use it¶
- When you need agents to interact via natural language "chat" to solve problems.
- When code execution is a central part of the agentic workflow.
When not to use it¶
- For static pipelines that don't benefit from back-and-forth conversation.
- If you prefer a more rigid, non-conversational orchestration model.
Getting started¶
Installation¶
pip install pyautogen
Minimal Python Example¶
from autogen import AssistantAgent, UserProxyAgent
# Assistant agent for reasoning
assistant = AssistantAgent("assistant", llm_config={"model": "gpt-4"})
# User proxy agent for executing code
user_proxy = UserProxyAgent("user_proxy", code_execution_config={"work_dir": "coding"})
# Start the conversation
user_proxy.initiate_chat(assistant, message="Show me the stock price of NVDA for the last 3 months.")
Related tools / concepts¶
- CrewAI
- LangGraph
- Semantic Kernel
- Multi-Agent KnowledgeOps
- Agent Protocols
- Claude Code Router
- Model Context Protocol (MCP)
- Plandex
- OpenSwarm
Sources / References¶
Contribution Metadata¶
- Last reviewed: 2026-05-17
- Confidence: high