Skip to content

Chat

Waldiez chat model.

WaldiezChat

Bases: WaldiezBase

Chat class.

Attributes:

NameTypeDescription
idstr

The chat ID.

sourcestr

The source of the chat (sender).

targetstr

The target of the chat (recipient).

typeWaldiezChatType

The type of the chat data: "chat", "nested", "group", or "hidden".

dataWaldiezChatData

The chat data. See waldiez.models.chat.WaldiezChatData for more information.

namestr

The chat name.

nested_chatWaldiezChatNested

The nested chat message/reply if any.

messageWaldiezChatMessage

The chat message.

message_contentOptional[str]

The chat message content if any. If method, the method's body.

Methods:

NameDescription
get_chat_args

Get the chat arguments to use in autogen.

as_handoff

as_handoff() -> WaldiezHandoff

Convert the chat to a handoff.

Returns:

TypeDescription
WaldiezHandoff

The handoff representation of the chat.

Source code in waldiez/models/chat/chat.py
def as_handoff(
    self,
) -> WaldiezHandoff:
    """Convert the chat to a handoff.

    Returns
    -------
    WaldiezHandoff
        The handoff representation of the chat.
    """
    target: WaldiezTransitionTarget = WaldiezAgentTarget(
        target_type="AgentTarget",
        value=[self.target],
    )
    return WaldiezHandoff(
        target=target,
        condition=self.condition,
        available=self.available,
    )

available property

Get the transition availability.

chat_id property

chat_id: int

Get the chat ID.

condition property

condition: WaldiezHandoffCondition

Get the handoff condition.

description property

description: str

Get the description.

get_chat_args

get_chat_args(
    for_queue: bool, sender: Optional[WaldiezAgent] = None
) -> dict[str, Any]

Get the chat arguments to use in autogen.

Parameters:

NameTypeDescriptionDefault
for_queuebool

Whether to get the chat arguments for a chat queue.

required
senderWaldiezAgent

The sender agent, to check if it's a RAG user.

None

Returns:

TypeDescription
dict

The chat arguments.

Source code in waldiez/models/chat/chat.py
def get_chat_args(
    self,
    for_queue: bool,
    sender: Optional[WaldiezAgent] = None,
) -> dict[str, Any]:
    """Get the chat arguments to use in autogen.

    Parameters
    ----------
    for_queue : bool
        Whether to get the chat arguments for a chat queue.
    sender : WaldiezAgent, optional
        The sender agent, to check if it's a RAG user.

    Returns
    -------
    dict
        The chat arguments.
    """
    args_dict = self.data.get_chat_args(for_queue)
    if (
        isinstance(sender, WaldiezRagUserProxy)
        and sender.is_rag_user
        and self.message.type == "rag_message_generator"
    ):
        # check for n_results in agent data, to add in context
        n_results = sender.data.retrieve_config.n_results
        if isinstance(n_results, int) and n_results > 0:
            args_dict["n_results"] = n_results
    return args_dict

get_message_function

get_message_function(
    name_prefix: Optional[str] = None,
    name_suffix: Optional[str] = None,
    is_rag: bool = False,
) -> tuple[str, str]

Get the message function.

Parameters:

NameTypeDescriptionDefault
name_prefixstr

The function name prefix.

None
name_suffixstr

The function name suffix.

None
is_ragbool

If the message is from a RAG user.

False

Returns:

TypeDescription
tuple[str, str]

The message function and the function name.

