Conversation-Based Multi-Agent (AutoGen)
Microsoft AutoGen lets multiple agents chat with each other until they reach consensus.
Conversation-Based Multi-Agent (AutoGen) is a free AI Agents lesson on CoddyKit — lesson 1 of 4. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the AI Agents learning path, one of 4 lessons in the course, and your progress syncs across the web and the CoddyKit app.
Why Multi-Agent?
One agent with all tools is often worse than two specialized agents who talk to each other. Specialization > generalist.
Examples:
- Researcher + Writer — one gathers info, one composes the answer
- Coder + Reviewer — one writes code, one critiques it
- User-Proxy + Assistant — represents the user, talks to the worker
AutoGen Pattern
Microsoft AutoGen lets agents converse: each is an AssistantAgent or UserProxyAgent. They exchange messages until reaching consensus.
Two-Agent Example
# pip install pyautogen
from autogen import AssistantAgent, UserProxyAgent
llm_config = {'model': 'gpt-4o-mini', 'api_key': '...'}
assistant = AssistantAgent(
name='coder',
system_message='You write Python code. Reply with code only.',
llm_config=llm_config
)
user_proxy = UserProxyAgent(
name='user',
human_input_mode='NEVER',
code_execution_config={'work_dir': './workdir'}
)
user_proxy.initiate_chat(assistant, message='Write a function that returns the factorial of n.')UserProxyAgent
Represents the human (or a script). Can execute code returned by the assistant, ask clarifying questions, and decide when the task is done.
Conversable Agents
All AutoGen agents inherit from ConversableAgent. You can subclass for custom behavior.
GroupChat for >2 Agents
class AssistantAgent:
def __init__(self, name, system_message=''):
self.name = name
self.system_message = system_message
def initiate_chat(self, manager, message):
manager.run(self, message)
class GroupChat:
def __init__(self, agents, messages, max_round=12):
self.agents = agents
self.messages = messages
self.max_round = max_round
class GroupChatManager:
def __init__(self, groupchat, llm_config=None):
self.groupchat = groupchat
def run(self, initiator, message):
self.groupchat.messages.append({'role': initiator.name, 'content': message})
for i, agent in enumerate(self.groupchat.agents):
if i >= self.groupchat.max_round:
break
reply = f'{agent.name} contributes to: {message}'
self.groupchat.messages.append({'role': agent.name, 'content': reply})
print(reply)
user_proxy = AssistantAgent(name='user_proxy')
researcher = AssistantAgent(name='researcher')
writer = AssistantAgent(name='writer')
critic = AssistantAgent(name='critic')
group = GroupChat(agents=[user_proxy, researcher, writer, critic], messages=[], max_round=12)
manager = GroupChatManager(groupchat=group, llm_config={})
user_proxy.initiate_chat(manager, message='Write a blog post about RAG.')
Speaker Selection
The GroupChatManager decides who speaks next. Strategies:
- round_robin — fixed rotation
- auto — LLM picks based on the conversation
- manual — human picks
Termination Conditions
Conversations end when:
- An agent emits a TERMINATE keyword
- max_round is hit
- UserProxyAgent decides the task is done
Code Execution
UserProxyAgent can execute any code the assistant emits in code blocks. Use a sandbox:
user_proxy = UserProxyAgent(
name='user',
code_execution_config={
'work_dir': './workdir',
'use_docker': True # safer
}
)Cost Watch
Multi-agent conversations are expensive — N agents × M rounds = N×M LLM calls per task. Cap rounds aggressively.
When to Use
- Tasks with clear role separation (research, code, review)
- Tasks where critique improves quality
- Tasks too complex for a single agent prompt
When NOT to Use
- Simple Q&A — single agent is faster and cheaper
- Latency-critical paths
- Tasks where one agent can do the whole job well
AutoGen vs LangGraph
AutoGen = conversation-driven (free-form chats between agents). LangGraph = graph-driven (explicit state machine). Both are valid; pick based on how naturally your task fits.
AutoGen Pattern
What is the central abstraction in AutoGen?
Recap
AutoGen = role-based agents conversing. Great for tasks where one agent supervises and others specialize. Watch cost; cap rounds.
Frequently asked questions
Is the “Conversation-Based Multi-Agent (AutoGen)” lesson free?
Yes — the full text of “Conversation-Based Multi-Agent (AutoGen)” is free to read here on the web, and the AI Agents course includes 4 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the AI Agents course, upgrade to CoddyKit PRO.
What will I learn in “Conversation-Based Multi-Agent (AutoGen)”?
Microsoft AutoGen lets multiple agents chat with each other until they reach consensus. You practise AI Agents with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.
Do I need any experience to start AI Agents?
No prior experience is required. AI Agents on CoddyKit is structured for beginners through advanced learners; this is — lesson 1 of 4, so you can start here or from the beginning and move at your own pace.
How long does the “Conversation-Based Multi-Agent (AutoGen)” lesson take?
Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.
Can I write and run code in this AI Agents lesson?
Yes. Every AI Agents lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.
All lessons in this course
- Conversation-Based Multi-Agent (AutoGen)
- Hierarchical Supervisors (Orchestrator + Workers)
- Agent Roles and Specialisations
- Communication Protocols (Message Buses)