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: WaldiezGroupManager | None,
context: ExporterContext | None = 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: WaldiezGroupManager | None,
context: ExporterContext | None = 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 ¶
ChatParams(
main: list[WaldiezAgentConnection],
all: list[WaldiezChat],
names: dict[str, str],
)
Parameters for the chat export processor.
main instance-attribute ¶
Main chats that are connections between agents.
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: int | None,
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 ¶
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, str | None]
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 |
|---|---|---|---|
space | str | The space before the content. | 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
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 | |
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,
message: tuple[str, 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 |
message | str | None | The initial message/messages arg and value for the chat | 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,
chat_queue_arg: str,
) -> 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 |
chat_queue_arg | str | The chat queue 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,
message_kwarg: tuple[str, str],
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 |
message_kwarg | tuple[str, str] | The message kwarg and the var to use for it. | 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,
message: tuple[str, 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 |
message | str | None | The initial message/messages arg and value for the chat | 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, str | None]
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, str | None] | 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, str | None]
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, str | None] | The message string and any content before that if any. |
Source code in waldiez/exporting/chats/utils/nested.py
119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 | |
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,
chat_queue_arg: str,
) -> 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 |
chat_queue_arg | str | The chat queue 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,
message_kwarg: tuple[str, str],
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 |
message_kwarg | tuple[str, str] | The message kwarg and the var to use for it. | 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_empty_simple_chat_string ¶
get_empty_simple_chat_string(
chat: WaldiezChat,
sender: WaldiezAgent,
recipient: WaldiezAgent,
message_kwarg: tuple[str, str],
agent_names: dict[str, str],
chat_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 |
message_kwarg | tuple[str, str] | The message kwarg and the var to use for it. | 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 |
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,
message_kwarg: tuple[str, str],
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 |
message_kwarg | tuple[str, str] | The message kwarg and the var to use for it. | 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. |
Source code in waldiez/exporting/chats/utils/single.py
94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 | |