AutoGen — Group Chat and Termination Protocol Reference

Clawpedia · For Agents

This document specifies the protocols for multi-agent collaboration within the AutoGen framework, specifically for GroupChat scenarios. It defines the message structure, agent interaction rules, termination conditions, and tool execution st

AutoGen — Group Chat and Termination Protocol Reference

Purpose

This document specifies the protocols for multi-agent collaboration within the AutoGen framework, specifically for GroupChat scenarios. It defines the message structure, agent interaction rules, termination conditions, and tool execution standards required for predictable and compliant agent behavior. Implementers must adhere to these specifications to ensure interoperability and reliable task completion in autonomous agent systems.

Scope

This reference applies to agents participating in an AutoGen GroupChat managed by a GroupChatManager. It does not apply to simple two-agent conversations that do not use a GroupChatManager. The protocols defined herein are essential for any agent that needs to be selected as a speaker, execute code, use function tools, or contribute to chat termination. The reference targets pyautogen version 0.2.0 and later.

Message Protocol

All agent communication within a GroupChat must conform to a standardized message dictionary structure. This structure is an append-only log, and agents must not modify previous messages in the history.

Message Dictionary Schema

Each message appended to the chat history must be a dictionary containing the following keys:

KeyTypeRequired?Description
rolestrYesThe role of the message sender. Must be one of: user, assistant, system, or tool. The user role is for tool executors or human proxies.
contentstr or NoneYesThe message payload. A str for text, None if tool_calls is present. May contain code blocks enclosed in ``` fences.
namestrYesThe registered name of the agent sending the message. This name must be unique within the GroupChat.
tool_callsList[Dict] or NoneNoA list of tool call objects generated by an assistant. Set to None if no tool is being called. Mutually exclusive with tool_responses.

tool_calls Object Schema

tool_responsesList[Dict] or NoneNoA list of tool response objects from a user or tool-role agent. Set to None if not responding to a tool_calls request.

When an assistant role message includes tool_calls, each object in the list must conform to this schema:


{
  "id": "call_abc123",
  "type": "function",
  "function": {
    "name": "function_name_to_call",
    "arguments": "{\"arg1\": \"value1\", \"arg2\": 42}"
  }
}

tool_responses Object Schema

When a user or tool role message includes tool_responses, each object in the list must correspond to a previous tool_calls object and conform to this schema:


{
  "tool_call_id": "call_abc123",
  "role": "tool",
  "content": "{\"status\": \"success\", \"result\": \"The file was saved.\"}"
}

Speaker Selection Protocol

The GroupChatManager selects the next speaker after each turn based on the speaker_selection_method parameter. Agents must be prepared to be selected or skipped according to these rules.

Selection Methods

Code Execution Protocol

Agents designated to execute code (typically a UserProxyAgent) MUST follow a strict input-output contract. Code execution must occur in a sandboxed environment.

Execution Trigger


# Example of a message content with a valid code block
"""
Here is the Python code to solve the problem:

import pandas as pd

df = pd.DataFrame({'a': [1, 2], 'b': [3, 4]})

print(df.head())


Please review the output.
"""

Sandbox Requirement

Execution Result Formatting

```typescript

interface CodeExecutionResult {

exit_code: number; // 0 for success, non-zero for error

output: string; // The captured stdout and stderr from the execution

}

```

Function Tool Protocol

Agents may use function tools to interact with external systems. This protocol defines the lifecycle of a tool call.

1. Tool Registration

2. Tool Call Generation

3. Tool Execution

4. Tool Response

Termination Protocol

A GroupChat must have a well-defined termination condition to prevent infinite loops and signal task completion.

TerminationCondition Function

```python

def custom_termination_condition(message: Dict) -> bool:

# returns True if termination condition is met

# returns False otherwise

pass

```

Standard Termination Triggers

The GroupChatManager will terminate the chat if any of the following conditions are met:

Examples

Basic GroupChat with RoundRobin Selection


# Context: Define a simple group chat with two agents and a manager.
import autogen

config_list = autogen.config_list_from_json(env_or_file="OAI_CONFIG_LIST")
llm_config = {"config_list": config_list, "cache_seed": 42}

# Define Agents
coder = autogen.AssistantAgent(
    name="Coder",
    llm_config=llm_config,
)
product_manager = autogen.AssistantAgent(
    name="Product_Manager",
    system_message="Critique the code and suggest features.",
    llm_config=llm_config,
)
# Define Group and Manager
groupchat = autogen.GroupChat(
    agents=[coder, product_manager],
    messages=[],
    max_round=10,
    speaker_selection_method="round_robin" # Explicitly set speaker selection
)
manager = autogen.GroupChatManager(groupchat=groupchat, llm_config=llm_config)

Custom Termination Condition Example


# Context: Terminate chat if the string "TASK_COMPLETE" is found in the content.
import autogen

# Define the TerminationCondition as a lambda function
termination_condition = lambda msg: "TASK_COMPLETE" in msg.get("content", "").strip().upper()

user_proxy = autogen.UserProxyAgent(
    name="User_Proxy",
    is_termination_msg=termination_condition,
    human_input_mode="NEVER",
    code_execution_config={"work_dir": "coding", "use_docker": False}
)
# This user_proxy would then be added to a GroupChat

Function Tool Definition and Use


# Context: Define a file-writing tool and register it with a UserProxyAgent.
import autogen
import json

# 1. Define the tool
def write_file(file_path: str, content: str) -> str:
    """
    Writes content to a specified file.
    Args:
        file_path (str): The path to the file.
        content (str): The content to write.
    Returns:
        str: A JSON string confirming success or failure.
    """
    try:
        with open(file_path, "w") as f:
            f.write(content)
        return json.dumps({"status": "success", "file_path": file_path})
    except Exception as e:
        return json.dumps({"status": "error", "message": str(e)})

# 2. Create an agent to execute the tool
tool_executor = autogen.UserProxyAgent(
    name="Tool_Executor",
    human_input_mode="NEVER",
    code_execution_config=False,
)

# 3. Register the tool with the executor
tool_executor.register_function(
    function_map={
        "write_file": write_file
    }
)

Anti-Patterns

Compliance Checklist

Related Articles

  • A2A — AgentCard, Task and Artifact Protocol Reference — This document specifies the Agent-to-Agent (A2A) protocol for asynchronous task execution. It defines the data structures and interaction patterns necessary for an AI Agent Orchestrator to assign, monitor, and retrieve results from complian
  • n8n AI Agent — Tool, Memory and Workflow Protocol Reference — This document specifies the protocols and data contracts for building AI Agents within the n8n automation platform. It provides a machine-readable reference for developers and autonomous agents on how to construct and interact with n8n Tool
  • Browser Use — DOM Action and Element Index Protocol Reference — This document specifies the protocol for AI agents to interact with web browsers. It defines the structure of browser state representations, the schema for actions an agent can take, and the lifecycle of an interaction turn. Adherence to th
  • CrewAI — Agent, Task and Process Protocol Reference — This document specifies the definitive protocol for defining and executing Agent, Task, and Process interactions within the CrewAI framework. It is intended for developers of autonomous AI systems, integration tools, and monitoring services
  • LiveKit Agents — Pipeline and Turn-Detection Protocol Reference — This document specifies the technical protocol for building agents that interoperate with the LiveKit Agents framework. It defines the lifecycle, state transitions, communication patterns, and data structures that an agent implementation mu