Source code in waldiez/models/chat/chat.py
def get_message_function(
    self,
    name_prefix: Optional[str] = None,
    name_suffix: Optional[str] = None,
    is_rag: bool = False,
) -> tuple[str, str]:
    """Get the message function.

    Parameters
    ----------
    name_prefix : str
        The function name prefix.
    name_suffix : str
        The function name suffix.
    is_rag : bool
        If the message is from a RAG user.

    Returns
    -------
    tuple[str, str]
        The message function and the function name.
    """
    if self.message.type in ("string", "none") or (
        not self.message_content and is_rag is False
    ):
        return "", ""
    function_types = CALLABLE_MESSAGE_TYPES
    function_name = CALLABLE_MESSAGE
    if name_prefix:
        function_name = f"{name_prefix}_{function_name}"
    if name_suffix:
        function_name = f"{function_name}_{name_suffix}"
    if is_rag and self.message.type == "rag_message_generator":
        function_types = CALLABLE_MESSAGE_RAG_WITH_CARRYOVER_TYPES
        return (
            generate_function(
                function_name=function_name,
                function_args=CALLABLE_MESSAGE_ARGS,
                function_types=function_types,
                function_body=self.message.content_body
                or RAG_METHOD_WITH_CARRYOVER_BODY,
            ),
            function_name,
        )
    return (
        generate_function(
            function_name=function_name,
            function_args=CALLABLE_MESSAGE_ARGS,
            function_types=function_types,
            function_body=self.message_content or "",
        ),
        function_name,
    )

get_nested_chat_message_function

get_nested_chat_message_function(
    name_prefix: Optional[str] = None,
    name_suffix: Optional[str] = None,
) -> tuple[str, str]

Get the nested chat message function.

Parameters:

NameTypeDescriptionDefault
name_prefixstr

The function name prefix.

None
name_suffixstr

The function name suffix.

None

Returns:

TypeDescription
tuple[str, str]

The nested chat message function and the function name.

Source code in waldiez/models/chat/chat.py
def get_nested_chat_message_function(
    self,
    name_prefix: Optional[str] = None,
    name_suffix: Optional[str] = None,
) -> tuple[str, str]:
    """Get the nested chat message function.

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

    Returns
    -------
    tuple[str, str]
        The nested chat message function and the function name.
    """
    if not self.nested_chat.message or (
        self.nested_chat.message.use_carryover is False
        and self.nested_chat.message.type
        in (
            "string",
            "none",
        )
    ):
        return "", ""
    return self._get_nested_chat_function(
        content=self.nested_chat.message_content,
        function_name_base=NESTED_CHAT_MESSAGE,
        name_prefix=name_prefix,
        name_suffix=name_suffix,
    )

get_nested_chat_reply_function

get_nested_chat_reply_function(
    name_prefix: Optional[str] = None,
    name_suffix: Optional[str] = None,
) -> tuple[str, str]

Get the nested chat reply function.

Parameters:

NameTypeDescriptionDefault
name_prefixstr

The function name prefix.

None
name_suffixstr

The function name suffix.

None

Returns:

TypeDescription
tuple[str, str]

The nested chat reply function and the function name.

Source code in waldiez/models/chat/chat.py
def get_nested_chat_reply_function(
    self,
    name_prefix: Optional[str] = None,
    name_suffix: Optional[str] = None,
) -> tuple[str, str]:
    """Get the nested chat reply function.

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

    Returns
    -------
    tuple[str, str]
        The nested chat reply function and the function name.
    """
    if not self.nested_chat.reply or (
        self.nested_chat.reply.use_carryover is False
        and self.nested_chat.reply.type
        in (
            "string",
            "none",
        )
    ):
        return "", ""
    return self._get_nested_chat_function(
        content=self.nested_chat.reply_content,
        function_name_base=NESTED_CHAT_REPLY,
        name_prefix=name_prefix,
        name_suffix=name_suffix,
    )

max_turns property

max_turns: Optional[int]

Get the max rounds for the chat.

message property

Get the message.

message_content property

message_content: Optional[str]

Get the message content.

model_dump

model_dump(**kwargs: Any) -> dict[str, Any]

Dump the model to a dict including the chat attributes.

Parameters:

NameTypeDescriptionDefault
kwargsAny

The keyword arguments.

{}

Returns:

TypeDescription
dict[str, Any]

The model dump with the chat attributes.

