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.

Files changed (248) hide show
  1. waldiez/__init__.py +5 -5
  2. waldiez/_version.py +1 -1
  3. waldiez/cli.py +97 -102
  4. waldiez/exporter.py +61 -19
  5. waldiez/exporting/__init__.py +25 -6
  6. waldiez/exporting/agent/__init__.py +7 -3
  7. waldiez/exporting/agent/code_execution.py +114 -0
  8. waldiez/exporting/agent/exporter.py +354 -0
  9. waldiez/exporting/agent/extras/__init__.py +15 -0
  10. waldiez/exporting/agent/extras/captain_agent_extras.py +315 -0
  11. waldiez/exporting/agent/extras/group/target.py +178 -0
  12. waldiez/exporting/agent/extras/group_manager_agent_extas.py +500 -0
  13. waldiez/exporting/agent/extras/group_member_extras.py +181 -0
  14. waldiez/exporting/agent/extras/handoffs/__init__.py +19 -0
  15. waldiez/exporting/agent/extras/handoffs/after_work.py +78 -0
  16. waldiez/exporting/agent/extras/handoffs/available.py +74 -0
  17. waldiez/exporting/agent/extras/handoffs/condition.py +158 -0
  18. waldiez/exporting/agent/extras/handoffs/handoff.py +171 -0
  19. waldiez/exporting/agent/extras/handoffs/target.py +189 -0
  20. waldiez/exporting/agent/extras/rag/__init__.py +10 -0
  21. waldiez/exporting/agent/{utils/rag_user/chroma_utils.py → extras/rag/chroma_extras.py} +37 -24
  22. waldiez/exporting/agent/{utils/rag_user/mongo_utils.py → extras/rag/mongo_extras.py} +10 -10
  23. waldiez/exporting/agent/{utils/rag_user/pgvector_utils.py → extras/rag/pgvector_extras.py} +13 -13
  24. waldiez/exporting/agent/{utils/rag_user/qdrant_utils.py → extras/rag/qdrant_extras.py} +13 -13
  25. waldiez/exporting/agent/{utils/rag_user/vector_db.py → extras/rag/vector_db_extras.py} +59 -46
  26. waldiez/exporting/agent/extras/rag_user_proxy_agent_extras.py +245 -0
  27. waldiez/exporting/agent/extras/reasoning_agent_extras.py +88 -0
  28. waldiez/exporting/agent/factory.py +95 -0
  29. waldiez/exporting/agent/processor.py +150 -0
  30. waldiez/exporting/agent/system_message.py +36 -0
  31. waldiez/exporting/agent/termination.py +50 -0
  32. waldiez/exporting/chats/__init__.py +7 -3
  33. waldiez/exporting/chats/exporter.py +97 -0
  34. waldiez/exporting/chats/factory.py +65 -0
  35. waldiez/exporting/chats/processor.py +226 -0
  36. waldiez/exporting/chats/utils/__init__.py +6 -5
  37. waldiez/exporting/chats/utils/common.py +11 -45
  38. waldiez/exporting/chats/utils/group.py +55 -0
  39. waldiez/exporting/chats/utils/nested.py +37 -52
  40. waldiez/exporting/chats/utils/sequential.py +72 -61
  41. waldiez/exporting/chats/utils/{single_chat.py → single.py} +48 -50
  42. waldiez/exporting/core/__init__.py +196 -0
  43. waldiez/exporting/core/constants.py +17 -0
  44. waldiez/exporting/core/content.py +69 -0
  45. waldiez/exporting/core/context.py +244 -0
  46. waldiez/exporting/core/enums.py +89 -0
  47. waldiez/exporting/core/errors.py +19 -0
  48. waldiez/exporting/core/exporter.py +390 -0
  49. waldiez/exporting/core/exporters.py +67 -0
  50. waldiez/exporting/core/extras/__init__.py +39 -0
  51. waldiez/exporting/core/extras/agent_extras/__init__.py +27 -0
  52. waldiez/exporting/core/extras/agent_extras/captain_extras.py +57 -0
  53. waldiez/exporting/core/extras/agent_extras/group_manager_extras.py +102 -0
  54. waldiez/exporting/core/extras/agent_extras/rag_user_extras.py +53 -0
  55. waldiez/exporting/core/extras/agent_extras/reasoning_extras.py +68 -0
  56. waldiez/exporting/core/extras/agent_extras/standard_extras.py +263 -0
  57. waldiez/exporting/core/extras/base.py +241 -0
  58. waldiez/exporting/core/extras/chat_extras.py +118 -0
  59. waldiez/exporting/core/extras/flow_extras.py +70 -0
  60. waldiez/exporting/core/extras/model_extras.py +73 -0
  61. waldiez/exporting/core/extras/path_resolver.py +93 -0
  62. waldiez/exporting/core/extras/serializer.py +138 -0
  63. waldiez/exporting/core/extras/tool_extras.py +82 -0
  64. waldiez/exporting/core/protocols.py +259 -0
  65. waldiez/exporting/core/result.py +705 -0
  66. waldiez/exporting/core/types.py +329 -0
  67. waldiez/exporting/core/utils/__init__.py +11 -0
  68. waldiez/exporting/core/utils/comment.py +33 -0
  69. waldiez/exporting/core/utils/llm_config.py +117 -0
  70. waldiez/exporting/core/validation.py +96 -0
  71. waldiez/exporting/flow/__init__.py +6 -2
  72. waldiez/exporting/flow/execution_generator.py +193 -0
  73. waldiez/exporting/flow/exporter.py +107 -0
  74. waldiez/exporting/flow/factory.py +94 -0
  75. waldiez/exporting/flow/file_generator.py +214 -0
  76. waldiez/exporting/flow/merger.py +387 -0
  77. waldiez/exporting/flow/orchestrator.py +411 -0
  78. waldiez/exporting/flow/utils/__init__.py +9 -36
  79. waldiez/exporting/flow/utils/common.py +206 -0
  80. waldiez/exporting/flow/utils/importing.py +373 -0
  81. waldiez/exporting/flow/utils/linting.py +200 -0
  82. waldiez/exporting/flow/utils/{logging_utils.py → logging.py} +23 -9
  83. waldiez/exporting/models/__init__.py +3 -1
  84. waldiez/exporting/models/exporter.py +233 -0
  85. waldiez/exporting/models/factory.py +66 -0
  86. waldiez/exporting/models/processor.py +139 -0
  87. waldiez/exporting/tools/__init__.py +11 -0
  88. waldiez/exporting/tools/exporter.py +207 -0
  89. waldiez/exporting/tools/factory.py +57 -0
  90. waldiez/exporting/tools/processor.py +248 -0
  91. waldiez/exporting/tools/registration.py +133 -0
  92. waldiez/io/__init__.py +128 -0
  93. waldiez/io/_ws.py +199 -0
  94. waldiez/io/models/__init__.py +60 -0
  95. waldiez/io/models/base.py +66 -0
  96. waldiez/io/models/constants.py +78 -0
  97. waldiez/io/models/content/__init__.py +23 -0
  98. waldiez/io/models/content/audio.py +43 -0
  99. waldiez/io/models/content/base.py +45 -0
  100. waldiez/io/models/content/file.py +43 -0
  101. waldiez/io/models/content/image.py +96 -0
  102. waldiez/io/models/content/text.py +37 -0
  103. waldiez/io/models/content/video.py +43 -0
  104. waldiez/io/models/user_input.py +269 -0
  105. waldiez/io/models/user_response.py +215 -0
  106. waldiez/io/mqtt.py +681 -0
  107. waldiez/io/redis.py +782 -0
  108. waldiez/io/structured.py +439 -0
  109. waldiez/io/utils.py +184 -0
  110. waldiez/io/ws.py +298 -0
  111. waldiez/logger.py +481 -0
  112. waldiez/models/__init__.py +108 -51
  113. waldiez/models/agents/__init__.py +34 -70
  114. waldiez/models/agents/agent/__init__.py +10 -4
  115. waldiez/models/agents/agent/agent.py +466 -65
  116. waldiez/models/agents/agent/agent_data.py +119 -47
  117. waldiez/models/agents/agent/agent_type.py +13 -2
  118. waldiez/models/agents/agent/code_execution.py +12 -12
  119. waldiez/models/agents/agent/human_input_mode.py +8 -0
  120. waldiez/models/agents/agent/{linked_skill.py → linked_tool.py} +7 -7
  121. waldiez/models/agents/agent/nested_chat.py +35 -7
  122. waldiez/models/agents/agent/termination_message.py +30 -22
  123. waldiez/models/agents/{swarm_agent → agent}/update_system_message.py +22 -22
  124. waldiez/models/agents/agents.py +58 -63
  125. waldiez/models/agents/assistant/assistant.py +4 -4
  126. waldiez/models/agents/assistant/assistant_data.py +13 -1
  127. waldiez/models/agents/{captain_agent → captain}/captain_agent.py +5 -5
  128. waldiez/models/agents/{captain_agent → captain}/captain_agent_data.py +5 -5
  129. waldiez/models/agents/extra_requirements.py +11 -16
  130. waldiez/models/agents/group_manager/group_manager.py +103 -13
  131. waldiez/models/agents/group_manager/group_manager_data.py +36 -14
  132. waldiez/models/agents/group_manager/speakers.py +77 -24
  133. waldiez/models/agents/{rag_user → rag_user_proxy}/__init__.py +16 -16
  134. waldiez/models/agents/rag_user_proxy/rag_user_proxy.py +64 -0
  135. waldiez/models/agents/{rag_user/rag_user_data.py → rag_user_proxy/rag_user_proxy_data.py} +6 -5
  136. waldiez/models/agents/{rag_user → rag_user_proxy}/retrieve_config.py +182 -114
  137. waldiez/models/agents/{rag_user → rag_user_proxy}/vector_db_config.py +13 -13
  138. waldiez/models/agents/reasoning/reasoning_agent.py +6 -6
  139. waldiez/models/agents/reasoning/reasoning_agent_data.py +110 -63
  140. waldiez/models/agents/reasoning/reasoning_agent_reason_config.py +38 -10
  141. waldiez/models/agents/user_proxy/user_proxy.py +11 -7
  142. waldiez/models/agents/user_proxy/user_proxy_data.py +2 -2
  143. waldiez/models/chat/__init__.py +2 -1
  144. waldiez/models/chat/chat.py +166 -87
  145. waldiez/models/chat/chat_data.py +99 -136
  146. waldiez/models/chat/chat_message.py +33 -23
  147. waldiez/models/chat/chat_nested.py +31 -30
  148. waldiez/models/chat/chat_summary.py +10 -8
  149. waldiez/models/common/__init__.py +52 -2
  150. waldiez/models/common/ag2_version.py +1 -1
  151. waldiez/models/common/base.py +38 -7
  152. waldiez/models/common/dict_utils.py +42 -17
  153. waldiez/models/common/handoff.py +459 -0
  154. waldiez/models/common/id_generator.py +19 -0
  155. waldiez/models/common/method_utils.py +130 -68
  156. waldiez/{exporting/base/utils → models/common}/naming.py +38 -61
  157. waldiez/models/common/waldiez_version.py +37 -0
  158. waldiez/models/flow/__init__.py +9 -2
  159. waldiez/models/flow/connection.py +18 -0
  160. waldiez/models/flow/flow.py +311 -215
  161. waldiez/models/flow/flow_data.py +207 -40
  162. waldiez/models/flow/info.py +85 -0
  163. waldiez/models/flow/naming.py +131 -0
  164. waldiez/models/model/__init__.py +7 -1
  165. waldiez/models/model/extra_requirements.py +3 -12
  166. waldiez/models/model/model.py +76 -21
  167. waldiez/models/model/model_data.py +108 -20
  168. waldiez/models/tool/__init__.py +16 -0
  169. waldiez/models/tool/extra_requirements.py +36 -0
  170. waldiez/models/{skill/skill.py → tool/tool.py} +88 -88
  171. waldiez/models/tool/tool_data.py +51 -0
  172. waldiez/models/tool/tool_type.py +8 -0
  173. waldiez/models/waldiez.py +97 -80
  174. waldiez/runner.py +115 -61
  175. waldiez/running/__init__.py +13 -7
  176. waldiez/running/environment.py +49 -68
  177. waldiez/running/gen_seq_diagram.py +16 -14
  178. waldiez/running/post_run.py +119 -0
  179. waldiez/running/pre_run.py +149 -0
  180. waldiez/running/util.py +134 -0
  181. waldiez/utils/__init__.py +2 -4
  182. waldiez/utils/cli_extras/jupyter.py +5 -3
  183. waldiez/utils/cli_extras/runner.py +6 -4
  184. waldiez/utils/cli_extras/studio.py +6 -4
  185. waldiez/utils/conflict_checker.py +15 -9
  186. waldiez/utils/flaml_warnings.py +5 -5
  187. waldiez/utils/version.py +47 -0
  188. {waldiez-0.4.7.dist-info → waldiez-0.4.9.dist-info}/METADATA +235 -91
  189. waldiez-0.4.9.dist-info/RECORD +203 -0
  190. waldiez/exporting/agent/agent_exporter.py +0 -297
  191. waldiez/exporting/agent/utils/__init__.py +0 -23
  192. waldiez/exporting/agent/utils/captain_agent.py +0 -263
  193. waldiez/exporting/agent/utils/code_execution.py +0 -65
  194. waldiez/exporting/agent/utils/group_manager.py +0 -220
  195. waldiez/exporting/agent/utils/rag_user/__init__.py +0 -7
  196. waldiez/exporting/agent/utils/rag_user/rag_user.py +0 -209
  197. waldiez/exporting/agent/utils/reasoning.py +0 -36
  198. waldiez/exporting/agent/utils/swarm_agent.py +0 -469
  199. waldiez/exporting/agent/utils/teachability.py +0 -41
  200. waldiez/exporting/agent/utils/termination_message.py +0 -44
  201. waldiez/exporting/base/__init__.py +0 -25
  202. waldiez/exporting/base/agent_position.py +0 -75
  203. waldiez/exporting/base/base_exporter.py +0 -118
  204. waldiez/exporting/base/export_position.py +0 -48
  205. waldiez/exporting/base/import_position.py +0 -23
  206. waldiez/exporting/base/mixin.py +0 -137
  207. waldiez/exporting/base/utils/__init__.py +0 -18
  208. waldiez/exporting/base/utils/comments.py +0 -96
  209. waldiez/exporting/base/utils/path_check.py +0 -68
  210. waldiez/exporting/base/utils/to_string.py +0 -84
  211. waldiez/exporting/chats/chats_exporter.py +0 -240
  212. waldiez/exporting/chats/utils/swarm.py +0 -210
  213. waldiez/exporting/flow/flow_exporter.py +0 -528
  214. waldiez/exporting/flow/utils/agent_utils.py +0 -204
  215. waldiez/exporting/flow/utils/chat_utils.py +0 -71
  216. waldiez/exporting/flow/utils/def_main.py +0 -77
  217. waldiez/exporting/flow/utils/flow_content.py +0 -202
  218. waldiez/exporting/flow/utils/flow_names.py +0 -116
  219. waldiez/exporting/flow/utils/importing_utils.py +0 -227
  220. waldiez/exporting/models/models_exporter.py +0 -199
  221. waldiez/exporting/models/utils.py +0 -174
  222. waldiez/exporting/skills/__init__.py +0 -9
  223. waldiez/exporting/skills/skills_exporter.py +0 -176
  224. waldiez/exporting/skills/utils.py +0 -369
  225. waldiez/models/agents/agent/teachability.py +0 -70
  226. waldiez/models/agents/rag_user/rag_user.py +0 -60
  227. waldiez/models/agents/swarm_agent/__init__.py +0 -50
  228. waldiez/models/agents/swarm_agent/after_work.py +0 -179
  229. waldiez/models/agents/swarm_agent/on_condition.py +0 -105
  230. waldiez/models/agents/swarm_agent/on_condition_available.py +0 -142
  231. waldiez/models/agents/swarm_agent/on_condition_target.py +0 -40
  232. waldiez/models/agents/swarm_agent/swarm_agent.py +0 -107
  233. waldiez/models/agents/swarm_agent/swarm_agent_data.py +0 -124
  234. waldiez/models/flow/utils.py +0 -232
  235. waldiez/models/skill/__init__.py +0 -16
  236. waldiez/models/skill/extra_requirements.py +0 -36
  237. waldiez/models/skill/skill_data.py +0 -53
  238. waldiez/models/skill/skill_type.py +0 -8
  239. waldiez/running/running.py +0 -369
  240. waldiez/utils/pysqlite3_checker.py +0 -308
  241. waldiez/utils/rdps_checker.py +0 -122
  242. waldiez-0.4.7.dist-info/RECORD +0 -149
  243. /waldiez/models/agents/{captain_agent → captain}/__init__.py +0 -0
  244. /waldiez/models/agents/{captain_agent → captain}/captain_agent_lib_entry.py +0 -0
  245. {waldiez-0.4.7.dist-info → waldiez-0.4.9.dist-info}/WHEEL +0 -0
  246. {waldiez-0.4.7.dist-info → waldiez-0.4.9.dist-info}/entry_points.txt +0 -0
  247. {waldiez-0.4.7.dist-info → waldiez-0.4.9.dist-info}/licenses/LICENSE +0 -0
  248. {waldiez-0.4.7.dist-info → waldiez-0.4.9.dist-info}/licenses/NOTICE.md +0 -0
