AI Model Wiki

    Skip to main content
    45 min
    Lesson 2 of 5

    Group Chat & Multi-Agent Patterns

    From the course AutoGen: Multi-Agent Conversations

    Multi-Agent Group Conversations

    Setting Up Group Chat

    from autogen import GroupChat, GroupChatManager
    
    coder = AssistantAgent(
        name="coder",
        system_message="You write Python code to solve problems.",
        llm_config=llm_config,
    )
    
    reviewer = AssistantAgent(
        name="reviewer",
        system_message="You review code for bugs, performance, and best practices.",
        llm_config=llm_config,
    )
    
    tester = AssistantAgent(
        name="tester",
        system_message="You write comprehensive test cases.",
        llm_config=llm_config,
    )
    
    group_chat = GroupChat(
        agents=[user_proxy, coder, reviewer, tester],
        messages=[],
        max_round=12,
        speaker_selection_method="auto",
    )
    
    manager = GroupChatManager(groupchat=group_chat, llm_config=llm_config)
    user_proxy.initiate_chat(manager, message="Build a URL shortener service")
    

    Speaker Selection

    Control who speaks next:

    • auto: LLM decides based on conversation context
    • round_robin: Fixed rotation through agents
    • random: Random selection
    • manual: Human chooses
    • Custom function: Your logic decides

    Conversation Patterns

    • Debate: Two agents argue opposing viewpoints
    • Pipeline: Each agent handles one stage
    • Review loop: Creator → Reviewer → Creator (iterative refinement)
    • Consensus: Multiple agents vote on best approach

    Common Pitfall: Choosing "auto" Speaker Selection for All Group Chats

    The auto speaker selection method uses an LLM call to decide who speaks next — this doubles the token cost and latency of every turn. For straightforward pipelines where the conversation flow is predictable (research → review → write), use a custom function instead:

    def select_speaker(last_speaker, groupchat):
        agents = groupchat.agents
        order = {"user": 0, "coder": 1, "reviewer": 2, "tester": 3}
        next_idx = (order.get(last_speaker.name, 0) + 1) % len(agents)
        return agents[next_idx]
    
    group_chat = GroupChat(
        agents=[user_proxy, coder, reviewer, tester],
        messages=[],
        max_round=12,
        speaker_selection_method=select_speaker,
    )
    

    Best Practice: Give Each Agent a Distinct, Non-Overlapping Specialty

    Agent effectiveness in group chat degrades when multiple agents have overlapping responsibilities. Define each agent's scope narrowly and make it explicit in the system message. For example, tell the reviewer explicitly "You review ONLY code quality — do not suggest new features. If a feature request is needed, say DEFER_TO_CODER."

    Named Product Reference: OpenAI GPT-4o for Group Chat Management

    The GroupChatManager makes LLM calls to coordinate conversations. Using GPT-4o-mini as the manager model significantly reduces cost with minimal coordination quality loss for most workflows. Reserve GPT-4o for the specialist agents doing complex reasoning. A typical group-chat setup might spend 80% of tokens on the manager — right-sizing the manager model alone can halve total API costs.

    Key Takeaways

    • •GroupChat enables multi-agent conversations with managed turns
    • •Speaker selection methods control conversation flow
    • •GroupChatManager coordinates agent interactions
    • •Design patterns include debate, pipeline, review loop, and consensus
    0 of 5 lessons marked complete

    Progress is kept in this browser only.