Source code in waldiez/models/chat/chat.py
def model_dump(self, **kwargs: Any) -> dict[str, Any]:
    """Dump the model to a dict including the chat attributes.

    Parameters
    ----------
    kwargs : Any
        The keyword arguments.

    Returns
    -------
    dict[str, Any]
        The model dump with the chat attributes.
    """
    dump = super().model_dump(**kwargs)
    dump["name"] = self.name
    dump["description"] = self.description
    dump["nested_chat"] = self.nested_chat.model_dump()
    dump["message"] = self.message.model_dump()
    dump["message_content"] = self.message_content
    dump["max_turns"] = self.max_turns
    return dump

name property

name: str

Get the name.

nested_chat property

nested_chat: WaldiezChatNested

Get the nested chat.

order property

order: int

Get the order.

prerequisites property

prerequisites: list[int]

Get the chat prerequisites.

set_chat_id

set_chat_id(value: int) -> None

Set the chat ID.

Parameters:

NameTypeDescriptionDefault
valueint

The chat ID.

required
Source code in waldiez/models/chat/chat.py
def set_chat_id(self, value: int) -> None:
    """Set the chat ID.

    Parameters
    ----------
    value : int
        The chat ID.
    """
    self.data.set_chat_id(value)

set_prerequisites

set_prerequisites(value: list[int]) -> None

Set the chat prerequisites.

Parameters:

NameTypeDescriptionDefault
valuelist[int]

The chat prerequisites.

required
Source code in waldiez/models/chat/chat.py
def set_prerequisites(self, value: list[int]) -> None:
    """Set the chat prerequisites.

    Parameters
    ----------
    value : list[int]
        The chat prerequisites.
    """
    self.data.set_prerequisites(value)

WaldiezChatType module-attribute

WaldiezChatType = Literal[
    "chat", "nested", "group", "hidden"
]

Possible chat types: "chat", "nested", "group", "hidden".

Chat data model.

WaldiezChatData

Bases: WaldiezBase

Chat data class.

Attributes:

NameTypeDescription
namestr

The name of the chat.

source_typeWaldiezAgentType

The agent type of the chat source.

target_typeWaldiezAgentType

The agent type of the chat target.

descriptionstr

The description of the chat.

positionint

The position of the chat. Ignored (UI related).

orderint

The of the chat. If negative, ignored.

clear_history(Optional[bool], optional)

Whether to clear the chat history, by default None.

messageUnion[str, WaldiezChatMessage]

The message of the chat.

nested_chatWaldiezChatNested

The nested chat config.

summaryWaldiezChatSummary

The summary method and options for the chat.

max_turnsOptional[int]

The maximum number of turns for the chat, by default None (no limit).

silent(bool, optional)

Whether to run the chat silently, by default False (not silent).

summary_argsOptional[dict[str, Any]]

The summary args to use in autogen.

handoff_condition(Optional[WaldiezHandoffCondition], optional)

The handoff condition to use, by default None (for group chat).

real_sourceOptional[str]

The real source of the chat (overrides the source).

real_targetOptional[str]

The real target of the chat (overrides the target).

get_chat_args

get_chat_args(for_queue: bool) -> dict[str, Any]

Get the chat arguments to use in autogen.

Without the 'message' key.

Parameters:

NameTypeDescriptionDefault
for_queuebool

Whether to get the arguments for a chat queue.

required

Returns:

TypeDescription
dict[str, Any]

The dictionary to pass as kwargs.

