Skip to content

Agent

Base agent class to be inherited by all agents.

WaldiezAgent

Bases: WaldiezBase

Waldiez Agent.

Attributes:

NameTypeDescription
idstr

The ID of the agent.

typeLiteral['agent']

The type of the "node" in a graph: "agent"

agent_typeWaldiezAgentType

The type of the agent

namestr

The name of the agent.

descriptionstr

The description of the agent.

tagsList[str]

Tags for this agent.

requirementsList[str]

Python requirements for the agent.

created_atstr

The date and time when the agent was created.

updated_atstr

The date and time when the agent was last updated.

dataWaldiezAgentData

The data (properties) of this agent. See waldiez.models.agents.WaldiezAgentData for more info.

Methods:

NameDescription
validate_linked_skills

Validate the skills linked to the agent.

validate_linked_models

Validate the models linked to the agent.

ag2_class: str property

Return the AG2 class of the agent.

ag2_imports: Set[str] property

Return the AG2 imports of the agent.

validate_code_execution(skill_ids: List[str]) -> None

Validate the code execution config.

Parameters:

NameTypeDescriptionDefault
skill_idsList[str]

The list of skill IDs.

required

Raises:

TypeDescription
ValueError

If a function is not found

Source code in waldiez/models/agents/agent/agent.py
def validate_code_execution(self, skill_ids: List[str]) -> None:
    """Validate the code execution config.

    Parameters
    ----------
    skill_ids : List[str]
        The list of skill IDs.

    Raises
    ------
    ValueError
        If a function is not found
    """
    # if the config dict has functions, make sure they can be found
    if isinstance(
        self.data.code_execution_config, WaldiezAgentCodeExecutionConfig
    ):
        for function in self.data.code_execution_config.functions:
            if function not in skill_ids:
                raise ValueError(
                    f"Function '{function}' not found in skills"
                )

validate_linked_models(model_ids: List[str]) -> None

Validate the models.

Parameters:

NameTypeDescriptionDefault
model_idsList[str]

The list of model IDs.

required

Raises:

TypeDescription
ValueError

If a model is not found

Source code in waldiez/models/agents/agent/agent.py
def validate_linked_models(self, model_ids: List[str]) -> None:
    """Validate the models.

    Parameters
    ----------
    model_ids : List[str]
        The list of model IDs.

    Raises
    ------
    ValueError
        If a model is not found
    """
    # if the config dict has models, make sure they can be found
    for model in self.data.model_ids:
        if model not in model_ids:
            raise ValueError(
                f"Model '{model}' not found in agent's {self.id} models"
            )

validate_linked_skills(skill_ids: List[str], agent_ids: List[str]) -> None

Validate the skills.

Parameters:

NameTypeDescriptionDefault
skill_idsList[str]

The list of skill IDs.

required
agent_idsList[str]

The list of agent IDs.

required

Raises:

TypeDescription
ValueError

If a skill or agent is not found

Source code in waldiez/models/agents/agent/agent.py
def validate_linked_skills(
    self, skill_ids: List[str], agent_ids: List[str]
) -> None:
    """Validate the skills.

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

    Raises
    ------
    ValueError
        If a skill or agent is not found
    """
    # if the config dict has skills, make sure they can be found
    for skill in self.data.skills:
        if skill.id not in skill_ids:
            raise ValueError(
                f"Skill '{skill.id}' not found in agent's {self.id} skills"
            )
        if skill.executor_id not in agent_ids:
            raise ValueError(
                f"Agent '{skill.executor_id}' not found in agents"
            )

Common data structures for agents.

WaldiezAgentData

Bases: WaldiezBase

Waldiez Agent Data.

Attributes:

NameTypeDescription
system_messageOptional[str]

The agent's system message. Default: None (depends on the agent's type)

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

The human input mode to use for the agent.

code_execution_configUnion[WaldiezAgentCodeExecutionConfig, False]

The code execution config. Either False (no execution) or a dict.

agent_default_auto_replyOptional[str]

The agent's default auto reply when no input is received.

max_consecutive_auto_replyOptional[int]

The maximum number or consecutive auto replies to use before ending the chat. Default: None (no limit).

terminationWaldiezAgentTerminationMessage

The message termination check to use (keyword, method, none)

teachabilityWaldiezAgentTeachability

The agent teachability configuration.

model_idsList[str]

A list of models (their ids) to link with the agent.

skillsList[WaldiezAgentLinkedSkill]

A list of skills (id and executor) to register.

nested_chatsList[WaldiezAgentNestedChat]

A list of nested chats (triggered_by, messages), to register.

is_multimodalbool

A flag to indicate if the agent is multimodal.

Waldiez Agent types.

WaldiezAgentType = Literal['user', 'assistant', 'manager', 'rag_user', 'swarm', 'reasoning', 'captain'] module-attribute

Possible types of a Waldiez Agent: user, assistant, manager, rag_user, swarm, reasoning, captain.

