waldiez 0.4.7__py3-none-any.whl → 0.4.8__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 (244) hide show
  1. waldiez/__init__.py +5 -5
  2. waldiez/_version.py +1 -1
  3. waldiez/cli.py +112 -73
  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} +16 -15
  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 +419 -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 +114 -49
  175. waldiez/running/__init__.py +1 -1
  176. waldiez/running/environment.py +49 -68
  177. waldiez/running/gen_seq_diagram.py +16 -14
  178. waldiez/running/running.py +53 -34
  179. waldiez/utils/__init__.py +0 -4
  180. waldiez/utils/cli_extras/jupyter.py +5 -3
  181. waldiez/utils/cli_extras/runner.py +6 -4
  182. waldiez/utils/cli_extras/studio.py +6 -4
  183. waldiez/utils/conflict_checker.py +15 -9
  184. waldiez/utils/flaml_warnings.py +5 -5
  185. {waldiez-0.4.7.dist-info → waldiez-0.4.8.dist-info}/METADATA +235 -91
  186. waldiez-0.4.8.dist-info/RECORD +200 -0
  187. waldiez/exporting/agent/agent_exporter.py +0 -297
  188. waldiez/exporting/agent/utils/__init__.py +0 -23
  189. waldiez/exporting/agent/utils/captain_agent.py +0 -263
  190. waldiez/exporting/agent/utils/code_execution.py +0 -65
  191. waldiez/exporting/agent/utils/group_manager.py +0 -220
  192. waldiez/exporting/agent/utils/rag_user/__init__.py +0 -7
  193. waldiez/exporting/agent/utils/rag_user/rag_user.py +0 -209
  194. waldiez/exporting/agent/utils/reasoning.py +0 -36
  195. waldiez/exporting/agent/utils/swarm_agent.py +0 -469
  196. waldiez/exporting/agent/utils/teachability.py +0 -41
  197. waldiez/exporting/agent/utils/termination_message.py +0 -44
  198. waldiez/exporting/base/__init__.py +0 -25
  199. waldiez/exporting/base/agent_position.py +0 -75
  200. waldiez/exporting/base/base_exporter.py +0 -118
  201. waldiez/exporting/base/export_position.py +0 -48
  202. waldiez/exporting/base/import_position.py +0 -23
  203. waldiez/exporting/base/mixin.py +0 -137
  204. waldiez/exporting/base/utils/__init__.py +0 -18
  205. waldiez/exporting/base/utils/comments.py +0 -96
  206. waldiez/exporting/base/utils/path_check.py +0 -68
  207. waldiez/exporting/base/utils/to_string.py +0 -84
  208. waldiez/exporting/chats/chats_exporter.py +0 -240
  209. waldiez/exporting/chats/utils/swarm.py +0 -210
  210. waldiez/exporting/flow/flow_exporter.py +0 -528
  211. waldiez/exporting/flow/utils/agent_utils.py +0 -204
  212. waldiez/exporting/flow/utils/chat_utils.py +0 -71
  213. waldiez/exporting/flow/utils/def_main.py +0 -77
  214. waldiez/exporting/flow/utils/flow_content.py +0 -202
  215. waldiez/exporting/flow/utils/flow_names.py +0 -116
  216. waldiez/exporting/flow/utils/importing_utils.py +0 -227
  217. waldiez/exporting/models/models_exporter.py +0 -199
  218. waldiez/exporting/models/utils.py +0 -174
  219. waldiez/exporting/skills/__init__.py +0 -9
  220. waldiez/exporting/skills/skills_exporter.py +0 -176
  221. waldiez/exporting/skills/utils.py +0 -369
  222. waldiez/models/agents/agent/teachability.py +0 -70
  223. waldiez/models/agents/rag_user/rag_user.py +0 -60
  224. waldiez/models/agents/swarm_agent/__init__.py +0 -50
  225. waldiez/models/agents/swarm_agent/after_work.py +0 -179
  226. waldiez/models/agents/swarm_agent/on_condition.py +0 -105
  227. waldiez/models/agents/swarm_agent/on_condition_available.py +0 -142
  228. waldiez/models/agents/swarm_agent/on_condition_target.py +0 -40
  229. waldiez/models/agents/swarm_agent/swarm_agent.py +0 -107
  230. waldiez/models/agents/swarm_agent/swarm_agent_data.py +0 -124
  231. waldiez/models/flow/utils.py +0 -232
  232. waldiez/models/skill/__init__.py +0 -16
  233. waldiez/models/skill/extra_requirements.py +0 -36
  234. waldiez/models/skill/skill_data.py +0 -53
  235. waldiez/models/skill/skill_type.py +0 -8
  236. waldiez/utils/pysqlite3_checker.py +0 -308
  237. waldiez/utils/rdps_checker.py +0 -122
  238. waldiez-0.4.7.dist-info/RECORD +0 -149
  239. /waldiez/models/agents/{captain_agent → captain}/__init__.py +0 -0
  240. /waldiez/models/agents/{captain_agent → captain}/captain_agent_lib_entry.py +0 -0
  241. {waldiez-0.4.7.dist-info → waldiez-0.4.8.dist-info}/WHEEL +0 -0
  242. {waldiez-0.4.7.dist-info → waldiez-0.4.8.dist-info}/entry_points.txt +0 -0
  243. {waldiez-0.4.7.dist-info → waldiez-0.4.8.dist-info}/licenses/LICENSE +0 -0
  244. {waldiez-0.4.7.dist-info → waldiez-0.4.8.dist-info}/licenses/NOTICE.md +0 -0
