Agent DailyAgent Daily
videointermediate

4 AI Agents Debate a Topic 🤯 | AutoGen Round Robin Multi-Agent System (Python)

By Nidhi Chouhanyoutube
View original on youtube

This tutorial demonstrates building a round-robin multi-agent debate system using AutoGen in Python, where four AI agents with different personas engage in structured discussions on a given topic. The system showcases how to configure agents with distinct roles, implement conversation management, and orchestrate multi-agent interactions. Key concepts include agent initialization, message passing, and debate orchestration patterns that enable autonomous agent collaboration.

Key Points

  • •Set up multiple AI agents with distinct personas and roles (e.g., moderator, expert, skeptic, analyst) for structured debates
  • •Configure agents with specific system prompts to define their debate style, expertise, and communication patterns
  • •Implement round-robin conversation flow where agents take turns responding to maintain organized discussion structure
  • •Use AutoGen's GroupChat and GroupChatManager to orchestrate multi-agent interactions and manage message routing
  • •Define conversation termination conditions (max rounds, consensus reached, or specific keywords) to control debate length
  • •Leverage agent memory and context to ensure agents reference previous statements and build coherent arguments
  • •Implement custom message handlers to log debates, track argument quality, and extract key discussion points
  • •Test debate quality by varying topics, agent configurations, and conversation parameters to optimize interactions

Found this useful? Add it to a playbook for a step-by-step implementation guide.

Workflow Diagram

Start Process
Step A
Step B
Step C
Complete
Quality★★★★★

Concepts

Artifacts (2)

autogen_debate_systempythonscript
# AutoGen Round Robin Multi-Agent Debate System
import autogen
from autogen import AssistantAgent, UserProxyAgent, GroupChat, GroupChatManager

# Configure LLM settings
config_list = [
    {
        "model": "gpt-4",
        "api_key": "YOUR_API_KEY",
    }
]

# Initialize agents with distinct personas
moderator = AssistantAgent(
    name="Moderator",
    system_message="You are a fair debate moderator. Keep discussion on track and ensure all voices are heard.",
    llm_config={"config_list": config_list}
)

expert = AssistantAgent(
    name="Expert",
    system_message="You are a subject matter expert. Provide evidence-based arguments and cite sources.",
    llm_config={"config_list": config_list}
)

skeptic = AssistantAgent(
    name="Skeptic",
    system_message="You are a critical thinker. Challenge assumptions and ask probing questions.",
    llm_config={"config_list": config_list}
)

analyst = AssistantAgent(
    name="Analyst",
    system_message="You are a data analyst. Focus on facts, statistics, and logical reasoning.",
    llm_config={"config_list": config_list}
)

# Create user proxy for initiating debate
user_proxy = UserProxyAgent(
    name="User",
    human_input_mode="NEVER",
    code_execution_config={"work_dir": "."},
)

# Set up group chat with round-robin speaker selection
agents = [moderator, expert, skeptic, analyst]
groupchat = GroupChat(
    agents=agents,
    messages=[],
    max_round=10,
    speaker_selection_method="round_robin"
)

manager = GroupChatManager(groupchat=groupchat, llm_config={"config_list": config_list})

# Initiate debate
topic = "Should AI be regulated by governments?"
user_proxy.initiate_chat(
    manager,
    message=f"Let's debate the following topic: {topic}"
)
agent_configurationpythonconfig
# Agent Configuration Dictionary
AGENT_CONFIG = {
    "moderator": {
        "role": "Moderator",
        "system_prompt": "You are a fair and impartial debate moderator. Your role is to keep the discussion on track, ensure all participants get equal speaking time, and summarize key points.",
        "temperature": 0.7,
        "max_tokens": 500
    },
    "expert": {
        "role": "Subject Matter Expert",
        "system_prompt": "You are a leading expert in this field. Provide well-researched arguments, cite credible sources, and explain complex concepts clearly.",
        "temperature": 0.6,
        "max_tokens": 600
    },
    "skeptic": {
        "role": "Critical Skeptic",
        "system_prompt": "You are a critical thinker who questions assumptions. Challenge weak arguments, ask probing questions, and identify logical fallacies.",
        "temperature": 0.8,
        "max_tokens": 550
    },
    "analyst": {
        "role": "Data Analyst",
        "system_prompt": "You are a data-driven analyst. Focus on statistics, empirical evidence, and logical reasoning. Provide concrete examples and metrics.",
        "temperature": 0.6,
        "max_tokens": 550
    }
}

DEBATE_CONFIG = {
    "max_rounds": 10,
    "speaker_selection": "round_robin",
    "termination_keywords": ["consensus", "agreement", "conclude"],
    "timeout_seconds": 300
}