waldiez 0.2.2__py3-none-any.whl → 0.3.0__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 (138) hide show
  1. waldiez/__init__.py +2 -0
  2. waldiez/__main__.py +2 -0
  3. waldiez/_version.py +3 -1
  4. waldiez/cli.py +13 -3
  5. waldiez/cli_extras.py +4 -3
  6. waldiez/conflict_checker.py +4 -3
  7. waldiez/exporter.py +28 -105
  8. waldiez/exporting/__init__.py +8 -9
  9. waldiez/exporting/agent/__init__.py +7 -0
  10. waldiez/exporting/agent/agent_exporter.py +279 -0
  11. waldiez/exporting/agent/utils/__init__.py +23 -0
  12. waldiez/exporting/agent/utils/agent_class_name.py +34 -0
  13. waldiez/exporting/agent/utils/agent_imports.py +50 -0
  14. waldiez/exporting/{agents → agent/utils}/code_execution.py +9 -11
  15. waldiez/exporting/{agents → agent/utils}/group_manager.py +47 -35
  16. waldiez/exporting/{agents → agent/utils}/rag_user/__init__.py +2 -0
  17. waldiez/exporting/{agents → agent/utils}/rag_user/chroma_utils.py +22 -17
  18. waldiez/exporting/{agents → agent/utils}/rag_user/mongo_utils.py +14 -10
  19. waldiez/exporting/{agents → agent/utils}/rag_user/pgvector_utils.py +12 -8
  20. waldiez/exporting/{agents → agent/utils}/rag_user/qdrant_utils.py +11 -8
  21. waldiez/exporting/{agents → agent/utils}/rag_user/rag_user.py +78 -55
  22. waldiez/exporting/{agents → agent/utils}/rag_user/vector_db.py +10 -8
  23. waldiez/exporting/agent/utils/swarm_agent.py +463 -0
  24. waldiez/exporting/{agents → agent/utils}/teachability.py +10 -6
  25. waldiez/exporting/{agents → agent/utils}/termination_message.py +7 -8
  26. waldiez/exporting/base/__init__.py +25 -0
  27. waldiez/exporting/base/agent_position.py +75 -0
  28. waldiez/exporting/base/base_exporter.py +118 -0
  29. waldiez/exporting/base/export_position.py +48 -0
  30. waldiez/exporting/base/import_position.py +23 -0
  31. waldiez/exporting/base/mixin.py +134 -0
  32. waldiez/exporting/base/utils/__init__.py +18 -0
  33. waldiez/exporting/{utils → base/utils}/comments.py +12 -55
  34. waldiez/exporting/{utils → base/utils}/naming.py +14 -4
  35. waldiez/exporting/base/utils/path_check.py +68 -0
  36. waldiez/exporting/{utils/object_string.py → base/utils/to_string.py} +21 -20
  37. waldiez/exporting/chats/__init__.py +5 -12
  38. waldiez/exporting/chats/chats_exporter.py +240 -0
  39. waldiez/exporting/chats/utils/__init__.py +15 -0
  40. waldiez/exporting/chats/utils/common.py +81 -0
  41. waldiez/exporting/chats/{nested.py → utils/nested.py} +125 -86
  42. waldiez/exporting/chats/utils/sequential.py +244 -0
  43. waldiez/exporting/chats/utils/single_chat.py +313 -0
  44. waldiez/exporting/chats/utils/swarm.py +207 -0
  45. waldiez/exporting/flow/__init__.py +5 -3
  46. waldiez/exporting/flow/flow_exporter.py +503 -0
  47. waldiez/exporting/flow/utils/__init__.py +47 -0
  48. waldiez/exporting/flow/utils/agent_utils.py +204 -0
  49. waldiez/exporting/flow/utils/chat_utils.py +71 -0
  50. waldiez/exporting/flow/utils/def_main.py +62 -0
  51. waldiez/exporting/flow/utils/flow_content.py +112 -0
  52. waldiez/exporting/flow/utils/flow_names.py +115 -0
  53. waldiez/exporting/flow/utils/importing_utils.py +179 -0
  54. waldiez/exporting/{utils → flow/utils}/logging_utils.py +34 -31
  55. waldiez/exporting/models/__init__.py +7 -242
  56. waldiez/exporting/models/models_exporter.py +192 -0
  57. waldiez/exporting/models/utils.py +166 -0
  58. waldiez/exporting/skills/__init__.py +7 -161
  59. waldiez/exporting/skills/skills_exporter.py +169 -0
  60. waldiez/exporting/skills/utils.py +281 -0
  61. waldiez/models/__init__.py +25 -7
  62. waldiez/models/agents/__init__.py +70 -0
  63. waldiez/models/agents/agent/__init__.py +11 -1
  64. waldiez/models/agents/agent/agent.py +9 -4
  65. waldiez/models/agents/agent/agent_data.py +3 -1
  66. waldiez/models/agents/agent/code_execution.py +2 -0
  67. waldiez/models/agents/agent/linked_skill.py +2 -0
  68. waldiez/models/agents/agent/nested_chat.py +2 -0
  69. waldiez/models/agents/agent/teachability.py +2 -0
  70. waldiez/models/agents/agent/termination_message.py +49 -13
  71. waldiez/models/agents/agents.py +15 -3
  72. waldiez/models/agents/assistant/__init__.py +2 -0
  73. waldiez/models/agents/assistant/assistant.py +2 -0
  74. waldiez/models/agents/assistant/assistant_data.py +2 -0
  75. waldiez/models/agents/group_manager/__init__.py +9 -1
  76. waldiez/models/agents/group_manager/group_manager.py +2 -0
  77. waldiez/models/agents/group_manager/group_manager_data.py +2 -0
  78. waldiez/models/agents/group_manager/speakers.py +49 -13
  79. waldiez/models/agents/rag_user/__init__.py +21 -4
  80. waldiez/models/agents/rag_user/rag_user.py +3 -1
  81. waldiez/models/agents/rag_user/rag_user_data.py +2 -0
  82. waldiez/models/agents/rag_user/retrieve_config.py +268 -17
  83. waldiez/models/agents/rag_user/vector_db_config.py +5 -3
  84. waldiez/models/agents/swarm_agent/__init__.py +49 -0
  85. waldiez/models/agents/swarm_agent/after_work.py +178 -0
  86. waldiez/models/agents/swarm_agent/on_condition.py +103 -0
  87. waldiez/models/agents/swarm_agent/on_condition_available.py +140 -0
  88. waldiez/models/agents/swarm_agent/on_condition_target.py +40 -0
  89. waldiez/models/agents/swarm_agent/swarm_agent.py +107 -0
  90. waldiez/models/agents/swarm_agent/swarm_agent_data.py +125 -0
  91. waldiez/models/agents/swarm_agent/update_system_message.py +144 -0
  92. waldiez/models/agents/user_proxy/__init__.py +2 -0
  93. waldiez/models/agents/user_proxy/user_proxy.py +2 -0
  94. waldiez/models/agents/user_proxy/user_proxy_data.py +2 -0
  95. waldiez/models/chat/__init__.py +21 -3
  96. waldiez/models/chat/chat.py +241 -7
  97. waldiez/models/chat/chat_data.py +192 -48
  98. waldiez/models/chat/chat_message.py +153 -144
  99. waldiez/models/chat/chat_nested.py +33 -53
  100. waldiez/models/chat/chat_summary.py +2 -0
  101. waldiez/models/common/__init__.py +6 -6
  102. waldiez/models/common/base.py +4 -1
  103. waldiez/models/common/method_utils.py +163 -83
  104. waldiez/models/flow/__init__.py +2 -0
  105. waldiez/models/flow/flow.py +176 -40
  106. waldiez/models/flow/flow_data.py +63 -2
  107. waldiez/models/flow/utils.py +172 -0
  108. waldiez/models/model/__init__.py +2 -0
  109. waldiez/models/model/model.py +25 -6
  110. waldiez/models/model/model_data.py +3 -1
  111. waldiez/models/skill/__init__.py +4 -1
  112. waldiez/models/skill/skill.py +30 -2
  113. waldiez/models/skill/skill_data.py +2 -0
  114. waldiez/models/waldiez.py +28 -4
  115. waldiez/runner.py +142 -228
  116. waldiez/running/__init__.py +33 -0
  117. waldiez/running/environment.py +83 -0
  118. waldiez/running/gen_seq_diagram.py +185 -0
  119. waldiez/running/running.py +300 -0
  120. {waldiez-0.2.2.dist-info → waldiez-0.3.0.dist-info}/METADATA +32 -26
  121. waldiez-0.3.0.dist-info/RECORD +125 -0
  122. waldiez-0.3.0.dist-info/licenses/LICENSE +201 -0
  123. waldiez/exporting/agents/__init__.py +0 -5
  124. waldiez/exporting/agents/agent.py +0 -236
  125. waldiez/exporting/agents/agent_skills.py +0 -67
  126. waldiez/exporting/agents/llm_config.py +0 -53
  127. waldiez/exporting/chats/chats.py +0 -46
  128. waldiez/exporting/chats/helpers.py +0 -420
  129. waldiez/exporting/flow/def_main.py +0 -32
  130. waldiez/exporting/flow/flow.py +0 -189
  131. waldiez/exporting/utils/__init__.py +0 -36
  132. waldiez/exporting/utils/importing.py +0 -265
  133. waldiez/exporting/utils/method_utils.py +0 -35
  134. waldiez/exporting/utils/path_check.py +0 -51
  135. waldiez-0.2.2.dist-info/RECORD +0 -92
  136. waldiez-0.2.2.dist-info/licenses/LICENSE +0 -21
  137. {waldiez-0.2.2.dist-info → waldiez-0.3.0.dist-info}/WHEEL +0 -0
  138. {waldiez-0.2.2.dist-info → waldiez-0.3.0.dist-info}/entry_points.txt +0 -0