Source code in waldiez/models/chat/chat_data.py
def get_chat_args(self, for_queue: bool) -> dict[str, Any]:
    """Get the chat arguments to use in autogen.

    Without the 'message' key.

    Parameters
    ----------
    for_queue : bool
        Whether to get the arguments for a chat queue.

    Returns
    -------
    dict[str, Any]
        The dictionary to pass as kwargs.
    """
    args: dict[str, Any] = {}
    if self.summary.method:  # pragma: no branch
        args["summary_method"] = str(self.summary.method)
    if self.summary_args:
        args["summary_args"] = self.summary_args
    if (
        isinstance(self.max_turns, int) and self.max_turns > 0
    ):  # pragma: no branch
        args["max_turns"] = self.max_turns
    args["clear_history"] = self.clear_history
    # args["silent"] = self.silent
    args.update(self._get_context_args())
    if for_queue:
        args["chat_id"] = self._chat_id
    if self._prerequisites:
        args["prerequisites"] = self._prerequisites
    return args

get_chat_id

get_chat_id() -> int

Get the chat id.

Returns:

TypeDescription
int

The chat id.

Source code in waldiez/models/chat/chat_data.py
def get_chat_id(self) -> int:
    """Get the chat id.

    Returns
    -------
    int
        The chat id.
    """
    return self._chat_id

get_prerequisites

get_prerequisites() -> list[int]

Get the chat prerequisites.

Returns:

TypeDescription
list[int]

The chat prerequisites (if async).

Source code in waldiez/models/chat/chat_data.py
def get_prerequisites(self) -> list[int]:
    """Get the chat prerequisites.

    Returns
    -------
    list[int]
        The chat prerequisites (if async).
    """
    return self._prerequisites

message_content property

message_content: Optional[str]

Get the message content.

set_chat_id

set_chat_id(value: int) -> None

Set the chat id.

Parameters:

NameTypeDescriptionDefault
valueint

The chat id.

required
Source code in waldiez/models/chat/chat_data.py
def set_chat_id(self, value: int) -> None:
    """Set the chat id.

    Parameters
    ----------
    value : int
        The chat id.
    """
    self._chat_id = value

set_prerequisites

set_prerequisites(value: list[int]) -> None

Set the chat prerequisites.

Parameters:

NameTypeDescriptionDefault
valuelist[int]

The chat prerequisites to set.

required
Source code in waldiez/models/chat/chat_data.py
def set_prerequisites(self, value: list[int]) -> None:
    """Set the chat prerequisites.

    Parameters
    ----------
    value : list[int]
        The chat prerequisites to set.
    """
    self._prerequisites = value

summary_args property

summary_args: Optional[dict[str, Any]]

Get the summary args.

validate_chat_data

validate_chat_data() -> Self

Validate the chat data.

Returns:

TypeDescription
WaldiezChatData

The validated chat data.

Raises:

TypeDescription
ValueError

