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())
(In preview) 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 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. 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 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. 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 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 will be called to select the next speaker. 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.
- max_retries_for_selecting_speaker: the maximum number of times the speaker selection requery process will run. If, during speaker selection, multiple agent names or no agent names are returned by the LLM as the next agent, it will be queried again up to the maximum number of times until a single agent is returned or it exhausts the maximum attempts. Applies only to "auto" speaker selection method. Default is 2.
- select_speaker_transform_messages: (optional) the message transformations to apply to the nested select speaker agent-to-agent chat messages. Takes a TransformMessages object, defaults to None and is only utilised when the speaker selection method is "auto".
- select_speaker_auto_verbose: whether to output the select speaker responses and selections. If set to True, the outputs from the two agents in the nested select speaker chat will be output, along with whether the responses were successful, or not, in selecting an agent. Applies only to "auto" speaker selection method.
- allow_repeat_speaker: whether to allow the same speaker to speak consecutively. Default is True, in which case all speakers are allowed to speak consecutively. If
allow_repeat_speakeris a list of Agents, then only those listed agents are allowed to repeat. If set to False, then no speakers are allowed to repeat.allow_repeat_speakerandallowed_or_disallowed_speaker_transitionsare mutually exclusive. - allowed_or_disallowed_speaker_transitions: dict. The keys are source agents, and the values are agents that the key agent can/can't transit to, depending on speaker_transitions_type. Default is None, which means all agents can transit to all other agents.
allow_repeat_speakerandallowed_or_disallowed_speaker_transitionsare mutually exclusive. - speaker_transitions_type: whether the speaker_transitions_type is a dictionary containing lists of allowed agents or disallowed agents. "allowed" means the
allowed_or_disallowed_speaker_transitionsis a dictionary containing lists of allowed agents. If set to "disallowed", then theallowed_or_disallowed_speaker_transitionsis a dictionary containing lists of disallowed agents. Must be supplied ifallowed_or_disallowed_speaker_transitionsis not None. - enable_clear_history: enable possibility to clear history of messages for agents manually by providing "clear history" phrase in user prompt. This is experimental feature. See description of GroupChatManager.clear_agents_history function for more info.
- send_introductions: send a round of introductions at the start of the group chat, so agents know who they can speak to (default: False)
- select_speaker_auto_model_client_cls: Custom model client class for the internal speaker select agent used during 'auto' speaker selection (optional)
- select_speaker_auto_llm_config: LLM config for the internal speaker select agent used during 'auto' speaker selection (optional)
- role_for_select_speaker_messages: sets the role name for speaker selection when in 'auto' mode, typically 'user' or 'system'. (default: 'system')
-
eligibility_policies: list of :class:
AgentEligibilityPolicyto filter candidate agents before speaker selection. All policies must returnTruefor an agent to be considered eligible (AND semantics). Default is[](no filtering).Note: Policies are not applied when
speaker_selection_methodis a Callable that returns an :class:Agentdirectly.
max_retries_for_selecting_speaker class-attribute instance-attribute #
allowed_or_disallowed_speaker_transitions class-attribute instance-attribute #
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_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_auto_verbose class-attribute instance-attribute #
select_speaker_auto_model_client_cls class-attribute instance-attribute #
select_speaker_auto_llm_config class-attribute instance-attribute #
role_for_select_speaker_messages class-attribute instance-attribute #
eligibility_policies class-attribute instance-attribute #
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)
reset #
append #
Append a message to the group chat. We cast the content to str here so that it can be managed by text-based model.
Source code in autogen/agentchat/groupchat.py
agent_by_name #
Returns the agent with a given name. If recursive is True, it will search in nested teams.
Source code in autogen/agentchat/groupchat.py
nested_agents #
Returns all agents in the group chat manager.
Source code in autogen/agentchat/groupchat.py
next_agent #
Return the next agent in the list.
Source code in autogen/agentchat/groupchat.py
select_speaker_msg #
Return the system message for selecting the next speaker. This is always the first message in the context.
Source code in autogen/agentchat/groupchat.py
select_speaker_prompt #
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.
Source code in autogen/agentchat/groupchat.py
introductions_msg #
Return the system message for selecting the next speaker. This is always the first message in the context.
Source code in autogen/agentchat/groupchat.py
manual_select_speaker #
Manually select the next speaker.
Source code in autogen/agentchat/groupchat.py
random_select_speaker #
select_speaker #
Select the next speaker (with requery).
Source code in autogen/agentchat/groupchat.py
a_select_speaker async #
Select the next speaker (with requery), asynchronously.
Source code in autogen/agentchat/groupchat.py
a_auto_select_speaker async #
(Asynchronous) Selects next speaker for the "auto" speaker selection method. Utilises its own two-agent chat to determine the next speaker and supports requerying.
Speaker selection for "auto" speaker selection method: 1. Create a two-agent chat with a speaker selector agent and a speaker validator agent, like a nested chat 2. Inject the group messages into the new chat 3. Run the two-agent chat, evaluating the result of response from the speaker selector agent: - If a single agent is provided then we return it and finish. If not, we add an additional message to this nested chat in an attempt to guide the LLM to a single agent response 4. Chat continues until a single agent is nominated or there are no more attempts left 5. If we run out of turns and no single agent can be determined, the next speaker in the list of agents is returned
| PARAMETER | DESCRIPTION |
|---|---|
last_speaker | The previous speaker in the group chat TYPE: |
selector | The ConversableAgent that initiated the speaker selection TYPE: |
messages | Current chat messages |
agents | Valid list of agents for speaker selection |
| RETURNS | DESCRIPTION |
|---|---|
Agent | A counter for mentioned agents. |
Source code in autogen/agentchat/groupchat.py
882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 | |