@@ -0,0 +1,503 @@
1
+ # SPDX-License-Identifier: Apache-2.0.
2
+ # Copyright (c) 2024 - 2025 Waldiez and contributors.
3
+ """Flow Exporter class.
4
+
5
+ - We gather all the exports (models, skills, agents, chats).
6
+
7
+ - We first add all the imports from the above exports.
8
+ - If we have skills, we include their imports.
9
+ (their files were generated when exporting the skills).
10
+ - Then, we write the all model configs.
11
+ - Next, we write the agent definitions
12
+ (using the `llm_config=...` argument from the model exports).
13
+ - If additional (nested_chats) are defined,
14
+ we write their registrations after all agents are defined.
15
+ - Next, we write the chat definitions
16
+ (using the agent names from the agent exports).
17
+ - If exporting to py,
18
+ we add the `run` function and the `def main()` to call the run function.
19
+ - If the flow is async, the `run` function is async.
20
+ """
21
+
22
+ # flake8: noqa E501
23
+ # pylint: disable=line-too-long
24
+
25
+ from functools import partial
26
+ from pathlib import Path
27
+ from typing import List, Optional, Tuple, Union
28
+
29
+ from waldiez.models import Waldiez, WaldiezAgent
30
+
31
+ from ..agent import AgentExporter
32
+ from ..base import (
33
+ AgentPosition,
34
+ AgentPositions,
35
+ BaseExporter,
36
+ ExporterMixin,
37
+ ExporterReturnType,
38
+ ExportPosition,
39
+ ExportPositions,
40
+ ImportPosition,
41
+ )
42
+ from ..chats import ChatsExporter
43
+ from ..models import ModelsExporter
44
+ from ..skills import SkillsExporter
45
+ from .utils import (
46
+ add_after_agent_content,
47
+ add_after_chat_content,
48
+ add_before_agent_content,
49
+ ensure_unique_names,
50
+ gather_agent_outputs,
51
+ gather_imports,
52
+ get_def_main,
53
+ get_ipynb_content_start,
54
+ get_logging_start_string,
55
+ get_logging_stop_string,
56
+ get_py_content_start,
57
+ get_sqlite_out,
58
+ get_sqlite_out_call,
59
+ get_the_imports_string,
60
+ )
61
+
62
+
63
+ # pylint: disable=too-many-instance-attributes
64
+ class FlowExporter(BaseExporter, ExporterMixin):
65
+ """Flow exporter."""
66
+
67
+ def __init__(
68
+ self,
69
+ waldiez: Waldiez,
70
+ for_notebook: bool,
71
+ output_dir: Optional[Union[str, Path]] = None,
72
+ ) -> None:
73
+ """Initialize the flow exporter."""
74
+ self.waldiez = waldiez
75
+ self.for_notebook = for_notebook
76
+ if output_dir is not None and not isinstance(output_dir, Path):
77
+ output_dir = Path(output_dir).resolve()
78
+ self.output_dir = output_dir
79
+ self.initialize()
80
+
81
+ def initialize(
82
+ self,
83
+ ) -> None:
84
+ """Get all the names in the flow.
85
+
86
+ We need to make sure that no duplicate names are used,
87
+ and that the names can be used as python variables.
88
+ """
89
+ unique_names = ensure_unique_names(
90
+ self.waldiez,
91
+ self.get_valid_instance_name,
92
+ )
93
+ self.flow_name = unique_names["flow_name"]
94
+ self.agents = unique_names["agents"]
95
+ self.models = unique_names["models"]
96
+ self.skills = unique_names["skills"]
97
+ self.chats = unique_names["chats"]
98
+ self.agent_names = unique_names["agent_names"]
99
+ self.model_names = unique_names["model_names"]
100
+ self.skill_names = unique_names["skill_names"]
101
+ self.chat_names = unique_names["chat_names"]
102
+
103
+ def export_flow(self) -> ExporterReturnType:
104
+ """Export the flow.
105
+
106
+ Returns
107
+ -------
108
+ ExporterReturnType
109
+ The exported flow.
110
+ """
111
+ models_output = self.export_models()
112
+ skills_output = self.export_skills()
113
+ chats_output = self.export_chats()
114
+ env_vars = self.gather_environment_variables(
115
+ model_env_vars=models_output["environment_variables"],
116
+ skill_env_vars=skills_output["environment_variables"],
117
+ chat_env_vars=chats_output["environment_variables"],
118
+ )
119
+ before_export = self.gather_exports(
120
+ model_export=models_output["before_export"],
121
+ skill_export=skills_output["before_export"],
122
+ chat_export=chats_output["before_export"],
123
+ )
124
+ after_export = self.gather_exports(
125
+ model_export=models_output["after_export"],
126
+ skill_export=skills_output["after_export"],
127
+ chat_export=chats_output["after_export"],
128
+ )
129
+ # agents last (to make sure we have any needed arguments)
130
+ # like `llm_config=...` from the models
131
+ agents_output = self.export_agents(
132
+ before_export=before_export,
133
+ after_export=after_export,
134
+ )
135
+ imports = gather_imports(
136
+ model_imports=models_output["imports"],
137
+ skill_imports=skills_output["imports"],
138
+ chat_imports=chats_output["imports"],
139
+ agent_imports=agents_output["imports"],
140
+ )
141
+ if agents_output["environment_variables"]:
142
+ env_vars.extend(agents_output["environment_variables"])
143
+ if agents_output["before_export"]:
144
+ before_export.extend(agents_output["before_export"])
145
+ if agents_output["after_export"]:
146
+ after_export.extend(agents_output["after_export"])
147
+ all_imports = (
148
+ get_the_imports_string(imports, is_async=self.waldiez.is_async),
149
+ ImportPosition.LOCAL,
150
+ )
151
+ before_chats_export = chats_output["before_export"] or []
152
+ content_before_chats = [
153
+ x[0]
154
+ for x in before_chats_export
155
+ if isinstance(x[1], ExportPosition)
156
+ and x[1].position == ExportPositions.CHATS
157
+ ]
158
+ before_chats = "\n".join(content_before_chats)
159
+ content = self.merge_exports(
160
+ imports=all_imports,
161
+ models_output=models_output["content"] or "",
162
+ skills_output=skills_output["content"] or "",
163
+ agents_content=agents_output["content"] or "",
164
+ chats_content=chats_output["content"] or "",
165
+ before_chats=before_chats,
166
+ )
167
+ return {
168
+ "content": content,
169
+ "imports": [all_imports],
170
+ "after_export": after_export,
171
+ "before_export": before_export,
172
+ "environment_variables": env_vars,
173
+ }
174
+
175
+ def merge_exports(
176
+ self,
177
+ imports: Tuple[str, ImportPosition],
178
+ models_output: str,
179
+ skills_output: str,
180
+ agents_content: str,
181
+ chats_content: str,
182
+ before_chats: str,
183
+ ) -> str:
184
+ """Merge all the export contents.
185
+
186
+ Parameters
187
+ ----------
188
+ imports : Tuple[str, ImportPosition]
189
+ The imports.
190
+ models_output : str
191
+ The models output.
192
+ skills_output : str
193
+ The skills output.
194
+ agents_content : str
195
+ The agents content.
196
+ chats_content : str
197
+ The chats content.
198
+ before_chats : str
199
+ Returns
200
+ -------
201
+ str
202
+ The merged export contents.
203
+ """
204
+ content = (
205
+ get_py_content_start(self.waldiez)
206
+ if not self.for_notebook
207
+ else get_ipynb_content_start(self.waldiez, comment=self.comment)
208
+ )
209
+ content += self.get_comment("imports", self.for_notebook) + "\n"
210
+ content += imports[0] + "\n"
211
+ content += self.get_comment("logging", self.for_notebook) + "\n"
212
+ content += get_logging_start_string(tabs=0) + "\n\n"
213
+ if models_output:
214
+ content += self.get_comment("models", self.for_notebook) + "\n"
215
+ content += models_output + "\n"
216
+ if skills_output:
217
+ content += self.get_comment("skills", self.for_notebook) + "\n"
218
+ content += skills_output + "\n"
219
+ if agents_content:
220
+ content += self.get_comment("agents", self.for_notebook) + "\n"
221
+ content += agents_content + "\n"
222
+ if before_chats:
223
+ content += before_chats + "\n"
224
+ content += get_sqlite_out() + "\n"
225
+ content += self.get_comment("run", self.for_notebook) + "\n"
226
+ if self.for_notebook is False:
227
+ content += get_def_main(
228
+ chats_content, is_async=self.waldiez.is_async
229
+ )
230
+ else:
231
+ content += "\n" + chats_content + "\n"
232
+ content += get_logging_stop_string(tabs=0) + "\n"
233
+ content += get_sqlite_out_call(tabs=0) + "\n"
234
+ content = content.replace("\n\n\n\n", "\n\n\n")
235
+ return content
236
+
237
+ @staticmethod
238
+ def gather_environment_variables(
239
+ model_env_vars: Optional[List[Tuple[str, str]]],
240
+ skill_env_vars: Optional[List[Tuple[str, str]]],
241
+ chat_env_vars: Optional[List[Tuple[str, str]]],
242
+ ) -> List[Tuple[str, str]]:
243
+ """
244
+ Gather all the environment variables.
245
+
246
+ Parameters
247
+ ----------
248
+ model_env_vars : Optional[List[Tuple[str, str]]]
249
+ The model environment variables.
250
+ skill_env_vars : Optional[List[Tuple[str, str]]]
251
+ The skill environment variables.
252
+ chat_env_vars : Optional[List[Tuple[str, str]]]
253
+ The chat environment variables.
254
+
255
+ Returns
256
+ -------
257
+ List[Tuple[str, str]]
258
+ The gathered environment variables.
259
+ """
260
+ all_env_vars: List[Tuple[str, str]] = []
261
+ if model_env_vars:
262
+ all_env_vars.extend(model_env_vars)
263
+ if skill_env_vars:
264
+ all_env_vars.extend(skill_env_vars)
265
+ if chat_env_vars:
266
+ all_env_vars.extend(chat_env_vars)
267
+ return all_env_vars
268
+
269
+ @staticmethod
270
+ def gather_exports(
271
+ model_export: Optional[
272
+ List[Tuple[str, Union[ExportPosition, AgentPosition]]]
273
+ ],
274
+ skill_export: Optional[
275
+ List[Tuple[str, Union[ExportPosition, AgentPosition]]]
276
+ ],
277
+ chat_export: Optional[
278
+ List[Tuple[str, Union[ExportPosition, AgentPosition]]]
279
+ ],
280
+ ) -> List[Tuple[str, Union[ExportPosition, AgentPosition]]]:
281
+ """Gather all (but agents) the before or after exports.
282
+
283
+ Parameters
284
+ ----------
285
+ model_export : Optional[List[Tuple[str, Union[ExportPosition, AgentPosition]]]]
286
+ The model exports.
287
+ skill_export : Optional[List[Tuple[str, Union[ExportPosition, AgentPosition]]]]
288
+ The skill exports.
289
+ chat_export : Optional[List[Tuple[str, Union[ExportPosition, AgentPosition]]]]
290
+ The chat exports.
291
+
292
+ Returns
293
+ -------
294
+ List[Tuple[str, Union[ExportPosition, AgentPosition]]]
295
+ The gathered exports.
296
+ """
297
+ all_exports: List[Tuple[str, Union[ExportPosition, AgentPosition]]] = []
298
+ if model_export:
299
+ all_exports.extend(model_export)
300
+ if skill_export:
301
+ all_exports.extend(skill_export)
302
+ if chat_export:
303
+ all_exports.extend(chat_export)
304
+ return all_exports
305
+
306
+ def export_models(self) -> ExporterReturnType:
307
+ """Export the models.
308
+
309
+ Returns
310
+ -------
311
+ str
312
+ The exported models.
313
+ """
314
+ exporter = ModelsExporter(
315
+ flow_name=self.flow_name,
316
+ agents=self.agents,
317
+ agent_names=self.agent_names,
318
+ models=self.models,
319
+ model_names=self.model_names,
320
+ for_notebook=self.for_notebook,
321
+ output_dir=self.output_dir,
322
+ )
323
+ return exporter.export()
324
+
325
+ def export_skills(self) -> ExporterReturnType:
326
+ """Export the skills.
327
+
328
+ Returns
329
+ -------
330
+ str
331
+ The exported skills.
332
+ """
333
+ exporter = SkillsExporter(
334
+ flow_name=self.flow_name,
335
+ agents=self.agents,
336
+ agent_names=self.agent_names,
337
+ skills=self.skills,
338
+ skill_names=self.skill_names,
339
+ output_dir=self.output_dir,
340
+ )
341
+ return exporter.export()
342
+
343
+ @staticmethod
344
+ def gather_agent_arguments(
345
+ before_export: List[Tuple[str, Union[ExportPosition, AgentPosition]]],
346
+ after_export: List[Tuple[str, Union[ExportPosition, AgentPosition]]],
347
+ ) -> List[Tuple[str, AgentPosition]]:
348
+ """Gather the agent arguments.
349
+
350
+ Parameters
351
+ ----------
352
+ before_export : List[Tuple[str, Union[ExportPosition, AgentPosition]]]
353
+ The before export.
354
+ after_export : List[Tuple[str, Union[ExportPosition, AgentPosition]]]
355
+ The after export.
356
+
357
+ Returns
358
+ -------
359
+ List[Tuple[str, AgentPosition]]
360
+ The gathered agent arguments.
361
+ """
362
+ exported_with_agent_arg: List[Tuple[str, AgentPosition]] = []
363
+ for before in before_export:
364
+ position = before[1]
365
+ if (
366
+ isinstance(position, AgentPosition)
367
+ and position.position == AgentPositions.AS_ARGUMENT
368
+ ):
369
+ exported_with_agent_arg.append((before[0], position))
370
+ for after in after_export:
371
+ position = after[1]
372
+ if (
373
+ isinstance(position, AgentPosition)
374
+ and position.position == AgentPositions.AS_ARGUMENT
375
+ ):
376
+ exported_with_agent_arg.append((after[0], position))
377
+ return exported_with_agent_arg
378
+
379
+ def export_agents(
380
+ self,
381
+ before_export: List[Tuple[str, Union[ExportPosition, AgentPosition]]],
382
+ after_export: List[Tuple[str, Union[ExportPosition, AgentPosition]]],
383
+ ) -> ExporterReturnType:
384
+ """Export the agents.
385
+
386
+ Parameters
387
+ ----------
388
+ before_export : List[Tuple[str, Union[ExportPosition, AgentPosition]]]
389
+ The before export.
390
+ after_export : List[Tuple[str, Union[ExportPosition, AgentPosition]]]
391
+ The after export.
392
+ Returns
393
+ -------
394
+ str
395
+ The exported agents.
396
+ """
397
+ agent_outputs = []
398
+ for agent in self.agents:
399
+ exported_with_agent_arg = self.gather_agent_arguments(
400
+ before_export, after_export
401
+ )
402
+ arguments_resolver = partial(
403
+ self.agent_arguments_resolver,
404
+ exported_with_agent_arg,
405
+ )
406
+ group_chat_members = self.waldiez.get_group_chat_members(agent)
407
+ exporter = AgentExporter(
408
+ agent=agent,
409
+ agent_names=self.agent_names,
410
+ model_names=self.model_names,
411
+ skill_names=self.skill_names,
412
+ chats=(self.chats, self.chat_names),
413
+ is_async=self.waldiez.is_async,
414
+ for_notebook=self.for_notebook,
415
+ output_dir=self.output_dir,
416
+ group_chat_members=group_chat_members,
417
+ arguments_resolver=arguments_resolver,
418
+ )
419
+ agent_output = exporter.export()
420
+ agent_content = agent_output["content"] or ""
421
+ after_agent_export = agent_output["after_export"]
422
+ if after_agent_export:
423
+ after_export.extend(after_agent_export)
424
+ before_agent_export = agent_output["before_export"]
425
+ if before_agent_export:
426
+ before_export.extend(before_agent_export)
427
+ if agent_content:
428
+ agent_content = add_before_agent_content(
429
+ agent_content,
430
+ before_export,
431
+ agent,
432
+ )
433
+ agent_content = add_after_agent_content(
434
+ agent_content,
435
+ after_export,
436
+ agent,
437
+ )
438
+ agent_output["content"] = agent_content
439
+ agent_outputs.append(agent_output)
440
+ return gather_agent_outputs(
441
+ before_export=before_export,
442
+ after_export=after_export,
443
+ agent_outputs=agent_outputs,
444
+ )
445
+
446
+ @staticmethod
447
+ def agent_arguments_resolver(
448
+ additional_exports: List[Tuple[str, AgentPosition]], agent: WaldiezAgent
449
+ ) -> List[str]:
450
+ """Resolve the arguments for the agent.
451
+
452
+ Parameters
453
+ ----------
454
+ additional_exports : List[Tuple[str, AgentPosition]]
455
+ The additional exports.
456
+ agent : WaldiezAgent
457
+ The agent.
458
+
459
+ Returns
460
+ -------
461
+ List[str]
462
+ The arguments for the agent.
463
+ """
464
+ return [x[0] for x in additional_exports if x[1].agent == agent]
465
+
466
+ def export_chats(self) -> ExporterReturnType:
467
+ """Export the chats.
468
+
469
+ Returns
470
+ -------
471
+ str
472
+ The exported chats.
473
+ """
474
+ exporter = ChatsExporter(
475
+ get_swarm_members=self.waldiez.get_swarm_members,
476
+ all_agents=self.agents,
477
+ agent_names=self.agent_names,
478
+ all_chats=self.chats,
479
+ chat_names=self.chat_names,
480
+ main_chats=self.waldiez.chats,
481
+ for_notebook=self.for_notebook,
482
+ is_async=self.waldiez.is_async,
483
+ )
484
+ output = exporter.export()
485
+ chat_contents = output["content"] or ""
486
+ after_chats = output["after_export"]
487
+ if chat_contents and after_chats:
488
+ chat_contents = add_after_chat_content(
489
+ chat_contents,
490
+ after_chats,
491
+ )
492
+ output["content"] = chat_contents
493
+ return output
494
+
495
+ def export(self) -> ExporterReturnType:
496
+ """Export the flow.
497
+
498
+ Returns
499
+ -------
500
+ SubExporterReturnType
501
+ The exported flow.
502
+ """
503
+ return self.export_flow()
@@ -0,0 +1,47 @@
1
+ # SPDX-License-Identifier: Apache-2.0.
2
+ # Copyright (c) 2024 - 2025 Waldiez and contributors.
3
+ """Utility functions for exporting waldiez to different formats."""
4
+
5
+ from .agent_utils import (
6
+ add_after_agent_content,
7
+ add_after_all_agents_content,
8
+ add_before_agent_content,
9
+ add_before_all_agents_content,
10
+ gather_agent_outputs,
11
+ )
12
+ from .chat_utils import add_after_chat_content, add_before_chat_content
13
+ from .def_main import get_def_main
14
+ from .flow_content import get_ipynb_content_start, get_py_content_start
15
+ from .flow_names import ensure_unique_names
16
+ from .importing_utils import (
17
+ gather_imports,
18
+ get_standard_imports,
19
+ get_the_imports_string,
20
+ )
21
+ from .logging_utils import (
22
+ get_logging_start_string,
23
+ get_logging_stop_string,
24
+ get_sqlite_out,
25
+ get_sqlite_out_call,
26
+ )
27
+
28
+ __all__ = [
29
+ "add_after_agent_content",
30
+ "add_after_all_agents_content",
31
+ "add_before_agent_content",
32
+ "add_before_all_agents_content",
33
+ "add_after_chat_content",
34
+ "add_before_chat_content",
35
+ "ensure_unique_names",
36
+ "gather_agent_outputs",
37
+ "gather_imports",
38
+ "get_def_main",
39
+ "get_py_content_start",
40
+ "get_ipynb_content_start",
41
+ "get_logging_start_string",
42
+ "get_logging_stop_string",
43
+ "get_sqlite_out",
44
+ "get_sqlite_out_call",
45
+ "get_standard_imports",
46
+ "get_the_imports_string",
47
+ ]