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
@@ -2,16 +2,21 @@
2
2
  # Copyright (c) 2024 - 2025 Waldiez and contributors.
3
3
  """Chat data model."""
4
4
 
5
- from typing import Any, Dict, List, Optional, Union
5
+ from typing import Any, Optional, Union
6
6
 
7
7
  from pydantic import Field, field_validator, model_validator
8
8
  from typing_extensions import Annotated, Self
9
9
 
10
- from ..agents.swarm_agent import (
11
- WaldiezSwarmAfterWork,
12
- WaldiezSwarmOnConditionAvailable,
10
+ from ..agents import WaldiezAgentType
11
+ from ..common import (
12
+ WaldiezBase,
13
+ WaldiezDefaultCondition,
14
+ WaldiezHandoffCondition,
15
+ WaldiezHandoffTransition,
16
+ WaldiezTransitionAvailability,
17
+ check_function,
18
+ update_dict,
13
19
  )
14
- from ..common import WaldiezBase, check_function, update_dict
15
20
  from .chat_message import (
16
21
  CALLABLE_MESSAGE,
17
22
  CALLABLE_MESSAGE_ARGS,
@@ -28,10 +33,10 @@ class WaldiezChatData(WaldiezBase):
28
33
  ----------
29
34
  name : str
30
35
  The name of the chat.
31
- source : str
32
- The source of the chat (sender).
33
- target : str
34
- The target of the chat (recipient).
36
+ source_type : WaldiezAgentType
37
+ The agent type of the chat source.
38
+ target_type : WaldiezAgentType
39
+ The agent type of the chat target.
35
40
  description : str
36
41
  The description of the chat.
37
42
  position : int
@@ -48,83 +53,54 @@ class WaldiezChatData(WaldiezBase):
48
53
  The summary method and options for the chat.
49
54
  max_turns : Optional[int]
50
55
  The maximum number of turns for the chat, by default None (no limit).
51
- silent : Optional[bool], optional
52
- Whether to run the chat silently, by default None (ignored).
53
- summary_args : Optional[Dict[str, Any]]
56
+ silent : bool, optional
57
+ Whether to run the chat silently, by default False (not silent).
58
+ summary_args : Optional[dict[str, Any]]
54
59
  The summary args to use in autogen.
60
+ handoff_condition : Optional[WaldiezHandoffCondition], optional
61
+ The handoff condition to use, by default None (for group chat).
55
62
  real_source : Optional[str]
56
63
  The real source of the chat (overrides the source).
57
64
  real_target : Optional[str]
58
65
  The real target of the chat (overrides the target).
59
- max_rounds : int
60
- Maximum number of conversation rounds (swarm).
61
- after_work : Optional[WaldiezSwarmAfterWork]
62
- The work to do after the chat (swarm).
63
-
64
- Functions
65
- ---------
66
- validate_message(value: Any)
67
- Validate the message.
68
- validate_summary_method(value: Optional[WaldiezChatSummaryMethod])
69
- Validate the summary method.
70
- serialize_summary_method(value: Any, info: FieldSerializationInfo)
71
- Serialize summary method.
72
- get_chat_args()
73
- Get the chat arguments to use in autogen.
74
66
  """
75
67
 
76
68
  name: Annotated[
77
69
  str, Field(..., title="Name", description="The name of the chat.")
78
70
  ]
79
- source: Annotated[
80
- str,
81
- Field(
82
- ...,
83
- title="Source",
84
- description="The source of the chat (sender).",
85
- ),
86
- ]
87
- target: Annotated[
88
- str,
89
- Field(
90
- ...,
91
- title="Target",
92
- description="The target of the chat (recipient).",
93
- ),
94
- ]
95
71
  description: Annotated[
96
72
  str,
97
73
  Field(
98
- ...,
74
+ default="A new chat",
99
75
  title="Description",
100
76
  description="The description of the chat.",
101
77
  ),
102
- ]
78
+ ] = "A new chat"
103
79
  position: Annotated[
104
80
  int,
105
81
  Field(
106
- -1,
82
+ default=-1,
107
83
  title="Position",
108
84
  description="The position of the chat in the flow (Ignored).",
109
85
  ),
110
- ]
86
+ ] = -1
111
87
  order: Annotated[
112
88
  int,
113
89
  Field(
114
- -1,
90
+ default=-1,
115
91
  title="Order",
116
92
  description="The order of the chat in the flow.",
117
93
  ),
118
- ]
94
+ ] = -1
119
95
  clear_history: Annotated[
120
- Optional[bool],
96
+ bool,
121
97
  Field(
122
- None,
98
+ default=True,
123
99
  alias="clearHistory",
124
100
  title="Clear History",
125
101
  description="Whether to clear the chat history.",
126
102
  ),
127
- ]
103
+ ] = True
128
104
  message: Annotated[
129
105
  Union[str, WaldiezChatMessage],
130
106
  Field(
@@ -153,84 +129,96 @@ class WaldiezChatData(WaldiezBase):
153
129
  max_turns: Annotated[
154
130
  Optional[int],
155
131
  Field(
156
- None,
132
+ default=None,
157
133
  alias="maxTurns",
158
134
  title="Max Turns",
159
135
  description="The maximum number of turns for the chat.",
160
136
  ),
161
- ]
137
+ ] = None
162
138
  prerequisites: Annotated[
163
- List[str],
139
+ list[str],
164
140
  Field(
165
141
  title="Prerequisites",
166
142
  description="The prerequisites (chat ids) for the chat (if async).",
167
143
  default_factory=list,
168
144
  ),
169
- ]
145
+ ] = []
170
146
  silent: Annotated[
171
- Optional[bool],
147
+ bool,
172
148
  Field(
173
- None,
149
+ default=False,
174
150
  title="Silent",
175
151
  description="Whether to run the chat silently.",
176
152
  ),
177
- ]
153
+ ] = False
178
154
  real_source: Annotated[
179
155
  Optional[str],
180
156
  Field(
181
- None,
157
+ default=None,
182
158
  alias="realSource",
183
159
  title="Real Source",
184
160
  description="The real source of the chat (overrides the source).",
185
161
  ),
186
- ]
162
+ ] = None
187
163
  real_target: Annotated[
188
164
  Optional[str],
189
165
  Field(
190
- None,
166
+ default=None,
191
167
  alias="realTarget",
192
168
  title="Real Target",
193
169
  description="The real target of the chat (overrides the target).",
194
170
  ),
195
- ]
196
- max_rounds: Annotated[
197
- int,
171
+ ] = None
172
+ source_type: Annotated[
173
+ WaldiezAgentType,
198
174
  Field(
199
- 20,
200
- title="Max Rounds",
201
- description="Maximum number of conversation rounds.(swarm)",
175
+ ...,
176
+ alias="sourceType",
177
+ title="Source Type",
178
+ description="The agent type of the source.",
202
179
  ),
203
- ] = 20
204
- after_work: Annotated[
205
- Optional[WaldiezSwarmAfterWork],
180
+ ]
181
+ target_type: Annotated[
182
+ WaldiezAgentType,
206
183
  Field(
207
- None,
208
- alias="afterWork",
209
- title="After Work",
210
- description="The work to do after the chat (swarm).",
184
+ ...,
185
+ alias="targetType",
186
+ title="Target Type",
187
+ description="The agent type of the target.",
211
188
  ),
212
- ] = None
213
- context_variables: Annotated[
214
- Optional[Dict[str, Any]],
189
+ ]
190
+ condition: Annotated[
191
+ WaldiezHandoffCondition,
215
192
  Field(
216
- None,
217
- alias="contextVariables",
218
- title="Context Variables",
219
- description="The context variables to use in the chat.",
193
+ default_factory=WaldiezDefaultCondition.create,
194
+ alias="condition",
195
+ title="Handoff Condition",
196
+ description="The handoff condition to use.",
220
197
  ),
221
- ] = None
198
+ ]
222
199
  available: Annotated[
223
- WaldiezSwarmOnConditionAvailable,
200
+ WaldiezTransitionAvailability,
224
201
  Field(
225
- default_factory=WaldiezSwarmOnConditionAvailable,
226
- title="Available",
227
- description="The available condition for the chat.",
202
+ default_factory=WaldiezTransitionAvailability,
203
+ title="Availability",
204
+ description="The availability condition for the chat.",
228
205
  ),
229
206
  ]
230
-
207
+ after_work: Annotated[
208
+ Optional[WaldiezHandoffTransition],
209
+ Field(
210
+ None,
211
+ title="After Work",
212
+ description=(
213
+ "The target to transfer control to after the chat has "
214
+ "finished its work. (used if in a group chat)"
215
+ ),
216
+ alias="afterWork",
217
+ ),
218
+ ] = None
231
219
  _message_content: Optional[str] = None
232
220
  _chat_id: int = 0
233
- _prerequisites: List[int] = []
221
+ _prerequisites: list[int] = []
234
222
 
235
223
  @property
236
224
  def message_content(self) -> Optional[str]:
@@ -257,22 +245,22 @@ class WaldiezChatData(WaldiezBase):
257
245
  """
258
246
  self._chat_id = value
259
247
 
260
- def get_prerequisites(self) -> List[int]:
248
+ def get_prerequisites(self) -> list[int]:
261
249
  """Get the chat prerequisites.
262
250
 
263
251
  Returns
264
252
  -------
265
- List[int]
253
+ list[int]
266
254
  The chat prerequisites (if async).
267
255
  """
268
256
  return self._prerequisites
269
257
 
270
- def set_prerequisites(self, value: List[int]) -> None:
258
+ def set_prerequisites(self, value: list[int]) -> None:
271
259
  """Set the chat prerequisites.
272
260
 
273
261
  Parameters
274
262
  ----------
275
- value : List[int]
263
+ value : list[int]
276
264
  The chat prerequisites to set.
277
265
  """
278
266
  self._prerequisites = value
@@ -309,6 +297,7 @@ class WaldiezChatData(WaldiezBase):
309
297
  self._message_content = error_or_body
310
298
  return self
311
299
 
300
+ # noinspection PyNestedDecorators
312
301
  @field_validator("message", mode="before")
313
302
  @classmethod
314
303
  def validate_message(cls, value: Any) -> WaldiezChatMessage:
@@ -348,62 +337,36 @@ class WaldiezChatData(WaldiezBase):
348
337
  )
349
338
  return value
350
339
 
351
- @field_validator("context_variables", mode="after")
352
- @classmethod
353
- def validate_context_variables(
354
- cls, value: Optional[Dict[str, Any]]
355
- ) -> Optional[Dict[str, Any]]:
356
- """Validate the context variables.
357
-
358
- Parameters
359
- ----------
360
- value : Optional[Dict[str, Any]]
361
- The context variables value.
362
-
363
- Returns
364
- -------
365
- Optional[Dict[str, Any]]
366
- The validated context variables value.
367
-
368
- Raises
369
- ------
370
- ValueError
371
- If the validation fails.
372
- """
373
- if value is None:
374
- return None
375
- return update_dict(value)
376
-
377
340
  @property
378
- def summary_args(self) -> Optional[Dict[str, Any]]:
341
+ def summary_args(self) -> Optional[dict[str, Any]]:
379
342
  """Get the summary args."""
380
343
  if self.summary.method not in (
381
344
  "reflection_with_llm",
382
345
  "reflectionWithLlm",
383
346
  ):
384
347
  return None
385
- args: Dict[str, Any] = {}
386
- if self.summary.prompt:
348
+ args: dict[str, Any] = {}
349
+ if self.summary.prompt: # pragma: no branch
387
350
  args["summary_prompt"] = self.summary.prompt
388
- if self.summary.args:
351
+ if self.summary.args: # pragma: no branch
389
352
  args.update(self.summary.args)
390
353
  return args
391
354
 
392
- def _get_context_args(self) -> Dict[str, Any]:
355
+ def _get_context_args(self) -> dict[str, Any]:
393
356
  """Get the context arguments to use in autogen.
394
357
 
395
358
  Returns
396
359
  -------
397
- Dict[str, Any]
360
+ dict[str, Any]
398
361
  The dictionary to use for generating the kwargs.
399
362
  """
400
- extra_args: Dict[str, Any] = {}
363
+ extra_args: dict[str, Any] = {}
401
364
  if not isinstance(self.message, WaldiezChatMessage): # pragma: no cover
402
365
  return extra_args
403
366
  extra_args.update(update_dict(self.message.context))
404
367
  return extra_args
405
368
 
406
- def get_chat_args(self, for_queue: bool) -> Dict[str, Any]:
369
+ def get_chat_args(self, for_queue: bool) -> dict[str, Any]:
407
370
  """Get the chat arguments to use in autogen.
408
371
 
409
372
  Without the 'message' key.
@@ -415,20 +378,20 @@ class WaldiezChatData(WaldiezBase):
415
378
 
416
379
  Returns
417
380
  -------
418
- Dict[str, Any]
381
+ dict[str, Any]
419
382
  The dictionary to pass as kwargs.
420
383
  """
421
- args: Dict[str, Any] = {}
422
- if self.summary.method:
423
- args["summary_method"] = self.summary.method
384
+ args: dict[str, Any] = {}
385
+ if self.summary.method: # pragma: no branch
386
+ args["summary_method"] = str(self.summary.method)
424
387
  if self.summary_args:
425
388
  args["summary_args"] = self.summary_args
426
- if isinstance(self.max_turns, int) and self.max_turns > 0:
389
+ if (
390
+ isinstance(self.max_turns, int) and self.max_turns > 0
391
+ ): # pragma: no branch
427
392
  args["max_turns"] = self.max_turns
428
- if isinstance(self.clear_history, bool):
429
- args["clear_history"] = self.clear_history
430
- if isinstance(self.silent, bool):
431
- args["silent"] = self.silent
393
+ args["clear_history"] = self.clear_history
394
+ # args["silent"] = self.silent
432
395
  args.update(self._get_context_args())
433
396
  if for_queue:
434
397
  args["chat_id"] = self._chat_id
@@ -2,7 +2,7 @@
2
2
  # Copyright (c) 2024 - 2025 Waldiez and contributors.
3
3
  """Waldiez Message Model."""
4
4
 
5
- from typing import Any, Dict, List, Optional
5
+ from typing import Any, Optional
6
6
 
7
7
  from pydantic import Field, model_validator
8
8
  from typing_extensions import Annotated, Literal, Self
@@ -17,12 +17,12 @@ WaldiezChatMessageType = Literal[
17
17
  CALLABLE_MESSAGE = "callable_message"
18
18
  CALLABLE_MESSAGE_ARGS = ["sender", "recipient", "context"]
19
19
  CALLABLE_MESSAGE_TYPES = (
20
- ["ConversableAgent", "ConversableAgent", "Dict[str, Any]"],
21
- "Union[Dict[str, Any], str]",
20
+ ["ConversableAgent", "ConversableAgent", "dict[str, Any]"],
21
+ "Union[dict[str, Any], str]",
22
22
  )
23
23
  CALLABLE_MESSAGE_RAG_WITH_CARRYOVER_TYPES = (
24
- ["RetrieveUserProxyAgent", "ConversableAgent", "Dict[str, Any]"],
25
- "Union[Dict[str, Any], str]",
24
+ ["RetrieveUserProxyAgent", "ConversableAgent", "dict[str, Any]"],
25
+ "Union[dict[str, Any], str]",
26
26
  )
27
27
 
28
28
 
@@ -52,14 +52,14 @@ class WaldiezChatMessage(WaldiezBase):
52
52
  the `{sender}.message_generator` method will be used.
53
53
  content : Optional[str]
54
54
  The content of the message (string or method).
55
- context : Dict[str, Any]
55
+ context : dict[str, Any]
56
56
  Extra context of the message.
57
57
  """
58
58
 
59
59
  type: Annotated[
60
60
  WaldiezChatMessageType,
61
61
  Field(
62
- "none",
62
+ default="none",
63
63
  title="Type",
64
64
  description=(
65
65
  "The type of the message: "
@@ -72,34 +72,44 @@ class WaldiezChatMessage(WaldiezBase):
72
72
  "the `sender.message_generator` method will be used."
73
73
  ),
74
74
  ),
75
- ]
75
+ ] = "none"
76
76
  use_carryover: Annotated[
77
77
  bool,
78
78
  Field(
79
- False,
79
+ default=False,
80
80
  title="Use Carryover",
81
81
  description="Use the carryover from the context.",
82
82
  ),
83
- ]
83
+ ] = False
84
84
  content: Annotated[
85
85
  Optional[str],
86
86
  Field(
87
- None,
87
+ default=None,
88
88
  title="Content",
89
89
  description="The content of the message (string or method).",
90
90
  ),
91
- ]
91
+ ] = None
92
92
  context: Annotated[
93
- Dict[str, Any],
93
+ dict[str, Any],
94
94
  Field(
95
95
  default_factory=dict,
96
96
  title="Context",
97
97
  description="Extra context of the message.",
98
98
  ),
99
- ]
99
+ ] = {}
100
100
 
101
101
  _content_body: Optional[str] = None
102
102
 
103
+ def is_method(self) -> bool:
104
+ """Check if the message is a method.
105
+
106
+ Returns
107
+ -------
108
+ bool
109
+ True if the message is a method, False otherwise.
110
+ """
111
+ return self.type in ("method", "rag_message_generator")
112
+
103
113
  @property
104
114
  def content_body(self) -> Optional[str]:
105
115
  """Get the content body."""
@@ -144,7 +154,7 @@ class WaldiezChatMessage(WaldiezBase):
144
154
  if not self.content:
145
155
  self.content = ""
146
156
  if self.use_carryover:
147
- content = get_last_carryover_method_content(
157
+ self.content = get_last_carryover_method_content(
148
158
  text_content=self.content,
149
159
  )
150
160
  content = self.content
@@ -162,7 +172,7 @@ class WaldiezChatMessage(WaldiezBase):
162
172
  def validate_method(
163
173
  self,
164
174
  function_name: str,
165
- function_args: List[str],
175
+ function_args: list[str],
166
176
  ) -> str:
167
177
  """Validate a method.
168
178
 
@@ -170,7 +180,7 @@ class WaldiezChatMessage(WaldiezBase):
170
180
  ----------
171
181
  function_name : str
172
182
  The method name.
173
- function_args : List[str]
183
+ function_args : list[str]
174
184
  The expected method arguments.
175
185
 
176
186
  Returns
@@ -219,12 +229,12 @@ def get_last_carryover_method_content(text_content: str) -> str:
219
229
  The source agent.
220
230
  recipient : ConversableAgent
221
231
  The target agent.
222
- context : Dict[str, Any]
232
+ context : dict[str, Any]
223
233
  The context.
224
234
 
225
235
  Returns
226
236
  -------
227
- Union[Dict[str, Any], str]
237
+ Union[dict[str, Any], str]
228
238
  The message to send using the last carryover.
229
239
  """
230
240
  carryover = context.get("carryover", "")
@@ -258,12 +268,12 @@ RAG_METHOD_WITH_CARRYOVER_BODY = '''
258
268
  The source agent.
259
269
  recipient : ConversableAgent
260
270
  The target agent.
261
- context : Dict[str, Any]
271
+ context : dict[str, Any]
262
272
  The context.
263
273
 
264
274
  Returns
265
275
  -------
266
- Union[Dict[str, Any], str]
276
+ Union[dict[str, Any], str]
267
277
  The message to send using the last carryover.
268
278
  """
269
279
  carryover = context.get("carryover", "")
@@ -285,7 +295,7 @@ RAG_METHOD_WITH_CARRYOVER = (
285
295
  "def callable_message(\n"
286
296
  " sender: RetrieveUserProxyAgent,\n"
287
297
  " recipient: ConversableAgent,\n"
288
- " context: Dict[str, Any],\n"
289
- ") -> Union[Dict[str, Any], str]:"
298
+ " context: dict[str, Any],\n"
299
+ ") -> Union[dict[str, Any], str]:"
290
300
  f"{RAG_METHOD_WITH_CARRYOVER_BODY}"
291
301
  )
@@ -16,11 +16,11 @@ NESTED_CHAT_ARGS = ["recipient", "messages", "sender", "config"]
16
16
  NESTED_CHAT_TYPES = (
17
17
  [
18
18
  "ConversableAgent",
19
- "List[Dict[str, Any]]",
19
+ "list[dict[str, Any]]",
20
20
  "ConversableAgent",
21
- "Dict[str, Any]",
21
+ "dict[str, Any]",
22
22
  ],
23
- "Union[Dict[str, Any], str]",
23
+ "Union[dict[str, Any], str]",
24
24
  )
25
25
 
26
26
 
@@ -38,19 +38,19 @@ class WaldiezChatNested(WaldiezBase):
38
38
  message: Annotated[
39
39
  Optional[WaldiezChatMessage],
40
40
  Field(
41
- None,
41
+ default=None,
42
42
  title="Message",
43
43
  description="The message in a nested chat (sender -> recipient).",
44
44
  ),
45
- ]
45
+ ] = None
46
46
  reply: Annotated[
47
47
  Optional[WaldiezChatMessage],
48
48
  Field(
49
- None,
49
+ default=None,
50
50
  title="Reply",
51
51
  description="The reply in a nested chat (recipient -> sender).",
52
52
  ),
53
- ]
53
+ ] = None
54
54
 
