Skip to content

Skill

Waldiez Skill model.

WaldiezSkill

Bases: WaldiezBase

Waldiez Skill.

Attributes:

NameTypeDescription
idstr

The ID of the skill.

typeLiteral['skill']

The type of the "node" in a graph: "skill".

namestr

The name of the skill.

descriptionstr

The description of the skill.

tagsList[str]

The tags of the skill.

requirementsList[str]

The requirements of the skill.

created_atstr

The date and time when the skill was created.

updated_atstr

The date and time when the skill was last updated.

dataWaldiezSkillData

The data of the skill. See WaldiezSkillData.

content: str property

Get the content (source) of the skill.

get_content() -> str

Get the content of the skill.

Returns:

TypeDescription
str

The content of the skill.

Source code in waldiez/models/skill/skill.py
def get_content(self) -> str:
    """Get the content of the skill.

    Returns
    -------
    str
        The content of the skill.
    """
    if self.is_shared or self.is_interop:
        return self.data.content
    # if custom, only the function content
    return get_function(self.data.content, self.name)

get_imports() -> Tuple[List[str], List[str]]

Get the skill imports.

Returns:

TypeDescription
Tuple[List[str], List[str]]

The builtin and external imports.

Source code in waldiez/models/skill/skill.py
def get_imports(self) -> Tuple[List[str], List[str]]:
    """Get the skill imports.

    Returns
    -------
    Tuple[List[str], List[str]]
        The builtin and external imports.
    """
    return self._skill_imports

is_interop: bool property

Check if the skill is interoperability.

Returns:

TypeDescription
bool

True if the skill is interoperability, False otherwise.

is_shared: bool property

Check if the skill is shared.

Returns:

TypeDescription
bool

True if the skill is shared, False otherwise.

load(data_or_path: Union[str, Path, Dict[str, Any]]) -> WaldiezSkill staticmethod

Load a skill from a read-only file.

Parameters:

NameTypeDescriptionDefault
data_or_pathUnion[str, Path, Dict[str, Any]]

The path to the read-only file or the loaded data.

required

Returns:

TypeDescription
WaldiezSkill

The skill.

Raises:

TypeDescription
FileNotFoundError

If the file is not found.

ValueError

If the JSON is invalid or the data is invalid.

Source code in waldiez/models/skill/skill.py
@staticmethod
def load(data_or_path: Union[str, Path, Dict[str, Any]]) -> "WaldiezSkill":
    """Load a skill from a read-only file.

    Parameters
    ----------
    data_or_path : Union[str, Path, Dict[str, Any]]
        The path to the read-only file or the loaded data.

    Returns
    -------
    WaldiezSkill
        The skill.

    Raises
    ------
    FileNotFoundError
        If the file is not found.
    ValueError
        If the JSON is invalid or the data is invalid.
    """
    if isinstance(data_or_path, dict):
        return WaldiezSkill.model_validate(data_or_path)
    if not isinstance(data_or_path, Path):
        data_or_path = Path(data_or_path)
    resolved = data_or_path.resolve()
    if not resolved.is_file():
        raise FileNotFoundError(f"File not found: {resolved}")
    with resolved.open("r", encoding="utf-8") as file:
        data_string = file.read()
        try:
            data_dict = json.loads(data_string)
        except BaseException as exc:  # pylint: disable=broad-except
            raise ValueError(f"Invalid WaldiezSkill/JSON: {exc}") from exc
        return WaldiezSkill.model_validate(data_dict)

secrets: Dict[str, str] property

Get the secrets (environment variables) of the skill.

skill_type: WaldiezSkillType property

Get the skill type.

Returns:

TypeDescription
WaldiezSkillType

The type of the skill: [shared, custom, langchain, crewai].

validate_data() -> Self

Validate the data.

Returns:

TypeDescription
WaldiezSkill

The skill.

Raises:

TypeDescription
ValueError

If the skill name is not in the content. If the skill content is invalid.

Source code in waldiez/models/skill/skill.py
@model_validator(mode="after")
def validate_data(self) -> Self:
    """Validate the data.

    Returns
    -------
    WaldiezSkill
        The skill.

    Raises
    ------
    ValueError
        If the skill name is not in the content.
        If the skill content is invalid.
    """
    self._validate_custom_skill()
    self._validate_interop_skill()
    self._skill_imports = gather_code_imports(
        self.data.content, self.is_interop
    )
    # remove the imports from the content
    # we 'll place them at the top of the file
    all_imports = self._skill_imports[0] + self._skill_imports[1]
    code_lines = self.data.content.splitlines()
    valid_lines = [
        line
        for line in code_lines
        if not any(line.startswith(imp) for imp in all_imports)
    ]
    # remove empty lines at the beginning and end
    # of the content
    while valid_lines and not valid_lines[0].strip():
        valid_lines.pop(0)
    while valid_lines and not valid_lines[-1].strip():
        valid_lines.pop()
    self.data.content = "\n".join(valid_lines)
    return self

Waldiez Skill model.

WaldiezSkillData

Bases: WaldiezBase

Waldiez Skill Data.

Attributes:

NameTypeDescription
skill_typeWaldiezSkillType

The type of the skill: shared, custom, langchain, crewai.

contentstr

The content (source code) of the skill.

secretsDict[str, str]

The secrets (environment variables) of the skill.

Waldiez Skill types.

WaldiezSkillType = Literal['shared', 'custom', 'langchain', 'crewai'] module-attribute

Possible types of a Waldiez Skill.