SwarmAgent
Swarm agent.
WaldiezSwarmAgent
¶
Bases: WaldiezAgent
Swarm agent.
It extends a user agent and has swarm related parameters.
Attributes:
Name | Type | Description |
---|---|---|
agent_type | Literal['swarm'] | The agent type: 'swarm' for a swarm agent. |
data | WaldiezSwarmAgentData | The swarm agent's data. See |
functions: List[str]
property
¶
handoffs: List[Union[WaldiezSwarmOnCondition, WaldiezSwarmAfterWork]]
property
¶
is_initial: bool
property
¶
Check if the agent is the initial agent.
Returns:
Type | Description |
---|---|
bool | Whether the agent is the initial agent. |
nested_chats: List[WaldiezAgentNestedChat]
property
¶
Swarm agent data.
WaldiezSwarmAgentData
¶
Bases: WaldiezAgentData
Swarm agent data.
Attributes:
Name | Type | Description |
---|---|---|
is_initial | bool | Whether the agent is the initial agent. |
functions | List[str] | A list of functions (skill ids) to register with the agent. |
update_agent_state_before_reply | List[str] | A list of functions, including |
handoffs | List[Union[WaldiezSwarmOnCondition, WaldiezSwarmAfterWork]] | A list of hand offs to register. |
Notes
Each agent should have at most one AfterWork
and (if any) it should be at the end the list of hand offs.
validate_handoffs() -> Self
¶
Validate the hand offs.
Returns:
Type | Description |
---|---|
Self | The swarm agent data. |
Raises:
Type | Description |
---|---|
ValueError | If there are more than one |
Source code in waldiez/models/agents/swarm_agent/swarm_agent_data.py
Swarm condition model for handoff.
WaldiezSwarmOnCondition
¶
Bases: WaldiezBase
Swarm condition to handle handoff.
Attributes:
Name | Type | Description |
---|---|---|
target | WaldiezSwarmOnConditionTarget | The agent or nested chat configuration to hand off to. |
target_type | Literal['agent', 'nested_chat'] | The type of the target. Can be either 'agent' or 'nested_chat'. Default is 'agent'. |
condition | str | The condition for transitioning to the target agent |
available | (str, optional) | Optional condition to determine if this OnCondition is available. Can be a Callable or a string. If a string, it will look up the value of the context variable with that name, which should be a bool. |
available_check_type | Literal['string', 'callable', 'none'] | The type of the |
get_available(name_prefix: Optional[str] = None, name_suffix: Optional[str] = None) -> Tuple[str, str]
¶
Get the available string.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
name_prefix | str | The prefix to add to the function name. Default is None. | None |
name_suffix | str | The suffix to add to the function name. Default is None. | None |
Returns:
Type | Description |
---|---|
Tuple[str, str] | The available string or function name and code if available. |
Source code in waldiez/models/agents/swarm_agent/on_condition.py
WaldiezSwarmOnConditionTargetType = Literal['agent', 'nested_chat']
module-attribute
¶
Possible types for the target of the OnCondition.
Swarm after work model.
Handles the next step in the conversation when an agent doesn't suggest a tool call or a handoff.
WaldiezSwarmAfterWork
¶
Bases: WaldiezBase
Swarm after work.
Attributes:
Name | Type | Description |
---|---|---|
recipient | str | The agent_id to hand off to, an AfterWork option, or the custom after work method. If it is an AfterWork option, it can be one of ('TERMINATE', 'REVERT_TO_USER', 'STAY', 'SWARM_MANAGER'). |
recipient_type | WaldiezSwarmAfterWorkRecipientType | The type of recipient. Can be 'agent', 'option', or 'callable'. If 'agent', the recipient is a Swarm Agent. If 'option', the recipient is an AfterWorkOption : ('TERMINATE', 'REVERT_TO_USER', 'STAY', 'SWARM_MANAGER'). If 'callable', it should have the signature: def custom_after_work( last_speaker: ConversableAgent, messages: List[dict], groupchat: GroupChat, ) -> Union[AfterWorkOption, ConversableAgent, str]: |
get_recipient(agent_names: Dict[str, str], name_prefix: Optional[str] = None, name_suffix: Optional[str] = None) -> Tuple[str, str]
¶
Get the recipient string.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
agent_names | Dict[str, str] | A mapping of agent id to agent name. | required |
name_prefix | Optional[str] | The prefix for the function name, by default None. | None |
name_suffix | Optional[str] | The suffix for the function name, by default None. | None |
Returns:
Type | Description |
---|---|
Tuple[str, str] | The recipient string and the function content if applicable. |
Source code in waldiez/models/agents/swarm_agent/after_work.py
validate_recipient() -> Self
¶
Validate the recipient.
Returns:
Type | Description |
---|---|
WaldiezSwarmAfterWork | The validated after work model. |
Raises:
Type | Description |
---|---|
ValueError | If the validation fails. |
Source code in waldiez/models/agents/swarm_agent/after_work.py
WaldiezSwarmAfterWorkOption = Literal['TERMINATE', 'REVERT_TO_USER', 'STAY', 'SWARM_MANAGER']
module-attribute
¶
The possible AfterWork options.
WaldiezSwarmAfterWorkRecipientType = Literal['agent', 'option', 'callable']
module-attribute
¶
The possible AfterWork recipient types.
Update the agent's system message before they reply.
WaldiezSwarmUpdateFunctionType = Literal['string', 'callable']
module-attribute
¶
Possible types for the update function.
WaldiezSwarmUpdateSystemMessage
¶
Bases: WaldiezBase
Update the agent's system message before they reply.
Attributes:
Name | Type | Description |
---|---|---|
update_function_type | Literal['string', 'callable'] | The type of the update function. Can be either a string or a callable. |
update_function | str | The string template or function definition to update the agent's system message. Can be a string or a Callable. If the |
get_update_function(name_prefix: Optional[str] = None, name_suffix: Optional[str] = None) -> Tuple[str, str]
¶
Get the update function.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
name_prefix | str | The prefix of the name, by default None | None |
name_suffix | str | The suffix of the name, by default None | None |
Returns:
Type | Description |
---|---|
Tuple[str, str] | The update function and the function name. |
Source code in waldiez/models/agents/swarm_agent/update_system_message.py
validate_update_system_message() -> Self
¶
Validate the update system message function.
Returns:
Type | Description |
---|---|
UpdateSystemMessage | The validated update system message. |
Raises:
Type | Description |
---|---|
ValueError | If the type is callable and the function is invalid. or if the function type is not 'string' or 'callable'. |