@@ -0,0 +1,150 @@
1
+ # SPDX-License-Identifier: Apache-2.0.
2
+ # Copyright (c) 2024 - 2025 Waldiez and contributors.
3
+ # pylint: disable=too-few-public-methods, no-self-use
4
+ """Processor for generating Waldiez agent definitions."""
5
+
6
+ import json
7
+ from dataclasses import dataclass
8
+ from typing import Callable
9
+
10
+ from waldiez.models import WaldiezAgent
11
+
12
+ from ..core.enums import GroupManagerStrategy
13
+ from ..core.extras.agent_extras import GroupManagerExtras, StandardExtras
14
+
15
+
16
+ @dataclass
17
+ class AgentProcessingResult:
18
+ """Result from processing an agent."""
19
+
20
+ content: str = ""
21
+
22
+
23
+ class AgentProcessor:
24
+ """Processor for main agent definition generation."""
25
+
26
+ def __init__(
27
+ self,
28
+ agent: WaldiezAgent,
29
+ agent_names: dict[str, str],
30
+ arguments_resolver: Callable[[WaldiezAgent], list[str]],
31
+ extras: StandardExtras,
32
+ ):
33
+ self.agent = agent
34
+ self.agent_names = agent_names
35
+ self.arguments_resolver = arguments_resolver
36
+ self.extras = extras
37
+
38
+ def _should_skip_group_manager(self) -> bool:
39
+ """Check if the group manager should be skipped.
40
+
41
+ Returns
42
+ -------
43
+ bool
44
+ True if the group manager should be skipped, False otherwise.
45
+ """
46
+ return (
47
+ isinstance(self.extras, GroupManagerExtras)
48
+ and self.extras.strategy == GroupManagerStrategy.PATTERN
49
+ )
50
+
51
+ def process(self) -> AgentProcessingResult:
52
+ """Process the agent and generate its definition.
53
+
54
+ Returns
55
+ -------
56
+ str
57
+ The generated agent definition string.
58
+ """
59
+ if (
60
+ isinstance(self.extras, GroupManagerExtras)
61
+ and self._should_skip_group_manager()
62
+ ):
63
+ return AgentProcessingResult(content="")
64
+ agent_name = self.agent_names[self.agent.id]
65
+
66
+ ag2_class = self.agent.ag2_class
67
+ # Build extra arguments
68
+ extra_args = ""
69
+ for arg in self.extras.extra_args:
70
+ extra_args += arg.get_content(append_new_line=True)
71
+
72
+ # Get additional arguments from resolver
73
+ resolved_args = self.arguments_resolver(self.agent)
74
+ if resolved_args: # pragma: no branch
75
+ extra_args += ",\n".join(resolved_args)
76
+ # Build the agent definition
77
+ agent_str = f"""{agent_name} = {ag2_class}(
78
+ {self.get_name_arg()}
79
+ {self.get_description_arg()},{self.extras.get_system_message_arg()}
80
+ {self.get_human_input_mode_arg()},
81
+ {self.get_max_consecutive_auto_reply_arg()},
82
+ {self.get_auto_reply_arg()},
83
+ {self.extras.get_code_execution_arg()}
84
+ {self.extras.get_termination_arg()}
85
+ {extra_args}
86
+ )"""
87
+
88
+ return AgentProcessingResult(content=agent_str)
89
+
90
+ def get_name_arg(self) -> str:
91
+ """Get the agent name argument.
92
+
93
+ Returns
94
+ -------
95
+ str
96
+ The agent name argument.
97
+ """
98
+ return f' name="{self.agent_names[self.agent.id]}",'
99
+
100
+ def get_human_input_mode_arg(self) -> str:
101
+ """Get the human input mode argument.
102
+
103
+ Returns
104
+ -------
105
+ str
106
+ The human input mode argument.
107
+ """
108
+ return f' human_input_mode="{self.agent.data.human_input_mode}"'
109
+
110
+ def get_max_consecutive_auto_reply_arg(self) -> str:
111
+ """Get the maximum consecutive auto reply argument.
112
+
113
+ Returns
114
+ -------
115
+ str
116
+ The maximum consecutive auto reply argument.
117
+ """
118
+ value = self.agent.data.max_consecutive_auto_reply
119
+ return f" max_consecutive_auto_reply={value}"
120
+
121
+ def get_description_arg(self) -> str:
122
+ """Get the agent description.
123
+
124
+ Returns
125
+ -------
126
+ str
127
+ The agent description.
128
+ """
129
+ description = (
130
+ json.dumps(self.agent.description)
131
+ if self.agent.description
132
+ else '""'
133
+ )
134
+ return f" description={description}"
135
+
136
+ def get_auto_reply_arg(self) -> str:
137
+ """Get the default auto reply argument.
138
+
139
+ Returns
140
+ -------
141
+ str
142
+ The default auto reply argument.
143
+ """
144
+ default_auto_reply = '""'
145
+ if self.agent.data.agent_default_auto_reply:
146
+ # Escape the default auto reply string
147
+ default_auto_reply = json.dumps(
148
+ self.agent.data.agent_default_auto_reply
149
+ )
150
+ return f" default_auto_reply={default_auto_reply}"
@@ -0,0 +1,36 @@
1
+ # SPDX-License-Identifier: Apache-2.0.
2
+ # Copyright (c) 2024 - 2025 Waldiez and contributors.
3
+ # pylint: disable=too-few-public-methods
4
+ """Termination message configuration for Waldiez agents."""
5
+
6
+ import json
7
+
8
+ from waldiez.models import WaldiezAgent
9
+
10
+ from ..core import SystemMessageConfig
11
+
12
+
13
+ class SystemMessageProcessor:
14
+ """Processor for system message configuration."""
15
+
16
+ def __init__(
17
+ self,
18
+ agent: WaldiezAgent,
19
+ ):
20
+ self.agent = agent
21
+
22
+ def process(self) -> SystemMessageConfig:
23
+ """Process system message configuration.
24
+
25
+ Returns
26
+ -------
27
+ SystemMessageConfig
28
+ The processed system message configuration.
29
+ """
30
+ if not self.agent.data.system_message:
31
+ return SystemMessageConfig()
32
+
33
+ return SystemMessageConfig(
34
+ before_agent_conent="",
35
+ system_message_arg=json.dumps(self.agent.data.system_message),
36
+ )
@@ -0,0 +1,50 @@
1
+ # SPDX-License-Identifier: Apache-2.0.
2
+ # Copyright (c) 2024 - 2025 Waldiez and contributors.
3
+ # pylint: disable=too-few-public-methods
4
+ """Termination message configuration for Waldiez agents."""
5
+
6
+ from waldiez.models import WaldiezAgent
7
+
8
+ from ..core import TerminationConfig
9
+
10
+
11
+ class TerminationProcessor:
12
+ """Processor for termination message configuration."""
13
+
14
+ def __init__(
15
+ self,
16
+ agent: WaldiezAgent,
17
+ agent_name: str,
18
+ ):
19
+ self.agent = agent
20
+ self.agent_name = agent_name
21
+
22
+ def process(self) -> TerminationConfig:
23
+ """Process termination configuration.
24
+
25
+ Returns
26
+ -------
27
+ TerminationConfig
28
+ The processed termination configuration.
29
+ """
30
+ if self.agent.data.termination.type == "none":
31
+ return TerminationConfig(
32
+ termination_arg="None",
33
+ before_content="",
34
+ )
35
+ if self.agent.data.termination.type == "keyword":
36
+ return TerminationConfig(
37
+ termination_arg=self.agent.data.termination.string,
38
+ before_content="",
39
+ )
40
+ if self.agent.data.termination.type == "method":
41
+ content, function_name = (
42
+ self.agent.data.termination.get_termination_function(
43
+ name_suffix=self.agent_name
44
+ )
45
+ )
46
+ return TerminationConfig(
47
+ termination_arg=function_name,
48
+ before_content="\n\n" + content + "\n",
49
+ )
50
+ return TerminationConfig()
@@ -1,7 +1,11 @@
1
1
  # SPDX-License-Identifier: Apache-2.0.
