GroupChat - AG2
GroupChat
autogen.GroupChat dataclass
GroupChat(agents, messages=list(), max_round=10, admin_name='Admin', func_call_filter=True, speaker_selection_method='auto', max_retries_for_selecting_speaker=2, allow_repeat_speaker=None, allowed_or_disallowed_speaker_transitions=None, speaker_transitions_type=None, enable_clear_history=False, send_introductions=False, select_speaker_message_template='You are in a role play game. The following roles are available:\n {roles}.\n Read the following conversation.\n Then select the next role from {agentlist} to play. Only return the role.', select_speaker_prompt_template=SELECT_SPEAKER_PROMPT_TEMPLATE, select_speaker_auto_multiple_template='You provided more than one name in your text, please return just the name of the next speaker. To determine the speaker use these prioritised rules:\n 1. If the context refers to themselves as a speaker e.g. "As the..." , choose that speaker's name\n 2. If it refers to the "next" speaker name, choose that name\n 3. Otherwise, choose the first provided speaker's name in the context\n The names are case-sensitive and should not be abbreviated or changed.\n Respond with ONLY the name of the speaker and DO NOT provide a reason.', select_speaker_auto_none_template='You didn\'t choose a speaker. As a reminder, to determine the speaker use these prioritised rules:\n 1. If the context refers to themselves as a speaker e.g. "As the..." , choose that speaker's name\n 2. If it refers to the "next" speaker name, choose that name\n 3. Otherwise, choose the first provided speaker's name in the context\n The names are case-sensitive and should not be abbreviated or changed.\n The only names that are accepted are {agentlist}.\n Respond with ONLY the name of the speaker and DO NOT provide a reason.', select_speaker_transform_messages=None, select_speaker_auto_verbose=False, select_speaker_auto_model_client_cls=None, select_speaker_auto_llm_config=None, role_for_select_speaker_messages='system', eligibility_policies=list())
A group chat class that contains the following data fields:
- agents: a list of participating agents.
- messages: a list of messages in the group chat.
- max_round: the maximum number of rounds.
- admin_name: the name of the admin agent if there is one. Default is "Admin". KeyBoardInterrupt will make the admin agent take over.
- func_call_filter: whether to enforce function call filter. Default is True. When set to True and when a message is a function call suggestion, the next speaker will be chosen from an agent which contains the corresponding function name in its
function_map. - select_speaker_message_template: customize the select speaker message (used in "auto" speaker selection), which appears first in the message context and generally includes the agent descriptions and list of agents. If the string contains
{roles}it will be replaced with the agent's and their role descriptions. If the string contains{agentlist}it will be replaced with a comma-separated list of agent names in square brackets. The default value is: "You are in a role play game. The following roles are available:{roles}. Read the following conversation. Then select the next role from{agentlist}to play. Only return the role." - select_speaker_prompt_template: customize the select speaker prompt (used in "auto" speaker selection), which appears last in the message context and generally includes the list of agents and guidance for the LLM to select the next agent. If the string contains
{agentlist}it will be replaced with a comma-separated list of agent names in square brackets. The default value is: "Read the above conversation. Then select the next role from{agentlist}to play. Only return the role." To ignore this prompt being used, set this to None. If set to None, ensure your instructions for selecting a speaker are in the select_speaker_message_template string. - select_speaker_auto_multiple_template: customize the follow-up prompt used when selecting a speaker fails with a response that contains multiple agent names. This prompt guides the LLM to return just one agent name. Applies only to "auto" speaker selection method. The default value is: "You provided more than one name in your text, please return just the name of the next speaker. To determine the speaker use these prioritised rules: 1. If the context refers to themselves as a speaker e.g. "As the..." , choose that speaker's name 2. If it refers to the "next" speaker name, choose that name 3. Otherwise, choose the first provided speaker's name in the context The names are case-sensitive and should not be abbreviated or changed. Respond with ONLY the name of the speaker and DO NOT provide a reason."
- select_speaker_auto_none_template: customize the follow-up prompt used when selecting a speaker fails with a response that contains no agent names. This prompt guides the LLM to return an agent name and provides a list of agent names. Applies only to "auto" speaker selection method. The default value is: "You didn't choose a speaker. As a reminder, to determine the speaker use these prioritised rules: 1. If the context refers to themselves as a speaker e.g. "As the..." , choose that speaker's name 2. If it refers to the "next" speaker name, choose that name 3. Otherwise, choose the first provided speaker's name in the context The names are case-sensitive and should not be abbreviated or changed. The only names that are accepted are
{agentlist}. Respond with ONLY the name of the speaker and DO NOT provide a reason." - speaker_selection_method: the method for selecting the next speaker. Default is "auto". Could be any of the following (case insensitive), will raise ValueError if not recognized:
- "auto": the next speaker is selected automatically by LLM.
- "manual": the next speaker is selected manually by user input.
- "random": the next speaker is selected randomly.
- "round_robin": the next speaker is selected in a round robin fashion, i.e., iterating in the same order as provided in
agents. - a customized speaker selection function (Callable): the function should take the last speaker and the group chat as input and return one of the following: 1. an
Agentclass, it must be one of the agents in the group chat. 2. a string from ['auto', 'manual', 'random', 'round_robin'] to select a default method to use. 3. None, which would terminate the conversation gracefully. When this is a Callable that returns an Agent directly, eligibility_policies are not applied to that agent.
agents instance-attribute
agents
messages class-attribute instance-attribute
messages = field(default_factory=list)
max_round class-attribute instance-attribute
max_round = 10
admin_name class-attribute instance-attribute
admin_name = 'Admin'
func_call_filter class-attribute instance-attribute
func_call_filter = True
speaker_selection_method class-attribute instance-attribute
speaker_selection_method = 'auto'
max_retries_for_selecting_speaker class-attribute instance-attribute
max_retries_for_selecting_speaker = 2
allow_repeat_speaker class-attribute instance-attribute
allow_repeat_speaker = None
allowed_or_disallowed_speaker_transitions class-attribute instance-attribute
allowed_or_disallowed_speaker_transitions = None
speaker_transitions_type class-attribute instance-attribute
speaker_transitions_type = None
enable_clear_history class-attribute instance-attribute
enable_clear_history = False
send_introductions class-attribute instance-attribute
send_introductions = False
select_speaker_message_template class-attribute instance-attribute
select_speaker_message_template = 'You are in a role play game. The following roles are available:\n {roles}.\n Read the following conversation.\n Then select the next role from {agentlist} to play. Only return the role.'
select_speaker_prompt_template class-attribute instance-attribute
select_speaker_prompt_template = SELECT_SPEAKER_PROMPT_TEMPLATE
select_speaker_auto_multiple_template class-attribute instance-attribute
select_speaker_auto_multiple_template = 'You provided more than one name in your text, please return just the name of the next speaker. To determine the speaker use these prioritised rules:\n 1. If the context refers to themselves as a speaker e.g. "As the..." , choose that speaker's name\n 2. If it refers to the "next" speaker name, choose that name\n 3. Otherwise, choose the first provided speaker's name in the context\n The names are case-sensitive and should not be abbreviated or changed.\n Respond with ONLY the name of the speaker and DO NOT provide a reason.'
select_speaker_auto_none_template class-attribute instance-attribute
select_speaker_auto_none_template = 'You didn\'t choose a speaker. As a reminder, to determine the speaker use these prioritised rules:\n 1. If the context refers to themselves as a speaker e.g. "As the..." , choose that speaker's name\n 2. If it refers to the "next" speaker name, choose that name\n 3. Otherwise, choose the first provided speaker's name in the context\n The names are case-sensitive and should not be abbreviated or changed.\n The only names that are accepted are {agentlist}.\n Respond with ONLY the name of the speaker and DO NOT provide a reason.'
select_speaker_transform_messages class-attribute instance-attribute
select_speaker_transform_messages = None
select_speaker_auto_verbose class-attribute instance-attribute
select_speaker_auto_verbose = False
select_speaker_auto_model_client_cls class-attribute instance-attribute
select_speaker_auto_model_client_cls = None
select_speaker_auto_llm_config class-attribute instance-attribute
select_speaker_auto_llm_config = None
role_for_select_speaker_messages class-attribute instance-attribute
role_for_select_speaker_messages = 'system'
eligibility_policies class-attribute instance-attribute
eligibility_policies = field(default_factory=list)
DEFAULT_INTRO_MSG class-attribute instance-attribute
DEFAULT_INTRO_MSG = 'Hello everyone. We have assembled a great team today to answer questions and solve tasks. In attendance are:'
allowed_speaker_transitions_dict class-attribute instance-attribute
allowed_speaker_transitions_dict = field(init=False)
agent_names property
agent_names
Return the names of the agents in the group chat.
reset
reset()
Reset the group chat.
append
append(message, speaker)
Append a message to the group chat.
agent_by_name
agent_by_name(name, recursive=False, raise_on_name_conflict=False)
Returns the agent with a given name. If recursive is True, it will search in nested teams.
nested_agents
nested_agents()
Returns all agents in the group chat manager.
next_agent
next_agent(agent, agents=None)
Return the next agent in the list.
select_speaker_msg
select_speaker_msg(agents=None)
Return the system message for selecting the next speaker. This is always the first message in the context.
select_speaker_prompt
select_speaker_prompt(agents=None)
Return the floating system prompt selecting the next speaker. This is always the last message in the context. Will return None if the select_speaker_prompt_template is None.
introductions_msg
introductions_msg(agents=None)
Return the system message for selecting the next speaker. This is always the first message in the context.
manual_select_speaker
manual_select_speaker(agents=None)
Manually select the next speaker.
random_select_speaker
random_select_speaker(agents=None)
Randomly select the next speaker.
select_speaker
select_speaker(last_speaker, selector)
Select the next speaker (with requery).
a_select_speaker
a_select_speaker(last_speaker, selector)
Select the next speaker (with requery), asynchronously.
a_auto_select_speaker
a_auto_select_speaker(last_speaker, selector, messages, agents)
(Asynchronous) Selects next speaker for the "auto" speaker selection method. Utilises its own two-agent chat to determine the next speaker and supports requerying.