If the validation fails.

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

    Returns
    -------
    WaldiezChatData
        The validated chat data.

    Raises
    ------
    ValueError
        If the validation fails.
    """
    if not isinstance(self.message, WaldiezChatMessage):  # pragma: no cover
        return self
    self._message_content = self.message.content
    if self.message.type == "none":
        self._message_content = None
    if self.message.type == "string":
        self._message_content = self.message.content
    if self.message.type == "method":
        valid, error_or_body = check_function(
            self.message.content or "",
            CALLABLE_MESSAGE,
            CALLABLE_MESSAGE_ARGS,
        )
        if not valid:
            raise ValueError(error_or_body)
        self._message_content = error_or_body
    return self

validate_message classmethod

validate_message(value: Any) -> WaldiezChatMessage

Validate the message.

Parameters:

NameTypeDescriptionDefault
valueAny

The message value.

required

Returns:

TypeDescription
WaldiezChatMessage

The validated message value.

Raises:

TypeDescription
ValueError

If the validation fails.

Source code in waldiez/models/chat/chat_data.py
@field_validator("message", mode="before")
@classmethod
def validate_message(cls, value: Any) -> WaldiezChatMessage:
    """Validate the message.

    Parameters
    ----------
    value : Any
        The message value.

    Returns
    -------
    WaldiezChatMessage
        The validated message value.

    Raises
    ------
    ValueError
        If the validation fails.
    """
    if value is None:
        return WaldiezChatMessage(
            type="none", use_carryover=False, content=None, context={}
        )
    if isinstance(value, (str, int, float, bool)):
        return WaldiezChatMessage(
            type="string",
            use_carryover=False,
            content=str(value),
            context={},
        )
    if isinstance(value, dict):
        return WaldiezChatMessage.model_validate(value)
    if not isinstance(value, WaldiezChatMessage):
        return WaldiezChatMessage(
            type="none", use_carryover=False, content=None, context={}
        )
    return value

Waldiez Message Model.

WaldiezChatMessage

Bases: WaldiezBase

Waldiez Message.

A generic message with a type and content.

If the type is not none, the content is a string. If the type is 'method', the content is the source code of a method. If the type is 'last_carryover', the content is a method to return the last carryover from the context. If the type is 'rag_message_generator', and the sender is a RAG user agent, the content will be generated by the sender.message_generator method.

Attributes:

NameTypeDescription
typeWaldiezChatMessageType

The type of the message: - string - method - rag_message_generator - none If the sender is a RAG user agent, and the type is rag_message_generator, the {sender}.message_generator method will be used.

contentOptional[str]

The content of the message (string or method).

contextdict[str, Any]

Extra context of the message.

content_body property

content_body: Optional[str]

Get the content body.

is_method

is_method() -> bool

Check if the message is a method.

Returns:

TypeDescription
bool

True if the message is a method, False otherwise.

Source code in waldiez/models/chat/chat_message.py
def is_method(self) -> bool:
    """Check if the message is a method.

    Returns
    -------
    bool
        True if the message is a method, False otherwise.
    """
    return self.type in ("method", "rag_message_generator")

validate_content

validate_content() -> Self

Validate the content (if not a method).

Returns:

TypeDescription
WaldiezChatMessage

The validated instance.

Raises:

TypeDescription
ValueError

If the content is invalid.

Source code in waldiez/models/chat/chat_message.py
@model_validator(mode="after")
def validate_content(self) -> Self:
    """Validate the content (if not a method).

    Returns
    -------
    WaldiezChatMessage
        The validated instance.

    Raises
    ------
    ValueError
        If the content is invalid.
    """
    content: Optional[str] = None
    if self.type == "none":
        content = "None"
    if self.type == "method":
        if not self.content:
            raise ValueError(
                "The message content is required for the method type"
            )
        content = self.content
    if self.type == "string":
        if not self.content:
            self.content = ""
        if self.use_carryover:
            self.content = get_last_carryover_method_content(
                text_content=self.content,
            )
        content = self.content
    if self.type == "rag_message_generator":
        if self.use_carryover:
            content = get_last_carryover_method_content(
                text_content=self.content or "",
            )
        else:
            content = RAG_METHOD_WITH_CARRYOVER_BODY
            self.content = RAG_METHOD_WITH_CARRYOVER
    self._content_body = content
    return self

validate_context_vars

validate_context_vars() -> Self

Try to detect bools nulls and numbers from the context values.

Returns:

TypeDescription
WaldiezChatMessage

The validated instance.

Source code in waldiez/models/chat/chat_message.py
@model_validator(mode="after")
def validate_context_vars(self) -> Self:
    """Try to detect bools nulls and numbers from the context values.

    Returns
    -------
    WaldiezChatMessage
        The validated instance.
    """
    self.context = update_dict(self.context)
    return self

validate_method

validate_method(
    function_name: str, function_args: list[str]
) -> str

Validate a method.

Parameters:

NameTypeDescriptionDefault
function_namestr

The method name.

required
function_argslist[str]

The expected method arguments.

required

Returns:

TypeDescription
str

The validated method body.

Raises:

TypeDescription
ValueError

If the validation fails.

Source code in waldiez/models/chat/chat_message.py
def validate_method(
    self,
    function_name: str,
    function_args: list[str],
) -> str:
    """Validate a method.

    Parameters
    ----------
    function_name : str
        The method name.
    function_args : list[str]
        The expected method arguments.

    Returns
    -------
    str
        The validated method body.

    Raises
    ------
    ValueError
        If the validation fails.
    """
    if not self.content:
        raise ValueError(
            "The message content is required for the method type"
        )
    is_valid, error_or_body = check_function(
        code_string=self.content,
        function_name=function_name,
        function_args=function_args,
    )
    if not is_valid:
        raise ValueError(error_or_body)
    return error_or_body

WaldiezChatMessageType module-attribute

WaldiezChatMessageType = Literal[
    "string", "method", "rag_message_generator", "none"
]

Possible types for the message.

get_last_carryover_method_content

get_last_carryover_method_content(text_content: str) -> str

Get the last carryover method content.

Parameters:

NameTypeDescriptionDefault
text_contentstr

Text content before the carryover.

required

Returns:

TypeDescription
str

The last carryover method content.

Source code in waldiez/models/chat/chat_message.py
def get_last_carryover_method_content(text_content: str) -> str:
    """Get the last carryover method content.

    Parameters
    ----------
    text_content : str
        Text content before the carryover.

    Returns
    -------
    str
        The last carryover method content.
    """
    method_content = '''
    """Get the message to send using the last carryover.

    Parameters
    ----------
    sender : ConversableAgent
        The source agent.
    recipient : ConversableAgent
        The target agent.
    context : dict[str, Any]
        The context.

    Returns
    -------
    Union[dict[str, Any], str]
        The message to send using the last carryover.
    """
    carryover = context.get("carryover", "")
    if isinstance(carryover, list):
        carryover = carryover[-1]
    if not isinstance(carryover, str):
        if isinstance(carryover, list):
            carryover = carryover[-1]
        elif isinstance(carryover, dict):
            carryover = carryover.get("content", "")
    if not isinstance(carryover, str):
        carryover = ""'''
    if text_content:
        method_content += f"""
    final_message = "{text_content}" + carryover
    return final_message
