Skip to content

GroupManager

Group chat manager agent.

WaldiezGroupManager

Bases: WaldiezAgent

Group chat manager agent.

A WaldiezAgent with agent_type manager, human_input_mode: "NEVER" and chat group related config for the agent. Also see WaldiezAgent, WaldiezGroupManagerData, WaldiezAgentData

Attributes:

NameTypeDescription
agent_typeLiteral['manager']

The agent type: 'manager' for a group manager agent

dataWaldiezGroupManagerData

The group manager agent's data.

Methods:

NameDescription
validate_transitions

Validate the transitions.

validate_transitions(agent_ids: List[str]) -> None

Validate the transitions.

If the selection mode is transition:

  • if allow_repeat is a list of agent_ids, make sure these ids exist.
  • make sure the allowed_or_disallowed_transitions mapping has valid agent ids.

Parameters:

NameTypeDescriptionDefault
agent_idsList[str]

The list of agent IDs.

required

Raises:

TypeDescription
ValueError

If the transitions are invalid.

Source code in waldiez/models/agents/group_manager/group_manager.py
def validate_transitions(self, agent_ids: List[str]) -> None:
    """Validate the transitions.

    If the selection mode is `transition`:

    - if `allow_repeat` is a list of agent_ids,
            make sure these ids exist.
    - make sure the `allowed_or_disallowed_transitions` mapping
            has valid agent ids.

    Parameters
    ----------
    agent_ids : List[str]
        The list of agent IDs.

    Raises
    ------
    ValueError
        If the transitions are invalid.
    """
    speakers: WaldiezGroupManagerSpeakers = self.data.speakers
    if speakers.selection_mode != "transition":
        return
    allow_repeat = speakers.allow_repeat
    if isinstance(allow_repeat, list):
        for agent_id in allow_repeat:
            if agent_id not in agent_ids:
                raise ValueError(f"Invalid agent id: {agent_id}")
    for (
        agent_id,
        transitions,
    ) in speakers.allowed_or_disallowed_transitions.items():
        if agent_id not in agent_ids:
            raise ValueError(f"Invalid agent id: {agent_id}")
        for agent_id in transitions:
            if agent_id not in agent_ids:
                raise ValueError(f"Invalid agent id: {agent_id}")

Group chat manager data.

WaldiezGroupManagerData

Bases: WaldiezAgentData

Group chat manager data class.

The data for an agent with human_input_mode set to "NEVER" as default. and the chat group's related extra properties. See the parent's docs (WaldiezAgentData) for the rest of the properties.

Attributes:

NameTypeDescription
human_input_modeLiteral['ALWAYS', 'NEVER', 'TERMINATE']

The human input mode, Defaults to NEVER

max_roundOptional[int]

The maximum number of rounds to have in the group.

admin_nameOptional[str]

The name of the group's admin. Make sure you use a name of an agent in the group.

speakersWaldiezGroupManagerSpeakers

The rules for the speaker selection and repetition

enable_clear_historyOptional[bool]

Enable clearing the history in the chat group.

send_introductionsbool

Send the group members' introductions.

Group chat speakers.

WaldiezGroupManagerSpeakers

Bases: WaldiezBase

Group chat speakers.

If the method for the speaker selection is custom the selection_custom_method contents (source code) will be used. The method must be called custom_speaker_selection, have two arguments:

  • last_speaker: autogen.ConversableAgent
  • groupchat: autogen.GroupChat

and return a Union[Agent, str, None]

Example
{
    "selectionMethod": "custom",
    "selectionCustomMethod": (
        "def custom_speaker_selection(last_speaker, groupchat):\n"
        "    return last_speaker"
    ),
    ...
}

Attributes:

NameTypeDescription
selection_methodWaldiezGroupManagerSpeakersSelectionMethod

The next speaker selection method.

selection_custom_methodOptional[str]

Method for custom selection.

max_retries_for_selectingOptional[int]

Max retries for selecting a speaker.

selection_modeWaldiezGroupManagerSpeakersSelectionMode

Selection mode.

allow_repeatUnion[bool, List[str]]

Allow repeat.

allowed_or_disallowed_transitionsDict[str, List[str]]

Allowed or disallowed transitions.

transitions_typeWaldiezGroupManagerSpeakersTransitionsType

The type of transition rules to use if if a mapping (agent => List[agents]) is used: allowed (default) or disallowed

custom_method_stringOptional[str]

The custom method string.

Methods:

NameDescription
validate_group_speakers_config

Validate the speakers config.

custom_method_string: Optional[str] property

Get the custom method string.

Returns:

TypeDescription
str

The custom method string.

get_custom_method_function(name_prefix: Optional[str] = None, name_suffix: Optional[str] = None) -> Tuple[str, str]

Get the custom method function.

Parameters:

NameTypeDescriptionDefault
name_prefixstr

The function name prefix.

None
name_suffixstr

The function name suffix.

None

Returns:

TypeDescription
Tuple[str, str]

The custom method function and the function name.

Source code in waldiez/models/agents/group_manager/speakers.py
def get_custom_method_function(
    self,
    name_prefix: Optional[str] = None,
    name_suffix: Optional[str] = None,
) -> Tuple[str, str]:
    """Get the custom method function.

    Parameters
    ----------
    name_prefix : str
        The function name prefix.
    name_suffix : str
        The function name suffix.

    Returns
    -------
    Tuple[str, str]
        The custom method function and the function name.
    """
    function_name = CUSTOM_SPEAKER_SELECTION
    if name_prefix:
        function_name = f"{name_prefix}_{function_name}"
    if name_suffix:
        function_name = f"{function_name}_{name_suffix}"
    return (
        generate_function(
            function_name=function_name,
            function_args=CUSTOM_SPEAKER_SELECTION_ARGS,
            function_types=CUSTOM_SPEAKER_SELECTION_TYPES,
            function_body=self.custom_method_string or "",
        ),
        function_name,
    )

validate_group_speakers_config() -> Self

Validate the speakers config.

Returns:

TypeDescription
GroupManagerSpeakers

The group manager speakers config.

Raises:

TypeDescription
ValueError

If the custom method is invalid.

Source code in waldiez/models/agents/group_manager/speakers.py
@model_validator(mode="after")
def validate_group_speakers_config(self) -> Self:
    """Validate the speakers config.

    Returns
    -------
    GroupManagerSpeakers
        The group manager speakers config.

    Raises
    ------
    ValueError
        If the custom method is invalid.
    """
    if self.selection_method == "custom":
        if not self.selection_custom_method:
            raise ValueError("No custom method provided.")
        is_valid, error_or_body = check_function(
            code_string=self.selection_custom_method,
            function_name=CUSTOM_SPEAKER_SELECTION,
            function_args=CUSTOM_SPEAKER_SELECTION_ARGS,
        )
        if not is_valid or not error_or_body:
            # pylint: disable=inconsistent-quotes
            raise ValueError(
                f"Invalid custom method: {error_or_body or 'no content'}"
            )
        self._custom_method_string = error_or_body
    return self

WaldiezGroupManagerSpeakersSelectionMethod = Literal['auto', 'manual', 'random', 'round_robin', 'custom'] module-attribute

Possible methods for the speaker selection.

WaldiezGroupManagerSpeakersSelectionMode = Literal['repeat', 'transition'] module-attribute

Possible selection modes: repeat, transition.

WaldiezGroupManagerSpeakersTransitionsType = Literal['allowed', 'disallowed'] module-attribute

Possible transitions types: allowed, disallowed.