55
55
  _message_content: Optional[str] = None
56
56
  _reply_content: Optional[str] = None
@@ -65,6 +65,7 @@ class WaldiezChatNested(WaldiezBase):
65
65
  """Get the reply content."""
66
66
  return self._reply_content
67
67
 
68
+ # noinspection PyNestedDecorators
68
69
  @field_validator("message", "reply", mode="before")
69
70
  @classmethod
70
71
  def validate_message(cls, value: Any) -> WaldiezChatMessage:
@@ -113,27 +114,27 @@ class WaldiezChatNested(WaldiezBase):
113
114
  ValueError
114
115
  If the validation fails.
115
116
  """
116
- if self.message is not None:
117
- self._message_content = self.message.content_body
118
- if self.message.type == "none":
119
- self._message_content = ""
120
- if self.message.type == "string":
121
- self._message_content = self.message.content
122
- if self.message.type == "method":
123
- self._message_content = self.message.validate_method(
124
- function_name=NESTED_CHAT_MESSAGE,
125
- function_args=NESTED_CHAT_ARGS,
126
- )
127
-
128
- if self.reply is not None:
129
- self._reply_content = self.reply.content_body
130
- if self.reply.type == "none":
131
- self._reply_content = ""
132
- if self.reply.type == "string":
133
- self._reply_content = self.reply.content
134
- if self.reply.type == "method":
135
- self._reply_content = self.reply.validate_method(
136
- function_name=NESTED_CHAT_REPLY,
137
- function_args=NESTED_CHAT_ARGS,
138
- )
117
+ for attr, content_attr, function_name in [
118
+ ("message", "_message_content", NESTED_CHAT_MESSAGE),
119
+ ("reply", "_reply_content", NESTED_CHAT_REPLY),
120
+ ]: # pragma: no branch
121
+ attr_value = getattr(self, attr)
122
+ if attr_value is not None:
123
+ if isinstance(
124
+ attr_value, WaldiezChatMessage
125
+ ): # pragma: no branch
126
+ setattr(self, content_attr, attr_value.content_body)
127
+ if attr_value.type == "none":
128
+ setattr(self, content_attr, "")
129
+ elif attr_value.type == "string":
130
+ setattr(self, content_attr, attr_value.content)
131
+ elif attr_value.type == "method": # pragma: no branch
132
+ setattr(
133
+ self,
134
+ content_attr,
135
+ attr_value.validate_method(
136
+ function_name=function_name,
137
+ function_args=NESTED_CHAT_ARGS,
138
+ ),
139
+ )
139
140
  return self