"""
    else:
        method_content += """
    return carryover
"""
    return method_content

Nested chat model.

WaldiezChatNested

Bases: WaldiezBase

Nested chat class.

Attributes:

NameTypeDescription
messageWaldiezChatMessage

The message in a nested chat (sender -> recipient).

replyWaldiezChatMessage

The reply in a nested chat (recipient -> sender).

message_content property

message_content: Optional[str]

Get the message content.

reply_content property

reply_content: Optional[str]

Get the reply content.

validate_message classmethod

validate_message(value: Any) -> WaldiezChatMessage

Validate the message.

Parameters:

NameTypeDescriptionDefault
valueAny

The value.

required

Returns:

TypeDescription
WaldiezChatMessage

The validated message.

Raises:

TypeDescription
ValueError

If the validation fails.

Source code in waldiez/models/chat/chat_nested.py
@field_validator("message", "reply", mode="before")
@classmethod
def validate_message(cls, value: Any) -> WaldiezChatMessage:
    """Validate the message.

    Parameters
    ----------
    value : Any
        The value.

    Returns
    -------
    WaldiezChatMessage
        The validated message.

    Raises
    ------
    ValueError
        If the validation fails.
    """
    if not value:
        return WaldiezChatMessage(
            type="none", use_carryover=False, content=None, context={}
        )
    if isinstance(value, str):
        return WaldiezChatMessage(
            type="string", use_carryover=False, content=value, context={}
        )
    if isinstance(value, dict):
        return WaldiezChatMessage.model_validate(value)
    if isinstance(value, WaldiezChatMessage):
        return value
    raise ValueError(f"Invalid message type: {type(value)}")

validate_nested_chat

validate_nested_chat() -> Self

Validate the nested chat.

Returns:

TypeDescription
WaldiezChatNested

The validated nested chat.

Raises:

TypeDescription
ValueError

If the validation fails.

Source code in waldiez/models/chat/chat_nested.py
@model_validator(mode="after")
def validate_nested_chat(self) -> Self:
    """Validate the nested chat.

    Returns
    -------
    WaldiezChatNested
        The validated nested chat.

    Raises
    ------
    ValueError
        If the validation fails.
    """
    for attr, content_attr, function_name in [
        ("message", "_message_content", NESTED_CHAT_MESSAGE),
        ("reply", "_reply_content", NESTED_CHAT_REPLY),
    ]:  # pragma: no branch
        attr_value = getattr(self, attr)
        if attr_value is not None:
            if isinstance(
                attr_value, WaldiezChatMessage
            ):  # pragma: no branch
                setattr(self, content_attr, attr_value.content_body)
                if attr_value.type == "none":
                    setattr(self, content_attr, "")
                elif attr_value.type == "string":
                    setattr(self, content_attr, attr_value.content)
                elif attr_value.type == "method":  # pragma: no branch
                    setattr(
                        self,
                        content_attr,
                        attr_value.validate_method(
                            function_name=function_name,
                            function_args=NESTED_CHAT_ARGS,
                        ),
                    )
    return self

Waldiez chat summary options.

WaldiezChatSummary

Bases: WaldiezBase

Llm summary method options.

Attributes:

NameTypeDescription
methodOptional[WaldiezChatSummaryMethod]

The method to use for the LLM summary. Defaults to "last_msg".

promptstr

The prompt for the LLM summary method.

argsOptional[dict[str, Any]]

The additional arguments for the LLM summary method, by default None.

serialize_summary_method classmethod

serialize_summary_method(
    value: Any, info: FieldSerializationInfo
) -> Any

Serialize summary method.

Parameters:

NameTypeDescriptionDefault
valueAny

The value to serialize.

required
infoFieldSerializationInfo

The serialization info.

required

Returns:

TypeDescription
Any

The serialized value.

Source code in waldiez/models/chat/chat_summary.py
@field_serializer("method")
@classmethod
def serialize_summary_method(
    cls, value: Any, info: FieldSerializationInfo
) -> Any:
    """Serialize summary method.

    Parameters
    ----------
    value : Any
        The value to serialize.
    info : FieldSerializationInfo
        The serialization info.

    Returns
    -------
    Any
        The serialized value.
    """
    if info.by_alias is True:
        if value == "reflection_with_llm":
            return "reflectionWithLlm"
        if value == "last_msg":
            return "lastMsg"
    return value

validate_summary_method classmethod

validate_summary_method(
    value: Optional[WaldiezChatSummaryMethod],
) -> Optional[WaldiezChatSummaryMethod]

Validate the summary method.

Parameters:

NameTypeDescriptionDefault
valueOptional[WaldiezChatSummaryMethod]

The passed WaldiezChatSummaryMethod

required

Returns:

TypeDescription
Optional[WaldiezChatSummaryMethod]

The validated message summary method

Source code in waldiez/models/chat/chat_summary.py
@field_validator("method", mode="before")
@classmethod
def validate_summary_method(
    cls, value: Optional[WaldiezChatSummaryMethod]
) -> Optional[WaldiezChatSummaryMethod]:
    """Validate the summary method.

    Parameters
    ----------
    value : Optional[WaldiezChatSummaryMethod]
        The passed WaldiezChatSummaryMethod

    Returns
    -------
    Optional[WaldiezChatSummaryMethod]
        The validated message summary method
    """
    if str(value).lower() == "none":
        return None
    if value == "lastMsg":
        return "last_msg"
    if value == "reflectionWithLlm":
        return "reflection_with_llm"
    return value

WaldiezChatSummaryMethod module-attribute

WaldiezChatSummaryMethod = Literal[
    "reflectionWithLlm",
    "lastMsg",
    "reflection_with_llm",
    "last_msg",
]

Possible methods for the LLM summary.