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
@@ -1,204 +0,0 @@
1
- # SPDX-License-Identifier: Apache-2.0.
2
- # Copyright (c) 2024 - 2025 Waldiez and contributors.
3
- """Handle agent contents before and after the agent(s) exports."""
4
-
5
- from typing import List, Tuple, Union
6
-
7
- from waldiez.exporting.base import (
8
- AgentPosition,
9
- AgentPositions,
10
- ExporterReturnType,
11
- ExportPosition,
12
- )
13
- from waldiez.models import WaldiezAgent
14
-
15
-
16
- def add_after_all_agents_content(
17
- agents_contents: str,
18
- after_export: List[Tuple[str, Union[ExportPosition, AgentPosition]]],
19
- ) -> str:
20
- """Add the after all agents content.
21
-
22
- Parameters
23
- ----------
24
- agents_contents : str
25
- The agents content.
26
- after_export : List[Tuple[str, Union[ExportPosition, AgentPosition]]]
27
- The after export.
28
-
29
- Returns
30
- -------
31
- str
32
- The agents content with the after all agents content.
33
- """
34
- new_content = str(agents_contents)
35
- # let's get the list first, and sort it by the order
36
- after_all_agent_exports = [
37
- (content, position)
38
- for content, position in after_export
39
- if isinstance(position, AgentPosition)
40
- and position.position == AgentPositions.AFTER_ALL
41
- ]
42
- by_order = sorted(after_all_agent_exports, key=lambda x: x[1].order)
43
- for content, _ in by_order:
44
- new_content += content + "\n"
45
- if not new_content.endswith("\n"):
46
- new_content += "\n"
47
- return new_content
48
-
49
-
50
- def add_before_all_agents_content(
51
- agents_contents: str,
52
- before_export: List[Tuple[str, Union[ExportPosition, AgentPosition]]],
53
- ) -> str:
54
- """Add the before all agents content.
55
-
56
- Parameters
57
- ----------
58
- agents_contents : str
59
- The agents content.
60
- before_export : List[Tuple[str, Union[ExportPosition, AgentPosition]]]
61
- The before export.
62
-
63
- Returns
64
- -------
65
- str
66
- The agents content with the before all agents content.
67
- """
68
- new_content = str(agents_contents)
69
- before_all_agents_exports = [
70
- (content, position)
71
- for content, position in before_export
72
- if isinstance(position, AgentPosition)
73
- and position.position == AgentPositions.BEFORE_ALL
74
- ]
75
- for content, _ in before_all_agents_exports:
76
- new_content = content + "\n" + new_content
77
- if not new_content.startswith("\n"):
78
- new_content = "\n" + new_content
79
- return new_content
80
-
81
-
82
- def add_before_agent_content(
83
- agent_content: str,
84
- before_export: List[Tuple[str, Union[ExportPosition, AgentPosition]]],
85
- agent: WaldiezAgent,
86
- ) -> str:
87
- """Add the before agent content.
88
-
89
- Parameters
90
- ----------
91
- agent_content : str
92
- The agent content.
93
- before_export : List[Tuple[str, Union[ExportPosition, AgentPosition]]]
94
- The before export.
95
- agent : WaldiezAgent
96
- The agent.
97
-
98
- Returns
99
- -------
100
- str
101
- The agent content with the before agent content.
102
- """
103
- new_content = str(agent_content)
104
- for content, position in before_export:
105
- if (
106
- isinstance(position, AgentPosition)
107
- and position.agent == agent
108
- and position.position == AgentPositions.BEFORE
109
- ):
110
- new_content = content + "\n" + new_content
111
- if not new_content.startswith("\n"):
112
- new_content = "\n" + new_content
113
- return new_content
114
-
115
-
116
- def add_after_agent_content(
117
- agent_content: str,
118
- after_export: List[Tuple[str, Union[ExportPosition, AgentPosition]]],
119
- agent: WaldiezAgent,
120
- ) -> str:
121
- """Add the after agent content.
122
-
123
- Parameters
124
- ----------
125
- agent_content : str
126
- The agent content.
127
- after_export : List[Tuple[str, Union[ExportPosition, AgentPosition]]]
128
- The after export.
129
- agent : WaldiezAgent
130
- The agent.
131
-
132
- Returns
133
- -------
134
- str
135
- The agent content with the after agent content.
136
- """
137
- new_content = str(agent_content)
138
- for content, position in after_export:
139
- if (
140
- isinstance(position, AgentPosition)
141
- and position.agent == agent
142
- and position.position == AgentPositions.AFTER
143
- ):
144
- new_content += content + "\n"
145
- if not new_content.endswith("\n"):
146
- new_content += "\n"
147
- return new_content
148
-
149
-
150
- def gather_agent_outputs(
151
- before_export: List[Tuple[str, Union[ExportPosition, AgentPosition]]],
152
- after_export: List[Tuple[str, Union[ExportPosition, AgentPosition]]],
153
- agent_outputs: List[ExporterReturnType],
154
- ) -> ExporterReturnType:
155
- """Gather all the agent outputs.
156
-
157
- Parameters
158
- ----------
159
- before_export : List[Tuple[str, Union[ExportPosition, AgentPosition]]]
160
- The before export.
161
- after_export : List[Tuple[str, Union[ExportPosition, AgentPosition]]]
162
- The after export.
163
- agent_outputs : List[ExporterReturnType]
164
- The agent outputs.
165
-
166
- Returns
167
- -------
168
- ExporterReturnType
169
- The gathered agent outputs.
170
- """
171
- agents_contents = ""
172
- agents_imports = []
173
- agents_before_export = []
174
- agents_after_export = []
175
- agents_env_vars = []
176
- for output in agent_outputs:
177
- if output["content"]:
178
- agents_contents += output["content"]
179
- if output["imports"]:
180
- agents_imports.extend(output["imports"])
181
- if output["before_export"]:
182
- agents_before_export.extend(output["before_export"])
183
- if output["after_export"]:
184
- agents_after_export.extend(output["after_export"])
185
- if output["environment_variables"]:
186
- agents_env_vars.extend(output["environment_variables"])
187
- agents_contents = add_before_all_agents_content(
188
- agents_contents,
189
- before_export,
190
- )
191
- agents_contents = add_after_all_agents_content(
192
- agents_contents,
193
- after_export,
194
- )
195
- agents_contents = agents_contents.replace("\n\n\n\n", "\n\n\n")
196
- while agents_contents.endswith("\n\n\n"):
197
- agents_contents = agents_contents[: -len("\n")]
198
- return {
199
- "content": agents_contents,
200
- "imports": agents_imports,
201
- "before_export": agents_before_export,
202
- "after_export": agents_after_export,
203
- "environment_variables": agents_env_vars,
204
- }
@@ -1,71 +0,0 @@
1
- # SPDX-License-Identifier: Apache-2.0.
2
- # Copyright (c) 2024 - 2025 Waldiez and contributors.
3
- """Utilities for chat content after exporting."""
4
-
5
- from typing import List, Tuple, Union
6
-
7
- from waldiez.exporting.base import (
8
- AgentPosition,
9
- ExportPosition,
10
- ExportPositions,
11
- )
12
-
13
-
14
- def add_before_chat_content(
15
- chat_content: str,
16
- before_export: List[Tuple[str, Union[ExportPosition, AgentPosition]]],
17
- ) -> str:
18
- """Add the before chat content.
19
-
20
- Parameters
21
- ----------
22
- chat_content : str
23
- The chat content.
24
- before_export : List[Tuple[str, Union[ExportPosition, AgentPosition]]]
25
- The before export.
26
-
27
- Returns
28
- -------
29
- str
30
- The chat content with the before chat content.
31
- """
32
- new_content = str(chat_content)
33
- for content, position in before_export:
34
- if (
35
- isinstance(position, ExportPosition)
36
- and position.position == ExportPositions.CHATS
37
- ):
38
- new_content = content + "\n" + new_content
39
- if not new_content.endswith("\n"):
40
- new_content += "\n"
41
- return new_content
42
-
43
-
44
- def add_after_chat_content(
45
- chat_content: str,
46
- after_export: List[Tuple[str, Union[ExportPosition, AgentPosition]]],
47
- ) -> str:
48
- """Add the after chat content.
49
-
50
- Parameters
51
- ----------
52
- chat_content : str
53
- The chat content.
54
- after_export : List[Tuple[str, Union[ExportPosition, AgentPosition]]]
55
- The after export.
56
-
57
- Returns
58
- -------
59
- str
60
- The chat content with the after chat content.
61
- """
62
- new_content = str(chat_content)
63
- for content, position in after_export:
64
- if (
65
- isinstance(position, ExportPosition)
66
- and position.position == ExportPositions.CHATS
67
- ):
68
- new_content += content + "\n"
69
- if not new_content.endswith("\n"):
70
- new_content += "\n"
71
- return new_content
@@ -1,77 +0,0 @@
1
- # SPDX-License-Identifier: Apache-2.0.
2
- # Copyright (c) 2024 - 2025 Waldiez and contributors.
3
- # flake8: noqa: E501
4
- # pylint: disable=inconsistent-quotes, line-too-long
5
- """Get the main function."""
6
-
7
- from typing import Optional
8
-
9
-
10
- def get_def_main(
11
- flow_chats: str, after_run: str, is_async: bool, cache_seed: Optional[int]
12
- ) -> str:
13
- """Get the main function.
14
-
15
- When exporting to python, waldiez_chats string will be the
16
- content of the main function. It contains either a
17
- `{sender.initiate_chat(recipient, ...)}` (if there is only one chat)
18
- or `initiate_chats([..])`, with the list of chats to initiate.
19
- If async: (sender.a_initiate_chat, a_initiate_chats)
20
-
21
- Parameters
22
- ----------
23
- flow_chats : str
24
- The content of the main function.
25
- after_run : str
26
- The content after the run of the flow.
27
- is_async : bool
28
- Whether the main function is asynchronous.
29
- cache_seed : Optional[int]
30
- The seed for the cache. If None, cache should be disabled.
31
-
32
- Returns
33
- -------
34
- str
35
- The main function.
36
- """
37
- if flow_chats.startswith("\n"):
38
- flow_chats = flow_chats[1:]
39
- content = ""
40
- if is_async:
41
- content += "async "
42
- content += "def main() -> Union[ChatResult, List[ChatResult], Dict[int, ChatResult]]:\n"
43
- content += ' """Start chatting."""\n'
44
- content += f" with Cache.disk(cache_seed={cache_seed}" + ") as cache:\n"
45
- content += f"{flow_chats}" + "\n"
46
- if is_async:
47
- content += " await stop_logging()"
48
- else:
49
- content += " stop_logging()"
50
- content += after_run
51
- content += "\n return results\n\n\n"
52
- if is_async:
53
- content += "async def call_main():\n"
54
- else:
55
- content += "def call_main() -> None:\n"
56
- content += ' """Run the main function and print the results."""\n'
57
- content += " results: Union[ChatResult, List[ChatResult], Dict[int, ChatResult]] = "
58
- if is_async:
59
- content += "await "
60
- content += "main()\n"
61
- content += " if isinstance(results, dict):\n"
62
- content += " # order by key\n"
63
- content += " ordered_results = dict(sorted(results.items()))\n"
64
- content += " for _, result in ordered_results.items():\n"
65
- content += " pprint(asdict(result))\n"
66
- content += " else:\n"
67
- content += " if not isinstance(results, list):\n"
68
- content += " results = [results]\n"
69
- content += " for result in results:\n"
70
- content += " pprint(asdict(result))\n"
71
- content += "\n\n"
72
- content += 'if __name__ == "__main__":\n'
73
- if is_async:
74
- content += " anyio.run(call_main)\n"
75
- else:
76
- content += " call_main()\n"
77
- return content
@@ -1,202 +0,0 @@
1
- # SPDX-License-Identifier: Apache-2.0.
2
- # Copyright (c) 2024 - 2025 Waldiez and contributors.
3
- # flake8: noqa: E501
4
- # pylint: disable=line-too-long
5
- """Utils to generate the content of a flow."""
6
-
7
- from typing import Callable, Dict, List, Optional
8
-
9
- from waldiez.models import Waldiez
10
-
11
-
12
- def get_py_content_start(waldiez: Waldiez) -> str:
13
- """Get the first part of the python script.
14
-
15
- Parameters
16
- ----------
17
- waldiez : Waldiez
18
- The waldiez object.
19
-
20
- Returns
21
- -------
22
- str
23
- The first part of the python script.
24
- """
25
- content = "#!/usr/bin/env python\n"
26
- content += "# flake8: noqa: E501\n"
27
- content += get_pylint_ignore_comment(False)
28
- content += "# cspell: disable\n"
29
- content += f'"""{waldiez.name}.' + "\n\n"
30
- content += f"{waldiez.description}" + "\n\n"
31
- tags = ", ".join(waldiez.tags)
32
- content += f"Tags: {tags}" + "\n\n"
33
- requirements = " ".join(waldiez.requirements)
34
- content += f"Requirements: {requirements}" + "\n\n"
35
- content += '"""\n\n'
36
- return content
37
-
38
-
39
- def get_ipynb_content_start(
40
- waldiez: Waldiez, comment: Callable[[bool, int], str]
41
- ) -> str:
42
- """Get the first part of the ipynb file.
43
-
44
- Parameters
45
- ----------
46
- waldiez : Waldiez
47
- The waldiez object.
48
- comment : Callable[[bool, int], str]
49
- The function to create a comment.
50
-
51
- Returns
52
- -------
53
- str
54
- The first part of the ipynb file.
55
- """
56
- content = f"{comment(True, 1)}{waldiez.name}." + "\n\n"
57
- content += f"{comment(True, 2)}{waldiez.description}" + "\n\n"
58
- content += f"{comment(True, 2)}Dependencies" + "\n\n"
59
- content += "import sys\n"
60
- requirements = " ".join(waldiez.requirements)
61
- if requirements:
62
- # fmt: off
63
- content += "# " + f"!{{sys.executable}} -m pip install -q {requirements}" + "\n"
64
- # fmt: on
65
- content += "# flake8: noqa: E501"
66
- content += get_pylint_ignore_comment(True)
67
- content += "# cspell: disable\n"
68
- return content
69
-
70
-
71
- PYLINT_RULES = [
72
- "line-too-long",
73
- "unknown-option-value",
74
- "unused-argument",
75
- "unused-import",
76
- "unused-variable",
77
- "invalid-name",
78
- "import-error",
79
- "inconsistent-quotes",
80
- "missing-function-docstring",
81
- "missing-param-doc",
82
- "missing-return-doc",
83
- "ungrouped-imports",
84
- ]
85
-
86
-
87
- def get_pylint_ignore_comment(
88
- notebook: bool, rules: Optional[List[str]] = None
89
- ) -> str:
90
- """Get the pylint ignore comment string.
91
-
92
- Parameters
93
- ----------
94
- notebook : bool
95
- Whether the comment is for a notebook.
96
- rules : Optional[List[str]], optional
97
- The pylint rules to ignore, by default None.
98
-
99
- Returns
100
- -------
101
- str
102
- The pylint ignore comment string.
103
-
104
- Example
105
- -------
106
- ```python
107
- >>> get_pylint_ignore_comment(True, ["invalid-name", "line-too-long"])
108
-
109
- # pylint: disable=invalid-name, line-too-long
110
- ```
111
- """
112
- if not rules:
113
- rules = PYLINT_RULES
114
- line = "# pylint: disable=" + ",".join(rules)
115
- if notebook is True:
116
- line = "\n" + line
117
- return line + "\n"
118
-
119
-
120
- def get_after_run_content(
121
- waldiez: Waldiez,
122
- agent_names: Dict[str, str],
123
- tabs: int,
124
- ) -> str:
125
- """Get content to add after the flow is run.
126
-
127
- Parameters
128
- ----------
129
- waldiez : Waldiez
130
- The waldiez object.
131
- agent_names : Dict[str, str]
132
- The dictionary of agent names and their corresponding ids
133
- tabs : int
134
- The number of tabs to add before the content.
135
-
136
- Returns
137
- -------
138
- str
139
- The content to add after the flow is run.
140
- """
141
- # if the flow has a reasoning agents, we add
142
- # agent.visualize_tree() for each agent
143
- content = ""
144
- tab = " "
145
- space = tab * tabs
146
- for agent in waldiez.agents:
147
- if agent.agent_type == "reasoning":
148
- agent_name = agent_names[agent.id]
149
- content += f"""
150
- {space}# pylint: disable=broad-except,too-many-try-statements
151
- {space}try:
152
- {space}{tab}{agent_name}.visualize_tree()
153
- {space}{tab}if os.path.exists("tree_of_thoughts.png"):
154
- {space}{tab}{tab}new_name = "{agent_name}_tree_of_thoughts.png"
155
- {space}{tab}{tab}os.rename("tree_of_thoughts.png", new_name)
156
- {space}except BaseException:
157
- {space}{tab}pass
158
- {space}# save the tree to json
159
- {space}try:
160
- {space}{tab}data = {agent_name}._root.to_dict() # pylint: disable=protected-access
161
- {space}{tab}with open("{agent_name}_reasoning_tree.json", "w", encoding="utf-8") as f:
162
- {space}{tab}{tab}json.dump(data, f)
163
- {space}except BaseException:
164
- {space}{tab}pass
165
- """
166
- return content
167
-
168
-
169
- def get_np_no_nep50_handle() -> str:
170
- """Handle catching the "module numpy has no attribute _no_pep50_warning" error.
171
-
172
- Returns
173
- -------
174
- str
175
- The content to handle the error.
176
- """
177
- # https://github.com/numpy/numpy/blob/v2.2.2/\
178
- # doc/source/release/2.2.0-notes.rst#nep-50-promotion-state-option-removed
179
- content = '''
180
- # try to make sure we don't get:
181
- # module 'numpy' has no attribute '_no_nep50_warning'"
182
- os.environ["NEP50_DEPRECATION_WARNING"] = "0"
183
- os.environ["NEP50_DISABLE_WARNING"] = "1"
184
- os.environ["NPY_PROMOTION_STATE"] = "weak"
185
- if not hasattr(np, "_no_pep50_warning"):
186
-
187
- import contextlib
188
- from typing import Generator
189
-
190
- @contextlib.contextmanager
191
- def _np_no_nep50_warning() -> Generator[None, None, None]:
192
- """Dummy function to avoid the warning.
193
-
194
- Yields
195
- ------
196
- None
197
- Nothing.
198
- """
199
- yield
200
- setattr(np, "_no_pep50_warning", _np_no_nep50_warning) # noqa
201
- '''
202
- return content
@@ -1,116 +0,0 @@
1
- # SPDX-License-Identifier: Apache-2.0.
2
- # Copyright (c) 2024 - 2025 Waldiez and contributors.
3
- """Ensure unique names for agents, models, skills, and chats."""
4
-
5
- from typing import Callable, Dict, List, TypedDict
6
-
7
- from waldiez.models import (
8
- Waldiez,
9
- WaldiezAgent,
10
- WaldiezChat,
11
- WaldiezModel,
12
- WaldiezSkill,
13
- )
14
-
15
-
16
- class ResultType(TypedDict):
17
- """The result type for ensure_unique_names."""
18
-
19
- agent_names: Dict[str, str]
20
- model_names: Dict[str, str]
21
- skill_names: Dict[str, str]
22
- chat_names: Dict[str, str]
23
- agents: List[WaldiezAgent]
24
- models: List[WaldiezModel]
25
- skills: List[WaldiezSkill]
26
- chats: List[WaldiezChat]
27
- flow_name: str
28
-
29
-
30
- # pylint: disable=too-many-locals
31
- def ensure_unique_names(
32
- waldiez: Waldiez,
33
- get_valid_instance_name: Callable[..., Dict[str, str]],
34
- max_length: int = 46,
35
- flow_name_max_length: int = 20,
36
- ) -> ResultType:
37
- """Ensure unique names for agents, models, skills, and chats and flow.
38
-
39
- Parameters
40
- ----------
41
- waldiez : Waldiez
42
- The Waldiez instance.
43
- get_valid_instance_name : Callable[..., Dict[str, str]]
44
- The function to get a valid instance name.
45
- max_length : int, optional
46
- The maximum length of the name, by default 64
47
- flow_name_max_length : int, optional
48
- The maximum length of the flow name, by default 20
49
-
50
- Returns
51
- -------
52
- ResultType
53
- The result with unique names for agents, models, skills, chats, flow.
54
- """
55
- all_names: Dict[str, str] = {}
56
- agent_names: Dict[str, str] = {}
57
- model_names: Dict[str, str] = {}
58
- skill_names: Dict[str, str] = {}
59
- chat_names: Dict[str, str] = {}
60
- agents: List[WaldiezAgent] = []
61
- models: List[WaldiezModel] = []
62
- skills: List[WaldiezSkill] = []
63
- chats: List[WaldiezChat] = []
64
-
65
- for agent in waldiez.agents:
66
- all_names = get_valid_instance_name(
67
- (agent.id, agent.name),
68
- all_names,
69
- prefix="wa",
70
- max_length=max_length,
71
- )
72
- agent_names[agent.id] = all_names[agent.id]
73
- agents.append(agent)
74
- for model in waldiez.models:
75
- all_names = get_valid_instance_name(
76
- (model.id, model.name),
77
- all_names,
78
- prefix="wm",
79
- max_length=max_length,
80
- )
81
- model_names[model.id] = all_names[model.id]
82
- models.append(model)
83
- for skill in waldiez.skills:
84
- all_names = get_valid_instance_name(
85
- (skill.id, skill.name),
86
- all_names,
87
- prefix="ws",
88
- max_length=max_length,
89
- )
90
- skill_names[skill.id] = all_names[skill.id]
91
- skills.append(skill)
92
- for chat in waldiez.flow.data.chats:
93
- all_names = get_valid_instance_name(
94
- (chat.id, chat.name), all_names, prefix="wc", max_length=max_length
95
- )
96
- chat_names[chat.id] = all_names[chat.id]
97
- chats.append(chat)
98
- all_names = get_valid_instance_name(
99
- (waldiez.flow.id, waldiez.flow.name),
100
- all_names,
101
- prefix="wf",
102
- max_length=flow_name_max_length,
103
- )
104
- flow_name = all_names[waldiez.flow.id]
105
- result: ResultType = {
106
- "agent_names": agent_names,
107
- "model_names": model_names,
108
- "skill_names": skill_names,
109
- "chat_names": chat_names,
110
- "agents": agents,
111
- "models": models,
112
- "skills": skills,
113
- "chats": chats,
114
- "flow_name": flow_name,
115
- }
116
- return result