2
2
  # Copyright (c) 2024 - 2025 Waldiez and contributors.
3
- """Export chats in a flow."""
3
+ """Chats exporter."""
4
4
 
5
- from .chats_exporter import ChatsExporter
5
+ from .exporter import ChatsExporter
6
+ from .factory import create_chats_exporter
6
7
 
7
- __all__ = ["ChatsExporter"]
8
+ __all__ = [
9
+ "ChatsExporter",
10
+ "create_chats_exporter",
11
+ ]
@@ -0,0 +1,97 @@
1
+ # SPDX-License-Identifier: Apache-2.0.
2
+ # Copyright (c) 2024 - 2025 Waldiez and contributors.
3
+ """Chats exporter."""
4
+
5
+ from typing import Any, Optional
6
+
7
+ from waldiez.models import (
8
+ WaldiezAgent,
9
+ WaldiezAgentConnection,
10
+ WaldiezChat,
11
+ WaldiezGroupManager,
12
+ )
13
+
14
+ from ..core import ChatExtras, Exporter, ExporterContext
15
+ from .processor import ChatsProcessor
16
+
17
+
18
+ class ChatsExporter(Exporter[ChatExtras]):
19
+ """Chats exporter with structured extras."""
20
+
21
+ def __init__(
22
+ self,
23
+ all_agents: list[WaldiezAgent],
24
+ agent_names: dict[str, str],
25
+ all_chats: list[WaldiezChat],
26
+ chat_names: dict[str, str],
27
+ main_chats: list[WaldiezAgentConnection],
28
+ root_group_manager: Optional[WaldiezGroupManager],
29
+ context: Optional[ExporterContext] = None,
30
+ **kwargs: Any,
31
+ ) -> None:
32
+ """Initialize the chats exporter.
33
+
34
+ Parameters
35
+ ----------
36
+ all_agents : list[WaldiezAgent]
37
+ All agents involved in the chats.
38
+ agent_names : dict[str, str]
39
+ Mapping of agent IDs to their names.
40
+ all_chats : list[WaldiezChat]
41
+ All chats to be exported.
42
+ chat_names : dict[str, str]
43
+ Mapping of chat IDs to their names.
44
+ main_chats : list[WaldiezAgentConnection]
45
+ Main chats that are connections between agents.
46
+ root_group_manager : Optional[WaldiezGroupManager]
47
+ The root group manager for managing chat groups, if any.
48
+ context : Optional[ExporterContext], optional
49
+ Exporter context with dependencies, by default None
50
+ **kwargs : Any
51
+ Additional keyword arguments for the exporter.
52
+ """
53
+ super().__init__(context, **kwargs)
54
+
55
+ self.all_agents = all_agents
56
+ self.agent_names = agent_names
57
+ self.all_chats = all_chats
58
+ self.chat_names = chat_names
59
+ self.main_chats = main_chats
60
+ self.root_group_manager = root_group_manager
61
+ config = self.context.get_config()
62
+ self.for_notebook = config.for_notebook
63
+ self.is_async = config.is_async
64
+ self.cache_seed = config.cache_seed
65
+ # Initialize extras with processed chat content
66
+ self._extras = self._create_chat_extras()
67
+
68
+ @property
69
+ def extras(self) -> ChatExtras:
70
+ """Get the chat extras."""
71
+ return self._extras
72
+
73
+ # pylint: disable=no-self-use
74
+ def _create_chat_extras(self) -> ChatExtras:
75
+ """Create and populate chat extras."""
76
+ extras = ChatExtras("chats")
77
+ processor = ChatsProcessor(
78
+ all_agents=self.all_agents,
79
+ agent_names=self.agent_names,
80
+ all_chats=self.all_chats,
81
+ chat_names=self.chat_names,
82
+ main_chats=self.main_chats,
83
+ root_group_manager=self.root_group_manager,
84
+ for_notebook=self.for_notebook,
85
+ is_async=self.is_async,
86
+ cache_seed=self.cache_seed,
87
+ serializer=self.context.get_serializer(),
88
+ extras=extras,
89
+ )
90
+ processor.process()
91
+ if extras.chat_registration:
92
+ extras.append_after_all_agents(extras.chat_registration)
93
+ return extras
94
+
95
+ def generate_main_content(self) -> Optional[str]:
96
+ """Generate the main content of the export."""
97
+ return None
@@ -0,0 +1,65 @@
1
+ # SPDX-License-Identifier: Apache-2.0.
2
+ # Copyright (c) 2024 - 2025 Waldiez and contributors.
3
+ """Factory function for creating a ChatsExporter instance."""
4
+
5
+ from typing import Any, Optional
6
+
7
+ from waldiez.models import (
8
+ WaldiezAgent,
9
+ WaldiezAgentConnection,
10
+ WaldiezChat,
11
+ WaldiezGroupManager,
12
+ )
13
+
14
+ from ..core import ExporterContext, get_default_exporter_context
15
+ from .exporter import ChatsExporter
16
+
17
+
18
+ def create_chats_exporter(
19
+ all_agents: list[WaldiezAgent],
20
+ agent_names: dict[str, str],
21
+ all_chats: list[WaldiezChat],
22
+ chat_names: dict[str, str],
23
+ main_chats: list[WaldiezAgentConnection],
24
+ root_group_manager: Optional[WaldiezGroupManager] = None,
25
+ context: Optional[ExporterContext] = None,
26
+ **kwargs: Any,
27
+ ) -> ChatsExporter:
28
+ """Create a chats exporter.
29
+
30
+ Parameters
31
+ ----------
32
+ all_agents : list[WaldiezAgent]
33
+ All agents involved in the chats.
34
+ agent_names : dict[str, str]
35
+ Mapping of agent IDs to their names.
36
+ all_chats : list[WaldiezChat]
37
+ All chats to be exported.
38
+ chat_names : dict[str, str]
39
+ Mapping of chat IDs to their names.
40
+ main_chats : list[WaldiezAgentConnection]
41
+ Main chats that are connections between agents.
42
+ root_group_manager : Optional[WaldiezGroupManager], optional
43
+ The root group manager for managing chat groups, if any.
44
+ context : Optional[ExporterContext], optional
45
+ Exporter context with dependencies, by default None
46
+ **kwargs : Any
47
+ Additional keyword arguments for the exporter.
48
+
49
+ Returns
50
+ -------
51
+ ChatsExporter
52
+ The created chats exporter.
53
+ """
54
+ if context is None:
55
+ context = get_default_exporter_context()
56
+ return ChatsExporter(
57
+ all_agents=all_agents,
58
+ agent_names=agent_names,
59
+ all_chats=all_chats,
60
+ chat_names=chat_names,
61
+ main_chats=main_chats,
62
+ root_group_manager=root_group_manager,
63
+ context=context,
64
+ **kwargs,
65
+ )
@@ -0,0 +1,226 @@
1
+ # SPDX-License-Identifier: Apache-2.0.
2
+ # Copyright (c) 2024 - 2025 Waldiez and contributors.
3
+ """Chats processor."""
4
+
5
+ from dataclasses import dataclass
6
+ from typing import Optional
7
+
8
+ from waldiez.models import (
9
+ WaldiezAgent,
10
+ WaldiezAgentConnection,
11
+ WaldiezChat,
12
+ WaldiezGroupManager,
13
+ )
14
+
15
+ from ..core import (
16
+ ChatExtras,
17
+ ImportPosition,
18
+ ImportStatement,
19
+ Serializer,
20
+ )
21
+ from .utils import (
22
+ export_group_chats,
23
+ export_nested_chat_registration,
24
+ export_sequential_chat,
25
+ export_single_chat,
26
+ )
27
+
28
+
29
+ @dataclass
30
+ class ChatParams:
31
+ """Parameters for the chat export processor."""
32
+
33
+ main: list[WaldiezAgentConnection]
34
+ """Main chats that are connections between agents."""
35
+ all: list[WaldiezChat]
36
+ """All the chats in the flow."""
37
+ names: dict[str, str]
38
+ """Mapping of chat IDs to their names."""
39
+
40
+
41
+ # pylint: disable=too-many-arguments,too-many-positional-arguments
42
+ class ChatsProcessor:
43
+ """Processor for chats export."""
44
+
45
+ def __init__(
46
+ self,
47
+ all_agents: list[WaldiezAgent],
48
+ agent_names: dict[str, str],
49
+ all_chats: list[WaldiezChat],
50
+ chat_names: dict[str, str],
51
+ main_chats: list[WaldiezAgentConnection],
52
+ root_group_manager: Optional[WaldiezGroupManager],
53
+ for_notebook: bool,
54
+ is_async: bool,
55
+ cache_seed: Optional[int],
56
+ serializer: Serializer,
57
+ extras: ChatExtras,
58
+ ) -> None:
59
+ """Initialize the chats processor.
60
+
61
+ Parameters
62
+ ----------
63
+ extras : ChatExtras
64
+ The structured extras for the chats export.
65
+ """
66
+ self._all_agents = all_agents
67
+ self._agent_names = agent_names
68
+ self._chats = ChatParams(
69
+ main=main_chats,
70
+ all=all_chats,
71
+ names=chat_names,
72
+ )
73
+ self._root_group_manager = root_group_manager
74
+ self._is_async = is_async
75
+ self._for_notebook = for_notebook
76
+ self._cache_seed = cache_seed
77
+ self._serializer = serializer
78
+ self._extras = extras
79
+ chat_tabs = 1
80
+ if cache_seed is not None:
81
+ chat_tabs += 1
82
+ self._chat_tabs = chat_tabs
83
+
84
+ def is_group_patterned(self) -> bool:
85
+ """Check if the chats are group patterned.
86
+
87
+ Returns
88
+ -------
89
+ bool
90
+ True if the chats are group patterned, False otherwise.
91
+ """
92
+ if len(self._chats.main) == 0 and self._root_group_manager is not None:
93
+ return True
94
+ if len(self._chats.main) == 1:
95
+ main_chat = self._chats.main[0]
96
+ sender = main_chat["source"]
97
+ recipient = main_chat["target"]
98
+ if recipient.is_group_manager or sender.is_group_member:
99
+ return True
100
+ return False
101
+
102
+ def process(self) -> None:
103
+ """Process the chats export."""
104
+ self._gather_imports()
105
+ self._handle_chat_registrations()
106
+ chat_initiation = self._generate_chat_initation()
107
+ self._extras.set_chat_initiation(chat_initiation)
108
+
109
+ def _generate_chat_initation(self) -> str:
110
+ """Generate the chat definition string.
111
+
112
+ Returns
113
+ -------
114
+ str
115
+ The chat definition string.
116
+ """
117
+ if len(self._chats.main) == 0:
118
+ if not self._root_group_manager:
119
+ return ""
120
+ return export_group_chats(
121
+ agent_names=self._agent_names,
122
+ manager=self._root_group_manager,
123
+ intial_chat=None,
124
+ tabs=self._chat_tabs,
125
+ is_async=self._is_async,
126
+ )
127
+ if len(self._chats.main) == 1:
128
+ main_chat = self._chats.main[0]
129
+ chat = main_chat["chat"]
130
+ sender = main_chat["source"]
131
+ recipient = main_chat["target"]
132
+ if (
133
+ isinstance(recipient, WaldiezGroupManager)
134
+ and not chat.message.is_method()
135
+ ):
136
+ chat_massage_string: str | None = None
137
+ if chat.message.type == "string":
138
+ chat_massage_string = chat.message.content
139
+ return export_group_chats(
140
+ agent_names=self._agent_names,
141
+ manager=recipient,
142
+ intial_chat=chat_massage_string,
143
+ tabs=self._chat_tabs,
144
+ is_async=self._is_async,
145
+ )
146
+ chat_string, before_chat = export_single_chat(
147
+ sender=sender,
148
+ recipient=recipient,
149
+ chat=chat,
150
+ agent_names=self._agent_names,
151
+ chat_names=self._chats.names,
152
+ serializer=self._serializer.serialize,
153
+ tabs=self._chat_tabs,
154
+ is_async=self._is_async,
155
+ skip_cache=self._cache_seed is None,
156
+ )
157
+ if before_chat:
158
+ self._extras.set_chat_prerequisites(before_chat)
159
+ return chat_string
160
+ chat_string, before_chat = export_sequential_chat(
161
+ main_chats=self._chats.main,
162
+ agent_names=self._agent_names,
163
+ chat_names=self._chats.names,
164
+ serializer=self._serializer.serialize,
165
+ tabs=self._chat_tabs,
166
+ is_async=self._is_async,
167
+ skip_cache=self._cache_seed is None,
168
+ )
169
+ if before_chat:
170
+ self._extras.set_chat_prerequisites(before_chat)
171
+ return chat_string
172
+
173
+ def _handle_chat_registrations(self) -> None:
174
+ """Handle chat registrations."""
175
+ for agent in self._all_agents:
176
+ if (
177
+ agent.agent_type != "group_manager"
178
+ and not agent.is_group_member
179
+ ):
180
+ registration_string = export_nested_chat_registration(
181
+ agent=agent,
182
+ all_chats=self._chats.all,
183
+ chat_names=self._chats.names,
184
+ agent_names=self._agent_names,
185
+ serializer=self._serializer.serialize,
186
+ is_async=self._is_async,
187
+ )
188
+ self._extras.add_registration(registration_string)
189
+
190
+ def _gather_imports(self) -> None:
191
+ """Get the imports string.
192
+
193
+ Returns
194
+ -------
195
+ list[tuple[str, ImportPosition]]
196
+ List of import strings and their positions.
197
+ """
198
+ if self.is_group_patterned():
199
+ if self._is_async:
200
+ import_string = (
201
+ "from autogen.agentchat import a_initiate_group_chat"
202
+ )
203
+ else:
204
+ import_string = (
205
+ "from autogen.agentchat import initiate_group_chat"
206
+ )
207
+ self._extras.add_import(
208
+ ImportStatement(
209
+ statement=import_string, position=ImportPosition.THIRD_PARTY
210
+ )
211
+ )
212
+ return
213
+ if len(self._chats.main) == 1:
214
+ # no additional imports, it is `sender.initiate_chat(....)`
215
+ return
216
+ if self._is_async:
217
+ import_string = (
218
+ "from autogen.agentchat.chat import a_initiate_chats"
219
+ )
220
+ else:
221
+ import_string = "from autogen.agentchat.chat import initiate_chats"
222
+ self._extras.add_import(
223
+ ImportStatement(
224
+ statement=import_string, position=ImportPosition.THIRD_PARTY
225
+ )
226
+ )
@@ -1,15 +1,16 @@
1
1
  # SPDX-License-Identifier: Apache-2.0.
2
2
  # Copyright (c) 2024 - 2025 Waldiez and contributors.
3
- """Utils for exporting chats."""
3
+ """Chat utils for exporting chatsper chat type."""
4
4
 
5
- from .nested import export_nested_chat_registration
5
+ from .group import export_group_chats
6
+ from .nested import export_nested_chat_registration, get_nested_chat_queue
6
7
  from .sequential import export_sequential_chat
7
- from .single_chat import export_single_chat
8
- from .swarm import export_swarm_chat
8
+ from .single import export_single_chat
9
9
 
10
10
  __all__ = [
11
+ "export_group_chats",
11
12
  "export_nested_chat_registration",
13
+ "get_nested_chat_queue",
12
14
  "export_sequential_chat",
13
15
  "export_single_chat",
14
- "export_swarm_chat",
15
16
  ]