Agent
Base agent class to be inherited by all agents.
WaldiezAgent ¶
Bases: WaldiezBase
Waldiez Agent to be inherited by all other agents.
Attributes:
Name | Type | Description |
---|---|---|
id | str | The ID of the agent. |
type | Literal['agent'] | The type of the "node" in a graph: "agent" |
agent_type | WaldiezAgentType | The type of the agent |
name | str | The name of the agent. |
description | str | The description of the agent. |
tags | list[str] | Tags for this agent. |
requirements | list[str] | Python requirements for the agent. |
created_at | str | The date and time when the agent was created. |
updated_at | str | The date and time when the agent was last updated. |
data | WaldiezAgentData | The data (properties) of this agent. See |
Methods:
Name | Description |
---|---|
validate_linked_tools | Validate the tools linked to the agent. |
validate_linked_models | Validate the models linked to the agent. |
gather_handoff_ids ¶
gather_handoff_ids(
group_chats: list[WaldiezChat], nested_chat_id: str
) -> None
Gather all the handoff IDs for this agent.
This method will gather all the handoff IDs from the agent's data, including those that might not be passed in data.handoffs.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
group_chats | list[WaldiezChat] | The list of group chats that this agent is part of. | required |
nested_chat_id | str | The ID of the nested chat to include in handoffs if it exists. | required |
Source code in waldiez/models/agents/agent/agent.py
gather_handoffs ¶
gather_handoffs(
all_agents: list[WaldiezAgent],
all_chats: list[WaldiezChat],
) -> None
Gather all the handoffs including.
Including ones that might not be passed in data.handoffs.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
all_agents | list[WaldiezAgent] | The list of all agents in the flow. | required |
all_chats | list[WaldiezChat] | The list of all chats in the flow. | required |
Source code in waldiez/models/agents/agent/agent.py
gather_nested_chats ¶
gather_nested_chats(
all_agents: list[WaldiezAgent],
all_chats: list[WaldiezChat],
) -> None
Gather the nested chats for the agent.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
all_agents | list[WaldiezAgent] | All the agents in the flow. | required |
all_chats | list[WaldiezChat] | All the chats in the flow. | required |
Source code in waldiez/models/agents/agent/agent.py
handoffs property
¶
handoffs: list[WaldiezHandoff]
Get the handoffs for this agent.
Returns:
Type | Description |
---|---|
list[WaldiezHandoff] | The list of handoffs for this agent. |
Raises:
Type | Description |
---|---|
RuntimeError | If handoffs have not been gathered yet. |
is_captain property
¶
is_captain: bool
Check if the agent is a captain.
Returns:
Type | Description |
---|---|
bool | True if the agent is a captain, False otherwise. |
is_group_manager property
¶
is_group_manager: bool
Check if the agent is a group manager.
Returns:
Type | Description |
---|---|
bool | True if the agent is a group manager, False otherwise. |
is_group_member property
¶
is_group_member: bool
Check if the agent is a group member.
Returns:
Type | Description |
---|---|
bool | True if the agent is a group member, False otherwise. |
is_rag_user property
¶
is_rag_user: bool
Check if the agent is a RAG user.
Returns:
Type | Description |
---|---|
bool | True if the agent is a RAG user, False otherwise. |
is_reasoning property
¶
is_reasoning: bool
Check if the agent is a reasoning agent.
Returns:
Type | Description |
---|---|
bool | True if the agent is a reasoning agent, False otherwise. |
is_user property
¶
is_user: bool
Check if the agent is a user.
Returns:
Type | Description |
---|---|
bool | True if the agent is a user, False otherwise. |
validate_agent_type classmethod
¶
validate_agent_type(
v: WaldiezAgentType,
) -> WaldiezAgentType
Validate the agent type.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
v | WaldiezAgentType | The agent type. | required |
Returns:
Type | Description |
---|---|
WaldiezAgentType | The validated agent type. |
Raises:
Type | Description |
---|---|
ValueError | If the agent type is not valid. |
Source code in waldiez/models/agents/agent/agent.py
validate_code_execution ¶
Validate the code execution config.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
tool_ids | list[str] | The list of tool IDs. | required |
Raises:
Type | Description |
---|---|
ValueError | If a function is not found |
Source code in waldiez/models/agents/agent/agent.py
validate_linked_models ¶
Validate the models.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
model_ids | List[str] | The list of model IDs. | required |
Raises:
Type | Description |
---|---|
ValueError | If a model is not found |
Source code in waldiez/models/agents/agent/agent.py
validate_linked_tools ¶
Validate the tools.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
tool_ids | list[str] | The list of tool IDs. | required |
agent_ids | list[str] | The list of agent IDs. | required |
Raises:
Type | Description |
---|---|
ValueError | If a tool or agent is not found |
Source code in waldiez/models/agents/agent/agent.py
Common data structures for agents.
WaldiezAgentData ¶
Bases: WaldiezBase
Waldiez Agent Data.
Attributes:
Name | Type | Description |
---|---|---|
system_message | Optional[str] | The agent's system message. Default: None (depends on the agent's type) |
human_input_mode | Literal['ALWAYS', 'NEVER', 'TERMINATE'] | The human input mode to use for the agent. |
code_execution_config | Union[WaldiezAgentCodeExecutionConfig, False] | The code execution config. Either False (no execution) or a dict. |
agent_default_auto_reply | Optional[str] | The agent's default auto reply when no input is received. |
max_consecutive_auto_reply | Optional[int] | The maximum number or consecutive auto replies to use before ending the chat. Default: None (no limit). |
termination | WaldiezAgentTerminationMessage | The message termination check to use (keyword, method, none) |
model_ids | List[str] | The ids of the models to link with the agent. |
tools | list[WaldiezAgentLinkedTool] | A list of tools (id and executor) to register. |
nested_chats | list[WaldiezAgentNestedChat] | A list of nested chats (triggered_by, messages), to register. |
context_variables | Optional[dict[str, Any]] | Context variables that provide a persistent context for the agent. Note: This will be a reference to a shared context for multi-agent chats. Behaves like a dictionary with keys and values (akin to dict[str, Any]). |
update_agent_state_before_reply | list[str | WaldiezAgentUpdateSystemMessage] | A list of functions, including UpdateSystemMessage, called to update the agent's state before it replies. Each function is called when the agent is selected and before it speaks. |
handoffs | list[WaldiezAgentHandoff] | A list of handoffs (conditions, targets) to register. |
Waldiez Agent types.
WaldiezAgentType module-attribute
¶
WaldiezAgentType = Literal[
"user_proxy",
"assistant",
"group_manager",
"manager",
"rag_user",
"swarm",
"reasoning",
"captain",
"user",
"rag_user_proxy",
]
Possible types of a Waldiez Agent: - user_proxy, - assistant, - group_manager, - rag_user_proxy, - reasoning, - captain, - swarm (deprecated: do not use it), - user (deprecated: use user_proxy) - rag_user (deprecated: user rag_user_proxy) - manager (deprecated: use group_manager)
Waldiez Agent Code Execution Configuration.
WaldiezAgentCodeExecutionConfig ¶
Bases: WaldiezBase
Waldiez Agent Code Execution Configuration.
Attributes:
Name | Type | Description |
---|---|---|
work_dir | Optional[str] | The working directory for the code execution. |
use_docker | Optional[bool] | Run the code in a docker container. |
timeout | Optional[float] | The timeout for the code execution. By default None (no timeout). |
last_n_messages | Optional[int] | The chat's last n messages to consider for the code execution. |
functions | Optional[list[str]] | If not using docker, a list of function ids to use. |
Waldiez Agent Tool Model.
WaldiezAgentLinkedTool ¶
Bases: WaldiezBase
Waldiez Agent Linked Tool.
Attributes:
Name | Type | Description |
---|---|---|
id | str | The id of the tool to use. |
executor_id | str | The id of the agent to use that tool. |
Waldiez Agent Nested Chat.
WaldiezAgentNestedChat ¶
Bases: WaldiezBase
Waldiez Agent Nested Chat.
Attributes:
Name | Type | Description |
---|---|---|
triggered_by | list[str] | A list of agent ids that trigger the nested chat. |
messages | list[WaldiezAgentNestedChatMessage] | The list of messages (chat ids and 'is_reply'z) to include the in the nested chat registration. |
order | int | The order of the nested chat (if used as a handoff). Defaults to 0. |
WaldiezAgentNestedChatMessage ¶
Bases: WaldiezBase
Waldiez Agent nested chat message.
A reference to a chat's message or reply in a nested chat
Attributes:
Name | Type | Description |
---|---|---|
id | str | The id of the chat. |
is_reply | bool | Whether to use the reply in the chat or not. |
Waldiez Agent Termination Message Check.
WaldiezAgentTerminationMessage ¶
Bases: WaldiezBase
Waldiez Agent Termination Message Check.
Attributes:
Name | Type | Description |
---|---|---|
type | Literal['none', 'keyword', 'method'] | The type of the termination check to use: "none", "keyword", "method" |
keywords | list[str] | If the type is "keyword", the keywords to search in the message. |
criterion | Optional[Literal["found", "ending", "exact"]] = None | If the type is "keyword", the criterion to use (e.g.: in, endswith, ==) |
method_content | Optional[str] | If the type is "method", the code of the method to use. The method must be called |
string | str | The value of the termination message. |
Methods:
Name | Description |
---|---|
validate_termination_message | Validate the termination message configuration. |
get_termination_function ¶
get_termination_function(
name_prefix: Optional[str] = None,
name_suffix: Optional[str] = None,
) -> tuple[str, str]
Get the termination function.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
name_prefix | str | The function name prefix. | None |
name_suffix | str | The function name suffix. | None |
Returns:
Type | Description |
---|---|
tuple[str, str] | The termination function and the function name. |
Source code in waldiez/models/agents/agent/termination_message.py
string property
¶
string: str
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:
Type | Description |
---|---|
str | The value of the termination message. |
validate_termination_message ¶
validate_termination_message() -> Self
Validate the termination message configuration.
Raises:
Type | Description |
---|---|
ValueError | If the configuration is invalid. |
Returns:
Type | Description |
---|---|
WaldiezAgentTerminationMessage | The validated termination message configuration. |