Skip to Content

AutoGen (Multi-Agent Conversations)

When to use

Build multi-agent systems where specialised agents chat with each other to solve a problem — code execution, debate, voting.

Analogy

A panel discussion. Moderator poses a question, experts respond and argue, moderator synthesises a final answer. Each participant has a different persona and tool set.

Data-flow diagram

   user_proxy  <->  assistant  <->  critic
       |                |
       v                v
   exec_python      write_draft
       |                |
       +--> answer <---+

Deep explanation

AutoGen from Microsoft Research is conversational: agents exchange messages and can call functions. UserProxyAgent simulates a human; AssistantAgent calls the model. GroupChatManager orchestrates many agents. Use AutoGen when you want agents that talk to each other in natural-language loops and run code to verify facts.

Examples

Example 1

from autogen import AssistantAgent, UserProxyAgent
llm_cfg = {'config_list': [{'model':'gpt-4o-mini','api_key':'sk-...'}]}
assistant = AssistantAgent(name='coder', llm_config=llm_cfg)
user      = UserProxyAgent(name='user', code_execution_config={'work_dir':'coding'})
user.initiate_chat(assistant, message='Write Python that reads /tmp/x.csv and prints mean.')

user.initiate_chat(assistant, …) starts a back-and-forth conversation; user can run tools.

Example 2

# group chat with critic agent
from autogen import GroupChat, GroupChatManager
critic   = AssistantAgent(name='critic',  llm_config=llm_cfg,
                          system_message='Review the code for bugs.')
chat     = GroupChat(agents=[user, assistant, critic], messages=[], max_round=10)
manager  = GroupChatManager(groupchat=chat, llm_config=llm_cfg)
user.initiate_chat(manager, message='Build a calculator.')

GroupChat with manager enables multi-agent debates; max_round caps loop length.

Example 3

# terminate conversation with cost cap
import autogen
def is_termination(msg):
    return 'TERMINATE' in msg.get('content','') or cost_so_far() > 0.50
user = UserProxyAgent(name='user', is_termination_msg=is_termination)

is_termination_msg lets you add a cost cap or domain-specific stop signal.

Common mistake

Without max_round or cost cap, agents loop forever. Each round burns tokens; 20 rounds at gpt-4o costs 4 USD.

Key takeaway

AutoGen equals agents + conversations. Always cap max_round and is_termination_msg. Use GroupChatManager for multi-agent debate.

Production Failure Playbook

Failure scenario 1: agent-loop-burn

Failure scenario 2: persona-collision