Chats
Chats exporter.
ChatsExporter ¶
ChatsExporter(
all_agents: list[WaldiezAgent],
agent_names: dict[str, str],
all_chats: list[WaldiezChat],
chat_names: dict[str, str],
main_chats: list[WaldiezAgentConnection],
root_group_manager: Optional[WaldiezGroupManager],
context: Optional[ExporterContext] = None,
**kwargs: Any
)
Bases: Exporter[ChatExtras]
Chats exporter with structured extras.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
all_agents | list[WaldiezAgent] | All agents involved in the chats. | required |
agent_names | dict[str, str] | Mapping of agent IDs to their names. | required |
all_chats | list[WaldiezChat] | All chats to be exported. | required |
chat_names | dict[str, str] | Mapping of chat IDs to their names. | required |
main_chats | list[WaldiezAgentConnection] | Main chats that are connections between agents. | required |
root_group_manager | WaldiezGroupManager | None | The root group manager for managing chat groups, if any. | required |
context | ExporterContext | None | Exporter context with dependencies, by default None | None |
**kwargs | Any | Additional keyword arguments for the exporter. | {} |
Source code in waldiez/exporting/chats/exporter.py
create_chats_exporter ¶
create_chats_exporter(
all_agents: list[WaldiezAgent],
agent_names: dict[str, str],
all_chats: list[WaldiezChat],
chat_names: dict[str, str],
main_chats: list[WaldiezAgentConnection],
root_group_manager: WaldiezGroupManager | None = None,
context: ExporterContext | None = None,
**kwargs: Any
) -> ChatsExporter
Create a chats exporter.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
all_agents | list[WaldiezAgent] | All agents involved in the chats. | required |
agent_names | dict[str, str] | Mapping of agent IDs to their names. | required |
all_chats | list[WaldiezChat] | All chats to be exported. | required |
chat_names | dict[str, str] | Mapping of chat IDs to their names. | required |
main_chats | list[WaldiezAgentConnection] | Main chats that are connections between agents. | required |
root_group_manager | WaldiezGroupManager | None | The root group manager for managing chat groups, if any. | None |
context | ExporterContext | None | Exporter context with dependencies, by default None | None |
**kwargs | Any | Additional keyword arguments for the exporter. | {} |
Returns:
Type | Description |
---|---|
ChatsExporter | The created chats exporter. |
Source code in waldiez/exporting/chats/factory.py
exporter ¶
Chats exporter.
ChatsExporter ¶
ChatsExporter(
all_agents: list[WaldiezAgent],
agent_names: dict[str, str],
all_chats: list[WaldiezChat],
chat_names: dict[str, str],
main_chats: list[WaldiezAgentConnection],
root_group_manager: Optional[WaldiezGroupManager],
context: Optional[ExporterContext] = None,
**kwargs: Any
)
Bases: Exporter[ChatExtras]
Chats exporter with structured extras.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
all_agents | list[WaldiezAgent] | All agents involved in the chats. | required |
agent_names | dict[str, str] | Mapping of agent IDs to their names. | required |
all_chats | list[WaldiezChat] | All chats to be exported. | required |
chat_names | dict[str, str] | Mapping of chat IDs to their names. | required |
main_chats | list[WaldiezAgentConnection] | Main chats that are connections between agents. | required |
root_group_manager | WaldiezGroupManager | None | The root group manager for managing chat groups, if any. | required |
context | ExporterContext | None | Exporter context with dependencies, by default None | None |
**kwargs | Any | Additional keyword arguments for the exporter. | {} |
Source code in waldiez/exporting/chats/exporter.py
factory ¶
Factory function for creating a ChatsExporter instance.
create_chats_exporter ¶
create_chats_exporter(
all_agents: list[WaldiezAgent],
agent_names: dict[str, str],
all_chats: list[WaldiezChat],
chat_names: dict[str, str],
main_chats: list[WaldiezAgentConnection],
root_group_manager: WaldiezGroupManager | None = None,
context: ExporterContext | None = None,
**kwargs: Any
) -> ChatsExporter
Create a chats exporter.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
all_agents | list[WaldiezAgent] | All agents involved in the chats. | required |
agent_names | dict[str, str] | Mapping of agent IDs to their names. | required |
all_chats | list[WaldiezChat] | All chats to be exported. | required |
chat_names | dict[str, str] | Mapping of chat IDs to their names. | required |
main_chats | list[WaldiezAgentConnection] | Main chats that are connections between agents. | required |
root_group_manager | WaldiezGroupManager | None | The root group manager for managing chat groups, if any. | None |
context | ExporterContext | None | Exporter context with dependencies, by default None | None |
**kwargs | Any | Additional keyword arguments for the exporter. | {} |
Returns:
Type | Description |
---|---|
ChatsExporter | The created chats exporter. |
Source code in waldiez/exporting/chats/factory.py
processor ¶
Chats processor.
ChatParams dataclass
¶
Parameters for the chat export processor.
ChatsProcessor ¶
ChatsProcessor(
all_agents: list[WaldiezAgent],
agent_names: dict[str, str],
all_chats: list[WaldiezChat],
chat_names: dict[str, str],
main_chats: list[WaldiezAgentConnection],
root_group_manager: WaldiezGroupManager | None,
for_notebook: bool,
is_async: bool,
cache_seed: Optional[int],
serializer: Serializer,
extras: ChatExtras,
)
Processor for chats export.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
all_agents | list[WaldiezAgent] | All agents involved in the chats. | required |
agent_names | dict[str, str] | Mapping of agent IDs to their names. | required |
all_chats | list[WaldiezChat] | All chats to be exported. | required |
chat_names | dict[str, str] | Mapping of chat IDs to their names. | required |
main_chats | list[WaldiezAgentConnection] | Main chats that are connections between agents. | required |
root_group_manager | WaldiezGroupManager | None | The root group manager for managing chat groups, if any. | required |
for_notebook | bool | Whether the export is for a notebook. | required |
is_async | bool | Whether the chat is asynchronous. | required |
cache_seed | int | None | The cache seed for the export, if any. | required |
serializer | Serializer | The serializer to use for escaping quotes in strings. | required |
extras | ChatExtras | The structured extras for the chats export. | required |
Source code in waldiez/exporting/chats/processor.py
is_group_patterned ¶
is_group_patterned() -> bool
Check if the chats are group patterned.
Returns:
Type | Description |
---|---|
bool | True if the chats are group patterned, False otherwise. |
Source code in waldiez/exporting/chats/processor.py
process ¶
Process the chats export.
utils ¶
Chat utils for exporting chatsper chat type.
common ¶
Common utilities for exporting chats.
get_chat_message_string ¶
get_chat_message_string(
sender: WaldiezAgent,
chat: WaldiezChat,
chat_names: dict[str, str],
) -> tuple[str, Optional[str]]
Get the agent's message as a string.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
sender | WaldiezAgent | The sender. | required |
chat | WaldiezChat | The chat. | required |
chat_names | dict[str, str] | A mapping of chat id to chat name with all the chats in the flow. | required |
Returns:
Type | Description |
---|---|
tuple[str, Optional[str]] | If the message is a string, the message content and None. If the message is a method, the method name and the method content. If the message is None, 'None' and None. |
Source code in waldiez/exporting/chats/utils/common.py
get_event_handler_string ¶
Get the event handler string.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
tab | str | The tab string. | required |
is_async | bool | Whether the handler is asynchronous. | required |
Returns:
Type | Description |
---|---|
str | The event handler string. |
Source code in waldiez/exporting/chats/utils/common.py
get_result_dicts_string ¶
Get the result dicts string.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
tab | str | The space string to use for indentation. | required |
is_async | bool | Whether the function is asynchronous. | required |
Returns:
Type | Description |
---|---|
str | The result dicts string. |
Source code in waldiez/exporting/chats/utils/common.py
export_group_chats ¶
export_group_chats(
agent_names: dict[str, str],
manager: WaldiezGroupManager,
initial_chat: str | None,
tabs: int,
is_async: bool,
) -> str
Get the group chat string.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
agent_names | dict[str, str] | The agent names. | required |
manager | WaldiezGroupManager | The group manager agent. | required |
initial_chat | str | None | The initial chat to use if any. | required |
tabs | int | The number of tabs for indentation. | required |
is_async | bool | Whether the chat is asynchronous. | required |
Returns:
Type | Description |
---|---|
tuple[str, str] | The group chat string and the import string. |
Source code in waldiez/exporting/chats/utils/group.py
export_nested_chat_registration ¶
export_nested_chat_registration(
agent: WaldiezAgent,
all_chats: list[WaldiezChat],
chat_names: dict[str, str],
agent_names: dict[str, str],
serializer: Callable[..., str],
is_async: bool,
) -> str
Get the nested chat string.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
agent | WaldiezAgent | The agent. | required |
all_chats | list[WaldiezChat] | All the chats in the flow. | required |
chat_names | dict[str, str] | The chat names. | required |
agent_names | dict[str, str] | The agent names. | required |
serializer | Callable[..., str] | The serializer to use to escape quotes in a string. | required |
is_async | bool | Whether the chat is asynchronous. | required |
Returns:
Type | Description |
---|---|
str | The nested chat string. |
Source code in waldiez/exporting/chats/utils/nested.py
export_sequential_chat ¶
export_sequential_chat(
main_chats: list[WaldiezAgentConnection],
chat_names: dict[str, str],
agent_names: dict[str, str],
serializer: Callable[..., str],
tabs: int,
is_async: bool,
skip_cache: bool,
) -> tuple[str, str]
Get the chats content, when there are more than one chats in the flow.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
main_chats | list[WaldiezAgentConnection] | The main chats. | required |
chat_names | dict[str, str] | A mapping of chat id to chat name. | required |
agent_names | dict[str, str] | A mapping of agent id to agent name. | required |
serializer | Callable[..., str] | The serializer function to escape quotes in a string. | required |
tabs | int | The number of tabs to use for indentation. | required |
is_async | bool | Whether the chat is asynchronous. | required |
skip_cache | bool | Whether to skip the cache argument. | required |
Returns:
Type | Description |
---|---|
tuple[str, str] | The main chats content and additional methods string if any. |
Source code in waldiez/exporting/chats/utils/sequential.py
export_single_chat ¶
export_single_chat(
sender: WaldiezAgent,
recipient: WaldiezAgent,
chat: WaldiezChat,
agent_names: dict[str, str],
chat_names: dict[str, str],
serializer: Callable[[str], str],
tabs: int,
is_async: bool,
skip_cache: bool,
tab_length: int = 4,
) -> tuple[str, str]
Get the chat string when there is only one chat in the flow.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
sender | WaldiezAgent | The sender. | required |
recipient | WaldiezAgent | The recipient. | required |
chat | WaldiezChat | The chat. | required |
agent_names | dict[str, str] | A mapping of agent id to agent name. | required |
chat_names | dict[str, str] | A mapping of chat id to chat name. | required |
serializer | Callable[[str], str] | The serializer function to escape quotes in a string. | required |
tabs | int | The number of tabs to use for indentation. | required |
is_async | bool | Whether the chat is asynchronous. | required |
skip_cache | bool | Whether to skip the cache argument. | required |
tab_length | int | The length of the tab string, by default 4. | 4 |
Returns:
Type | Description |
---|---|
tuple[str, str] | The chat string and additional methods string if any |
Source code in waldiez/exporting/chats/utils/single.py
get_nested_chat_queue ¶
get_nested_chat_queue(
nested_chat: WaldiezAgentNestedChat,
agent: WaldiezAgent,
agent_names: dict[str, str],
chat_names: dict[str, str],
all_chats: list[WaldiezChat],
serializer: Callable[..., str],
) -> tuple[str, list[str]]
Get the nested chat queue.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
nested_chat | WaldiezAgentNestedChat | The nested chat. | required |
agent | WaldiezAgent | The agent. | required |
agent_names | dict[str, str] | A mapping of agent id to agent name. | required |
chat_names | dict[str, str] | A mapping of chat id to chat name. | required |
all_chats | list[WaldiezChat] | All the chats in the flow. | required |
serializer | Callable[..., str] | The serializer to use to escape quotes in a string. | required |
Returns:
Type | Description |
---|---|
tuple[str, list[str]] | The nested chat queue and the methods to include (methods: message string and method name if the message is a method). |
Source code in waldiez/exporting/chats/utils/nested.py
group ¶
Exporting group chat utils.
Using the group patterns (no group manager agent)
export_group_chats ¶
export_group_chats(
agent_names: dict[str, str],
manager: WaldiezGroupManager,
initial_chat: str | None,
tabs: int,
is_async: bool,
) -> str
Get the group chat string.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
agent_names | dict[str, str] | The agent names. | required |
manager | WaldiezGroupManager | The group manager agent. | required |
initial_chat | str | None | The initial chat to use if any. | required |
tabs | int | The number of tabs for indentation. | required |
is_async | bool | Whether the chat is asynchronous. | required |
Returns:
Type | Description |
---|---|
tuple[str, str] | The group chat string and the import string. |
Source code in waldiez/exporting/chats/utils/group.py
nested ¶
Nested chats exporting.
export_nested_chat_registration ¶
export_nested_chat_registration(
agent: WaldiezAgent,
all_chats: list[WaldiezChat],
chat_names: dict[str, str],
agent_names: dict[str, str],
serializer: Callable[..., str],
is_async: bool,
) -> str
Get the nested chat string.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
agent | WaldiezAgent | The agent. | required |
all_chats | list[WaldiezChat] | All the chats in the flow. | required |
chat_names | dict[str, str] | The chat names. | required |
agent_names | dict[str, str] | The agent names. | required |
serializer | Callable[..., str] | The serializer to use to escape quotes in a string. | required |
is_async | bool | Whether the chat is asynchronous. | required |
Returns:
Type | Description |
---|---|
str | The nested chat string. |
Source code in waldiez/exporting/chats/utils/nested.py
get_chat_nested_string ¶
get_chat_nested_string(
chat: WaldiezChat,
is_reply: bool,
chat_names: dict[str, str],
) -> tuple[str, Optional[str]]
Get the nested chat message.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
chat | WaldiezChat | The chat. | required |
is_reply | bool | Whether to use the nested chat's reply message or not. | required |
chat_names | dict[str, str] | A mapping of chat id to chat name.. | required |
Returns:
Type | Description |
---|---|
tuple[str, Optional[str]] | If the message is a string, the message content and None. If the message is a method, the method name and the method content. If the message is None, 'None' and None. |
Source code in waldiez/exporting/chats/utils/nested.py
get_nested_chat_message_string ¶
get_nested_chat_message_string(
waldiez_chat: WaldiezChat,
message: WaldiezAgentNestedChatMessage,
agent: WaldiezAgent,
agent_names: dict[str, str],
chat_names: dict[str, str],
serializer: Callable[..., str],
) -> tuple[str, Optional[str]]
Get the nested chat message string.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
waldiez_chat | WaldiezChat | The chat. | required |
message | WaldiezAgentNestedChatMessage | The message. | required |
agent | WaldiezAgent | The agent. | required |
agent_names | dict[str, str] | A mapping of agent id to agent name. | required |
chat_names | dict[str, str] | A mapping of chat id to chat name. | required |
serializer | Callable[..., str] | The function to serialize the chat arguments. | required |
Returns:
Type | Description |
---|---|
tuple[str, Optional[str]] | The message string and the method name if the message is a method. |
Source code in waldiez/exporting/chats/utils/nested.py
get_nested_chat_queue ¶
get_nested_chat_queue(
nested_chat: WaldiezAgentNestedChat,
agent: WaldiezAgent,
agent_names: dict[str, str],
chat_names: dict[str, str],
all_chats: list[WaldiezChat],
serializer: Callable[..., str],
) -> tuple[str, list[str]]
Get the nested chat queue.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
nested_chat | WaldiezAgentNestedChat | The nested chat. | required |
agent | WaldiezAgent | The agent. | required |
agent_names | dict[str, str] | A mapping of agent id to agent name. | required |
chat_names | dict[str, str] | A mapping of chat id to chat name. | required |
all_chats | list[WaldiezChat] | All the chats in the flow. | required |
serializer | Callable[..., str] | The serializer to use to escape quotes in a string. | required |
Returns:
Type | Description |
---|---|
tuple[str, list[str]] | The nested chat queue and the methods to include (methods: message string and method name if the message is a method). |
Source code in waldiez/exporting/chats/utils/nested.py
get_nested_chat_trigger_agent_names ¶
get_nested_chat_trigger_agent_names(
nested_chat: WaldiezAgentNestedChat,
agent_names: dict[str, str],
) -> str
Get the trigger agent names for the nested chat.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
nested_chat | WaldiezAgentNestedChat | The nested chat. | required |
agent_names | dict[str, str] | A mapping of agent id to agent name. | required |
Returns:
Type | Description |
---|---|
str | The trigger agent names. |
Source code in waldiez/exporting/chats/utils/nested.py
sequential ¶
Utility functions for exporting sequential chats.
export_sequential_chat ¶
export_sequential_chat(
main_chats: list[WaldiezAgentConnection],
chat_names: dict[str, str],
agent_names: dict[str, str],
serializer: Callable[..., str],
tabs: int,
is_async: bool,
skip_cache: bool,
) -> tuple[str, str]
Get the chats content, when there are more than one chats in the flow.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
main_chats | list[WaldiezAgentConnection] | The main chats. | required |
chat_names | dict[str, str] | A mapping of chat id to chat name. | required |
agent_names | dict[str, str] | A mapping of agent id to agent name. | required |
serializer | Callable[..., str] | The serializer function to escape quotes in a string. | required |
tabs | int | The number of tabs to use for indentation. | required |
is_async | bool | Whether the chat is asynchronous. | required |
skip_cache | bool | Whether to skip the cache argument. | required |
Returns:
Type | Description |
---|---|
tuple[str, str] | The main chats content and additional methods string if any. |
Source code in waldiez/exporting/chats/utils/sequential.py
single ¶
Utilities for exporting a single chat in a flow.
export_single_chat ¶
export_single_chat(
sender: WaldiezAgent,
recipient: WaldiezAgent,
chat: WaldiezChat,
agent_names: dict[str, str],
chat_names: dict[str, str],
serializer: Callable[[str], str],
tabs: int,
is_async: bool,
skip_cache: bool,
tab_length: int = 4,
) -> tuple[str, str]
Get the chat string when there is only one chat in the flow.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
sender | WaldiezAgent | The sender. | required |
recipient | WaldiezAgent | The recipient. | required |
chat | WaldiezChat | The chat. | required |
agent_names | dict[str, str] | A mapping of agent id to agent name. | required |
chat_names | dict[str, str] | A mapping of chat id to chat name. | required |
serializer | Callable[[str], str] | The serializer function to escape quotes in a string. | required |
tabs | int | The number of tabs to use for indentation. | required |
is_async | bool | Whether the chat is asynchronous. | required |
skip_cache | bool | Whether to skip the cache argument. | required |
tab_length | int | The length of the tab string, by default 4. | 4 |
Returns:
Type | Description |
---|---|
tuple[str, str] | The chat string and additional methods string if any |
Source code in waldiez/exporting/chats/utils/single.py
get_chat_message ¶
get_chat_message(
tab: str,
chat: WaldiezChat,
chat_names: dict[str, str],
sender: WaldiezAgent,
sender_name: str,
) -> tuple[str, str]
Get the chat message string.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
tab | str | The tab string. | required |
chat | WaldiezChat | The chat. | required |
chat_names | dict[str, str] | A mapping of chat id to chat name. | required |
sender | WaldiezAgent | The sender. | required |
sender_name | str | The sender name. | required |
Returns:
Type | Description |
---|---|
tuple[str, str] | The message argument and additional methods string if any. |
Source code in waldiez/exporting/chats/utils/single.py
get_empty_simple_chat_string ¶
get_empty_simple_chat_string(
chat: WaldiezChat,
sender: WaldiezAgent,
recipient: WaldiezAgent,
agent_names: dict[str, str],
tab: str,
is_async: bool,
skip_cache: bool,
) -> tuple[str, str]
Get the chat string when there are no chat arguments.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
chat | WaldiezChat | The chat. | required |
sender | WaldiezAgent | The sender. | required |
recipient | WaldiezAgent | The recipient. | required |
agent_names | dict[str, str] | A mapping of agent id to agent name. | required |
tab | str | The tab string. | required |
is_async | bool | Whether the chat is asynchronous. | required |
skip_cache | bool | Whether to skip the cache argument. | required |
Returns:
Type | Description |
---|---|
tuple[str, str] | The chat string and additional methods string if any |
Source code in waldiez/exporting/chats/utils/single.py
get_simple_chat_string ¶
get_simple_chat_string(
chat: WaldiezChat,
sender: WaldiezAgent,
recipient: WaldiezAgent,
agent_names: dict[str, str],
chat_names: dict[str, str],
chat_args: dict[str, Any],
serializer: Callable[..., str],
tabs: int,
is_async: bool,
skip_cache: bool,
) -> tuple[str, str]
Get the chat string when there are chat arguments.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
chat | WaldiezChat | The chat. | required |
sender | WaldiezAgent | The sender. | required |
recipient | WaldiezAgent | The recipient. | required |
agent_names | dict[str, str] | A mapping of agent id to agent name. | required |
chat_names | dict[str, str] | A mapping of chat id to chat name. | required |
chat_args | dict[str, Any] | The chat arguments. | required |
serializer | Callable[[str], str] | The serializer function to escape quotes in a string. | required |
tabs | int | The number of tabs to use for indentation. | required |
is_async | bool | Whether the chat is asynchronous. | required |
skip_cache | bool | Whether to skip the cache argument. | required |
Returns:
Type | Description |
---|---|
tuple[str, str] | The chat string and additional methods string if any. |