waldiez 0.4.7__py3-none-any.whl → 0.4.9__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of waldiez might be problematic. Click here for more details.
- waldiez/__init__.py +5 -5
- waldiez/_version.py +1 -1
- waldiez/cli.py +97 -102
- waldiez/exporter.py +61 -19
- waldiez/exporting/__init__.py +25 -6
- waldiez/exporting/agent/__init__.py +7 -3
- waldiez/exporting/agent/code_execution.py +114 -0
- waldiez/exporting/agent/exporter.py +354 -0
- waldiez/exporting/agent/extras/__init__.py +15 -0
- waldiez/exporting/agent/extras/captain_agent_extras.py +315 -0
- waldiez/exporting/agent/extras/group/target.py +178 -0
- waldiez/exporting/agent/extras/group_manager_agent_extas.py +500 -0
- waldiez/exporting/agent/extras/group_member_extras.py +181 -0
- waldiez/exporting/agent/extras/handoffs/__init__.py +19 -0
- waldiez/exporting/agent/extras/handoffs/after_work.py +78 -0
- waldiez/exporting/agent/extras/handoffs/available.py +74 -0
- waldiez/exporting/agent/extras/handoffs/condition.py +158 -0
- waldiez/exporting/agent/extras/handoffs/handoff.py +171 -0
- waldiez/exporting/agent/extras/handoffs/target.py +189 -0
- waldiez/exporting/agent/extras/rag/__init__.py +10 -0
- waldiez/exporting/agent/{utils/rag_user/chroma_utils.py → extras/rag/chroma_extras.py} +37 -24
- waldiez/exporting/agent/{utils/rag_user/mongo_utils.py → extras/rag/mongo_extras.py} +10 -10
- waldiez/exporting/agent/{utils/rag_user/pgvector_utils.py → extras/rag/pgvector_extras.py} +13 -13
- waldiez/exporting/agent/{utils/rag_user/qdrant_utils.py → extras/rag/qdrant_extras.py} +13 -13
- waldiez/exporting/agent/{utils/rag_user/vector_db.py → extras/rag/vector_db_extras.py} +59 -46
- waldiez/exporting/agent/extras/rag_user_proxy_agent_extras.py +245 -0
- waldiez/exporting/agent/extras/reasoning_agent_extras.py +88 -0
- waldiez/exporting/agent/factory.py +95 -0
- waldiez/exporting/agent/processor.py +150 -0
- waldiez/exporting/agent/system_message.py +36 -0
- waldiez/exporting/agent/termination.py +50 -0
- waldiez/exporting/chats/__init__.py +7 -3
- waldiez/exporting/chats/exporter.py +97 -0
- waldiez/exporting/chats/factory.py +65 -0
- waldiez/exporting/chats/processor.py +226 -0
- waldiez/exporting/chats/utils/__init__.py +6 -5
- waldiez/exporting/chats/utils/common.py +11 -45
- waldiez/exporting/chats/utils/group.py +55 -0
- waldiez/exporting/chats/utils/nested.py +37 -52
- waldiez/exporting/chats/utils/sequential.py +72 -61
- waldiez/exporting/chats/utils/{single_chat.py → single.py} +48 -50
- waldiez/exporting/core/__init__.py +196 -0
- waldiez/exporting/core/constants.py +17 -0
- waldiez/exporting/core/content.py +69 -0
- waldiez/exporting/core/context.py +244 -0
- waldiez/exporting/core/enums.py +89 -0
- waldiez/exporting/core/errors.py +19 -0
- waldiez/exporting/core/exporter.py +390 -0
- waldiez/exporting/core/exporters.py +67 -0
- waldiez/exporting/core/extras/__init__.py +39 -0
- waldiez/exporting/core/extras/agent_extras/__init__.py +27 -0
- waldiez/exporting/core/extras/agent_extras/captain_extras.py +57 -0
- waldiez/exporting/core/extras/agent_extras/group_manager_extras.py +102 -0
- waldiez/exporting/core/extras/agent_extras/rag_user_extras.py +53 -0
- waldiez/exporting/core/extras/agent_extras/reasoning_extras.py +68 -0
- waldiez/exporting/core/extras/agent_extras/standard_extras.py +263 -0
- waldiez/exporting/core/extras/base.py +241 -0
- waldiez/exporting/core/extras/chat_extras.py +118 -0
- waldiez/exporting/core/extras/flow_extras.py +70 -0
- waldiez/exporting/core/extras/model_extras.py +73 -0
- waldiez/exporting/core/extras/path_resolver.py +93 -0
- waldiez/exporting/core/extras/serializer.py +138 -0
- waldiez/exporting/core/extras/tool_extras.py +82 -0
- waldiez/exporting/core/protocols.py +259 -0
- waldiez/exporting/core/result.py +705 -0
- waldiez/exporting/core/types.py +329 -0
- waldiez/exporting/core/utils/__init__.py +11 -0
- waldiez/exporting/core/utils/comment.py +33 -0
- waldiez/exporting/core/utils/llm_config.py +117 -0
- waldiez/exporting/core/validation.py +96 -0
- waldiez/exporting/flow/__init__.py +6 -2
- waldiez/exporting/flow/execution_generator.py +193 -0
- waldiez/exporting/flow/exporter.py +107 -0
- waldiez/exporting/flow/factory.py +94 -0
- waldiez/exporting/flow/file_generator.py +214 -0
- waldiez/exporting/flow/merger.py +387 -0
- waldiez/exporting/flow/orchestrator.py +411 -0
- waldiez/exporting/flow/utils/__init__.py +9 -36
- waldiez/exporting/flow/utils/common.py +206 -0
- waldiez/exporting/flow/utils/importing.py +373 -0
- waldiez/exporting/flow/utils/linting.py +200 -0
- waldiez/exporting/flow/utils/{logging_utils.py → logging.py} +23 -9
- waldiez/exporting/models/__init__.py +3 -1
- waldiez/exporting/models/exporter.py +233 -0
- waldiez/exporting/models/factory.py +66 -0
- waldiez/exporting/models/processor.py +139 -0
- waldiez/exporting/tools/__init__.py +11 -0
- waldiez/exporting/tools/exporter.py +207 -0
- waldiez/exporting/tools/factory.py +57 -0
- waldiez/exporting/tools/processor.py +248 -0
- waldiez/exporting/tools/registration.py +133 -0
- waldiez/io/__init__.py +128 -0
- waldiez/io/_ws.py +199 -0
- waldiez/io/models/__init__.py +60 -0
- waldiez/io/models/base.py +66 -0
- waldiez/io/models/constants.py +78 -0
- waldiez/io/models/content/__init__.py +23 -0
- waldiez/io/models/content/audio.py +43 -0
- waldiez/io/models/content/base.py +45 -0
- waldiez/io/models/content/file.py +43 -0
- waldiez/io/models/content/image.py +96 -0
- waldiez/io/models/content/text.py +37 -0
- waldiez/io/models/content/video.py +43 -0
- waldiez/io/models/user_input.py +269 -0
- waldiez/io/models/user_response.py +215 -0
- waldiez/io/mqtt.py +681 -0
- waldiez/io/redis.py +782 -0
- waldiez/io/structured.py +439 -0
- waldiez/io/utils.py +184 -0
- waldiez/io/ws.py +298 -0
- waldiez/logger.py +481 -0
- waldiez/models/__init__.py +108 -51
- waldiez/models/agents/__init__.py +34 -70
- waldiez/models/agents/agent/__init__.py +10 -4
- waldiez/models/agents/agent/agent.py +466 -65
- waldiez/models/agents/agent/agent_data.py +119 -47
- waldiez/models/agents/agent/agent_type.py +13 -2
- waldiez/models/agents/agent/code_execution.py +12 -12
- waldiez/models/agents/agent/human_input_mode.py +8 -0
- waldiez/models/agents/agent/{linked_skill.py → linked_tool.py} +7 -7
- waldiez/models/agents/agent/nested_chat.py +35 -7
- waldiez/models/agents/agent/termination_message.py +30 -22
- waldiez/models/agents/{swarm_agent → agent}/update_system_message.py +22 -22
- waldiez/models/agents/agents.py +58 -63
- waldiez/models/agents/assistant/assistant.py +4 -4
- waldiez/models/agents/assistant/assistant_data.py +13 -1
- waldiez/models/agents/{captain_agent → captain}/captain_agent.py +5 -5
- waldiez/models/agents/{captain_agent → captain}/captain_agent_data.py +5 -5
- waldiez/models/agents/extra_requirements.py +11 -16
- waldiez/models/agents/group_manager/group_manager.py +103 -13
- waldiez/models/agents/group_manager/group_manager_data.py +36 -14
- waldiez/models/agents/group_manager/speakers.py +77 -24
- waldiez/models/agents/{rag_user → rag_user_proxy}/__init__.py +16 -16
- waldiez/models/agents/rag_user_proxy/rag_user_proxy.py +64 -0
- waldiez/models/agents/{rag_user/rag_user_data.py → rag_user_proxy/rag_user_proxy_data.py} +6 -5
- waldiez/models/agents/{rag_user → rag_user_proxy}/retrieve_config.py +182 -114
- waldiez/models/agents/{rag_user → rag_user_proxy}/vector_db_config.py +13 -13
- waldiez/models/agents/reasoning/reasoning_agent.py +6 -6
- waldiez/models/agents/reasoning/reasoning_agent_data.py +110 -63
- waldiez/models/agents/reasoning/reasoning_agent_reason_config.py +38 -10
- waldiez/models/agents/user_proxy/user_proxy.py +11 -7
- waldiez/models/agents/user_proxy/user_proxy_data.py +2 -2
- waldiez/models/chat/__init__.py +2 -1
- waldiez/models/chat/chat.py +166 -87
- waldiez/models/chat/chat_data.py +99 -136
- waldiez/models/chat/chat_message.py +33 -23
- waldiez/models/chat/chat_nested.py +31 -30
- waldiez/models/chat/chat_summary.py +10 -8
- waldiez/models/common/__init__.py +52 -2
- waldiez/models/common/ag2_version.py +1 -1
- waldiez/models/common/base.py +38 -7
- waldiez/models/common/dict_utils.py +42 -17
- waldiez/models/common/handoff.py +459 -0
- waldiez/models/common/id_generator.py +19 -0
- waldiez/models/common/method_utils.py +130 -68
- waldiez/{exporting/base/utils → models/common}/naming.py +38 -61
- waldiez/models/common/waldiez_version.py +37 -0
- waldiez/models/flow/__init__.py +9 -2
- waldiez/models/flow/connection.py +18 -0
- waldiez/models/flow/flow.py +311 -215
- waldiez/models/flow/flow_data.py +207 -40
- waldiez/models/flow/info.py +85 -0
- waldiez/models/flow/naming.py +131 -0
- waldiez/models/model/__init__.py +7 -1
- waldiez/models/model/extra_requirements.py +3 -12
- waldiez/models/model/model.py +76 -21
- waldiez/models/model/model_data.py +108 -20
- waldiez/models/tool/__init__.py +16 -0
- waldiez/models/tool/extra_requirements.py +36 -0
- waldiez/models/{skill/skill.py → tool/tool.py} +88 -88
- waldiez/models/tool/tool_data.py +51 -0
- waldiez/models/tool/tool_type.py +8 -0
- waldiez/models/waldiez.py +97 -80
- waldiez/runner.py +115 -61
- waldiez/running/__init__.py +13 -7
- waldiez/running/environment.py +49 -68
- waldiez/running/gen_seq_diagram.py +16 -14
- waldiez/running/post_run.py +119 -0
- waldiez/running/pre_run.py +149 -0
- waldiez/running/util.py +134 -0
- waldiez/utils/__init__.py +2 -4
- waldiez/utils/cli_extras/jupyter.py +5 -3
- waldiez/utils/cli_extras/runner.py +6 -4
- waldiez/utils/cli_extras/studio.py +6 -4
- waldiez/utils/conflict_checker.py +15 -9
- waldiez/utils/flaml_warnings.py +5 -5
- waldiez/utils/version.py +47 -0
- {waldiez-0.4.7.dist-info → waldiez-0.4.9.dist-info}/METADATA +235 -91
- waldiez-0.4.9.dist-info/RECORD +203 -0
- waldiez/exporting/agent/agent_exporter.py +0 -297
- waldiez/exporting/agent/utils/__init__.py +0 -23
- waldiez/exporting/agent/utils/captain_agent.py +0 -263
- waldiez/exporting/agent/utils/code_execution.py +0 -65
- waldiez/exporting/agent/utils/group_manager.py +0 -220
- waldiez/exporting/agent/utils/rag_user/__init__.py +0 -7
- waldiez/exporting/agent/utils/rag_user/rag_user.py +0 -209
- waldiez/exporting/agent/utils/reasoning.py +0 -36
- waldiez/exporting/agent/utils/swarm_agent.py +0 -469
- waldiez/exporting/agent/utils/teachability.py +0 -41
- waldiez/exporting/agent/utils/termination_message.py +0 -44
- waldiez/exporting/base/__init__.py +0 -25
- waldiez/exporting/base/agent_position.py +0 -75
- waldiez/exporting/base/base_exporter.py +0 -118
- waldiez/exporting/base/export_position.py +0 -48
- waldiez/exporting/base/import_position.py +0 -23
- waldiez/exporting/base/mixin.py +0 -137
- waldiez/exporting/base/utils/__init__.py +0 -18
- waldiez/exporting/base/utils/comments.py +0 -96
- waldiez/exporting/base/utils/path_check.py +0 -68
- waldiez/exporting/base/utils/to_string.py +0 -84
- waldiez/exporting/chats/chats_exporter.py +0 -240
- waldiez/exporting/chats/utils/swarm.py +0 -210
- waldiez/exporting/flow/flow_exporter.py +0 -528
- waldiez/exporting/flow/utils/agent_utils.py +0 -204
- waldiez/exporting/flow/utils/chat_utils.py +0 -71
- waldiez/exporting/flow/utils/def_main.py +0 -77
- waldiez/exporting/flow/utils/flow_content.py +0 -202
- waldiez/exporting/flow/utils/flow_names.py +0 -116
- waldiez/exporting/flow/utils/importing_utils.py +0 -227
- waldiez/exporting/models/models_exporter.py +0 -199
- waldiez/exporting/models/utils.py +0 -174
- waldiez/exporting/skills/__init__.py +0 -9
- waldiez/exporting/skills/skills_exporter.py +0 -176
- waldiez/exporting/skills/utils.py +0 -369
- waldiez/models/agents/agent/teachability.py +0 -70
- waldiez/models/agents/rag_user/rag_user.py +0 -60
- waldiez/models/agents/swarm_agent/__init__.py +0 -50
- waldiez/models/agents/swarm_agent/after_work.py +0 -179
- waldiez/models/agents/swarm_agent/on_condition.py +0 -105
- waldiez/models/agents/swarm_agent/on_condition_available.py +0 -142
- waldiez/models/agents/swarm_agent/on_condition_target.py +0 -40
- waldiez/models/agents/swarm_agent/swarm_agent.py +0 -107
- waldiez/models/agents/swarm_agent/swarm_agent_data.py +0 -124
- waldiez/models/flow/utils.py +0 -232
- waldiez/models/skill/__init__.py +0 -16
- waldiez/models/skill/extra_requirements.py +0 -36
- waldiez/models/skill/skill_data.py +0 -53
- waldiez/models/skill/skill_type.py +0 -8
- waldiez/running/running.py +0 -369
- waldiez/utils/pysqlite3_checker.py +0 -308
- waldiez/utils/rdps_checker.py +0 -122
- waldiez-0.4.7.dist-info/RECORD +0 -149
- /waldiez/models/agents/{captain_agent → captain}/__init__.py +0 -0
- /waldiez/models/agents/{captain_agent → captain}/captain_agent_lib_entry.py +0 -0
- {waldiez-0.4.7.dist-info → waldiez-0.4.9.dist-info}/WHEEL +0 -0
- {waldiez-0.4.7.dist-info → waldiez-0.4.9.dist-info}/entry_points.txt +0 -0
- {waldiez-0.4.7.dist-info → waldiez-0.4.9.dist-info}/licenses/LICENSE +0 -0
- {waldiez-0.4.7.dist-info → waldiez-0.4.9.dist-info}/licenses/NOTICE.md +0 -0
|
@@ -2,44 +2,16 @@
|
|
|
2
2
|
# Copyright (c) 2024 - 2025 Waldiez and contributors.
|
|
3
3
|
"""Common utilities for exporting chats."""
|
|
4
4
|
|
|
5
|
-
from typing import
|
|
5
|
+
from typing import Optional
|
|
6
6
|
|
|
7
7
|
from waldiez.models import WaldiezAgent, WaldiezChat
|
|
8
8
|
|
|
9
9
|
|
|
10
|
-
def update_summary_chat_args(
|
|
11
|
-
chat_args: Dict[str, Any],
|
|
12
|
-
string_escape: Callable[[str], str],
|
|
13
|
-
) -> Dict[str, Any]:
|
|
14
|
-
"""Escape quotes in the summary args if they are strings.
|
|
15
|
-
|
|
16
|
-
Parameters
|
|
17
|
-
----------
|
|
18
|
-
chat_args : Dict[str, Any]
|
|
19
|
-
The chat arguments.
|
|
20
|
-
string_escape : Callable[[str], str]
|
|
21
|
-
The function to escape the string
|
|
22
|
-
|
|
23
|
-
Returns
|
|
24
|
-
-------
|
|
25
|
-
Dict[str, Any]
|
|
26
|
-
The chat arguments with the summary prompt escaped.
|
|
27
|
-
"""
|
|
28
|
-
if "summary_args" in chat_args and isinstance(
|
|
29
|
-
chat_args["summary_args"], dict
|
|
30
|
-
):
|
|
31
|
-
for key, value in chat_args["summary_args"].items():
|
|
32
|
-
if isinstance(value, str):
|
|
33
|
-
chat_args["summary_args"][key] = string_escape(value)
|
|
34
|
-
return chat_args
|
|
35
|
-
|
|
36
|
-
|
|
37
10
|
def get_chat_message_string(
|
|
38
11
|
sender: WaldiezAgent,
|
|
39
12
|
chat: WaldiezChat,
|
|
40
|
-
chat_names:
|
|
41
|
-
|
|
42
|
-
) -> Tuple[str, Optional[str]]:
|
|
13
|
+
chat_names: dict[str, str],
|
|
14
|
+
) -> tuple[str, Optional[str]]:
|
|
43
15
|
"""Get the agent's message as a string.
|
|
44
16
|
|
|
45
17
|
Parameters
|
|
@@ -48,31 +20,25 @@ def get_chat_message_string(
|
|
|
48
20
|
The sender.
|
|
49
21
|
chat : WaldiezChat
|
|
50
22
|
The chat.
|
|
51
|
-
chat_names :
|
|
23
|
+
chat_names : dict[str, str]
|
|
52
24
|
A mapping of chat id to chat name with all the chats in the flow.
|
|
53
|
-
string_escape : Callable[[str], str]
|
|
54
|
-
The function to escape the string.
|
|
55
25
|
|
|
56
26
|
Returns
|
|
57
27
|
-------
|
|
58
|
-
|
|
28
|
+
tuple[str, Optional[str]]
|
|
59
29
|
If the message is a string, the message content and None.
|
|
60
30
|
If the message is a method, the method name and the method content.
|
|
61
31
|
If the message is None, 'None' and None.
|
|
62
32
|
"""
|
|
63
|
-
if
|
|
64
|
-
not chat.message
|
|
65
|
-
or chat.message.type == "none"
|
|
66
|
-
or chat.message.content is None
|
|
67
|
-
or chat.message_content is None
|
|
68
|
-
):
|
|
33
|
+
if not chat.message or chat.message.type == "none":
|
|
69
34
|
return "None", None
|
|
70
35
|
if chat.message.type == "string":
|
|
71
|
-
|
|
36
|
+
if chat.message.content is None: # pragma: no cover
|
|
37
|
+
# should be coverred previousliy on pydantic validation
|
|
38
|
+
return "None", None
|
|
39
|
+
return chat.message.content, None
|
|
72
40
|
|
|
73
|
-
is_rag_with_carryover =
|
|
74
|
-
sender.agent_type == "rag_user" and chat.message.use_carryover
|
|
75
|
-
)
|
|
41
|
+
is_rag_with_carryover = sender.is_rag_user and chat.message.use_carryover
|
|
76
42
|
chat_name = chat_names[chat.id]
|
|
77
43
|
function_content, function_name = chat.get_message_function(
|
|
78
44
|
name_suffix=chat_name,
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
# SPDX-License-Identifier: Apache-2.0.
|
|
2
|
+
# Copyright (c) 2024 - 2025 Waldiez and contributors.
|
|
3
|
+
|
|
4
|
+
"""Exporting group chat utils.
|
|
5
|
+
|
|
6
|
+
Using the group patterns (no group manager agent)
|
|
7
|
+
"""
|
|
8
|
+
|
|
9
|
+
import json
|
|
10
|
+
|
|
11
|
+
from waldiez.models import WaldiezGroupManager
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
def export_group_chats(
|
|
15
|
+
agent_names: dict[str, str],
|
|
16
|
+
manager: WaldiezGroupManager,
|
|
17
|
+
intial_chat: str | None,
|
|
18
|
+
tabs: int,
|
|
19
|
+
is_async: bool,
|
|
20
|
+
) -> str:
|
|
21
|
+
"""Get the group chat string.
|
|
22
|
+
|
|
23
|
+
Parameters
|
|
24
|
+
----------
|
|
25
|
+
agent_names : dict[str, str]
|
|
26
|
+
The agent names.
|
|
27
|
+
manager : WaldiezGroupManager
|
|
28
|
+
The group manager agent.
|
|
29
|
+
intial_chat : str | None
|
|
30
|
+
The initial chat to use if any.
|
|
31
|
+
tabs : int
|
|
32
|
+
The number of tabs for indentation.
|
|
33
|
+
is_async : bool
|
|
34
|
+
Whether the chat is asynchronous.
|
|
35
|
+
|
|
36
|
+
Returns
|
|
37
|
+
-------
|
|
38
|
+
tuple[str, str]
|
|
39
|
+
The group chat string and the import string.
|
|
40
|
+
"""
|
|
41
|
+
tab = " " * tabs
|
|
42
|
+
initiate_group_chat = "initiate_group_chat"
|
|
43
|
+
if is_async:
|
|
44
|
+
initiate_group_chat = "a_initiate_group_chat"
|
|
45
|
+
manager_name = agent_names[manager.id]
|
|
46
|
+
pattern_name = f"{manager_name}_pattern"
|
|
47
|
+
content = f"{tab}results, _, __ = {initiate_group_chat}(" + "\n"
|
|
48
|
+
content += f"{tab} pattern={pattern_name}," + "\n"
|
|
49
|
+
if intial_chat:
|
|
50
|
+
content += f"{tab} messages={json.dumps(intial_chat)}," + "\n"
|
|
51
|
+
else:
|
|
52
|
+
content += f'{tab} messages="",\n'
|
|
53
|
+
content += f"{tab} max_rounds={manager.data.max_round},\n"
|
|
54
|
+
content += f"{tab})\n"
|
|
55
|
+
return content
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
# pylint: disable=too-many-locals
|
|
4
4
|
"""Nested chats exporting."""
|
|
5
5
|
|
|
6
|
-
from typing import
|
|
6
|
+
from typing import Any, Callable, Optional
|
|
7
7
|
|
|
8
8
|
from waldiez.models import (
|
|
9
9
|
WaldiezAgent,
|
|
@@ -12,16 +12,15 @@ from waldiez.models import (
|
|
|
12
12
|
WaldiezChat,
|
|
13
13
|
)
|
|
14
14
|
|
|
15
|
-
from .common import update_summary_chat_args
|
|
15
|
+
# from .common import update_summary_chat_args
|
|
16
16
|
|
|
17
17
|
|
|
18
18
|
def export_nested_chat_registration(
|
|
19
19
|
agent: WaldiezAgent,
|
|
20
|
-
all_chats:
|
|
21
|
-
chat_names:
|
|
22
|
-
agent_names:
|
|
20
|
+
all_chats: list[WaldiezChat],
|
|
21
|
+
chat_names: dict[str, str],
|
|
22
|
+
agent_names: dict[str, str],
|
|
23
23
|
serializer: Callable[..., str],
|
|
24
|
-
string_escape: Callable[[str], str],
|
|
25
24
|
is_async: bool,
|
|
26
25
|
) -> str:
|
|
27
26
|
"""Get the nested chat string.
|
|
@@ -30,16 +29,14 @@ def export_nested_chat_registration(
|
|
|
30
29
|
----------
|
|
31
30
|
agent : WaldiezAgent
|
|
32
31
|
The agent.
|
|
33
|
-
all_chats :
|
|
32
|
+
all_chats : list[WaldiezChat]
|
|
34
33
|
All the chats in the flow.
|
|
35
|
-
chat_names :
|
|
34
|
+
chat_names : dict[str, str]
|
|
36
35
|
The chat names.
|
|
37
|
-
agent_names :
|
|
36
|
+
agent_names : dict[str, str]
|
|
38
37
|
The agent names.
|
|
39
38
|
serializer : Callable[..., str]
|
|
40
39
|
The serializer to use to escape quotes in a string.
|
|
41
|
-
string_escape : Callable[[str], str]
|
|
42
|
-
The string escape function.
|
|
43
40
|
is_async : bool
|
|
44
41
|
Whether the chat is asynchronous.
|
|
45
42
|
|
|
@@ -51,7 +48,7 @@ def export_nested_chat_registration(
|
|
|
51
48
|
if not agent.data.nested_chats:
|
|
52
49
|
return ""
|
|
53
50
|
content = ""
|
|
54
|
-
extra_contents = []
|
|
51
|
+
extra_contents: list[str] = []
|
|
55
52
|
agent_name = agent_names[agent.id]
|
|
56
53
|
use_suffix = len(agent.data.nested_chats) > 1
|
|
57
54
|
for index, entry in enumerate(agent.data.nested_chats):
|
|
@@ -65,7 +62,6 @@ def export_nested_chat_registration(
|
|
|
65
62
|
chat_names=chat_names,
|
|
66
63
|
all_chats=all_chats,
|
|
67
64
|
serializer=serializer,
|
|
68
|
-
string_escape=string_escape,
|
|
69
65
|
)
|
|
70
66
|
if not chat_queue: # pragma: no cover
|
|
71
67
|
continue
|
|
@@ -75,9 +71,9 @@ def export_nested_chat_registration(
|
|
|
75
71
|
if use_suffix
|
|
76
72
|
else f"{agent_name}_chat_queue"
|
|
77
73
|
)
|
|
78
|
-
content += f"{var_name} = {chat_queue}" + "\n"
|
|
74
|
+
content += f"{var_name}: list[dict[str, Any]] = {chat_queue}" + "\n"
|
|
79
75
|
content += f"""
|
|
80
|
-
{agent_name}.register_nested_chats(
|
|
76
|
+
{agent_name}.register_nested_chats( # pyright: ignore
|
|
81
77
|
trigger={trigger_names},
|
|
82
78
|
chat_queue={var_name},
|
|
83
79
|
use_async={is_async},
|
|
@@ -100,7 +96,7 @@ def export_nested_chat_registration(
|
|
|
100
96
|
|
|
101
97
|
def get_nested_chat_trigger_agent_names(
|
|
102
98
|
nested_chat: WaldiezAgentNestedChat,
|
|
103
|
-
agent_names:
|
|
99
|
+
agent_names: dict[str, str],
|
|
104
100
|
) -> str:
|
|
105
101
|
"""Get the trigger agent names for the nested chat.
|
|
106
102
|
|
|
@@ -108,7 +104,7 @@ def get_nested_chat_trigger_agent_names(
|
|
|
108
104
|
----------
|
|
109
105
|
nested_chat : WaldiezAgentNestedChat
|
|
110
106
|
The nested chat.
|
|
111
|
-
agent_names :
|
|
107
|
+
agent_names : dict[str, str]
|
|
112
108
|
A mapping of agent id to agent name.
|
|
113
109
|
|
|
114
110
|
Returns
|
|
@@ -126,11 +122,10 @@ def get_nested_chat_message_string(
|
|
|
126
122
|
waldiez_chat: WaldiezChat,
|
|
127
123
|
message: WaldiezAgentNestedChatMessage,
|
|
128
124
|
agent: WaldiezAgent,
|
|
129
|
-
agent_names:
|
|
130
|
-
chat_names:
|
|
125
|
+
agent_names: dict[str, str],
|
|
126
|
+
chat_names: dict[str, str],
|
|
131
127
|
serializer: Callable[..., str],
|
|
132
|
-
|
|
133
|
-
) -> Tuple[str, Optional[str]]:
|
|
128
|
+
) -> tuple[str, Optional[str]]:
|
|
134
129
|
"""Get the nested chat message string.
|
|
135
130
|
|
|
136
131
|
Parameters
|
|
@@ -141,18 +136,16 @@ def get_nested_chat_message_string(
|
|
|
141
136
|
The message.
|
|
142
137
|
agent : WaldiezAgent
|
|
143
138
|
The agent.
|
|
144
|
-
agent_names :
|
|
139
|
+
agent_names : dict[str, str]
|
|
145
140
|
A mapping of agent id to agent name.
|
|
146
|
-
chat_names :
|
|
141
|
+
chat_names : dict[str, str]
|
|
147
142
|
A mapping of chat id to chat name.
|
|
148
143
|
serializer : Callable[..., str]
|
|
149
144
|
The function to serialize the chat arguments.
|
|
150
|
-
string_escape : Callable[[str], str]
|
|
151
|
-
The function to escape the string.
|
|
152
145
|
|
|
153
146
|
Returns
|
|
154
147
|
-------
|
|
155
|
-
|
|
148
|
+
tuple[str, Optional[str]]
|
|
156
149
|
The message string and the method name if the message is a method.
|
|
157
150
|
"""
|
|
158
151
|
sender_name: Optional[str] = None
|
|
@@ -163,8 +156,8 @@ def get_nested_chat_message_string(
|
|
|
163
156
|
if sender_id != agent.id:
|
|
164
157
|
sender_name = agent_names[sender_id]
|
|
165
158
|
recipient_name = agent_names[recipient_id]
|
|
166
|
-
chat_dict = waldiez_chat.get_chat_args(for_queue=True)
|
|
167
|
-
chat_dict = update_summary_chat_args(chat_dict
|
|
159
|
+
chat_dict: dict[str, Any] = waldiez_chat.get_chat_args(for_queue=True)
|
|
160
|
+
# chat_dict = update_summary_chat_args(chat_dict)
|
|
168
161
|
chat_dict["recipient"] = recipient_name
|
|
169
162
|
if sender_name:
|
|
170
163
|
chat_dict["sender"] = sender_name
|
|
@@ -172,7 +165,6 @@ def get_nested_chat_message_string(
|
|
|
172
165
|
chat=waldiez_chat,
|
|
173
166
|
is_reply=message.is_reply,
|
|
174
167
|
chat_names=chat_names,
|
|
175
|
-
string_escape=string_escape,
|
|
176
168
|
)
|
|
177
169
|
chat_dict["message"] = message_value
|
|
178
170
|
message_dict_str = serializer(chat_dict, tabs=1)
|
|
@@ -180,7 +172,7 @@ def get_nested_chat_message_string(
|
|
|
180
172
|
# it's not a string, its the name of the function
|
|
181
173
|
message_dict_str = message_dict_str.replace(
|
|
182
174
|
f': "{message_value}"', f": {message_value}"
|
|
183
|
-
)
|
|
175
|
+
).replace(f'"{message_value}"', f"{message_value}")
|
|
184
176
|
if sender_name:
|
|
185
177
|
message_dict_str = message_dict_str.replace(
|
|
186
178
|
f': "{sender_name}"', f": {sender_name}"
|
|
@@ -195,12 +187,11 @@ def get_nested_chat_message_string(
|
|
|
195
187
|
def get_nested_chat_queue(
|
|
196
188
|
nested_chat: WaldiezAgentNestedChat,
|
|
197
189
|
agent: WaldiezAgent,
|
|
198
|
-
agent_names:
|
|
199
|
-
chat_names:
|
|
200
|
-
all_chats:
|
|
190
|
+
agent_names: dict[str, str],
|
|
191
|
+
chat_names: dict[str, str],
|
|
192
|
+
all_chats: list[WaldiezChat],
|
|
201
193
|
serializer: Callable[..., str],
|
|
202
|
-
|
|
203
|
-
) -> Tuple[str, List[str]]:
|
|
194
|
+
) -> tuple[str, list[str]]:
|
|
204
195
|
"""Get the nested chat queue.
|
|
205
196
|
|
|
206
197
|
Parameters
|
|
@@ -209,24 +200,22 @@ def get_nested_chat_queue(
|
|
|
209
200
|
The nested chat.
|
|
210
201
|
agent : WaldiezAgent
|
|
211
202
|
The agent.
|
|
212
|
-
agent_names :
|
|
203
|
+
agent_names : dict[str, str]
|
|
213
204
|
A mapping of agent id to agent name.
|
|
214
|
-
chat_names :
|
|
205
|
+
chat_names : dict[str, str]
|
|
215
206
|
A mapping of chat id to chat name.
|
|
216
|
-
all_chats :
|
|
207
|
+
all_chats : list[WaldiezChat]
|
|
217
208
|
All the chats in the flow.
|
|
218
209
|
serializer : Callable[..., str]
|
|
219
210
|
The serializer to use to escape quotes in a string.
|
|
220
|
-
string_escape : Callable[[str], str]
|
|
221
|
-
The function to escape the string.
|
|
222
211
|
|
|
223
212
|
Returns
|
|
224
213
|
-------
|
|
225
|
-
|
|
214
|
+
tuple[str, list[str]]
|
|
226
215
|
The nested chat queue and the methods to include
|
|
227
216
|
(methods: message string and method name if the message is a method).
|
|
228
217
|
"""
|
|
229
|
-
message_methods_to_include = []
|
|
218
|
+
message_methods_to_include: list[str] = []
|
|
230
219
|
chat_messages_str = "[\n"
|
|
231
220
|
for message in nested_chat.messages:
|
|
232
221
|
waldiez_chat = next(chat for chat in all_chats if chat.id == message.id)
|
|
@@ -237,7 +226,6 @@ def get_nested_chat_queue(
|
|
|
237
226
|
agent_names=agent_names,
|
|
238
227
|
chat_names=chat_names,
|
|
239
228
|
serializer=serializer,
|
|
240
|
-
string_escape=string_escape,
|
|
241
229
|
)
|
|
242
230
|
if message_source:
|
|
243
231
|
message_methods_to_include.append(message_source)
|
|
@@ -251,9 +239,8 @@ def get_nested_chat_queue(
|
|
|
251
239
|
def get_chat_nested_string(
|
|
252
240
|
chat: WaldiezChat,
|
|
253
241
|
is_reply: bool,
|
|
254
|
-
chat_names:
|
|
255
|
-
|
|
256
|
-
) -> Tuple[str, Optional[str]]:
|
|
242
|
+
chat_names: dict[str, str],
|
|
243
|
+
) -> tuple[str, Optional[str]]:
|
|
257
244
|
"""Get the nested chat message.
|
|
258
245
|
|
|
259
246
|
Parameters
|
|
@@ -262,14 +249,12 @@ def get_chat_nested_string(
|
|
|
262
249
|
The chat.
|
|
263
250
|
is_reply : bool
|
|
264
251
|
Whether to use the nested chat's reply message or not.
|
|
265
|
-
chat_names :
|
|
266
|
-
A mapping of chat id to chat name
|
|
267
|
-
string_escape : Callable[[str], str]
|
|
268
|
-
The function to escape the string.
|
|
252
|
+
chat_names : dict[str, str]
|
|
253
|
+
A mapping of chat id to chat name..
|
|
269
254
|
|
|
270
255
|
Returns
|
|
271
256
|
-------
|
|
272
|
-
|
|
257
|
+
tuple[str, Optional[str]]
|
|
273
258
|
If the message is a string, the message content and None.
|
|
274
259
|
If the message is a method, the method name and the method content.
|
|
275
260
|
If the message is None, 'None' and None.
|
|
@@ -282,7 +267,7 @@ def get_chat_nested_string(
|
|
|
282
267
|
if not message or message.type == "none" or message.content is None:
|
|
283
268
|
return "None", None
|
|
284
269
|
if message.type == "string":
|
|
285
|
-
return
|
|
270
|
+
return message.content, None
|
|
286
271
|
chat_name = chat_names[chat.id]
|
|
287
272
|
if is_reply:
|
|
288
273
|
function_content, function_name = chat.get_nested_chat_message_function(
|
|
@@ -2,49 +2,48 @@
|
|
|
2
2
|
# Copyright (c) 2024 - 2025 Waldiez and contributors.
|
|
3
3
|
"""Utility functions for exporting sequential chats."""
|
|
4
4
|
|
|
5
|
-
from typing import Callable
|
|
5
|
+
from typing import Callable
|
|
6
6
|
|
|
7
7
|
from waldiez.models import (
|
|
8
|
-
|
|
9
|
-
WaldiezChat,
|
|
8
|
+
WaldiezAgentConnection,
|
|
10
9
|
WaldiezChatMessage,
|
|
11
|
-
|
|
10
|
+
WaldiezRagUserProxy,
|
|
12
11
|
)
|
|
13
12
|
|
|
14
|
-
from .common import get_chat_message_string
|
|
13
|
+
from .common import get_chat_message_string
|
|
15
14
|
|
|
16
15
|
|
|
17
16
|
def export_sequential_chat(
|
|
18
|
-
main_chats:
|
|
19
|
-
chat_names:
|
|
20
|
-
agent_names:
|
|
17
|
+
main_chats: list[WaldiezAgentConnection],
|
|
18
|
+
chat_names: dict[str, str],
|
|
19
|
+
agent_names: dict[str, str],
|
|
21
20
|
serializer: Callable[..., str],
|
|
22
|
-
string_escape: Callable[[str], str],
|
|
23
21
|
tabs: int,
|
|
24
22
|
is_async: bool,
|
|
25
|
-
|
|
23
|
+
skip_cache: bool,
|
|
24
|
+
) -> tuple[str, str]:
|
|
26
25
|
r"""Get the chats content, when there are more than one chats in the flow.
|
|
27
26
|
|
|
28
27
|
Parameters
|
|
29
28
|
----------
|
|
30
|
-
main_chats :
|
|
29
|
+
main_chats : list[WaldiezAgentConnection]
|
|
31
30
|
The main chats.
|
|
32
|
-
chat_names :
|
|
31
|
+
chat_names : dict[str, str]
|
|
33
32
|
A mapping of chat id to chat name.
|
|
34
|
-
agent_names :
|
|
33
|
+
agent_names : dict[str, str]
|
|
35
34
|
A mapping of agent id to agent name.
|
|
36
35
|
serializer : Callable[..., str]
|
|
37
36
|
The serializer function to escape quotes in a string.
|
|
38
|
-
string_escape : Callable[[str], str]
|
|
39
|
-
The string escape function.
|
|
40
37
|
tabs : int
|
|
41
38
|
The number of tabs to use for indentation.
|
|
42
39
|
is_async : bool
|
|
43
40
|
Whether the chat is asynchronous.
|
|
41
|
+
skip_cache : bool
|
|
42
|
+
Whether to skip the cache argument.
|
|
44
43
|
|
|
45
44
|
Returns
|
|
46
45
|
-------
|
|
47
|
-
|
|
46
|
+
tuple[str, str]
|
|
48
47
|
The main chats content and additional methods string if any.
|
|
49
48
|
|
|
50
49
|
Example
|
|
@@ -117,16 +116,14 @@ def export_sequential_chat(
|
|
|
117
116
|
content = "\n"
|
|
118
117
|
additional_methods_string = ""
|
|
119
118
|
content += _get_initiate_chats_line(tab, is_async)
|
|
120
|
-
for
|
|
119
|
+
for connection in main_chats:
|
|
121
120
|
chat_string, additional_methods = _get_chat_dict_string(
|
|
122
|
-
chat=chat,
|
|
123
121
|
chat_names=chat_names,
|
|
124
|
-
|
|
125
|
-
recipient=recipient,
|
|
122
|
+
connection=connection,
|
|
126
123
|
agent_names=agent_names,
|
|
127
124
|
serializer=serializer,
|
|
128
|
-
string_escape=string_escape,
|
|
129
125
|
tabs=tabs + 1,
|
|
126
|
+
skip_cache=skip_cache,
|
|
130
127
|
)
|
|
131
128
|
additional_methods_string += additional_methods
|
|
132
129
|
content += "\n" + f"{tab} {chat_string}"
|
|
@@ -134,17 +131,14 @@ def export_sequential_chat(
|
|
|
134
131
|
return content, additional_methods_string
|
|
135
132
|
|
|
136
133
|
|
|
137
|
-
# pylint: disable=too-many-locals
|
|
138
134
|
def _get_chat_dict_string(
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
chat_names: Dict[str, str],
|
|
143
|
-
agent_names: Dict[str, str],
|
|
135
|
+
connection: WaldiezAgentConnection,
|
|
136
|
+
chat_names: dict[str, str],
|
|
137
|
+
agent_names: dict[str, str],
|
|
144
138
|
serializer: Callable[..., str],
|
|
145
|
-
string_escape: Callable[[str], str],
|
|
146
139
|
tabs: int,
|
|
147
|
-
|
|
140
|
+
skip_cache: bool,
|
|
141
|
+
) -> tuple[str, str]:
|
|
148
142
|
"""Get a chat dictionary string.
|
|
149
143
|
|
|
150
144
|
If the chat message is a separate method and not a string or a lambda,
|
|
@@ -153,62 +147,50 @@ def _get_chat_dict_string(
|
|
|
153
147
|
|
|
154
148
|
Parameters
|
|
155
149
|
----------
|
|
156
|
-
|
|
157
|
-
The chat.
|
|
158
|
-
|
|
159
|
-
The sender.
|
|
160
|
-
recipient : WaldiezAgent
|
|
161
|
-
The recipient.
|
|
162
|
-
chat_names : Dict[str, str]
|
|
150
|
+
connection : WaldiezAgentConnection
|
|
151
|
+
The connection object containing the chat and agents.
|
|
152
|
+
chat_names : dict[str, str]
|
|
163
153
|
A mapping of chat id to chat name.
|
|
164
|
-
agent_names :
|
|
154
|
+
agent_names : dict[str, str]
|
|
165
155
|
A mapping of agent id to agent name.
|
|
166
156
|
serializer : Callable[[str], str]
|
|
167
157
|
The function to serialize the dictionaries or lists.
|
|
168
|
-
string_escape : Callable[[str], str]
|
|
169
|
-
The function to escape the string.
|
|
170
158
|
tabs : int
|
|
171
159
|
The number of tabs to use for indentation.
|
|
160
|
+
skip_cache : bool
|
|
161
|
+
Whether to skip the cache argument.
|
|
172
162
|
|
|
173
163
|
Returns
|
|
174
164
|
-------
|
|
175
|
-
|
|
165
|
+
tuple[str, str]
|
|
176
166
|
The chat dictionary string and additional methods string if any.
|
|
177
167
|
"""
|
|
178
168
|
tab = " " * tabs
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
chat_string =
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
chat_string += "\n" + f'{tab} "{key}": "{value}",'
|
|
189
|
-
elif isinstance(value, dict):
|
|
190
|
-
chat_string += (
|
|
191
|
-
"\n" + f'{tab} "{key}": {serializer(value, tabs=tabs + 1)},'
|
|
192
|
-
)
|
|
193
|
-
else:
|
|
194
|
-
chat_string += "\n" + f'{tab} "{key}": {value},'
|
|
169
|
+
chat = connection["chat"]
|
|
170
|
+
sender = connection["source"]
|
|
171
|
+
chat_string = _get_chat_strig_start(
|
|
172
|
+
connection=connection,
|
|
173
|
+
agent_names=agent_names,
|
|
174
|
+
serializer=serializer,
|
|
175
|
+
tabs=tabs,
|
|
176
|
+
skip_cache=skip_cache,
|
|
177
|
+
)
|
|
195
178
|
if (
|
|
196
|
-
sender.
|
|
197
|
-
and isinstance(sender,
|
|
179
|
+
sender.is_rag_user
|
|
180
|
+
and isinstance(sender, WaldiezRagUserProxy)
|
|
198
181
|
and chat.message.type == "rag_message_generator"
|
|
199
182
|
):
|
|
200
183
|
message = f"{agent_names[sender.id]}.message_generator"
|
|
201
184
|
chat_string += "\n" + f'{tab} "message": {message},'
|
|
202
185
|
chat_string += "\n" + tab + "},"
|
|
203
|
-
return chat_string,
|
|
186
|
+
return chat_string, ""
|
|
187
|
+
additional_methods_string = ""
|
|
204
188
|
message, method_content = get_chat_message_string(
|
|
205
189
|
sender=sender,
|
|
206
190
|
chat=chat,
|
|
207
191
|
chat_names=chat_names,
|
|
208
|
-
string_escape=string_escape,
|
|
209
192
|
)
|
|
210
193
|
if message and isinstance(chat.data.message, WaldiezChatMessage):
|
|
211
|
-
message = string_escape(message)
|
|
212
194
|
if chat.data.message.type == "method":
|
|
213
195
|
if method_content:
|
|
214
196
|
additional_methods_string += "\n" + method_content
|
|
@@ -219,6 +201,35 @@ def _get_chat_dict_string(
|
|
|
219
201
|
return chat_string, additional_methods_string
|
|
220
202
|
|
|
221
203
|
|
|
204
|
+
def _get_chat_strig_start(
|
|
205
|
+
connection: WaldiezAgentConnection,
|
|
206
|
+
agent_names: dict[str, str],
|
|
207
|
+
serializer: Callable[..., str],
|
|
208
|
+
tabs: int,
|
|
209
|
+
skip_cache: bool,
|
|
210
|
+
) -> str:
|
|
211
|
+
tab = " " * tabs
|
|
212
|
+
chat = connection["chat"]
|
|
213
|
+
sender = connection["source"]
|
|
214
|
+
recipient = connection["target"]
|
|
215
|
+
chat_args = chat.get_chat_args(for_queue=True, sender=sender)
|
|
216
|
+
# chat_args = update_summary_chat_args(chat_args)
|
|
217
|
+
chat_string = "{"
|
|
218
|
+
chat_string += "\n" + f'{tab} "sender": {agent_names[sender.id]},'
|
|
219
|
+
chat_string += "\n" + f'{tab} "recipient": {agent_names[recipient.id]},'
|
|
220
|
+
if skip_cache is False:
|
|
221
|
+
chat_string += "\n" + f'{tab} "cache": cache,'
|
|
222
|
+
# additional_methods_string = ""
|
|
223
|
+
for key, value in chat_args.items():
|
|
224
|
+
if isinstance(value, (dict, str)):
|
|
225
|
+
chat_string += (
|
|
226
|
+
"\n" + f'{tab} "{key}": {serializer(value, tabs=tabs + 1)},'
|
|
227
|
+
)
|
|
228
|
+
else:
|
|
229
|
+
chat_string += "\n" + f'{tab} "{key}": {value},'
|
|
230
|
+
return chat_string
|
|
231
|
+
|
|
232
|
+
|
|
222
233
|
def _get_initiate_chats_line(
|
|
223
234
|
tab: str,
|
|
224
235
|
is_async: bool,
|