Skip to content

Waldiez

Waldiez

A Waldiez class contains all the information that is needed to generate and run an autogen workflow. It has the model/LLM configurations, the agent definitions and their optional additional skills to be used.

Waldiez(flow: WaldiezFlow) dataclass

Waldiez data class.

It contains all the information to generate and run an autogen workflow.

agents: Iterator[WaldiezAgent] property

Get the agents.

Yields:

TypeDescription
WaldiezAgent

The flow agents.

cache_seed: Optional[int] property

Get the cache seed.

chats: List[Tuple[WaldiezChat, WaldiezAgent, WaldiezAgent]] property

Get the chats.

description: str property

Get the flow description.

from_dict(data: Dict[str, Any], flow_id: Optional[str] = None, name: Optional[str] = None, description: Optional[str] = None, tags: Optional[List[str]] = None, requirements: Optional[List[str]] = None) -> Waldiez classmethod

Create a Waldiez from dict.

Parameters:

NameTypeDescriptionDefault
dataDict[str, Any]

The data.

required
flow_idOptional[str]

The flow id, by default None (retrieved from data or generated).

None
nameOptional[str]

The name, by default None (retrieved from data).

None
descriptionOptional[str]

The description, by default None (retrieved from data).

None
tagsOptional[List[str]]

The tags, by default None (retrieved from data).

None
requirementsOptional[List[str]]

The requirements, by default None (retrieved from data).

None

Returns:

TypeDescription
Waldiez

The Waldiez.

Source code in waldiez/models/waldiez.py
@classmethod
def from_dict(
    cls,
    data: Dict[str, Any],
    flow_id: Optional[str] = None,
    name: Optional[str] = None,
    description: Optional[str] = None,
    tags: Optional[List[str]] = None,
    requirements: Optional[List[str]] = None,
) -> "Waldiez":
    """Create a Waldiez from dict.

    Parameters
    ----------
    data : Dict[str, Any]
        The data.
    flow_id : Optional[str], optional
        The flow id, by default None (retrieved from data or generated).
    name : Optional[str], optional
        The name, by default None (retrieved from data).
    description : Optional[str], optional
        The description, by default None (retrieved from data).
    tags : Optional[List[str]], optional
        The tags, by default None (retrieved from data).
    requirements : Optional[List[str]], optional
        The requirements, by default None (retrieved from data).

    Returns
    -------
    Waldiez
        The Waldiez.
    """
    flow = get_flow_data(
        data,
        flow_id=flow_id,
        name=name,
        description=description,
        tags=tags,
        requirements=requirements,
    )
    return cls(flow=WaldiezFlow.model_validate(flow))

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

Get the flow environment variables.

Returns:

TypeDescription
List[Tuple[str, str]]

The environment variables for the flow.

Source code in waldiez/models/waldiez.py
def get_flow_env_vars(self) -> List[Tuple[str, str]]:
    """Get the flow environment variables.

    Returns
    -------
    List[Tuple[str, str]]
        The environment variables for the flow.
    """
    env_vars: List[Tuple[str, str]] = []
    for skill in self.skills:
        for secret_key, secret_value in skill.secrets.items():
            env_vars.append((secret_key, secret_value))
    return env_vars

get_group_chat_members(agent: WaldiezAgent) -> List[WaldiezAgent]

Get the chat members that connect to a group chat manager agent.

Parameters:

NameTypeDescriptionDefault
agentWaldiezAgent

The agent (group chat manager).

required

Returns:

TypeDescription
List[WaldiezAgent]

The group chat members.

Source code in waldiez/models/waldiez.py
def get_group_chat_members(self, agent: WaldiezAgent) -> List[WaldiezAgent]:
    """Get the chat members that connect to a group chat manager agent.

    Parameters
    ----------
    agent : WaldiezAgent
        The agent (group chat manager).

    Returns
    -------
    List[WaldiezAgent]
        The group chat members.
    """
    if agent.agent_type != "manager":
        return []
    return self.flow.get_group_chat_members(agent.id)

get_swarm_members(initial_agent: WaldiezAgent) -> Tuple[List[WaldiezAgent], Optional[WaldiezAgent]]

Get the chat members that connect to a swarm agent.

Parameters:

NameTypeDescriptionDefault
initial_agentWaldiezAgent

The initial agent.

required

Returns:

