Overview
TheGroupChat class enables collaborative conversations among multiple agents (or callables) with flexible speaker selection strategies, conversation history management, and interactive terminal sessions. Agents can @mention each other to request input or delegate tasks.
Class Definition
Parameters
Unique identifier for the group chat
Name of the group chat
Description of the group chat’s purpose
List of agent objects or callables that will participate in the conversation
Maximum number of conversation loops per run
Output format for conversation history. Options: “dict”, “str”, “list”, “json”
If True, enables interactive terminal REPL session for human-in-the-loop conversations
Speaker selection strategy. Options: “round-robin-speaker”, “random-speaker”, “priority-speaker”, “random-dynamic-speaker”, or custom callable
State/configuration for the speaker function (e.g., priorities for priority-speaker)
Rules for the conversation that will be added to conversation history
Whether to enable timestamps in conversation messages
Speaker Functions
Built-in Speaker Functions
round-robin-speaker
Cycles through agents in order, ensuring each agent gets a turn sequentially.random-speaker
Randomly selects exactly one agent to respond to each user query.priority-speaker
Selects agents based on priority weights. Requires priority configuration in speaker_state.random-dynamic-speaker
Randomly selects the first agent, then follows @mentions in responses for subsequent speakers. Supports both sequential and parallel execution strategies.Custom Speaker Functions
You can provide custom speaker selection logic:Methods
run()
The user input or task to process. Can include @mentions to target specific agents
Optional image input for the agents
Optional list of images for the agents
The formatted conversation history (format depends on output_type)
GroupChatError: If an unexpected error occursAgentNotFoundError: If a mentioned agent is not found
start_interactive_session()
- Chat with agents using @mentions (optional)
- See available agents and descriptions
- Change speaker function mid-conversation
- Exit using ‘exit’ or ‘quit’
- Get help using ‘help’ or ’?’
GroupChatError: If interactive mode is not enabled
set_speaker_function()
Either a string name of predefined function or custom callable
Optional state for the speaker function
InvalidSpeakerFunctionError: If the speaker function is invalid
get_available_speaker_functions()
List of available speaker function names
get_current_speaker_function()
Name of current speaker function, or “custom” if it’s a custom function
Collaboration Features
@Mentions
Agents can mention other agents using @agent_name syntax:Automatic Prompt Augmentation
GroupChat automatically adds collaboration instructions to each agent’s system prompt:- How to use @mentions
- Collaboration guidelines
- Task completion protocols
- Response structure recommendations
Conversation Context
Each agent receives the complete conversation history, enabling:- Context-aware responses
- Building upon others’ contributions
- Acknowledging previous agents’ work
Usage Examples
Basic GroupChat
Interactive Session
Priority-Based Selection
Exception Classes
GroupChatError: Base exception for GroupChat errorsAgentNotFoundError: Raised when a mentioned agent is not foundInvalidTaskFormatError: Raised when task format is invalidInvalidSpeakerFunctionError: Raised when invalid speaker function is provided