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
@@ -1,50 +0,0 @@
1
- # SPDX-License-Identifier: Apache-2.0.
2
- # Copyright (c) 2024 - 2025 Waldiez and contributors.
3
- """Swarm Agent."""
4
-
5
- from .after_work import (
6
- CUSTOM_AFTER_WORK,
7
- CUSTOM_AFTER_WORK_ARGS,
8
- CUSTOM_AFTER_WORK_TYPES,
9
- WaldiezSwarmAfterWork,
10
- WaldiezSwarmAfterWorkOption,
11
- WaldiezSwarmAfterWorkRecipientType,
12
- )
13
- from .on_condition import WaldiezSwarmOnCondition
14
- from .on_condition_available import (
15
- CUSTOM_ON_CONDITION_AVAILABLE,
16
- CUSTOM_ON_CONDITION_AVAILABLE_ARGS,
17
- CUSTOM_ON_CONDITION_AVAILABLE_TYPES,
18
- WaldiezSwarmOnConditionAvailable,
19
- )
20
- from .on_condition_target import WaldiezSwarmOnConditionTarget
21
- from .swarm_agent import WaldiezSwarmAgent
22
- from .swarm_agent_data import WaldiezSwarmAgentData, WaldiezSwarmHandoff
23
- from .update_system_message import (
24
- CUSTOM_UPDATE_SYSTEM_MESSAGE,
25
- CUSTOM_UPDATE_SYSTEM_MESSAGE_ARGS,
26
- CUSTOM_UPDATE_SYSTEM_MESSAGE_TYPES,
27
- WaldiezSwarmUpdateSystemMessage,
28
- )
29
-
30
- __all__ = [
31
- "CUSTOM_AFTER_WORK",
32
- "CUSTOM_AFTER_WORK_ARGS",
33
- "CUSTOM_AFTER_WORK_TYPES",
34
- "CUSTOM_ON_CONDITION_AVAILABLE",
35
- "CUSTOM_ON_CONDITION_AVAILABLE_ARGS",
36
- "CUSTOM_ON_CONDITION_AVAILABLE_TYPES",
37
- "CUSTOM_UPDATE_SYSTEM_MESSAGE",
38
- "CUSTOM_UPDATE_SYSTEM_MESSAGE_ARGS",
39
- "CUSTOM_UPDATE_SYSTEM_MESSAGE_TYPES",
40
- "WaldiezSwarmAfterWork",
41
- "WaldiezSwarmAfterWorkOption",
42
- "WaldiezSwarmAgent",
43
- "WaldiezSwarmAgentData",
44
- "WaldiezSwarmAfterWorkRecipientType",
45
- "WaldiezSwarmHandoff",
46
- "WaldiezSwarmOnCondition",
47
- "WaldiezSwarmOnConditionTarget",
48
- "WaldiezSwarmOnConditionAvailable",
49
- "WaldiezSwarmUpdateSystemMessage",
50
- ]
@@ -1,179 +0,0 @@
1
- # SPDX-License-Identifier: Apache-2.0.
2
- # Copyright (c) 2024 - 2025 Waldiez and contributors.
3
- """Swarm after work model.
4
-
5
- Handles the next step in the conversation when an
6
- agent doesn't suggest a tool call or a handoff.
7
-
8
- """
9
-
10
- # pylint: disable=line-too-long
11
-
12
- from typing import Dict, Optional, Tuple
13
-
14
- from pydantic import Field, model_validator
15
- from typing_extensions import Annotated, Literal, Self
16
-
17
- from ...common import WaldiezBase, check_function, generate_function
18
-
19
- WaldiezSwarmAfterWorkRecipientType = Literal["agent", "option", "callable"]
20
- """The possible AfterWork recipient types."""
21
- WaldiezSwarmAfterWorkOption = Literal[
22
- "TERMINATE", "REVERT_TO_USER", "STAY", "SWARM_MANAGER"
23
- ]
24
- """The possible AfterWork options."""
25
-
26
-
27
- CUSTOM_AFTER_WORK = "custom_after_work"
28
- CUSTOM_AFTER_WORK_ARGS = ["last_speaker", "messages", "groupchat"]
29
- CUSTOM_AFTER_WORK_TYPES = (
30
- ["ConversableAgent", "List[Dict[str, Any]]", "GroupChat"],
31
- "Union[AfterWorkOption, ConversableAgent, str]",
32
- )
33
-
34
-
35
- class WaldiezSwarmAfterWork(WaldiezBase):
36
- """Swarm after work.
37
-
38
- Attributes
39
- ----------
40
- recipient : str
41
- The agent_id to hand off to, an AfterWork option,
42
- or the custom after work method.
43
- If it is an AfterWork option, it can be one of
44
- ('TERMINATE', 'REVERT_TO_USER', 'STAY', 'SWARM_MANAGER').
45
-
46
- recipient_type : WaldiezSwarmAfterWorkRecipientType
47
- The type of recipient.
48
- Can be 'agent', 'option', or 'callable'.
49
- If 'agent', the recipient is a Swarm Agent.
50
- If 'option', the recipient is an AfterWorkOption :
51
- ('TERMINATE', 'REVERT_TO_USER', 'STAY', 'SWARM_MANAGER').
52
- If 'callable', it should have the signature:
53
- def custom_after_work(
54
- last_speaker: ConversableAgent,
55
- messages: List[dict],
56
- groupchat: GroupChat,
57
- ) -> Union[AfterWorkOption, ConversableAgent, str]:
58
-
59
- """
60
-
61
- recipient: Annotated[
62
- str,
63
- Field(
64
- "TERMINATE",
65
- title="Recipient",
66
- description=(
67
- "The agent_id to hand off to, an AfterWork option, "
68
- "or the custom after work method. "
69
- "If it is an AfterWork option, it can be one of "
70
- "('TERMINATE', 'REVERT_TO_USER', 'STAY')"
71
- ),
72
- ),
73
- ]
74
- recipient_type: Annotated[
75
- WaldiezSwarmAfterWorkRecipientType,
76
- Field(
77
- "option",
78
- alias="recipientType",
79
- title="Recipient Type",
80
- description=(
81
- "The type of recipient. "
82
- "Can be 'agent', 'option', or 'callable'. "
83
- "If 'agent', the recipient is a Swarm Agent. "
84
- "If 'option', the recipient is an AfterWorkOption :"
85
- " ('TERMINATE', 'REVERT_TO_USER', 'STAY', 'SWARM_MANAGER'). "
86
- "If 'callable', it should have the signature: "
87
- "def custom_after_work("
88
- " last_speaker: ConversableAgent,"
89
- " messages: List[Dict[str, Any]],"
90
- " groupchat: GroupChat,"
91
- ") -> Union[AfterWorkOption, ConversableAgent, str]:"
92
- ),
93
- ),
94
- ]
95
-
96
- _recipient_string: str = ""
97
-
98
- def get_recipient(
99
- self,
100
- agent_names: Dict[str, str],
101
- name_prefix: Optional[str] = None,
102
- name_suffix: Optional[str] = None,
103
- ) -> Tuple[str, str]:
104
- """Get the recipient string.
105
-
106
- Parameters
107
- ----------
108
- agent_names : Dict[str, str]
109
- A mapping of agent id to agent name.
110
- name_prefix : Optional[str], optional
111
- The prefix for the function name, by default None.
112
- name_suffix : Optional[str], optional
113
- The suffix for the function name, by default None.
114
-
115
- Returns
116
- -------
117
- Tuple[str, str]
118
- The recipient string and the function content if applicable.
119
- """
120
- if self.recipient_type == "option":
121
- return f"AfterWork(AfterWorkOption.{self.recipient})", ""
122
- if self.recipient_type == "agent":
123
- # the the recipient is passed as the agent name
124
- # (and not its id), care should be taken to ensure
125
- # the all the agents in the flow have unique names
126
- agent_instance = agent_names.get(self.recipient, self.recipient)
127
- return f"AfterWork({agent_instance})", ""
128
-
129
- function_name = CUSTOM_AFTER_WORK
130
- if name_prefix:
131
- function_name = f"{name_prefix}_{function_name}"
132
- if name_suffix:
133
- function_name = f"{function_name}_{name_suffix}"
134
- return (
135
- f"AfterWork({function_name})",
136
- generate_function(
137
- function_name=function_name,
138
- function_args=CUSTOM_AFTER_WORK_ARGS,
139
- function_body=self._recipient_string,
140
- function_types=CUSTOM_AFTER_WORK_TYPES,
141
- ),
142
- )
143
-
144
- @model_validator(mode="after")
145
- def validate_recipient(self) -> Self:
146
- """Validate the recipient.
147
-
148
- Returns
149
- -------
150
- WaldiezSwarmAfterWork
151
- The validated after work model.
152
-
153
- Raises
154
- ------
155
- ValueError
156
- If the validation fails.
157
- """
158
- self._recipient_string = self.recipient
159
- if self.recipient_type == "callable":
160
- is_valid, error_or_body = check_function(
161
- code_string=self.recipient,
162
- function_name=CUSTOM_AFTER_WORK,
163
- function_args=CUSTOM_AFTER_WORK_ARGS,
164
- )
165
- if not is_valid or not error_or_body:
166
- # pylint: disable=inconsistent-quotes
167
- raise ValueError(
168
- f"Invalid custom method: {error_or_body or 'no content'}"
169
- )
170
- self._recipient_string = error_or_body
171
- elif self.recipient_type == "option":
172
- if self.recipient not in [
173
- "TERMINATE",
174
- "REVERT_TO_USER",
175
- "STAY",
176
- "SWARM_MANAGER",
177
- ]:
178
- raise ValueError("Invalid option.")
179
- return self
@@ -1,105 +0,0 @@
1
- # SPDX-License-Identifier: Apache-2.0.
2
- # Copyright (c) 2024 - 2025 Waldiez and contributors.
3
- """Swarm condition model for handoff."""
4
-
5
- from typing import Optional, Tuple
6
-
7
- from pydantic import Field
8
- from typing_extensions import Annotated, Literal
9
-
10
- from ...common import WaldiezBase
11
- from .on_condition_available import WaldiezSwarmOnConditionAvailable
12
- from .on_condition_target import WaldiezSwarmOnConditionTarget
13
-
14
- WaldiezSwarmOnConditionTargetType = Literal["agent", "nested_chat"]
15
- """Possible types for the target of the OnCondition."""
16
-
17
-
18
- class WaldiezSwarmOnCondition(WaldiezBase):
19
- """Swarm condition to handle handoff.
20
-
21
- Attributes
22
- ----------
23
- target : WaldiezSwarmOnConditionTarget
24
- The agent or nested chat configuration to hand off to.
25
-
26
- target_type: Literal["agent", "nested_chat"]
27
- The type of the target. Can be either 'agent' or 'nested_chat'.
28
- Default is 'agent'.
29
-
30
- condition : str
31
- The condition for transitioning to the target agent
32
-
33
- available: str, optional
34
- Optional condition to determine if this OnCondition is available.
35
- Can be a Callable or a string. If a string, it will look up the
36
- value of the context variable with that name, which should be a bool.
37
-
38
- available_check_type : Literal["string", "callable", "none"]
39
- The type of the `available` property to check. Default is "none".
40
- """
41
-
42
- target: Annotated[
43
- WaldiezSwarmOnConditionTarget,
44
- Field(
45
- title="Target",
46
- description=(
47
- "The agent or nested chat configuration to hand off to."
48
- ),
49
- ),
50
- ]
51
- target_type: Annotated[
52
- WaldiezSwarmOnConditionTargetType,
53
- Field(
54
- "agent",
55
- alias="targetType",
56
- title="Target Type",
57
- description=(
58
- "The type of the target. "
59
- "Can be either 'agent' or 'nested_chat'.Default is 'agent'."
60
- ),
61
- ),
62
- ] = "agent"
63
- condition: Annotated[
64
- str,
65
- Field(
66
- ...,
67
- title="Condition",
68
- description="The condition for transitioning to the target agent",
69
- ),
70
- ]
71
- available: Annotated[
72
- WaldiezSwarmOnConditionAvailable,
73
- Field(
74
- default_factory=WaldiezSwarmOnConditionAvailable,
75
- title="Available",
76
- description=(
77
- "Optional condition to determine if this OnCondition "
78
- "is available."
79
- ),
80
- ),
81
- ]
82
-
83
- def get_available(
84
- self,
85
- name_prefix: Optional[str] = None,
86
- name_suffix: Optional[str] = None,
87
- ) -> Tuple[str, str]:
88
- """Get the available string.
89
-
90
- Parameters
91
- ----------
92
- name_prefix : str, optional
93
- The prefix to add to the function name. Default is None.
94
- name_suffix : str, optional
95
- The suffix to add to the function name. Default is None.
96
-
97
- Returns
98
- -------
99
- Tuple[str, str]
100
- The available string or function name and code if available.
101
- """
102
- return self.available.get_available(
103
- name_prefix,
104
- name_suffix,
105
- )
@@ -1,142 +0,0 @@
1
- # SPDX-License-Identifier: Apache-2.0.
2
- # Copyright (c) 2024 - 2025 Waldiez and contributors.
3
- """Waldiez Swarm Agent ON_CONDITION Available Model."""
4
-
5
- from typing import Optional, Tuple
6
-
7
- from pydantic import Field, model_validator
8
- from typing_extensions import Annotated, Literal, Self
9
-
10
- from ...common import WaldiezBase, check_function, generate_function
11
-
12
- WaldiezSwarmOnConditionAvailableCheckType = Literal[
13
- "string", "callable", "none"
14
- ]
15
- """Possible types for the `available` check."""
16
-
17
- CUSTOM_ON_CONDITION_AVAILABLE = "custom_on_condition_available"
18
- CUSTOM_ON_CONDITION_AVAILABLE_ARGS = ["agent", "message"]
19
- CUSTOM_ON_CONDITION_AVAILABLE_TYPES = (
20
- ["ConversableAgent", "Dict[str, Any]"],
21
- "bool",
22
- )
23
-
24
- # In ag2 it is used as:
25
- #
26
- # if on_condition.available is not None:
27
- # if isinstance(on_condition.available, Callable):
28
- # is_available = on_condition.available(
29
- # agent, next(iter(agent.chat_messages.values()))
30
- # )
31
- # elif isinstance(on_condition.available, str):
32
- # is_available = agent.get_context(on_condition.available) or False
33
-
34
-
35
- class WaldiezSwarmOnConditionAvailable(WaldiezBase):
36
- """Swarm condition availability check."""
37
-
38
- type: Annotated[
39
- WaldiezSwarmOnConditionAvailableCheckType,
40
- Field(
41
- "none",
42
- alias="availableCheckType",
43
- title="Available Check Type",
44
- description=("The type of the `available` property to check. "),
45
- ),
46
- ] = "none"
47
- value: Annotated[
48
- Optional[str],
49
- Field(
50
- None,
51
- title="Available",
52
- description=(
53
- "Optional condition to determine if this ON_CONDITION "
54
- "is available. Can be a Callable or a string. If a string, "
55
- " it will look up the value of the context variable with that "
56
- "name, which should be a bool."
57
- ),
58
- ),
59
- ]
60
-
61
- _available_string: str = ""
62
-
63
- @property
64
- def available_string(self) -> str:
65
- """Get the available string.
66
-
67
- Returns
68
- -------
69
- str
70
- The available string.
71
- """
72
- return self._available_string
73
-
74
- def get_available(
75
- self,
76
- name_prefix: Optional[str] = None,
77
- name_suffix: Optional[str] = None,
78
- ) -> Tuple[str, str]:
79
- """Get the available string.
80
-
81
- Parameters
82
- ----------
83
- name_prefix : str, optional
84
- The prefix to add to the function name. Default is None.
85
- name_suffix : str, optional
86
- The suffix to add to the function name. Default is None.
87
-
88
- Returns
89
- -------
90
- Tuple[str, str]
91
- The available string or function name and code if available.
92
- """
93
- if self.type == "none" or not self.value:
94
- return "", ""
95
- if self.type == "string":
96
- return self._available_string, ""
97
- function_name = CUSTOM_ON_CONDITION_AVAILABLE
98
- if name_prefix:
99
- function_name = f"{name_prefix}_{function_name}"
100
- if name_suffix:
101
- function_name = f"{function_name}_{name_suffix}"
102
- return function_name, generate_function(
103
- function_name=function_name,
104
- function_args=CUSTOM_ON_CONDITION_AVAILABLE_ARGS,
105
- function_types=CUSTOM_ON_CONDITION_AVAILABLE_TYPES,
106
- function_body=self._available_string,
107
- )
108
-
109
- @model_validator(mode="after")
110
- def validate_available(self) -> Self:
111
- """Validate the available check.
112
-
113
- Returns
114
- -------
115
- Self
116
- The swarm agent's on condition available model.
117
-
118
- Raises
119
- ------
120
- ValueError
121
- If the available check fails.
122
- """
123
- if self.type == "callable":
124
- if not self.value:
125
- raise ValueError(
126
- "A callable is expected, but no value was provided."
127
- )
128
- is_valid, error_or_body = check_function(
129
- code_string=self.value,
130
- function_name=CUSTOM_ON_CONDITION_AVAILABLE,
131
- function_args=CUSTOM_ON_CONDITION_AVAILABLE_ARGS,
132
- )
133
- if not is_valid:
134
- raise ValueError(error_or_body)
135
- self._available_string = error_or_body
136
- if self.type == "string":
137
- if not self.value:
138
- raise ValueError(
139
- "A string is expected, but no value was provided."
140
- )
141
- self._available_string = self.value
142
- return self
@@ -1,40 +0,0 @@
1
- # SPDX-License-Identifier: Apache-2.0.
2
- # Copyright (c) 2024 - 2025 Waldiez and contributors.
3
- """Swarm condition model for handoff."""
4
-
5
- from pydantic import Field
6
- from typing_extensions import Annotated
7
-
8
- from ...common import WaldiezBase
9
-
10
-
11
- class WaldiezSwarmOnConditionTarget(WaldiezBase):
12
- """Swarm condition target.
13
-
14
- If the condition's target is "agent", the id refers to the agent's ID.
15
- If the condition's target is "nested_chat", the id refers to the edge's ID.
16
-
17
- Attributes
18
- ----------
19
- id : str
20
- The ID of the target agent or edge.
21
- order : int
22
- The order of the target agent or edge.
23
- """
24
-
25
- id: Annotated[
26
- str,
27
- Field(
28
- ...,
29
- title="ID",
30
- description="The ID of the target agent or edge.",
31
- ),
32
- ]
33
- order: Annotated[
34
- int,
35
- Field(
36
- ...,
37
- title="Order",
38
- description="The order of the target agent or edge.",
39
- ),
40
- ]
@@ -1,107 +0,0 @@
1
- # SPDX-License-Identifier: Apache-2.0.
2
- # Copyright (c) 2024 - 2025 Waldiez and contributors.
3
- """Swarm agent."""
4
-
5
- from typing import List, Union
6
-
7
- from pydantic import Field
8
- from typing_extensions import Annotated, Literal
9
-
10
- from ..agent import WaldiezAgent, WaldiezAgentNestedChat
11
- from .after_work import WaldiezSwarmAfterWork
12
- from .on_condition import WaldiezSwarmOnCondition
13
- from .swarm_agent_data import WaldiezSwarmAgentData
14
- from .update_system_message import WaldiezSwarmUpdateSystemMessage
15
-
16
-
17
- class WaldiezSwarmAgent(WaldiezAgent):
18
- """Swarm agent.
19
-
20
- It extends a user agent and has swarm related parameters.
21
-
22
- Attributes
23
- ----------
24
- agent_type : Literal["swarm"]
25
- The agent type: 'swarm' for a swarm agent.
26
- data : WaldiezSwarmAgentData
27
- The swarm agent's data.
28
- See `WaldiezSwarmAgentData` for more info.
29
- """
30
-
31
- agent_type: Annotated[
32
- Literal["swarm"],
33
- Field(
34
- "swarm",
35
- title="Agent type",
36
- description="The agent type: 'swarm' for a swarm agent.",
37
- alias="agentType",
38
- ),
39
- ]
40
-
41
- data: Annotated[
42
- WaldiezSwarmAgentData,
43
- Field(
44
- title="Data",
45
- description="The swarm agent's data",
46
- default_factory=WaldiezSwarmAgentData,
47
- ),
48
- ]
49
-
50
- @property
51
- def functions(self) -> List[str]:
52
- """Get the functions that the agent can use.
53
-
54
- Returns
55
- -------
56
- List[str]
57
- The functions that the agent can use.
58
- """
59
- return self.data.functions
60
-
61
- @property
62
- def update_agent_state_before_reply(
63
- self,
64
- ) -> List[Union[str, WaldiezSwarmUpdateSystemMessage]]:
65
- """Get the functions that update the agent's state before it replies.
66
-
67
- Returns
68
- -------
69
- List[str]
70
- The functions that update the agent's state before it replies.
71
- """
72
- return self.data.update_agent_state_before_reply
73
-
74
- @property
75
- def handoffs(
76
- self,
77
- ) -> List[Union[WaldiezSwarmOnCondition, WaldiezSwarmAfterWork]]:
78
- """Get the hand offs to register.
79
-
80
- Returns
81
- -------
82
- List[str]
83
- The hand offs to register.
84
- """
85
- return self.data.handoffs
86
-
87
- @property
88
- def nested_chats(self) -> List[WaldiezAgentNestedChat]:
89
- """Get the nested chats.
90
-
91
- Returns
92
- -------
93
- List[WaldiezChat]
94
- The nested chats.
95
- """
96
- return self.data.nested_chats
97
-
98
- @property
99
- def is_initial(self) -> bool:
100
- """Check if the agent is the initial agent.
101
-
102
- Returns
103
- -------
104
- bool
105
- Whether the agent is the initial agent.
106
- """
107
- return self.data.is_initial