@@ -0,0 +1,245 @@
1
+ # SPDX-License-Identifier: Apache-2.0.
2
+ # Copyright (c) 2024 - 2025 Waldiez and contributors.
3
+ """RAG user proxy agent configuration processor."""
4
+
5
+ from typing import Union
6
+
7
+ from waldiez.models import (
8
+ WaldiezAgent,
9
+ WaldiezRagUserProxy,
10
+ WaldiezRagUserProxyModels,
11
+ WaldiezRagUserProxyRetrieveConfig,
12
+ )
13
+
14
+ from ...core import (
15
+ DefaultPathResolver,
16
+ DefaultSerializer,
17
+ ImportPosition,
18
+ ImportStatement,
19
+ InstanceArgument,
20
+ PathResolver,
21
+ Serializer,
22
+ )
23
+ from ...core.extras.agent_extras import RAGUserExtras
24
+ from .rag import VectorDBExtras, get_vector_db_extras
25
+
26
+
27
+ # pylint: disable=too-few-public-methods
28
+ class RagUserProxyAgentProcessor:
29
+ """Processor for RAG user proxy agent configuration."""
30
+
31
+ _before_agent: str = ""
32
+
33
+ def __init__(
34
+ self,
35
+ agent: WaldiezAgent,
36
+ agent_name: str,
37
+ model_names: dict[str, str],
38
+ path_resolver: PathResolver | None = None,
39
+ serializer: Serializer | None = None,
40
+ ):
41
+ """Initialize the processor.
42
+
43
+ Parameters
44
+ ----------
45
+ agent : WaldiezAgent
46
+ The Waldiez RAG user proxy agent to process.
47
+ model_names : dict[str, str]
48
+ A mapping from model id to model name.
49
+ path_resolver : PathResolver | None
50
+ Optional path resolver for resolving paths.
51
+ Defaults to DefaultPathResolver if not provided.
52
+ serializer : Serializer | None
53
+ Optional serializer for the RAG configuration.
54
+ Defaults to DefaultSerializer if not provided.
55
+ """
56
+ self.agent = agent
57
+ self.agent_name = agent_name
58
+ self.model_names = model_names
59
+ self.path_resolver = path_resolver or DefaultPathResolver()
60
+ self.serializer = serializer or DefaultSerializer()
61
+
62
+ def process(self) -> RAGUserExtras:
63
+ """Process RAG user proxy agent configuration.
64
+
65
+ Returns
66
+ -------
67
+ RAGConfig
68
+ The processed result containing extra arguments, before content,
69
+ imports, and environment variables.
70
+ """
71
+ result = RAGUserExtras(self.agent.id)
72
+ if not self.agent.is_rag_user or not isinstance(
73
+ self.agent, WaldiezRagUserProxy
74
+ ):
75
+ return result
76
+ # Get the extra args
77
+ vector_db_extras = get_vector_db_extras(
78
+ agent=self.agent, agent_name=self.agent_name
79
+ )
80
+ before_agent, arg_value = self._get_retrieve_config(vector_db_extras)
81
+ if before_agent:
82
+ self._before_agent += before_agent
83
+ if arg_value:
84
+ retrieve_arg = InstanceArgument(
85
+ instance_id=self.agent.id,
86
+ name="retrieve_config",
87
+ value=arg_value,
88
+ tabs=1,
89
+ )
90
+ result.add_arg(retrieve_arg)
91
+ for import_statement in vector_db_extras.imports:
92
+ result.add_import(
93
+ ImportStatement(
94
+ statement=import_statement,
95
+ position=ImportPosition.THIRD_PARTY,
96
+ )
97
+ )
98
+ if self._before_agent:
99
+ result.prepend_before_agent(self._before_agent)
100
+ return result
101
+
102
+ def _get_retrieve_config(
103
+ self, vector_db_extras: VectorDBExtras
104
+ ) -> tuple[str, str]:
105
+ """Get the retrieve config argument for the agent.
106
+
107
+ Returns
108
+ -------
109
+ InstanceArgument | None
110
+ The retrieve config argument if applicable, otherwise None.
111
+ """
112
+ if not isinstance(self.agent, WaldiezRagUserProxy):
113
+ return "", ""
114
+ retrieve_config: WaldiezRagUserProxyRetrieveConfig = (
115
+ self.agent.retrieve_config
116
+ )
117
+ if not retrieve_config:
118
+ return "", ""
119
+ args_dict = self._get_args_dict()
120
+ if not args_dict:
121
+ return "", ""
122
+ before_agent = vector_db_extras.before_arg
123
+ if self.agent.retrieve_config.use_custom_token_count:
124
+ function_content, token_count_arg_name = (
125
+ retrieve_config.get_custom_token_count_function(
126
+ name_suffix=self.agent_name
127
+ )
128
+ )
129
+ args_dict["custom_token_count_function"] = token_count_arg_name
130
+ before_agent += "\n" + function_content + "\n"
131
+ if self.agent.retrieve_config.use_custom_text_split:
132
+ function_content, text_split_arg_name = (
133
+ retrieve_config.get_custom_text_split_function(
134
+ name_suffix=self.agent_name
135
+ )
136
+ )
137
+ args_dict["custom_text_split_function"] = text_split_arg_name
138
+ before_agent += "\n" + function_content + "\n"
139
+ if before_agent.strip() and not before_agent.endswith("\n"):
140
+ before_agent += "\n"
141
+ return before_agent, self._get_args_string(
142
+ args_dict,
143
+ vector_db_extras,
144
+ before_agent,
145
+ )
146
+
147
+ def _get_args_string(
148
+ self,
149
+ args_dict: dict[str, Union[str, list[str]]],
150
+ vector_db_extras: VectorDBExtras,
151
+ before_agent: str,
152
+ ) -> str:
153
+ if not isinstance(self.agent, WaldiezRagUserProxy):
154
+ return ""
155
+ args_content = self.serializer.serialize(args_dict)
156
+ # get the last line (where the dict ends)
157
+ args_parts = args_content.split("\n")
158
+ before_vector_db = args_parts[:-1]
159
+ closing_arg = args_parts[-1]
160
+ args_content = "\n".join(before_vector_db)
161
+ # add the vector_db arg
162
+ args_content += (
163
+ ",\n"
164
+ + f' "vector_db": {vector_db_extras.vector_db_arg},'
165
+ + "\n"
166
+ )
167
+ # we should not need to include the client, but let's do it
168
+ # to avoid later issues (with telemetry or other client settings)
169
+ # https://github.com/ag2ai/ag2/blob/main/autogen/agentchat/\
170
+ # contrib/retrieve_user_proxy_agent.py#L265-L266
171
+ if (
172
+ f"{self.agent_name}_client" in before_agent
173
+ and self.agent.retrieve_config.vector_db == "chroma"
174
+ ):
175
+ args_content += (
176
+ f' "client": {self.agent_name}_client,' + "\n"
177
+ )
178
+ args_content += closing_arg
179
+ return args_content
180
+
181
+ def _get_model_arg(
182
+ self,
183
+ ) -> str:
184
+ if not isinstance(self.agent, WaldiezRagUserProxy):
185
+ return ""
186
+ if self.agent.data.model_ids:
187
+ model_name = self.model_names[self.agent.data.model_ids[0]]
188
+ new_model_name = f"{model_name}"
189
+ return f"{new_model_name}"
190
+ if self.agent.retrieve_config.model in self.model_names:
191
+ selected_model = self.model_names[self.agent.retrieve_config.model]
192
+ new_model_name = f"{selected_model}"
193
+ return f"{new_model_name}"
194
+ return WaldiezRagUserProxyModels[self.agent.retrieve_config.vector_db]
195
+
196
+ def _get_args_dict(self) -> dict[str, Union[str, list[str]]]:
197
+ if not isinstance(self.agent, WaldiezRagUserProxy):
198
+ return {}
199
+ model_arg = self._get_model_arg()
200
+ args_dict: dict[str, Union[str, list[str]]] = {
201
+ "task": self.agent.retrieve_config.task,
202
+ "model": model_arg,
203
+ }
204
+ optional_args = [
205
+ "chunk_token_size",
206
+ "context_max_tokens",
207
+ "customized_prompt",
208
+ "customized_answer_prefix",
209
+ ]
210
+ for arg in optional_args:
211
+ arg_value = getattr(self.agent.retrieve_config, arg)
212
+ if arg_value is not None:
213
+ args_dict[arg] = arg_value
214
+ args_dict[arg] = getattr(self.agent.retrieve_config, arg)
215
+ docs_path: Union[str, list[str]] = []
216
+ if self.agent.retrieve_config.docs_path:
217
+ doc_paths = (
218
+ self.agent.retrieve_config.docs_path
219
+ if isinstance(self.agent.retrieve_config.docs_path, list)
220
+ else [self.agent.retrieve_config.docs_path]
221
+ )
222
+ docs_path = [
223
+ item
224
+ for item in [
225
+ self.path_resolver.resolve(path) for path in doc_paths
226
+ ]
227
+ if item
228
+ ]
229
+ args_dict["docs_path"] = docs_path
230
+ if docs_path:
231
+ args_dict["docs_path"] = docs_path
232
+ non_optional_args = [
233
+ "new_docs",
234
+ "update_context",
235
+ "get_or_create",
236
+ "overwrite",
237
+ "recursive",
238
+ "chunk_mode",
239
+ "must_break_at_empty_line",
240
+ "collection_name",
241
+ "distance_threshold",
242
+ ]
243
+ for arg in non_optional_args:
244
+ args_dict[arg] = getattr(self.agent.retrieve_config, arg)
245
+ return args_dict
@@ -0,0 +1,88 @@
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
+ """Reasoning agent configuration processor."""
5
+
6
+ from typing import Optional
7
+
8
+ from waldiez.models import WaldiezAgent, WaldiezReasoningAgent
9
+
10
+ from ...core import (
11
+ CodeExecutionConfig,
12
+ DefaultSerializer,
13
+ InstanceArgument,
14
+ Serializer,
15
+ SystemMessageConfig,
16
+ TerminationConfig,
17
+ )
18
+ from ...core.extras.agent_extras import ReasoningExtras
19
+
20
+
21
+ class ReasoningAgentProcessor:
22
+ """Processor for reasoning agent configuration."""
23
+
24
+ def __init__(self, agent: WaldiezAgent, serializer: Serializer | None):
25
+ """Initialize the processor with the agent and serializer.
26
+
27
+ Parameters
28
+ ----------
29
+ agent : WaldiezAgent
30
+ The Waldiez agent to process.
31
+ serializer : Serializer | None
32
+ Optional serializer for the reasoning configuration.
33
+ Defaults to DefaultSerializer if not provided.
34
+ """
35
+ self.agent = agent
36
+ self.serializer = serializer or DefaultSerializer()
37
+
38
+ def process(
39
+ self,
40
+ code_execution_config: Optional[CodeExecutionConfig] = None,
41
+ termination_config: Optional[TerminationConfig] = None,
42
+ system_message_config: Optional[SystemMessageConfig] = None,
43
+ ) -> ReasoningExtras:
44
+ """Process reasoning agent configuration.
45
+
46
+ Parameters
47
+ ----------
48
+ code_execution_config : CodeExecutionConfig, optional
49
+ Configuration for code execution, if applicable.
50
+ termination_config : TerminationConfig, optional
51
+ Configuration for termination, if applicable.
52
+ system_message_config : SystemMessageConfig, optional
53
+ Configuration for system messages, if applicable.
54
+
55
+ Returns
56
+ -------
57
+ ReasoningExtras
58
+ The processed result containing extra arguments, before content,
59
+ imports, and environment variables.
60
+ """
61
+ result = ReasoningExtras(
62
+ instance_id=self.agent.id,
63
+ code_execution_config=code_execution_config,
64
+ termination_config=termination_config,
65
+ system_message_config=system_message_config,
66
+ )
67
+ if not self.agent.is_reasoning or not isinstance(
68
+ self.agent, WaldiezReasoningAgent
69
+ ): # pragma: no cover
70
+ return result
71
+
72
+ reasoning_config = self.agent.get_reasoning_config()
73
+ serialized = self.serializer.serialize(reasoning_config)
74
+ reason_arg = InstanceArgument(
75
+ instance_id=self.agent.id,
76
+ name="reason_config",
77
+ value=serialized,
78
+ tabs=1,
79
+ )
80
+ result.add_arg(reason_arg)
81
+ verbose_arg = InstanceArgument(
82
+ instance_id=self.agent.id,
83
+ name="verbose",
84
+ value=self.agent.data.verbose,
85
+ tabs=1,
86
+ )
87
+ result.add_arg(verbose_arg)
88
+ return result
@@ -0,0 +1,95 @@
1
+ # SPDX-License-Identifier: Apache-2.0.
2
+ # Copyright (c) 2024 - 2025 Waldiez and contributors.
3
+ # pylint: disable=too-few-public-methods,
4
+ # pylint: disable=too-many-arguments,too-many-positional-arguments
5
+ """Factory for creating agent exporter."""
6
+
7
+ from pathlib import Path
8
+ from typing import Any, Callable, Optional, Union
9
+
10
+ from waldiez.models import (
11
+ WaldiezAgent,
12
+ WaldiezAgentConnection,
13
+ WaldiezChat,
14
+ WaldiezModel,
15
+ )
16
+
17
+ from ..core import (
18
+ ExporterContext,
19
+ get_default_exporter_context,
20
+ )
21
+ from .exporter import AgentExporter
22
+
23
+
24
+ def create_agent_exporter(
25
+ agent: WaldiezAgent,
26
+ agent_names: dict[str, str],
27
+ models: tuple[list[WaldiezModel], dict[str, str]],
28
+ chats: tuple[list[WaldiezChat], dict[str, str]],
29
+ tool_names: dict[str, str],
30
+ initial_chats: list[WaldiezAgentConnection],
31
+ is_async: bool = False,
32
+ for_notebook: bool = False,
33
+ cache_seed: Optional[int] = None,
34
+ group_chat_members: Optional[list[WaldiezAgent]] = None,
35
+ arguments_resolver: Optional[Callable[[WaldiezAgent], list[str]]] = None,
36
+ output_dir: Optional[Union[str, Path]] = None,
37
+ context: Optional[ExporterContext] = None,
38
+ **kwargs: Any,
39
+ ) -> AgentExporter:
40
+ """Create an agent exporter.
41
+
42
+ Parameters
43
+ ----------
44
+ agent : WaldiezAgent
45
+ The agent to export.
46
+ agent_names : dict[str, str]
47
+ Mapping of agent IDs to names.
48
+ models : tuple[list[WaldiezModel], dict[str, str]]
49
+ All models and model names mapping.
50
+ chats : tuple[list[WaldiezChat], dict[str, str]]
51
+ All chats and chat names mapping.
52
+ tool_names : dict[str, str]
53
+ Mapping of tool IDs to names.
54
+ is_async : bool, optional
55
+ Whether the flow is async, by default False
56
+ for_notebook : bool, optional
57
+ Whether exporting for notebook, by default False
58
+ cache_seed : Optional[int], optional
59
+ Cache seed if any, by default None
60
+ initial_chats : Optional[list[WaldiezAgentConnection]], optional
61
+ Initial chats for group managers, by default None
62
+ group_chat_members : Optional[list[WaldiezAgent]], optional
63
+ Group chat members if group manager, by default None
64
+ arguments_resolver : Optional[Callable], optional
65
+ Function to resolve additional arguments, by default None
66
+ output_dir : Optional[Union[str, Path]], optional
67
+ Output directory for generated files, by default None
68
+ context : Optional[ExporterContext], optional
69
+ Exporter context with dependencies, by default None
70
+ **kwargs : Any
71
+ Additional keyword arguments.
72
+
73
+ Returns
74
+ -------
75
+ AgentExporter
76
+ The created agent exporter.
77
+ """
78
+ if context is None:
79
+ context = get_default_exporter_context()
80
+ return AgentExporter(
81
+ agent=agent,
82
+ agent_names=agent_names,
83
+ models=models,
84
+ chats=chats,
85
+ tool_names=tool_names,
86
+ is_async=is_async,
87
+ for_notebook=for_notebook,
88
+ cache_seed=cache_seed,
89
+ initial_chats=initial_chats,
90
+ group_chat_members=group_chat_members,
91
+ arguments_resolver=arguments_resolver,
92
+ output_dir=output_dir,
93
+ context=context,
94
+ **kwargs,
95
+ )
@@ -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
+ ]