Common
Common utils for all models.
WaldiezAgentTarget ¶
Bases: WaldiezBase
Agent target for handoff.
Attributes:
Name | Type | Description |
---|---|---|
target_type | Literal['AgentTarget'] | The type of the transition target. |
value | str | The agent id to transfer control to. |
order | int | The order of the target in the list of targets. If -1, the order is automatically determined by the json data. |
WaldiezBase ¶
Bases: BaseModel
Base model class to inherit from.
It contains the default configuration for all models. It also model_dumps
by alias by default.
model_dump ¶
Dump the model to a dictionary.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
**kwargs | Any | Additional keyword arguments. The following are from the Pydantic | {} |
Returns:
Type | Description |
---|---|
dict[str, Any] | The dictionary representation of the model. |
Source code in waldiez/models/common/base.py
model_dump_json ¶
Dump the model to a JSON string.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
**kwargs | Any | Additional keyword arguments. The following are from the Pydantic | {} |
Returns:
Type | Description |
---|---|
str | The JSON string. |
Source code in waldiez/models/common/base.py
WaldiezContextBasedTransition ¶
Bases: WaldiezBase
Condition wrapper for context conditions.
WaldiezContextStrLLMCondition ¶
Bases: WaldiezBase
Context variable-based LLM condition.
is_empty ¶
is_empty() -> bool
Check if the condition is empty.
Returns:
Type | Description |
---|---|
bool | True if the condition has an empty context string, False otherwise. |
WaldiezDefaultCondition ¶
Get the default condition for handoff transitions.
create classmethod
¶
Get the default condition for handoff transitions.
Returns:
Type | Description |
---|---|
WaldiezStringLLMCondition | A default LLM condition with empty prompt and data. |
Source code in waldiez/models/common/handoff.py
WaldiezExpressionContextCondition ¶
Bases: WaldiezBase
Expression-based context condition.
is_empty ¶
is_empty() -> bool
Check if the condition is empty.
Returns:
Type | Description |
---|---|
bool | True if the condition has an empty expression, False otherwise. |
WaldiezGroupOrNestedTarget ¶
Bases: WaldiezBase
Group or nested chat target for handoff.
Attributes:
Name | Type | Description |
---|---|---|
target_type | Literal['GroupChatTarget', 'NestedChatTarget'] | The type of the transition target. |
value | str | The id of the group or nested chat to transfer control to. |
order | int | The order of the target in the list of targets. |
WaldiezHandoff ¶
Bases: WaldiezBase
Handoff class for Waldiez agents and chats.
is_context_based ¶
is_context_based() -> bool
Check if the handoff is context-based.
Returns:
Type | Description |
---|---|
bool | True if the handoff condition is context-based, False otherwise. |
Source code in waldiez/models/common/handoff.py
is_empty ¶
is_empty() -> bool
Check if the handoff is empty.
Returns:
Type | Description |
---|---|
bool | True if the handoff has an empty target, condition, and availability, False otherwise. |
is_llm_based ¶
is_llm_based() -> bool
Check if the handoff is LLM-based.
Returns:
Type | Description |
---|---|
bool | True if the handoff condition is LLM-based, False otherwise. |
Source code in waldiez/models/common/handoff.py
WaldiezLLMBasedTransition ¶
Bases: WaldiezBase
Condition wrapper for LLM conditions.
WaldiezRandomAgentTarget ¶
Bases: WaldiezBase
Random agent target for handoff.
Attributes:
Name | Type | Description |
---|---|---|
target_type | Literal['RandomAgentTarget'] | The type of the transition target. |
value | list[str] | A list of agent ids to randomly select from. |
order | int | The order of the target in the list of targets. If -1, the order is automatically determined by the json data. |
WaldiezSimpleTarget ¶
Bases: WaldiezBase
Simple target for handoff.
Attributes:
Name | Type | Description |
---|---|---|
target_type | Literal[ | "AskUserTarget", "GroupManagerTarget", "RevertToUserTarget", "StayTarget", "TerminateTarget" |
] | The type of the transition target. | |
order | int | The order of the target in the list of targets. If -1, the order is automatically determined by the json data. |
target | str | The id of the group or nested chat to transfer control to. |
WaldiezStringContextCondition ¶
Bases: WaldiezBase
String-based context condition.
is_empty ¶
is_empty() -> bool
Check if the condition is empty.
Returns:
Type | Description |
---|---|
bool | True if the condition has an empty variable name, False otherwise. |
WaldiezStringLLMCondition ¶
Bases: WaldiezBase
String-based LLM condition.
is_empty ¶
is_empty() -> bool
Check if the condition is empty.
Returns:
Type | Description |
---|---|
bool | True if the condition has an empty prompt, False otherwise. |
WaldiezTransitionAvailability ¶
Bases: WaldiezBase
Availability condition for transitions.
Attributes:
Name | Type | Description |
---|---|---|
available | bool | Whether the transition is available. |
data | dict[str, Any] | Additional data for the availability condition. |
ag2_version ¶
Get the autogen version.
get_autogen_version cached
¶
get_autogen_version() -> str
Get the autogen version.
Returns:
Type | Description |
---|---|
str | The autogen version. |
Raises:
Type | Description |
---|---|
ValueError | If ag2 is not installed. |
Source code in waldiez/models/common/ag2_version.py
base ¶
Base class to inherit from.
WaldiezBase ¶
Bases: BaseModel
Base model class to inherit from.
It contains the default configuration for all models. It also model_dumps
by alias by default.
model_dump ¶
Dump the model to a dictionary.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
**kwargs | Any | Additional keyword arguments. The following are from the Pydantic | {} |
Returns:
Type | Description |
---|---|
dict[str, Any] | The dictionary representation of the model. |
Source code in waldiez/models/common/base.py
model_dump_json ¶
Dump the model to a JSON string.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
**kwargs | Any | Additional keyword arguments. The following are from the Pydantic | {} |
Returns:
Type | Description |
---|---|
str | The JSON string. |
Source code in waldiez/models/common/base.py
check_function ¶
check_function(
code_string: str,
function_name: str,
function_args: list[str],
) -> tuple[bool, str]
Check the function.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
code_string | str | The code string to check. | required |
function_name | str | The expected method name. | required |
function_args | list[str] | The expected method arguments. | required |
Returns:
Type | Description |
---|---|
tuple[bool, str] | If valid, True and the function body (only), no extra lines. If invalid, False and the error message. |
Source code in waldiez/models/common/method_utils.py
date_utils ¶
dict_utils ¶
Dictionary related utilities.
update_dict ¶
Try to determine the type of the dictionary values.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
original | dict[str, Any] | The original dictionary. | required |
Returns:
Type | Description |
---|---|
dict[str, Any] | The updated dictionary with values converted to the detected types. |
Source code in waldiez/models/common/dict_utils.py
gather_code_imports ¶
Gather the imports from the code string.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
code_string | str | The code string. | required |
is_interop | bool | If True, make sure the interoperability import is present. | required |
Returns:
Type | Description |
---|---|
tuple[list[str], list[str]] | The standard library imports and the third party imports. |
Source code in waldiez/models/common/method_utils.py
generate_function ¶
generate_function(
function_name: str,
function_args: list[str],
function_types: tuple[list[str], str],
function_body: str,
types_as_comments: bool = False,
) -> str
Generate a function.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
function_name | str | The function name. | required |
function_args | list[str] | The function arguments. | required |
function_types | tuple[list[str], str] | The function types. | required |
function_body | str | The function body. | required |
types_as_comments | bool | Include the type hints as comments (or in the function signature) (default is False). | False |
Returns:
Type | Description |
---|---|
str | The generated function. |
Source code in waldiez/models/common/method_utils.py
get_autogen_version cached
¶
get_autogen_version() -> str
Get the autogen version.
Returns:
Type | Description |
---|---|
str | The autogen version. |
Raises:
Type | Description |
---|---|
ValueError | If ag2 is not installed. |
Source code in waldiez/models/common/ag2_version.py
get_function ¶
Get the function signature and body.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
code_string | str | The code string. | required |
function_name | str | The function name. | required |
Returns:
Type | Description |
---|---|
str | The function signature and body. |
Source code in waldiez/models/common/method_utils.py
get_valid_instance_name ¶
get_valid_instance_name(
instance: tuple[str, str],
current_names: dict[str, str],
prefix: str = "w",
max_length: int = MAX_VARIABLE_LENGTH,
) -> dict[str, str]
Get a valid instance name.
If the instance id is already in the current names nothing is done. If the name already exists in the current names, the name is updated (with an index suffix).
Parameters:
Name | Type | Description | Default |
---|---|---|---|
instance | tuple[str, str] | The instance id and possible name. | required |
current_names | dict[str, str] | The current names. | required |
prefix | str | The prefix to use if the name starts with a digit, if the name is already in the current names, or if the name is already in the current names with an index suffix. | 'w' |
max_length | int | The maximum length of the variable name. | MAX_VARIABLE_LENGTH |
Returns:
Type | Description |
---|---|
dict[str, str] | The updated names. |
Source code in waldiez/models/common/naming.py
get_valid_python_variable_name ¶
get_valid_python_variable_name(
possible: str,
prefix: str = "w",
max_length: int = MAX_VARIABLE_LENGTH,
) -> str
Get a valid Python variable name from a possible name.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
possible | str | The possible name. | required |
prefix | str | The prefix to use if the name starts with a digit or special character | 'w' |
max_length | int | The maximum length of the variable name. | MAX_VARIABLE_LENGTH |
Returns:
Type | Description |
---|---|
str | The valid Python variable name. |
Source code in waldiez/models/common/naming.py
get_waldiez_version ¶
get_waldiez_version() -> str
Read the version from the version file.
Returns:
Type | Description |
---|---|
str | The version. |
Source code in waldiez/models/common/waldiez_version.py
handoff ¶
Waldiez Agent Handoff class.
WaldiezAgentTarget ¶
Bases: WaldiezBase
Agent target for handoff.
Attributes:
Name | Type | Description |
---|---|---|
target_type | Literal['AgentTarget'] | The type of the transition target. |
value | str | The agent id to transfer control to. |
order | int | The order of the target in the list of targets. If -1, the order is automatically determined by the json data. |
WaldiezContextBasedTransition ¶
Bases: WaldiezBase
Condition wrapper for context conditions.
WaldiezContextStrLLMCondition ¶
Bases: WaldiezBase
Context variable-based LLM condition.
is_empty ¶
is_empty() -> bool
Check if the condition is empty.
Returns:
Type | Description |
---|---|
bool | True if the condition has an empty context string, False otherwise. |
WaldiezExpressionContextCondition ¶
Bases: WaldiezBase
Expression-based context condition.
is_empty ¶
is_empty() -> bool
Check if the condition is empty.
Returns:
Type | Description |
---|---|
bool | True if the condition has an empty expression, False otherwise. |
WaldiezGroupOrNestedTarget ¶
Bases: WaldiezBase
Group or nested chat target for handoff.
Attributes:
Name | Type | Description |
---|---|---|
target_type | Literal['GroupChatTarget', 'NestedChatTarget'] | The type of the transition target. |
value | str | The id of the group or nested chat to transfer control to. |
order | int | The order of the target in the list of targets. |
WaldiezHandoff ¶
Bases: WaldiezBase
Handoff class for Waldiez agents and chats.
is_context_based ¶
is_context_based() -> bool
Check if the handoff is context-based.
Returns:
Type | Description |
---|---|
bool | True if the handoff condition is context-based, False otherwise. |
Source code in waldiez/models/common/handoff.py
is_empty ¶
is_empty() -> bool
Check if the handoff is empty.
Returns:
Type | Description |
---|---|
bool | True if the handoff has an empty target, condition, and availability, False otherwise. |
is_llm_based ¶
is_llm_based() -> bool
Check if the handoff is LLM-based.
Returns:
Type | Description |
---|---|
bool | True if the handoff condition is LLM-based, False otherwise. |
Source code in waldiez/models/common/handoff.py
WaldiezLLMBasedTransition ¶
Bases: WaldiezBase
Condition wrapper for LLM conditions.
WaldiezRandomAgentTarget ¶
Bases: WaldiezBase
Random agent target for handoff.
Attributes:
Name | Type | Description |
---|---|---|
target_type | Literal['RandomAgentTarget'] | The type of the transition target. |
value | list[str] | A list of agent ids to randomly select from. |
order | int | The order of the target in the list of targets. If -1, the order is automatically determined by the json data. |
WaldiezSimpleTarget ¶
Bases: WaldiezBase
Simple target for handoff.
Attributes:
Name | Type | Description |
---|---|---|
target_type | Literal[ | "AskUserTarget", "GroupManagerTarget", "RevertToUserTarget", "StayTarget", "TerminateTarget" |
] | The type of the transition target. | |
order | int | The order of the target in the list of targets. If -1, the order is automatically determined by the json data. |
target | str | The id of the group or nested chat to transfer control to. |
WaldiezStringContextCondition ¶
Bases: WaldiezBase
String-based context condition.
is_empty ¶
is_empty() -> bool
Check if the condition is empty.
Returns:
Type | Description |
---|---|
bool | True if the condition has an empty variable name, False otherwise. |
WaldiezStringLLMCondition ¶
Bases: WaldiezBase
String-based LLM condition.
is_empty ¶
is_empty() -> bool
Check if the condition is empty.
Returns:
Type | Description |
---|---|
bool | True if the condition has an empty prompt, False otherwise. |
id_generator ¶
method_utils ¶
Function related utilities.
ParseResult ¶
Bases: NamedTuple
Result of parsing a code string.
check_function ¶
check_function(
code_string: str,
function_name: str,
function_args: list[str],
) -> tuple[bool, str]
Check the function.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
code_string | str | The code string to check. | required |
function_name | str | The expected method name. | required |
function_args | list[str] | The expected method arguments. | required |
Returns:
Type | Description |
---|---|
tuple[bool, str] | If valid, True and the function body (only), no extra lines. If invalid, False and the error message. |
Source code in waldiez/models/common/method_utils.py
gather_code_imports ¶
Gather the imports from the code string.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
code_string | str | The code string. | required |
is_interop | bool | If True, make sure the interoperability import is present. | required |
Returns:
Type | Description |
---|---|
tuple[list[str], list[str]] | The standard library imports and the third party imports. |
Source code in waldiez/models/common/method_utils.py
generate_function ¶
generate_function(
function_name: str,
function_args: list[str],
function_types: tuple[list[str], str],
function_body: str,
types_as_comments: bool = False,
) -> str
Generate a function.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
function_name | str | The function name. | required |
function_args | list[str] | The function arguments. | required |
function_types | tuple[list[str], str] | The function types. | required |
function_body | str | The function body. | required |
types_as_comments | bool | Include the type hints as comments (or in the function signature) (default is False). | False |
Returns:
Type | Description |
---|---|
str | The generated function. |
Source code in waldiez/models/common/method_utils.py
get_function ¶
Get the function signature and body.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
code_string | str | The code string. | required |
function_name | str | The function name. | required |
Returns:
Type | Description |
---|---|
str | The function signature and body. |
Source code in waldiez/models/common/method_utils.py
is_standard_library ¶
Check if the module is part of the standard library.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
module_name | str | The module name. | required |
Returns:
Type | Description |
---|---|
bool | True if the module is part of the standard library. |
Source code in waldiez/models/common/method_utils.py
parse_code_string ¶
parse_code_string(code_string: str) -> ParseResult
Parse the code string.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
code_string | str | The code string. | required |
Returns:
Type | Description |
---|---|
ParseResult | If valid, None and the ast module. If invalid, the error message and None. |
Source code in waldiez/models/common/method_utils.py
naming ¶
Ensure unique names for agents, models, tools, and chats.
get_valid_instance_name ¶
get_valid_instance_name(
instance: tuple[str, str],
current_names: dict[str, str],
prefix: str = "w",
max_length: int = MAX_VARIABLE_LENGTH,
) -> dict[str, str]
Get a valid instance name.
If the instance id is already in the current names nothing is done. If the name already exists in the current names, the name is updated (with an index suffix).
Parameters:
Name | Type | Description | Default |
---|---|---|---|
instance | tuple[str, str] | The instance id and possible name. | required |
current_names | dict[str, str] | The current names. | required |
prefix | str | The prefix to use if the name starts with a digit, if the name is already in the current names, or if the name is already in the current names with an index suffix. | 'w' |
max_length | int | The maximum length of the variable name. | MAX_VARIABLE_LENGTH |
Returns:
Type | Description |
---|---|
dict[str, str] | The updated names. |
Source code in waldiez/models/common/naming.py
get_valid_python_variable_name ¶
get_valid_python_variable_name(
possible: str,
prefix: str = "w",
max_length: int = MAX_VARIABLE_LENGTH,
) -> str
Get a valid Python variable name from a possible name.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
possible | str | The possible name. | required |
prefix | str | The prefix to use if the name starts with a digit or special character | 'w' |
max_length | int | The maximum length of the variable name. | MAX_VARIABLE_LENGTH |
Returns:
Type | Description |
---|---|
str | The valid Python variable name. |
Source code in waldiez/models/common/naming.py
now ¶
now() -> str
Get the current date and time in UTC.
Returns:
Type | Description |
---|---|
str | The current date and time in UTC. |
Source code in waldiez/models/common/date_utils.py
parse_code_string ¶
parse_code_string(code_string: str) -> ParseResult
Parse the code string.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
code_string | str | The code string. | required |
Returns:
Type | Description |
---|---|
ParseResult | If valid, None and the ast module. If invalid, the error message and None. |
Source code in waldiez/models/common/method_utils.py
update_dict ¶
Try to determine the type of the dictionary values.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
original | dict[str, Any] | The original dictionary. | required |
Returns:
Type | Description |
---|---|
dict[str, Any] | The updated dictionary with values converted to the detected types. |
Source code in waldiez/models/common/dict_utils.py
waldiez_version ¶
Read the version from the version file.
get_waldiez_version ¶
get_waldiez_version() -> str
Read the version from the version file.
Returns:
Type | Description |
---|---|
str | The version. |