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')
(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 Agent
class, 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.
def custom_speaker_selection_func(
last_speaker: Agent, groupchat: GroupChat
) -> Union[Agent, str, None]:
allow_repeat_speaker
is 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_speaker
and allowed_or_disallowed_speaker_transitions
are 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_speaker
and allowed_or_disallowed_speaker_transitions
are 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_transitions
is a dictionary containing lists of allowed agents. If set to "disallowed", then the allowed_or_disallowed_speaker_transitions
is a dictionary containing lists of disallowed agents. Must be supplied if allowed_or_disallowed_speaker_transitions
is 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')
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
#
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 #
Randomly select the next 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
773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 |
|