Chat
Waldiez chat model.
WaldiezChat ¶
Bases: WaldiezBase
Chat class.
Attributes:
Name | Type | Description |
---|---|---|
id | str | The chat ID. |
source | str | The source of the chat (sender). |
target | str | The target of the chat (recipient). |
type | WaldiezChatType | The type of the chat data: "chat", "nested", "group", or "hidden". |
data | WaldiezChatData | The chat data. See |
name | str | The chat name. |
nested_chat | WaldiezChatNested | The nested chat message/reply if any. |
message | WaldiezChatMessage | The chat message. |
message_content | Optional[str] | The chat message content if any. If method, the method's body. |
Methods:
Name | Description |
---|---|
get_chat_args | Get the chat arguments to use in autogen. |
as_handoff ¶
as_handoff() -> WaldiezHandoff
Convert the chat to a handoff.
Returns:
Type | Description |
---|---|
WaldiezHandoff | The handoff representation of the chat. |
Source code in waldiez/models/chat/chat.py
get_chat_args ¶
Get the chat arguments to use in autogen.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
for_queue | bool | Whether to get the chat arguments for a chat queue. | required |
sender | WaldiezAgent | The sender agent, to check if it's a RAG user. | None |
Returns:
Type | Description |
---|---|
dict | The chat arguments. |
Source code in waldiez/models/chat/chat.py
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:
Name | Type | Description | Default |
---|---|---|---|
name_prefix | str | The function name prefix. | None |
name_suffix | str | The function name suffix. | None |
is_rag | bool | If the message is from a RAG user. | False |
Returns:
Type | Description |
---|---|
tuple[str, str] | The message function and the function name. |
Source code in waldiez/models/chat/chat.py
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:
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 nested chat message function and the function name. |
Source code in waldiez/models/chat/chat.py
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:
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 nested chat reply function and the function name. |
Source code in waldiez/models/chat/chat.py
model_dump ¶
Dump the model to a dict including the chat attributes.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
kwargs | Any | The keyword arguments. | {} |
Returns:
Type | Description |
---|---|
dict[str, Any] | The model dump with the chat attributes. |
Source code in waldiez/models/chat/chat.py
set_chat_id ¶
set_chat_id(value: int) -> None
Chat data model.
WaldiezChatData ¶
Bases: WaldiezBase
Chat data class.
Attributes:
Name | Type | Description |
---|---|---|
name | str | The name of the chat. |
source_type | WaldiezAgentType | The agent type of the chat source. |
target_type | WaldiezAgentType | The agent type of the chat target. |
description | str | The description of the chat. |
position | int | The position of the chat. Ignored (UI related). |
order | int | The of the chat. If negative, ignored. |
clear_history | (Optional[bool], optional) | Whether to clear the chat history, by default None. |
message | Union[str, WaldiezChatMessage] | The message of the chat. |
nested_chat | WaldiezChatNested | The nested chat config. |
summary | WaldiezChatSummary | The summary method and options for the chat. |
max_turns | Optional[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_args | Optional[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_source | Optional[str] | The real source of the chat (overrides the source). |
real_target | Optional[str] | The real target of the chat (overrides the target). |
get_chat_args ¶
Get the chat arguments to use in autogen.
Without the 'message' key.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
for_queue | bool | Whether to get the arguments for a chat queue. | required |
Returns:
Type | Description |
---|---|
dict[str, Any] | The dictionary to pass as kwargs. |
Source code in waldiez/models/chat/chat_data.py
get_prerequisites ¶
set_prerequisites ¶
validate_chat_data ¶
validate_chat_data() -> Self
Validate the chat data.
Returns:
Type | Description |
---|---|
WaldiezChatData | The validated chat data. |
Raises:
Type | Description |
---|---|
ValueError | If the validation fails. |
Source code in waldiez/models/chat/chat_data.py
validate_message classmethod
¶
validate_message(value: Any) -> WaldiezChatMessage
Validate the message.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
value | Any | The message value. | required |
Returns:
Type | Description |
---|---|
WaldiezChatMessage | The validated message value. |
Raises:
Type | Description |
---|---|
ValueError | If the validation fails. |
Source code in waldiez/models/chat/chat_data.py
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:
Name | Type | Description |
---|---|---|
type | WaldiezChatMessageType | The type of the message: - string - method - rag_message_generator - none If the sender is a RAG user agent, and the type is |
content | Optional[str] | The content of the message (string or method). |
context | dict[str, Any] | Extra context of the message. |
is_method ¶
is_method() -> bool
Check if the message is a method.
Returns:
Type | Description |
---|---|
bool | True if the message is a method, False otherwise. |
validate_content ¶
validate_content() -> Self
Validate the content (if not a method).
Returns:
Type | Description |
---|---|
WaldiezChatMessage | The validated instance. |
Raises:
Type | Description |
---|---|
ValueError | If the content is invalid. |
Source code in waldiez/models/chat/chat_message.py
validate_context_vars ¶
validate_context_vars() -> Self
Try to detect bools nulls and numbers from the context values.
Returns:
Type | Description |
---|---|
WaldiezChatMessage | The validated instance. |
Source code in waldiez/models/chat/chat_message.py
validate_method ¶
Validate a method.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
function_name | str | The method name. | required |
function_args | list[str] | The expected method arguments. | required |
Returns:
Type | Description |
---|---|
str | The validated method body. |
Raises:
Type | Description |
---|---|
ValueError | If the validation fails. |
Source code in waldiez/models/chat/chat_message.py
WaldiezChatMessageType module-attribute
¶
WaldiezChatMessageType = Literal[
"string", "method", "rag_message_generator", "none"
]
Possible types for the message.
get_last_carryover_method_content ¶
Get the last carryover method content.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
text_content | str | Text content before the carryover. | required |
Returns:
Type | Description |
---|---|
str | The last carryover method content. |
Source code in waldiez/models/chat/chat_message.py
Nested chat model.
WaldiezChatNested ¶
Bases: WaldiezBase
Nested chat class.
Attributes:
Name | Type | Description |
---|---|---|
message | WaldiezChatMessage | The message in a nested chat (sender -> recipient). |
reply | WaldiezChatMessage | The reply in a nested chat (recipient -> sender). |
validate_message classmethod
¶
validate_message(value: Any) -> WaldiezChatMessage
Validate the message.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
value | Any | The value. | required |
Returns:
Type | Description |
---|---|
WaldiezChatMessage | The validated message. |
Raises:
Type | Description |
---|---|
ValueError | If the validation fails. |
Source code in waldiez/models/chat/chat_nested.py
validate_nested_chat ¶
validate_nested_chat() -> Self
Validate the nested chat.
Returns:
Type | Description |
---|---|
WaldiezChatNested | The validated nested chat. |
Raises:
Type | Description |
---|---|
ValueError | If the validation fails. |
Source code in waldiez/models/chat/chat_nested.py
Waldiez chat summary options.
WaldiezChatSummary ¶
Bases: WaldiezBase
Llm summary method options.
Attributes:
Name | Type | Description |
---|---|---|
method | Optional[WaldiezChatSummaryMethod] | The method to use for the LLM summary. Defaults to "last_msg". |
prompt | str | The prompt for the LLM summary method. |
args | Optional[dict[str, Any]] | The additional arguments for the LLM summary method, by default None. |
serialize_summary_method classmethod
¶
Serialize summary method.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
value | Any | The value to serialize. | required |
info | FieldSerializationInfo | The serialization info. | required |
Returns:
Type | Description |
---|---|
Any | The serialized value. |
Source code in waldiez/models/chat/chat_summary.py
validate_summary_method classmethod
¶
validate_summary_method(
value: Optional[WaldiezChatSummaryMethod],
) -> Optional[WaldiezChatSummaryMethod]
Validate the summary method.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
value | Optional[WaldiezChatSummaryMethod] | The passed WaldiezChatSummaryMethod | required |
Returns:
Type | Description |
---|---|
Optional[WaldiezChatSummaryMethod] | The validated message summary method |