TypeDescription
Tuple[List[WaldiezAgent], Optional[WaldiezAgent]]

The swarm agents and the user agent.

Source code in waldiez/models/waldiez.py
def get_swarm_members(
    self, initial_agent: WaldiezAgent
) -> Tuple[List[WaldiezAgent], Optional[WaldiezAgent]]:
    """Get the chat members that connect to a swarm agent.

    Parameters
    ----------
    initial_agent : WaldiezAgent
        The initial agent.

    Returns
    -------
    Tuple[List[WaldiezAgent], Optional[WaldiezAgent]]
        The swarm agents and the user agent.
    """
    return self.flow.get_swarm_chat_members(initial_agent)

has_captain_agents: bool property

Check if the flow has captain agents.

has_multimodal_agents: bool property

Check if the flow has multimodal agents.

has_rag_agents: bool property

Check if the flow has RAG agents.

is_async: bool property

Check if the flow is asynchronous.

is_single_agent_mode: bool property

Check if the flow is single agent mode.

load(waldiez_file: Union[str, Path], name: Optional[str] = None, description: Optional[str] = None, tags: Optional[List[str]] = None, requirements: Optional[List[str]] = None) -> Waldiez classmethod

Load a Waldiez from a file.

Parameters:

NameTypeDescriptionDefault
waldiez_fileUnion[str, Path]

The Waldiez file.

required
nameOptional[str]

The name, by default None.

None
descriptionOptional[str]

The description, by default None.

None
tagsOptional[List[str]]

The tags, by default None.

None
requirementsOptional[List[str]]

The requirements, by default None.

None

Returns:

TypeDescription
Waldiez

The Waldiez.

Raises:

TypeDescription
ValueError

If the file is not found or invalid JSON.

Source code in waldiez/models/waldiez.py
@classmethod
def load(
    cls,
    waldiez_file: Union[str, Path],
    name: Optional[str] = None,
    description: Optional[str] = None,
    tags: Optional[List[str]] = None,
    requirements: Optional[List[str]] = None,
) -> "Waldiez":
    """Load a Waldiez from a file.

    Parameters
    ----------
    waldiez_file : Union[str, Path]
        The Waldiez file.
    name : Optional[str], optional
        The name, by default None.
    description : Optional[str], optional
        The description, by default None.
    tags : Optional[List[str]], optional
        The tags, by default None.
    requirements : Optional[List[str]], optional
        The requirements, by default None.

    Returns
    -------
    Waldiez
        The Waldiez.

    Raises
    ------
    ValueError
        If the file is not found or invalid JSON.
    """
    data: Dict[str, Any] = {}
    if not Path(waldiez_file).exists():
        raise ValueError(f"File not found: {waldiez_file}")
    with open(waldiez_file, "r", encoding="utf-8") as file:
        try:
            data = json.load(file)
        except json.decoder.JSONDecodeError as error:
            raise ValueError(f"Invalid JSON: {waldiez_file}") from error
    return cls.from_dict(
        data,
        name=name,
        description=description,
        tags=tags,
        requirements=requirements,
    )

model_dump_json(by_alias: bool = True, indent: Optional[int] = None) -> str

Get the model dump json.

We use by_alias=True by default to use the alias (toCamel).

Parameters:

NameTypeDescriptionDefault
by_aliasbool

Use alias (toCamel), by default True.

True
indentOptional[int]

The indent, by default None.

None

Returns:

TypeDescription
str

The model dump json.

Source code in waldiez/models/waldiez.py
def model_dump_json(
    self, by_alias: bool = True, indent: Optional[int] = None
) -> str:
    """Get the model dump json.

    We use `by_alias=True` by default to use the alias (toCamel).

    Parameters
    ----------
    by_alias : bool, optional
        Use alias (toCamel), by default True.
    indent : Optional[int], optional
        The indent, by default None.

    Returns
    -------
    str
        The model dump json.
    """
    return self.flow.model_dump_json(by_alias=by_alias, indent=indent)

models: Iterator[WaldiezModel] property

Get the models.

Yields:

TypeDescription
WaldiezModel

The flow models.

name: str property

Get the flow name.

requirements: List[str] property

Get the flow requirements.

skills: Iterator[WaldiezSkill] property

Get the flow skills.

Yields:

TypeDescription
WaldiezSkill

The skills.

tags: List[str] property

Get the flow tags.