waldiez 0.4.6__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.6.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.6.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.6.dist-info → waldiez-0.4.8.dist-info}/WHEEL +0 -0
  242. {waldiez-0.4.6.dist-info → waldiez-0.4.8.dist-info}/entry_points.txt +0 -0
  243. {waldiez-0.4.6.dist-info → waldiez-0.4.8.dist-info}/licenses/LICENSE +0 -0
  244. {waldiez-0.4.6.dist-info → waldiez-0.4.8.dist-info}/licenses/NOTICE.md +0 -0
@@ -1,469 +0,0 @@
1
- # SPDX-License-Identifier: Apache-2.0.
2
- # Copyright (c) 2024 - 2025 Waldiez and contributors.
3
- # pylint: disable=unused-argument
4
- """Get the extras for a swarm agent."""
5
-
6
- from typing import Callable, Dict, List, Tuple
7
-
8
- from waldiez.exporting.chats.utils.nested import get_nested_chat_queue
9
- from waldiez.models import (
10
- WaldiezAgent,
11
- WaldiezChat,
12
- WaldiezSwarmAfterWork,
13
- WaldiezSwarmAgent,
14
- WaldiezSwarmOnCondition,
15
- WaldiezSwarmUpdateSystemMessage,
16
- )
17
-
18
- # SwarmAgent is a subclass of ConversableAgent.
19
-
20
- # Additional args:
21
- # functions (List[Callable]):
22
- # -A list of functions to register with the agent.
23
- # update_agent_state_before_reply (List[Callable]):
24
- # - A list of functions, including UpdateSystemMessage,
25
- # called to update the agent before it replies.
26
-
27
- # Additional methods:
28
- # register_hand_off(agent, hand_offs: List[AfterWork|OnCondition]):
29
-
30
-
31
- def get_swarm_extras(
32
- agent: WaldiezAgent,
33
- agent_names: Dict[str, str],
34
- skill_names: Dict[str, str],
35
- chats: Tuple[List[WaldiezChat], Dict[str, str]],
36
- is_async: bool,
37
- serializer: Callable[..., str],
38
- string_escape: Callable[[str], str],
39
- ) -> Tuple[str, str, str]:
40
- """Get the extras of a swarm agent.
41
-
42
- Parameters
43
- ----------
44
- agent : WaldiezAgent
45
- The agent to get the extras for.
46
- agent_names : Dict[str, str]
47
- A mapping of agent IDs to agent names.
48
- skill_names : Dict[str, str]
49
- A mapping of skill IDs to skill names.
50
- chats : Tuple[List[WaldiezChat], Dict[str, str]]
51
- The list of all chats and the mapping of chat IDs to chat names.
52
- is_async : bool
53
- Whether the chat is asynchronous.
54
- serializer : Callable[..., str]
55
- The serializer to get the string representation of an object.
56
- string_escape : Callable[[str], str]
57
- The function to escape the string quotes and newlines.
58
-
59
- Returns
60
- -------
61
- Tuple[str, str, str]
62
- The extras of the swarm agent:
63
- the content before the agent,
64
- the extra argument(s) for the agent initialization,
65
- and the content after the agent.
66
- """
67
- args_string = ""
68
- before_agent = ""
69
- after_agent = ""
70
- if agent.agent_type != "swarm" or not isinstance(agent, WaldiezSwarmAgent):
71
- return args_string, before_agent, after_agent
72
- args_string = get_function_arg(agent, skill_names)
73
- before_reply = get_update_agent_state_before_reply_arg(
74
- agent=agent,
75
- agent_names=agent_names,
76
- skill_names=skill_names,
77
- string_escape=string_escape,
78
- )
79
- args_string += before_reply[0]
80
- before_agent += before_reply[1]
81
- before_registration, after_agent = get_agent_handoff_registrations(
82
- agent=agent,
83
- agent_names=agent_names,
84
- all_chats=chats[0],
85
- chat_names=chats[1],
86
- is_async=is_async,
87
- serializer=serializer,
88
- string_escape=string_escape,
89
- )
90
- before_agent += before_registration
91
- return before_agent, args_string, after_agent
92
-
93
-
94
- def get_function_arg(
95
- agent: WaldiezSwarmAgent,
96
- skill_names: Dict[str, str],
97
- ) -> str:
98
- """Get the function argument of a swarm agent.
99
-
100
- Parameters
101
- ----------
102
- agent : WaldiezSwarmAgent
103
- The swarm agent to get the function argument for.
104
- skill_names : Dict[str, str]
105
- A mapping of skill IDs to skill names.
106
-
107
- Returns
108
- -------
109
- str
110
- The function argument of the swarm agent.
111
- """
112
- tab = " "
113
- arg_string = f"{tab}functions=["
114
- added_skills = False
115
- for function in agent.data.functions:
116
- skill_name = skill_names.get(function, "")
117
- if skill_name:
118
- arg_string += "\n" + f"{tab}{tab}{skill_name},"
119
- added_skills = True
120
- if added_skills:
121
- arg_string += "\n" + tab
122
- arg_string += "],\n"
123
- return arg_string
124
-
125
-
126
- def get_update_agent_state_before_reply_arg(
127
- agent: WaldiezSwarmAgent,
128
- agent_names: Dict[str, str],
129
- skill_names: Dict[str, str],
130
- string_escape: Callable[[str], str],
131
- ) -> Tuple[str, str]:
132
- """Get the update_agent_state_before_reply argument of a swarm agent.
133
-
134
- Parameters
135
- ----------
136
- agent : WaldiezSwarmAgent
137
- The swarm agent to get the argument for.
138
- agent_names : Dict[str, str]
139
- A mapping of agent IDs to agent names.
140
- skill_names : Dict[str, str]
141
- A mapping of skill IDs to skill names.
142
- string_escape : Callable[[str], str]
143
- The function to escape the string quotes and newlines.
144
-
145
- Returns
146
- -------
147
- Tuple[str, str]
148
- The update_agent_state_before_reply argument of the swarm agent
149
- and the content before the agent if any.
150
- """
151
- # update_function_type : Literal["string", "callable"]
152
- # The type of the update function. Can be either a string or a callable.
153
- # update_function : str
154
- # "The string template or function definition to update "
155
- # "the agent's system message. Can be a string or a Callable. "
156
- # "If the function_type is 'string' it will be used as a "
157
- # "template and substitute the context variables. "
158
- # ag2 checks for: vars = re.findall(r"\{(\w+)\}", function)
159
- # "If function_type is 'callable', it should have signature:
160
- # "def custom_update_system_message("
161
- # " agent: ConversableAgent, "
162
- # " messages: List[Dict[str, Any]]
163
- # ) -> str"
164
- tab = " "
165
- before_agent = ""
166
- arg_string = f"{tab}update_agent_state_before_reply=["
167
- added_functions = False
168
- # pylint: disable=line-too-long
169
- for function in agent.data.update_agent_state_before_reply:
170
- if isinstance(function, WaldiezSwarmUpdateSystemMessage):
171
- added_functions = True
172
- if function.update_function_type == "callable":
173
- function_content, function_name = function.get_update_function(
174
- name_suffix=agent_names[agent.id],
175
- )
176
- arg_string += (
177
- "\n" + f"{tab}{tab}UpdateSystemMessage({function_name}),"
178
- )
179
- before_agent += "\n" + function_content + "\n"
180
- else:
181
- escaped_function = string_escape(function.update_function)
182
- arg_string += (
183
- "\n"
184
- + f'{tab}{tab}UpdateSystemMessage("{escaped_function}"),'
185
- )
186
- else:
187
- skill_name = skill_names.get(function, "")
188
- if skill_name:
189
- added_functions = True
190
- arg_string += "\n" + f"{tab}{tab}{skill_name},"
191
- if added_functions:
192
- arg_string = arg_string + "\n" + tab
193
- arg_string += "],\n"
194
- return arg_string, before_agent
195
-
196
-
197
- def get_agent_handoff_registrations(
198
- agent: WaldiezSwarmAgent,
199
- agent_names: Dict[str, str],
200
- all_chats: List[WaldiezChat],
201
- chat_names: Dict[str, str],
202
- is_async: bool,
203
- serializer: Callable[..., str],
204
- string_escape: Callable[[str], str],
205
- ) -> Tuple[str, str]:
206
- """Get the agent handoff registrations of a swarm agent.
207
-
208
- Parameters
209
- ----------
210
- agent : WaldiezSwarmAgent
211
- The swarm agent to get the agent handoff registrations for.
212
- agent_names : Dict[str, str]
213
- A mapping of agent IDs to agent names.
214
- all_chats : List[WaldiezChat]
215
- The list of all chats.
216
- chat_names : Dict[str, str]
217
- A mapping of chat IDs to chat names.
218
- is_async : bool
219
- Whether the chat is asynchronous.
220
- serializer : Callable[..., str]
221
- The serializer to get the string representation of an object.
222
- string_escape : Callable[[str], str]
223
- The function to escape the string quotes and newlines.
224
-
225
- Returns
226
- -------
227
- Tuple[str, str]
228
- the contents before and after the agent.
229
- """
230
- agent_name = agent_names[agent.id]
231
- registrations = []
232
- before_agent = ""
233
- after_agent = ""
234
- if not agent.handoffs:
235
- return before_agent, after_agent
236
- tab = " "
237
- # change {agent}.register_hand_off([...
238
- # to register_hand_off({agent}, [...
239
- # after_agent = f"{agent_name}.register_hand_off(" + "\n" + f"{tab}[" + "\n"
240
- after_agent = (
241
- "register_hand_off(\n" + f"{tab}{agent_name}," + "\n" + f"{tab}[" + "\n"
242
- )
243
- for hand_off in agent.handoffs:
244
- if isinstance(hand_off, WaldiezSwarmOnCondition):
245
- registration, before_handoff = get_agent_on_condition_handoff(
246
- agent=agent,
247
- hand_off=hand_off,
248
- agent_names=agent_names,
249
- all_chats=all_chats,
250
- chat_names=chat_names,
251
- is_async=is_async,
252
- serializer=serializer,
253
- string_escape=string_escape,
254
- )
255
- if registration:
256
- registrations.append(registration)
257
- before_agent += before_handoff
258
- elif isinstance(hand_off, WaldiezSwarmAfterWork):
259
- registration, before_handoff = get_agent_after_work_handoff(
260
- hand_off=hand_off,
261
- agent_names=agent_names,
262
- agent_name=agent_name,
263
- )
264
- registrations.append(registration)
265
- before_agent += before_handoff
266
- after_agent += "\n".join(registrations) + "\n" + f"{tab}]" + "\n" + ")"
267
- return before_agent, after_agent
268
-
269
-
270
- def get_agent_after_work_handoff(
271
- hand_off: WaldiezSwarmAfterWork,
272
- agent_names: Dict[str, str],
273
- agent_name: str,
274
- ) -> Tuple[str, str]:
275
- """Get the agent's after work hand off registration.
276
-
277
- Parameters
278
- ----------
279
- hand_off : WaldiezSwarmAfterWork
280
- The hand off to get the registration for.
281
- agent_names : Dict[str, str]
282
- A mapping of agent IDs to agent names.
283
- agent_name : str
284
- The name of the agent to register the hand off.
285
-
286
- Returns
287
- -------
288
- Tuple[str, str]
289
- The registration and the content before the agent.
290
- """
291
- before_agent = ""
292
- tab = " "
293
- recipient_type = hand_off.recipient_type
294
- recipient, function_content = hand_off.get_recipient(
295
- agent_names=agent_names,
296
- name_suffix=agent_name,
297
- )
298
- registration = f"{tab}{tab}{recipient},"
299
- if recipient_type == "callable" and function_content:
300
- before_agent += "\n" + function_content + "\n"
301
- return registration, before_agent
302
-
303
-
304
- def get_agent_on_condition_handoff(
305
- agent: WaldiezSwarmAgent,
306
- hand_off: WaldiezSwarmOnCondition,
307
- agent_names: Dict[str, str],
308
- all_chats: List[WaldiezChat],
309
- chat_names: Dict[str, str],
310
- is_async: bool,
311
- serializer: Callable[..., str],
312
- string_escape: Callable[[str], str],
313
- ) -> Tuple[str, str]:
314
- """Get the agent's on condition hand off registration.
315
-
316
- Parameters
317
- ----------
318
- agent : WaldiezSwarmAgent
319
- The agent to get the registration for.
320
- hand_off : WaldiezSwarmAfterWork
321
- The hand off to get the registration for.
322
- agent_names : Dict[str, str]
323
- A mapping of agent IDs to agent names.
324
- all_chats : List[WaldiezChat]
325
- The list of all chats.
326
- chat_names : Dict[str, str]
327
- A mapping of chat IDs to chat names.
328
- is_async : bool
329
- Whether the chat is asynchronous.
330
- serializer : Callable[..., str]
331
- The serializer to get the string representation of an object.
332
- string_escape : Callable[[str], str]
333
- The function to escape the string quotes and newlines.
334
-
335
- Returns
336
- -------
337
- Tuple[str, str]
338
- The registration and the content before the agent.
339
- """
340
- before_agent = ""
341
- registration = ""
342
- available, available_function = hand_off.get_available(
343
- name_suffix=agent_names[agent.id],
344
- )
345
- if available and not available_function:
346
- available = f'"{string_escape(available)}"'
347
- if hand_off.target_type == "agent":
348
- recipient = agent_names[hand_off.target.id]
349
- condition = (
350
- string_escape(hand_off.condition) or f"Transfer to {recipient}"
351
- )
352
- results = _get_agent_on_condition_handoff_to_agent(
353
- recipient=recipient,
354
- available=available,
355
- condition=condition,
356
- available_function=available_function,
357
- )
358
- before_agent += results[0]
359
- registration = results[1]
360
- # else: # target_type == "nested_chat"
361
- if hand_off.target_type == "nested_chat":
362
- condition = _get_condition_string(
363
- condition=hand_off.condition,
364
- chat_id=hand_off.target.id,
365
- all_chats=all_chats,
366
- agent_names=agent_names,
367
- )
368
- results = _get_agent_on_condition_handoff_to_nested_chat(
369
- agent=agent,
370
- agent_names=agent_names,
371
- condition=hand_off.condition,
372
- available=available,
373
- available_function=available_function,
374
- all_chats=all_chats,
375
- chat_names=chat_names,
376
- is_async=is_async,
377
- serializer=serializer,
378
- string_escape=string_escape,
379
- )
380
- before_agent += results[0]
381
- registration = results[1]
382
- return registration, before_agent
383
-
384
-
385
- def _get_agent_on_condition_handoff_to_agent(
386
- recipient: str,
387
- available: str,
388
- condition: str,
389
- available_function: str,
390
- ) -> Tuple[str, str]:
391
- before_agent = ""
392
- tab = " "
393
- on_condition = (
394
- f"{tab}{tab}OnCondition(" + "\n"
395
- f"{tab}{tab}{tab}target={recipient}," + "\n"
396
- f'{tab}{tab}{tab}condition="{condition}",' + "\n"
397
- )
398
- if available:
399
- on_condition += f"{tab}{tab}{tab}available={available}," + "\n"
400
- if available_function:
401
- before_agent += "\n" + available_function + "\n"
402
- on_condition += f"{tab}{tab}),"
403
- return before_agent, on_condition
404
-
405
-
406
- # pylint: disable=too-many-locals
407
- def _get_agent_on_condition_handoff_to_nested_chat(
408
- agent: WaldiezAgent,
409
- agent_names: Dict[str, str],
410
- condition: str,
411
- available: str,
412
- available_function: str,
413
- all_chats: List[WaldiezChat],
414
- chat_names: Dict[str, str],
415
- is_async: bool,
416
- serializer: Callable[..., str],
417
- string_escape: Callable[[str], str],
418
- ) -> Tuple[str, str]:
419
- if not agent.data.nested_chats or not agent.data.nested_chats[0].messages:
420
- return "", ""
421
- chat_queue, extra_methods = get_nested_chat_queue(
422
- nested_chat=agent.data.nested_chats[0],
423
- agent=agent,
424
- agent_names=agent_names,
425
- chat_names=chat_names,
426
- all_chats=all_chats,
427
- serializer=serializer,
428
- string_escape=string_escape,
429
- )
430
- if not chat_queue:
431
- return "", ""
432
- before_agent = ""
433
- tab = " "
434
- chat_queue_var_name = f"{agent_names[agent.id]}_handoff_nested_chat_queue"
435
- if extra_methods:
436
- before_agent += "\n".join(extra_methods) + "\n"
437
- before_agent += f"{chat_queue_var_name} = {chat_queue} " + "\n"
438
- condition_string = string_escape(condition)
439
- on_condition = (
440
- f"{tab}{tab}OnCondition(" + "\n"
441
- f"{tab}{tab}{tab}target=" + "{\n"
442
- f'{tab}{tab}{tab}{tab}"chat_queue": {chat_queue_var_name},' + "\n"
443
- f'{tab}{tab}{tab}{tab}"config": None,' + "\n"
444
- f'{tab}{tab}{tab}{tab}"reply_func_from_nested_chats": None,' + "\n"
445
- f'{tab}{tab}{tab}{tab}"use_async": {is_async},' + "\n"
446
- f"{tab}{tab}{tab}" + "},\n"
447
- f'{tab}{tab}{tab}condition="{condition_string}",' + "\n"
448
- )
449
- if available:
450
- on_condition += f"{tab}{tab}{tab}available={available}," + "\n"
451
- if available_function:
452
- before_agent += "\n" + available_function + "\n"
453
- on_condition += f"{tab}{tab}),"
454
- return before_agent, on_condition
455
-
456
-
457
- def _get_condition_string(
458
- condition: str,
459
- chat_id: str,
460
- all_chats: List[WaldiezChat],
461
- agent_names: Dict[str, str],
462
- ) -> str:
463
- if not condition:
464
- chat = next((c for c in all_chats if c.id == chat_id), None)
465
- if chat:
466
- target_name = agent_names[chat.target]
467
- return f"Transfer to {target_name}"
468
- return "Transfer to the next agent"
469
- return condition
@@ -1,41 +0,0 @@
1
- # SPDX-License-Identifier: Apache-2.0.
2
- # Copyright (c) 2024 - 2025 Waldiez and contributors.
3
- """Exporting teachability data for agents."""
4
-
5
- from typing import Dict
6
-
7
- from waldiez.models import WaldiezAgent
8
-
9
-
10
- def get_agent_teachability_string(
11
- agent: WaldiezAgent,
12
- agent_names: Dict[str, str],
13
- ) -> str:
14
- """Get the teachability string to use for the agent.
15
-
16
- Parameters
17
- ----------
18
- agent : WaldiezAgent
19
- The agent.
20
- agent_names : Dict[str, str]
21
- A mapping of agent id to agent name.
22
-
23
- Returns
24
- -------
25
- str
26
- The teachability string
27
- """
28
- if not agent.data.teachability or not agent.data.teachability.enabled:
29
- return ""
30
- agent_name = agent_names[agent.id]
31
- teachability = agent.data.teachability
32
- content = f"{agent_name}_teachability = teachability.Teachability(" + "\n"
33
- content += f" verbosity={teachability.verbosity}," + "\n"
34
- content += f" reset_db={teachability.reset_db}," + "\n"
35
- content += f" recall_threshold={teachability.recall_threshold}," + "\n"
36
- content += (
37
- f" max_num_retrievals={teachability.max_num_retrievals}," + "\n"
38
- )
39
- content += ")\n\n\n"
40
- content += f"{agent_name}_teachability.add_to_agent({agent_name})"
41
- return content
@@ -1,44 +0,0 @@
1
- # SPDX-License-Identifier: Apache-2.0.
2
- # Copyright (c) 2024 - 2025 Waldiez and contributors.
3
- """Get the `is_termination_message` check for the agent."""
4
-
5
- from typing import Tuple
6
-
7
- from waldiez.models import WaldiezAgent
8
-
9
-
10
- def get_is_termination_message(
11
- agent: WaldiezAgent, agent_name: str
12
- ) -> Tuple[str, str]:
13
- """Get the `is_termination_message` argument and content (if any).
14
-
15
- Parameters
16
- ----------
17
- agent : WaldiezAgent
18
- The agent.
19
- agent_name : str
20
- The agent name.
21
-
22
- Returns
23
- -------
24
- Tuple[str, str]
25
- - The termination function name or lambda or None.
26
- - The termination function definition and content if any.
27
-
28
- Raises
29
- ------
30
- ValueError
31
- If the termination type is invalid.
32
- """
33
- if agent.data.termination.type == "none":
34
- return "None", ""
35
- if agent.data.termination.type == "keyword":
36
- return agent.data.termination.string, ""
37
- if agent.data.termination.type == "method":
38
- content, function_name = (
39
- agent.data.termination.get_termination_function(
40
- name_suffix=agent_name
41
- )
42
- )
43
- return function_name, "\n\n" + content + "\n"
44
- raise ValueError(f"Invalid termination type: {agent.data.termination.type}")
@@ -1,25 +0,0 @@
1
- # SPDX-License-Identifier: Apache-2.0.
2
- # Copyright (c) 2024 - 2025 Waldiez and contributors.
3
- """Base classes, mixins, and utilities for exporting data.
4
-
5
- Each exporter should inherit from the `BaseExporter` class and implement the
6
- `export` method. The `export` method should return the exported content as an
7
- instance of the `ExporterReturnType` typed dictionary.
8
- """
9
-
10
- from .agent_position import AgentPosition, AgentPositions
11
- from .base_exporter import BaseExporter, ExporterReturnType
12
- from .export_position import ExportPosition, ExportPositions
13
- from .import_position import ImportPosition
14
- from .mixin import ExporterMixin
15
-
16
- __all__ = [
17
- "AgentPosition",
18
- "AgentPositions",
19
- "BaseExporter",
20
- "ExporterMixin",
21
- "ExportPosition",
22
- "ExportPositions",
23
- "ExporterReturnType",
24
- "ImportPosition",
25
- ]
@@ -1,75 +0,0 @@
1
- # SPDX-License-Identifier: Apache-2.0.
2
- # Copyright (c) 2024 - 2025 Waldiez and contributors.
3
- """Agent position generation."""
4
-
5
- from dataclasses import dataclass
6
- from enum import Enum
7
- from typing import Optional
8
-
9
- from waldiez.models import WaldiezAgent
10
-
11
-
12
- class AgentPositions(Enum):
13
- """Agent positions.
14
-
15
- Attributes
16
- ----------
17
- BEFORE_ALL: int
18
- Before all agents.
19
- BEFORE: int
20
- Before the agent.
21
- AS_ARGUMENT: int
22
- As an argument of the agent's initialization.
23
- AFTER: int
24
- After the agent.
25
- AFTER_ALL: int
26
- After all agents.
27
- """
28
-
29
- BEFORE_ALL = 0
30
- BEFORE = 1
31
- AS_ARGUMENT = 2
32
- AFTER = 3
33
- AFTER_ALL = 4
34
-
35
-
36
- POSITIONS_WITHOUT_AGENT = [
37
- AgentPositions.BEFORE_ALL,
38
- AgentPositions.AFTER_ALL,
39
- ]
40
-
41
-
42
- @dataclass(order=True, frozen=True, slots=True)
43
- class AgentPosition:
44
- """Agent position.
45
-
46
- Attributes
47
- ----------
48
- agent: Optional[WaldiezAgent]
49
- The agent.
50
- position: AgentPositions
51
- The position.
52
- order: int
53
- The order of the agent position.
54
-
55
- Raises
56
- ------
57
- ValueError
58
- If the position is not "BEFORE_ALL" or "AFTER_ALL"
59
- and the agent is not provided.
60
- """
61
-
62
- agent: Optional[WaldiezAgent]
63
- position: AgentPositions
64
- order: int = 0
65
-
66
- def __post_init__(self) -> None:
67
- """Post initialization.
68
-
69
- Raises
70
- ------
71
- ValueError
72
- If the agent is not provided for the given position.
73
- """
74
- if self.agent is None and self.position not in POSITIONS_WITHOUT_AGENT:
75
- raise ValueError("Agent must be provided for the given position.")