Waldiez Agent Code Execution Configuration.

WaldiezAgentCodeExecutionConfig

Bases: WaldiezBase

Waldiez Agent Code Execution Configuration.

Attributes:

NameTypeDescription
work_dirOptional[str]

The working directory for the code execution.

use_dockerOptional[bool]

Run the code in a docker container.

timeoutOptional[float]

The timeout for the code execution. By default None (no timeout).

last_n_messagesOptional[int]

The chat's last n messages to consider for the code execution.

functionsOptional[List[str]]

If not using docker, a list of function ids to use.

Waldiez Agent Skill Model.

WaldiezAgentLinkedSkill

Bases: WaldiezBase

Waldiez Agent Linked Skill.

Attributes:

NameTypeDescription
idstr

The id of the skill to use.

executor_idstr

The id of the agent to use that skill.

Waldiez Agent Nested Chat.

WaldiezAgentNestedChat

Bases: WaldiezBase

Waldiez Agent Nested Chat.

Attributes:

NameTypeDescription
triggered_byList[str]

A list of agent ids that trigger the nested chat.

messagesList[WaldiezAgentNestedChatMessage]

The list of messages (chat ids and 'is_reply'z) to include the in the nested chat registration.

WaldiezAgentNestedChatMessage

Bases: WaldiezBase

Waldiez Agent nested chat message.

A reference to a chat's message or reply in a nested chat

Attributes:

NameTypeDescription
idstr

The id of the chat.

is_replybool

Whether to use the reply in the chat or not.

Waldiez Agent Termination Message Check.

WaldiezAgentTerminationMessage

Bases: WaldiezBase

Waldiez Agent Termination Message Check.

Attributes:

NameTypeDescription
typeLiteral['none', 'keyword', 'method']

The type of the termination check to use: "none", "keyword", "method"

keywordsList[str]

If the type is "keyword", the keywords to search in the message.

criterionOptional[Literal["found", "ending", "exact"]] = None

If the type is "keyword", the criterion to use (e.g.: in, endswith, ==)

method_contentOptional[str]

If the type is "method", the code of the method to use. The method must be called is_termination_message, have one argument (message) which is a dict, and return a bool (whether the message is a termination message or not.)

stringstr

The value of the termination message.

Methods:

NameDescription
validate_termination_message

Validate the termination message configuration.

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

Get the termination function.

Parameters:

NameTypeDescriptionDefault
name_prefixstr

The function name prefix.

None
name_suffixstr

The function name suffix.

None

Returns:

TypeDescription
Tuple[str, str]

The termination function and the function name.

Source code in waldiez/models/agents/agent/termination_message.py
def get_termination_function(
    self,
    name_prefix: Optional[str] = None,
    name_suffix: Optional[str] = None,
) -> Tuple[str, str]:
    """Get the termination function.

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

    Returns
    -------
    Tuple[str, str]
        The termination function and the function name.
    """
    function_name = "is_termination_message"
    if name_prefix:
        function_name = f"{name_prefix}_{function_name}"
    if name_suffix:
        function_name = f"{function_name}_{name_suffix}"
    if self.type in ("none", "keyword"):
        return self.string, function_name
    return (
        generate_function(
            function_name=function_name,
            function_args=IS_TERMINATION_MESSAGE_ARGS,
            function_types=IS_TERMINATION_MESSAGE_TYPES,
            function_body=self.string,
        ),
        function_name,
    )

string: str property

Get the value of the termination message.

  • If the type is "none", the value is "None".
  • If the type is "keyword", the value is a lambda function that checks if any of the keywords comply with the criterion.
  • If the type is "method", the value is the method content.

Returns:

TypeDescription
str

The value of the termination message.

validate_termination_message() -> Self

Validate the termination message configuration.

Raises:

TypeDescription
ValueError

If the configuration is invalid.

Returns:

TypeDescription
WaldiezAgentTerminationMessage

The validated termination message configuration.

Source code in waldiez/models/agents/agent/termination_message.py
@model_validator(mode="after")
def validate_termination_message(self) -> Self:
    """Validate the termination message configuration.

    Raises
    ------
    ValueError
        If the configuration is invalid.
    Returns
    -------
    WaldiezAgentTerminationMessage
        The validated termination message configuration.
    """
    if self.type == "method":
        self._validate_method_content()
    if self.type == "keyword":
        self._validate_keyword()
    if self.type == "none":
        self._string = "None"
    return self

Waldiez Agent Teachability.

WaldiezAgentTeachability

Bases: WaldiezBase

Waldiez Agent Teachability.

Attributes:

NameTypeDescription
enabledbool

Whether the teachability is enabled.

verbosityLiteral[0, 1, 2, 3]

The verbosity level of the teachability. Default: 0

reset_dbbool

Whether to reset the database. Default: False

recall_thresholdfloat

The recall threshold. Default: 1.5

max_num_retrievalsint

The maximum number of retrievals. Default: 10