Skip to content

AutoGen

Overview

AutoGen by Microsoft enables multi-agent systems through conversational patterns.

Agents communicate by sending messages to each other.


Creating Conversable Agents

from autogen import AssistantAgent, UserProxyAgent

class AutoGenTeam:
 """Build team using AutoGen"""

 def __init__(self):
 # Create agent powered by Claude
 self.researcher = AssistantAgent(
 name="Researcher",
 llm_config={
 "model": "claude-3-5-sonnet-20241022",
 "api_key": "YOUR_API_KEY"
 },
 system_message="You are a research expert"
)

 # Create user proxy (represents human)
 self.user = UserProxyAgent(
 name="User",
 human_input_mode="TERMINATE",
 code_execution_config={"work_dir": "tmp"}
)

 def run(self, task):
 """Run multi-agent conversation"""

 # Initiate conversation
 self.user.initiate_chat(
 self.researcher,
 message=task
)

Tool Use & Code Execution

class AdvancedAutoGen:
 """Use tools and execute code"""

 def __init__(self):
 self.agent = AssistantAgent(
 name="CodeAgent",
 llm_config={"model": "claude-3-5-sonnet"},
 functions=[
 {
 "name": "python",
 "description": "Execute Python code"
 }
]
)

Proxy Agents

Agent that Calls Another Agent

class AgentProxy:
 """Agent that manages other agents"""

 def __init__(self):
 self.agent_a = AssistantAgent(name="Agent A")
 self.agent_b = AssistantAgent(name="Agent B")

3 Warnings

Warning 1: Conversation Explosion

# WRONG
# Agents keep messaging each other
# Conversation never ends
# Uses tons of tokens

# RIGHT
# Set max iterations
max_consecutive_auto_reply=3

Warning 2: Deadlocks

# WRONG
# Agent A waiting for Agent B
# Agent B waiting for Agent A
# Deadlock!

# RIGHT
# Clear termination conditions

Warning 3: Cost Spiraling

# WRONG
# Long conversations = high cost

# RIGHT
# Monitor token usage
# Set budgets

-

Last Updated: August 9, 2026