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
@@ -3,7 +3,7 @@
3
3
  # pylint: disable=too-many-locals
4
4
  """Nested chats exporting."""
5
5
 
6
- from typing import Callable, Dict, List, Optional, Tuple
6
+ from typing import Any, Callable, Optional
7
7
 
8
8
  from waldiez.models import (
9
9
  WaldiezAgent,
@@ -12,16 +12,15 @@ from waldiez.models import (
12
12
  WaldiezChat,
13
13
  )
14
14
 
15
- from .common import update_summary_chat_args
15
+ # from .common import update_summary_chat_args
16
16
 
17
17
 
18
18
  def export_nested_chat_registration(
19
19
  agent: WaldiezAgent,
20
- all_chats: List[WaldiezChat],
21
- chat_names: Dict[str, str],
22
- agent_names: Dict[str, str],
20
+ all_chats: list[WaldiezChat],
21
+ chat_names: dict[str, str],
22
+ agent_names: dict[str, str],
23
23
  serializer: Callable[..., str],
24
- string_escape: Callable[[str], str],
25
24
  is_async: bool,
26
25
  ) -> str:
27
26
  """Get the nested chat string.
@@ -30,16 +29,14 @@ def export_nested_chat_registration(
30
29
  ----------
31
30
  agent : WaldiezAgent
32
31
  The agent.
33
- all_chats : List[WaldiezChat]
32
+ all_chats : list[WaldiezChat]
34
33
  All the chats in the flow.
35
- chat_names : Dict[str, str]
34
+ chat_names : dict[str, str]
36
35
  The chat names.
37
- agent_names : Dict[str, str]
36
+ agent_names : dict[str, str]
38
37
  The agent names.
39
38
  serializer : Callable[..., str]
40
39
  The serializer to use to escape quotes in a string.
41
- string_escape : Callable[[str], str]
42
- The string escape function.
43
40
  is_async : bool
44
41
  Whether the chat is asynchronous.
45
42
 
@@ -51,7 +48,7 @@ def export_nested_chat_registration(
51
48
  if not agent.data.nested_chats:
52
49
  return ""
53
50
  content = ""
54
- extra_contents = []
51
+ extra_contents: list[str] = []
55
52
  agent_name = agent_names[agent.id]
56
53
  use_suffix = len(agent.data.nested_chats) > 1
57
54
  for index, entry in enumerate(agent.data.nested_chats):
@@ -65,7 +62,6 @@ def export_nested_chat_registration(
65
62
  chat_names=chat_names,
66
63
  all_chats=all_chats,
67
64
  serializer=serializer,
68
- string_escape=string_escape,
69
65
  )
70
66
  if not chat_queue: # pragma: no cover
71
67
  continue
@@ -75,9 +71,9 @@ def export_nested_chat_registration(
75
71
  if use_suffix
76
72
  else f"{agent_name}_chat_queue"
77
73
  )
78
- content += f"{var_name} = {chat_queue}" + "\n"
74
+ content += f"{var_name}: list[dict[str, Any]] = {chat_queue}" + "\n"
79
75
  content += f"""
80
- {agent_name}.register_nested_chats(
76
+ {agent_name}.register_nested_chats( # pyright: ignore
81
77
  trigger={trigger_names},
82
78
  chat_queue={var_name},
83
79
  use_async={is_async},
@@ -100,7 +96,7 @@ def export_nested_chat_registration(
100
96
 
101
97
  def get_nested_chat_trigger_agent_names(
102
98
  nested_chat: WaldiezAgentNestedChat,
103
- agent_names: Dict[str, str],
99
+ agent_names: dict[str, str],
104
100
  ) -> str:
105
101
  """Get the trigger agent names for the nested chat.
106
102
 
@@ -108,7 +104,7 @@ def get_nested_chat_trigger_agent_names(
108
104
  ----------
109
105
  nested_chat : WaldiezAgentNestedChat
110
106
  The nested chat.
111
- agent_names : Dict[str, str]
107
+ agent_names : dict[str, str]
112
108
  A mapping of agent id to agent name.
113
109
 
114
110
  Returns
@@ -126,11 +122,10 @@ def get_nested_chat_message_string(
126
122
  waldiez_chat: WaldiezChat,
127
123
  message: WaldiezAgentNestedChatMessage,
128
124
  agent: WaldiezAgent,
129
- agent_names: Dict[str, str],
130
- chat_names: Dict[str, str],
125
+ agent_names: dict[str, str],
126
+ chat_names: dict[str, str],
131
127
  serializer: Callable[..., str],
132
- string_escape: Callable[[str], str],
133
- ) -> Tuple[str, Optional[str]]:
128
+ ) -> tuple[str, Optional[str]]:
134
129
  """Get the nested chat message string.
135
130
 
136
131
  Parameters
@@ -141,18 +136,16 @@ def get_nested_chat_message_string(
141
136
  The message.
142
137
  agent : WaldiezAgent
143
138
  The agent.
144
- agent_names : Dict[str, str]
139
+ agent_names : dict[str, str]
145
140
  A mapping of agent id to agent name.
146
- chat_names : Dict[str, str]
141
+ chat_names : dict[str, str]
147
142
  A mapping of chat id to chat name.
148
143
  serializer : Callable[..., str]
149
144
  The function to serialize the chat arguments.
150
- string_escape : Callable[[str], str]
151
- The function to escape the string.
152
145
 
153
146
  Returns
154
147
  -------
155
- Tuple[str, Optional[str]]
148
+ tuple[str, Optional[str]]
156
149
  The message string and the method name if the message is a method.
157
150
  """
158
151
  sender_name: Optional[str] = None
@@ -163,8 +156,8 @@ def get_nested_chat_message_string(
163
156
  if sender_id != agent.id:
164
157
  sender_name = agent_names[sender_id]
165
158
  recipient_name = agent_names[recipient_id]
166
- chat_dict = waldiez_chat.get_chat_args(for_queue=True)
167
- chat_dict = update_summary_chat_args(chat_dict, string_escape)
159
+ chat_dict: dict[str, Any] = waldiez_chat.get_chat_args(for_queue=True)
160
+ # chat_dict = update_summary_chat_args(chat_dict)
168
161
  chat_dict["recipient"] = recipient_name
169
162
  if sender_name:
170
163
  chat_dict["sender"] = sender_name
@@ -172,7 +165,6 @@ def get_nested_chat_message_string(
172
165
  chat=waldiez_chat,
173
166
  is_reply=message.is_reply,
174
167
  chat_names=chat_names,
175
- string_escape=string_escape,
176
168
  )
177
169
  chat_dict["message"] = message_value
178
170
  message_dict_str = serializer(chat_dict, tabs=1)
@@ -180,7 +172,7 @@ def get_nested_chat_message_string(
180
172
  # it's not a string, its the name of the function
181
173
  message_dict_str = message_dict_str.replace(
182
174
  f': "{message_value}"', f": {message_value}"
183
- )
175
+ ).replace(f'"{message_value}"', f"{message_value}")
184
176
  if sender_name:
185
177
  message_dict_str = message_dict_str.replace(
186
178
  f': "{sender_name}"', f": {sender_name}"
@@ -195,12 +187,11 @@ def get_nested_chat_message_string(
195
187
  def get_nested_chat_queue(
196
188
  nested_chat: WaldiezAgentNestedChat,
197
189
  agent: WaldiezAgent,
198
- agent_names: Dict[str, str],
199
- chat_names: Dict[str, str],
200
- all_chats: List[WaldiezChat],
190
+ agent_names: dict[str, str],
191
+ chat_names: dict[str, str],
192
+ all_chats: list[WaldiezChat],
201
193
  serializer: Callable[..., str],
202
- string_escape: Callable[[str], str],
203
- ) -> Tuple[str, List[str]]:
194
+ ) -> tuple[str, list[str]]:
204
195
  """Get the nested chat queue.
205
196
 
206
197
  Parameters
@@ -209,24 +200,22 @@ def get_nested_chat_queue(
209
200
  The nested chat.
210
201
  agent : WaldiezAgent
211
202
  The agent.
212
- agent_names : Dict[str, str]
203
+ agent_names : dict[str, str]
213
204
  A mapping of agent id to agent name.
214
- chat_names : Dict[str, str]
205
+ chat_names : dict[str, str]
215
206
  A mapping of chat id to chat name.
216
- all_chats : List[WaldiezChat]
207
+ all_chats : list[WaldiezChat]
217
208
  All the chats in the flow.
218
209
  serializer : Callable[..., str]
219
210
  The serializer to use to escape quotes in a string.
220
- string_escape : Callable[[str], str]
221
- The function to escape the string.
222
211
 
223
212
  Returns
224
213
  -------
225
- Tuple[str, List[str]]
214
+ tuple[str, list[str]]
226
215
  The nested chat queue and the methods to include
227
216
  (methods: message string and method name if the message is a method).
228
217
  """
229
- message_methods_to_include = []
218
+ message_methods_to_include: list[str] = []
230
219
  chat_messages_str = "[\n"
231
220
  for message in nested_chat.messages:
232
221
  waldiez_chat = next(chat for chat in all_chats if chat.id == message.id)
@@ -237,7 +226,6 @@ def get_nested_chat_queue(
237
226
  agent_names=agent_names,
238
227
  chat_names=chat_names,
239
228
  serializer=serializer,
240
- string_escape=string_escape,
241
229
  )
242
230
  if message_source:
243
231
  message_methods_to_include.append(message_source)
@@ -251,9 +239,8 @@ def get_nested_chat_queue(
251
239
  def get_chat_nested_string(
252
240
  chat: WaldiezChat,
253
241
  is_reply: bool,
254
- chat_names: Dict[str, str],
255
- string_escape: Callable[[str], str],
256
- ) -> Tuple[str, Optional[str]]:
242
+ chat_names: dict[str, str],
243
+ ) -> tuple[str, Optional[str]]:
257
244
  """Get the nested chat message.
258
245
 
259
246
  Parameters
@@ -262,14 +249,12 @@ def get_chat_nested_string(
262
249
  The chat.
263
250
  is_reply : bool
264
251
  Whether to use the nested chat's reply message or not.
265
- chat_names : Dict[str, str]
266
- A mapping of chat id to chat name.
267
- string_escape : Callable[[str], str]
268
- The function to escape the string.
252
+ chat_names : dict[str, str]
253
+ A mapping of chat id to chat name..
269
254
 
270
255
  Returns
271
256
  -------
272
- Tuple[str, Optional[str]]
257
+ tuple[str, Optional[str]]
273
258
  If the message is a string, the message content and None.
274
259
  If the message is a method, the method name and the method content.
275
260
  If the message is None, 'None' and None.
@@ -282,7 +267,7 @@ def get_chat_nested_string(
282
267
  if not message or message.type == "none" or message.content is None:
283
268
  return "None", None
284
269
  if message.type == "string":
285
- return string_escape(message.content), None
270
+ return message.content, None
286
271
  chat_name = chat_names[chat.id]
287
272
  if is_reply:
288
273
  function_content, function_name = chat.get_nested_chat_message_function(
@@ -2,49 +2,48 @@
2
2
  # Copyright (c) 2024 - 2025 Waldiez and contributors.
3
3
  """Utility functions for exporting sequential chats."""
4
4
 
5
- from typing import Callable, Dict, List, Tuple
5
+ from typing import Callable
6
6
 
7
7
  from waldiez.models import (
8
- WaldiezAgent,
9
- WaldiezChat,
8
+ WaldiezAgentConnection,
10
9
  WaldiezChatMessage,
11
- WaldiezRagUser,
10
+ WaldiezRagUserProxy,
12
11
  )
13
12
 
14
- from .common import get_chat_message_string, update_summary_chat_args
13
+ from .common import get_chat_message_string
15
14
 
16
15
 
17
16
  def export_sequential_chat(
18
- main_chats: List[Tuple[WaldiezChat, WaldiezAgent, WaldiezAgent]],
19
- chat_names: Dict[str, str],
20
- agent_names: Dict[str, str],
17
+ main_chats: list[WaldiezAgentConnection],
18
+ chat_names: dict[str, str],
19
+ agent_names: dict[str, str],
21
20
  serializer: Callable[..., str],
22
- string_escape: Callable[[str], str],
23
21
  tabs: int,
24
22
  is_async: bool,
25
- ) -> Tuple[str, str]:
23
+ skip_cache: bool,
24
+ ) -> tuple[str, str]:
26
25
  r"""Get the chats content, when there are more than one chats in the flow.
27
26
 
28
27
  Parameters
29
28
  ----------
30
- main_chats : List[Tuple[WaldiezChat, WaldiezAgent, WaldiezAgent]]
29
+ main_chats : list[WaldiezAgentConnection]
31
30
  The main chats.
32
- chat_names : Dict[str, str]
31
+ chat_names : dict[str, str]
33
32
  A mapping of chat id to chat name.
34
- agent_names : Dict[str, str]
33
+ agent_names : dict[str, str]
35
34
  A mapping of agent id to agent name.
36
35
  serializer : Callable[..., str]
37
36
  The serializer function to escape quotes in a string.
38
- string_escape : Callable[[str], str]
39
- The string escape function.
40
37
  tabs : int
41
38
  The number of tabs to use for indentation.
42
39
  is_async : bool
43
40
  Whether the chat is asynchronous.
41
+ skip_cache : bool
42
+ Whether to skip the cache argument.
44
43
 
45
44
  Returns
46
45
  -------
47
- Tuple[str, str]
46
+ tuple[str, str]
48
47
  The main chats content and additional methods string if any.
49
48
 
50
49
  Example
@@ -117,16 +116,14 @@ def export_sequential_chat(
117
116
  content = "\n"
118
117
  additional_methods_string = ""
119
118
  content += _get_initiate_chats_line(tab, is_async)
120
- for chat, sender, recipient in main_chats:
119
+ for connection in main_chats:
121
120
  chat_string, additional_methods = _get_chat_dict_string(
122
- chat=chat,
123
121
  chat_names=chat_names,
124
- sender=sender,
125
- recipient=recipient,
122
+ connection=connection,
126
123
  agent_names=agent_names,
127
124
  serializer=serializer,
128
- string_escape=string_escape,
129
125
  tabs=tabs + 1,
126
+ skip_cache=skip_cache,
130
127
  )
131
128
  additional_methods_string += additional_methods
132
129
  content += "\n" + f"{tab} {chat_string}"
@@ -134,17 +131,14 @@ def export_sequential_chat(
134
131
  return content, additional_methods_string
135
132
 
136
133
 
137
- # pylint: disable=too-many-locals
138
134
  def _get_chat_dict_string(
139
- chat: WaldiezChat,
140
- sender: WaldiezAgent,
141
- recipient: WaldiezAgent,
142
- chat_names: Dict[str, str],
143
- agent_names: Dict[str, str],
135
+ connection: WaldiezAgentConnection,
136
+ chat_names: dict[str, str],
137
+ agent_names: dict[str, str],
144
138
  serializer: Callable[..., str],
145
- string_escape: Callable[[str], str],
146
139
  tabs: int,
147
- ) -> Tuple[str, str]:
140
+ skip_cache: bool,
141
+ ) -> tuple[str, str]:
148
142
  """Get a chat dictionary string.
149
143
 
150
144
  If the chat message is a separate method and not a string or a lambda,
@@ -153,62 +147,50 @@ def _get_chat_dict_string(
153
147
 
154
148
  Parameters
155
149
  ----------
156
- chat : WaldiezChat
157
- The chat.
158
- sender : WaldiezAgent
159
- The sender.
160
- recipient : WaldiezAgent
161
- The recipient.
162
- chat_names : Dict[str, str]
150
+ connection : WaldiezAgentConnection
151
+ The connection object containing the chat and agents.
152
+ chat_names : dict[str, str]
163
153
  A mapping of chat id to chat name.
164
- agent_names : Dict[str, str]
154
+ agent_names : dict[str, str]
165
155
  A mapping of agent id to agent name.
166
156
  serializer : Callable[[str], str]
167
157
  The function to serialize the dictionaries or lists.
168
- string_escape : Callable[[str], str]
169
- The function to escape the string.
170
158
  tabs : int
171
159
  The number of tabs to use for indentation.
160
+ skip_cache : bool
161
+ Whether to skip the cache argument.
172
162
 
173
163
  Returns
174
164
  -------
175
- Tuple[str, str]
165
+ tuple[str, str]
176
166
  The chat dictionary string and additional methods string if any.
177
167
  """
178
168
  tab = " " * tabs
179
- chat_args = chat.get_chat_args(for_queue=True, sender=sender)
180
- chat_args = update_summary_chat_args(chat_args, string_escape)
181
- chat_string = "{"
182
- chat_string += "\n" + f'{tab} "sender": {agent_names[sender.id]},'
183
- chat_string += "\n" + f'{tab} "recipient": {agent_names[recipient.id]},'
184
- chat_string += "\n" + f'{tab} "cache": cache,'
185
- additional_methods_string = ""
186
- for key, value in chat_args.items():
187
- if isinstance(value, str):
188
- chat_string += "\n" + f'{tab} "{key}": "{value}",'
189
- elif isinstance(value, dict):
190
- chat_string += (
191
- "\n" + f'{tab} "{key}": {serializer(value, tabs=tabs + 1)},'
192
- )
193
- else:
194
- chat_string += "\n" + f'{tab} "{key}": {value},'
169
+ chat = connection["chat"]
170
+ sender = connection["source"]
171
+ chat_string = _get_chat_strig_start(
172
+ connection=connection,
173
+ agent_names=agent_names,
174
+ serializer=serializer,
175
+ tabs=tabs,
176
+ skip_cache=skip_cache,
177
+ )
195
178
  if (
196
- sender.agent_type == "rag_user"
197
- and isinstance(sender, WaldiezRagUser)
179
+ sender.is_rag_user
180
+ and isinstance(sender, WaldiezRagUserProxy)
198
181
  and chat.message.type == "rag_message_generator"
199
182
  ):
200
183
  message = f"{agent_names[sender.id]}.message_generator"
201
184
  chat_string += "\n" + f'{tab} "message": {message},'
202
185
  chat_string += "\n" + tab + "},"
203
- return chat_string, additional_methods_string
186
+ return chat_string, ""
187
+ additional_methods_string = ""
204
188
  message, method_content = get_chat_message_string(
205
189
  sender=sender,
206
190
  chat=chat,
207
191
  chat_names=chat_names,
208
- string_escape=string_escape,
209
192
  )
210
193
  if message and isinstance(chat.data.message, WaldiezChatMessage):
211
- message = string_escape(message)
212
194
  if chat.data.message.type == "method":
213
195
  if method_content:
214
196
  additional_methods_string += "\n" + method_content
@@ -219,6 +201,35 @@ def _get_chat_dict_string(
219
201
  return chat_string, additional_methods_string
220
202
 
221
203
 
204
+ def _get_chat_strig_start(
205
+ connection: WaldiezAgentConnection,
206
+ agent_names: dict[str, str],
207
+ serializer: Callable[..., str],
208
+ tabs: int,
209
+ skip_cache: bool,
210
+ ) -> str:
211
+ tab = " " * tabs
212
+ chat = connection["chat"]
213
+ sender = connection["source"]
214
+ recipient = connection["target"]
215
+ chat_args = chat.get_chat_args(for_queue=True, sender=sender)
216
+ # chat_args = update_summary_chat_args(chat_args)
217
+ chat_string = "{"
218
+ chat_string += "\n" + f'{tab} "sender": {agent_names[sender.id]},'
219
+ chat_string += "\n" + f'{tab} "recipient": {agent_names[recipient.id]},'
220
+ if skip_cache is False:
221
+ chat_string += "\n" + f'{tab} "cache": cache,'
222
+ # additional_methods_string = ""
223
+ for key, value in chat_args.items():
224
+ if isinstance(value, (dict, str)):
225
+ chat_string += (
226
+ "\n" + f'{tab} "{key}": {serializer(value, tabs=tabs + 1)},'
227
+ )
228
+ else:
229
+ chat_string += "\n" + f'{tab} "{key}": {value},'
230
+ return chat_string
231
+
232
+
222
233
  def _get_initiate_chats_line(
223
234
  tab: str,
224
235
  is_async: bool,