waldiez 0.2.2__py3-none-any.whl → 0.3.0__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 (138) hide show
  1. waldiez/__init__.py +2 -0
  2. waldiez/__main__.py +2 -0
  3. waldiez/_version.py +3 -1
  4. waldiez/cli.py +13 -3
  5. waldiez/cli_extras.py +4 -3
  6. waldiez/conflict_checker.py +4 -3
  7. waldiez/exporter.py +28 -105
  8. waldiez/exporting/__init__.py +8 -9
  9. waldiez/exporting/agent/__init__.py +7 -0
  10. waldiez/exporting/agent/agent_exporter.py +279 -0
  11. waldiez/exporting/agent/utils/__init__.py +23 -0
  12. waldiez/exporting/agent/utils/agent_class_name.py +34 -0
  13. waldiez/exporting/agent/utils/agent_imports.py +50 -0
  14. waldiez/exporting/{agents → agent/utils}/code_execution.py +9 -11
  15. waldiez/exporting/{agents → agent/utils}/group_manager.py +47 -35
  16. waldiez/exporting/{agents → agent/utils}/rag_user/__init__.py +2 -0
  17. waldiez/exporting/{agents → agent/utils}/rag_user/chroma_utils.py +22 -17
  18. waldiez/exporting/{agents → agent/utils}/rag_user/mongo_utils.py +14 -10
  19. waldiez/exporting/{agents → agent/utils}/rag_user/pgvector_utils.py +12 -8
  20. waldiez/exporting/{agents → agent/utils}/rag_user/qdrant_utils.py +11 -8
  21. waldiez/exporting/{agents → agent/utils}/rag_user/rag_user.py +78 -55
  22. waldiez/exporting/{agents → agent/utils}/rag_user/vector_db.py +10 -8
  23. waldiez/exporting/agent/utils/swarm_agent.py +463 -0
  24. waldiez/exporting/{agents → agent/utils}/teachability.py +10 -6
  25. waldiez/exporting/{agents → agent/utils}/termination_message.py +7 -8
  26. waldiez/exporting/base/__init__.py +25 -0
  27. waldiez/exporting/base/agent_position.py +75 -0
  28. waldiez/exporting/base/base_exporter.py +118 -0
  29. waldiez/exporting/base/export_position.py +48 -0
  30. waldiez/exporting/base/import_position.py +23 -0
  31. waldiez/exporting/base/mixin.py +134 -0
  32. waldiez/exporting/base/utils/__init__.py +18 -0
  33. waldiez/exporting/{utils → base/utils}/comments.py +12 -55
  34. waldiez/exporting/{utils → base/utils}/naming.py +14 -4
  35. waldiez/exporting/base/utils/path_check.py +68 -0
  36. waldiez/exporting/{utils/object_string.py → base/utils/to_string.py} +21 -20
  37. waldiez/exporting/chats/__init__.py +5 -12
  38. waldiez/exporting/chats/chats_exporter.py +240 -0
  39. waldiez/exporting/chats/utils/__init__.py +15 -0
  40. waldiez/exporting/chats/utils/common.py +81 -0
  41. waldiez/exporting/chats/{nested.py → utils/nested.py} +125 -86
  42. waldiez/exporting/chats/utils/sequential.py +244 -0
  43. waldiez/exporting/chats/utils/single_chat.py +313 -0
  44. waldiez/exporting/chats/utils/swarm.py +207 -0
  45. waldiez/exporting/flow/__init__.py +5 -3
  46. waldiez/exporting/flow/flow_exporter.py +503 -0
  47. waldiez/exporting/flow/utils/__init__.py +47 -0
  48. waldiez/exporting/flow/utils/agent_utils.py +204 -0
  49. waldiez/exporting/flow/utils/chat_utils.py +71 -0
  50. waldiez/exporting/flow/utils/def_main.py +62 -0
  51. waldiez/exporting/flow/utils/flow_content.py +112 -0
  52. waldiez/exporting/flow/utils/flow_names.py +115 -0
  53. waldiez/exporting/flow/utils/importing_utils.py +179 -0
  54. waldiez/exporting/{utils → flow/utils}/logging_utils.py +34 -31
  55. waldiez/exporting/models/__init__.py +7 -242
  56. waldiez/exporting/models/models_exporter.py +192 -0
  57. waldiez/exporting/models/utils.py +166 -0
  58. waldiez/exporting/skills/__init__.py +7 -161
  59. waldiez/exporting/skills/skills_exporter.py +169 -0
  60. waldiez/exporting/skills/utils.py +281 -0
  61. waldiez/models/__init__.py +25 -7
  62. waldiez/models/agents/__init__.py +70 -0
  63. waldiez/models/agents/agent/__init__.py +11 -1
  64. waldiez/models/agents/agent/agent.py +9 -4
  65. waldiez/models/agents/agent/agent_data.py +3 -1
  66. waldiez/models/agents/agent/code_execution.py +2 -0
  67. waldiez/models/agents/agent/linked_skill.py +2 -0
  68. waldiez/models/agents/agent/nested_chat.py +2 -0
  69. waldiez/models/agents/agent/teachability.py +2 -0
  70. waldiez/models/agents/agent/termination_message.py +49 -13
  71. waldiez/models/agents/agents.py +15 -3
  72. waldiez/models/agents/assistant/__init__.py +2 -0
  73. waldiez/models/agents/assistant/assistant.py +2 -0
  74. waldiez/models/agents/assistant/assistant_data.py +2 -0
  75. waldiez/models/agents/group_manager/__init__.py +9 -1
  76. waldiez/models/agents/group_manager/group_manager.py +2 -0
  77. waldiez/models/agents/group_manager/group_manager_data.py +2 -0
  78. waldiez/models/agents/group_manager/speakers.py +49 -13
  79. waldiez/models/agents/rag_user/__init__.py +21 -4
  80. waldiez/models/agents/rag_user/rag_user.py +3 -1
  81. waldiez/models/agents/rag_user/rag_user_data.py +2 -0
  82. waldiez/models/agents/rag_user/retrieve_config.py +268 -17
  83. waldiez/models/agents/rag_user/vector_db_config.py +5 -3
  84. waldiez/models/agents/swarm_agent/__init__.py +49 -0
  85. waldiez/models/agents/swarm_agent/after_work.py +178 -0
  86. waldiez/models/agents/swarm_agent/on_condition.py +103 -0
  87. waldiez/models/agents/swarm_agent/on_condition_available.py +140 -0
  88. waldiez/models/agents/swarm_agent/on_condition_target.py +40 -0
  89. waldiez/models/agents/swarm_agent/swarm_agent.py +107 -0
  90. waldiez/models/agents/swarm_agent/swarm_agent_data.py +125 -0
  91. waldiez/models/agents/swarm_agent/update_system_message.py +144 -0
  92. waldiez/models/agents/user_proxy/__init__.py +2 -0
  93. waldiez/models/agents/user_proxy/user_proxy.py +2 -0
  94. waldiez/models/agents/user_proxy/user_proxy_data.py +2 -0
  95. waldiez/models/chat/__init__.py +21 -3
  96. waldiez/models/chat/chat.py +241 -7
  97. waldiez/models/chat/chat_data.py +192 -48
  98. waldiez/models/chat/chat_message.py +153 -144
  99. waldiez/models/chat/chat_nested.py +33 -53
  100. waldiez/models/chat/chat_summary.py +2 -0
  101. waldiez/models/common/__init__.py +6 -6
  102. waldiez/models/common/base.py +4 -1
  103. waldiez/models/common/method_utils.py +163 -83
  104. waldiez/models/flow/__init__.py +2 -0
  105. waldiez/models/flow/flow.py +176 -40
  106. waldiez/models/flow/flow_data.py +63 -2
  107. waldiez/models/flow/utils.py +172 -0
  108. waldiez/models/model/__init__.py +2 -0
  109. waldiez/models/model/model.py +25 -6
  110. waldiez/models/model/model_data.py +3 -1
  111. waldiez/models/skill/__init__.py +4 -1
  112. waldiez/models/skill/skill.py +30 -2
  113. waldiez/models/skill/skill_data.py +2 -0
  114. waldiez/models/waldiez.py +28 -4
  115. waldiez/runner.py +142 -228
  116. waldiez/running/__init__.py +33 -0
  117. waldiez/running/environment.py +83 -0
  118. waldiez/running/gen_seq_diagram.py +185 -0
  119. waldiez/running/running.py +300 -0
  120. {waldiez-0.2.2.dist-info → waldiez-0.3.0.dist-info}/METADATA +32 -26
  121. waldiez-0.3.0.dist-info/RECORD +125 -0
  122. waldiez-0.3.0.dist-info/licenses/LICENSE +201 -0
  123. waldiez/exporting/agents/__init__.py +0 -5
  124. waldiez/exporting/agents/agent.py +0 -236
  125. waldiez/exporting/agents/agent_skills.py +0 -67
  126. waldiez/exporting/agents/llm_config.py +0 -53
  127. waldiez/exporting/chats/chats.py +0 -46
  128. waldiez/exporting/chats/helpers.py +0 -420
  129. waldiez/exporting/flow/def_main.py +0 -32
  130. waldiez/exporting/flow/flow.py +0 -189
  131. waldiez/exporting/utils/__init__.py +0 -36
  132. waldiez/exporting/utils/importing.py +0 -265
  133. waldiez/exporting/utils/method_utils.py +0 -35
  134. waldiez/exporting/utils/path_check.py +0 -51
  135. waldiez-0.2.2.dist-info/RECORD +0 -92
  136. waldiez-0.2.2.dist-info/licenses/LICENSE +0 -21
  137. {waldiez-0.2.2.dist-info → waldiez-0.3.0.dist-info}/WHEEL +0 -0
  138. {waldiez-0.2.2.dist-info → waldiez-0.3.0.dist-info}/entry_points.txt +0 -0
@@ -0,0 +1,207 @@
1
+ # SPDX-License-Identifier: Apache-2.0.
2
+ # Copyright (c) 2024 - 2025 Waldiez and contributors.
3
+ # flake8: noqa E501
4
+ """Swarm chat exporting functions."""
5
+
6
+ from typing import Callable, Dict, List, Optional, Tuple
7
+
8
+ from waldiez.models import WaldiezAgent, WaldiezChat
9
+
10
+
11
+ # pylint: disable=too-many-locals,line-too-long
12
+ def export_swarm_chat(
13
+ chat: WaldiezChat,
14
+ agent_names: Dict[str, str],
15
+ chat_names: Dict[str, str],
16
+ sender: WaldiezAgent,
17
+ recipient: WaldiezAgent,
18
+ get_swarm_members: Callable[
19
+ [WaldiezAgent], Tuple[List[WaldiezAgent], WaldiezAgent | None]
20
+ ],
21
+ serializer: Callable[..., str],
22
+ string_escape: Callable[[str], str],
23
+ tabs: int,
24
+ is_async: bool,
25
+ ) -> Tuple[str, str]:
26
+ """Get the swarm chat message string.
27
+
28
+ Parameters
29
+ ----------
30
+ chat : WaldiezChat
31
+ The chat.
32
+ agent_names : Dict[str, str]
33
+ A mapping of agent id to agent name.
34
+ chat_names : Dict[str, str]
35
+ A mapping of chat id to chat name.
36
+ sender : WaldiezAgent
37
+ The sender.
38
+ recipient : WaldiezAgent
39
+ The recipient.
40
+ get_swarm_members: Callable[[WaldiezAgent], Tuple[List[WaldiezAgent], WaldiezAgent | None]],
41
+ The function to get the swarm members.
42
+ serializer : Callable[..., str]
43
+ The function to generate the string representation of an object.
44
+ string_escape : Callable[[str], str]
45
+ The function to escape the string.
46
+ tabs : int
47
+ The number of tabs to use for indentation.
48
+ is_async : bool
49
+ Whether the chat is asynchronous.
50
+ Returns
51
+ -------
52
+ Tuple[str, str]
53
+ The `initiate_swarm_chat` message string and additional methods string.
54
+
55
+ Raises
56
+ ------
57
+ ValueError
58
+ If neither the sender nor the recipient is a swarm agent.
59
+ """
60
+ # either the sender or the recipient can be the swarm agent
61
+ # one of them MUST be the swarm agent.
62
+ if sender.agent_type != "swarm" and recipient.agent_type != "swarm":
63
+ raise ValueError("One of the agents must be a swarm agent")
64
+ initial_agent = sender if sender.agent_type == "swarm" else recipient
65
+ tab = " " * tabs if tabs > 0 else ""
66
+ swarm_members = get_swarm_members(initial_agent)
67
+ swarm_agents_string, user_agent_string = get_swarm_agents_strings(
68
+ swarm_members=swarm_members,
69
+ sender=sender,
70
+ recipient=recipient,
71
+ agent_names=agent_names,
72
+ user_agent=None,
73
+ )
74
+ messages_string = get_swarm_messages_string(
75
+ chat=chat, string_escape=string_escape
76
+ )
77
+ context_vars_string = (
78
+ serializer(chat.context_variables, tabs=tabs + 1)
79
+ if chat.context_variables
80
+ else "{}"
81
+ )
82
+ chat_name = chat_names[chat.id]
83
+ after_work_string, additional_methods = get_swarm_after_work_string(
84
+ chat=chat,
85
+ agent_names=agent_names,
86
+ name_suffix=chat_name,
87
+ )
88
+ agent_name = agent_names[initial_agent.id]
89
+ results_is = f"{tab}results, _, __ = "
90
+ initiate = "initiate_swarm_chat"
91
+ if is_async:
92
+ results_is += "await "
93
+ initiate = "a_initiate_swarm_chat"
94
+ initiate_chat = "\n" + f"{results_is}{initiate}(" + "\n"
95
+ initiate_chat += f"{tab} initial_agent={agent_name}," + "\n"
96
+ initiate_chat += f"{tab} agents=[{swarm_agents_string}]," + "\n"
97
+ initiate_chat += f"{tab} messages={messages_string}," + "\n"
98
+ initiate_chat += f"{tab} context_variables={context_vars_string}," + "\n"
99
+ initiate_chat += f"{tab} user_agent={user_agent_string}," + "\n"
100
+ initiate_chat += f"{tab} after_work={after_work_string}," + "\n"
101
+ initiate_chat += f"{tab} max_rounds={chat.max_rounds}," + "\n"
102
+ initiate_chat += f"{tab})" + "\n"
103
+ return initiate_chat, additional_methods
104
+
105
+
106
+ def get_swarm_agents_strings(
107
+ swarm_members: Tuple[List[WaldiezAgent], WaldiezAgent | None],
108
+ sender: WaldiezAgent,
109
+ recipient: WaldiezAgent,
110
+ agent_names: Dict[str, str],
111
+ user_agent: Optional[WaldiezAgent],
112
+ ) -> Tuple[str, str]:
113
+ """Get the swarm agent strings to use in `initiate_swarm_chat`.
114
+
115
+ Parameters
116
+ ----------
117
+ swarm_members : Tuple[List[WaldiezAgent], WaldiezAgent | None]
118
+ The swarm agents and the user agent.
119
+ sender : WaldiezAgent
120
+ The chat initiator.
121
+ recipient : WaldiezAgent
122
+ The chat recipient.
123
+ agent_names : Dict[str, str]
124
+ A mapping of agent id to agent name.
125
+ user_agent : Optional[WaldiezAgent]
126
+ The user agent.
127
+ Returns
128
+ -------
129
+ Tuple[str, str]
130
+ The swarm agents string and the user agent string.
131
+ """
132
+ swarm_agents, user_member = swarm_members
133
+ if user_agent is None and user_member is not None:
134
+ user_agent = user_member
135
+ if user_agent is None: # pragma: no cover
136
+ if sender.agent_type in ("user", "rag_user"):
137
+ user_agent = sender
138
+ elif recipient.agent_type in ("user", "rag_user"):
139
+ user_agent = recipient
140
+ agents_string = ", ".join(
141
+ [f"{agent_names[agent.id]}" for agent in swarm_agents]
142
+ )
143
+ user_agent_string = "None"
144
+ if user_agent:
145
+ user_agent_string = agent_names[user_agent.id]
146
+ return agents_string, user_agent_string
147
+
148
+
149
+ def get_swarm_messages_string(
150
+ chat: WaldiezChat,
151
+ string_escape: Callable[[str], str],
152
+ ) -> str:
153
+ """Get the swarm chat messages string to use in `initiate_swarm_chat`.
154
+
155
+ Parameters
156
+ ----------
157
+ chat : WaldiezChat
158
+ The chat.
159
+ string_escape : Callable[[str], str]
160
+ The string escape function.
161
+
162
+ Returns
163
+ -------
164
+ str
165
+ The swarm chat messages string.
166
+ """
167
+ chat_message = chat.message
168
+ if chat.message.type == "string" and chat_message.content:
169
+ messages_string = '[{"role": "user", "content": '
170
+ escaped_message = string_escape(chat_message.content)
171
+ messages_string += f'"{escaped_message}"'
172
+ messages_string += "}]"
173
+ else:
174
+ messages_string = '"Start the chat."'
175
+ return messages_string
176
+
177
+
178
+ def get_swarm_after_work_string(
179
+ chat: WaldiezChat,
180
+ agent_names: Dict[str, str],
181
+ name_suffix: str,
182
+ ) -> Tuple[str, str]:
183
+ """Get the swarm after work string.
184
+
185
+ Parameters
186
+ ----------
187
+ chat : WaldiezChat
188
+ The chat.
189
+ agent_names : Dict[str, str]
190
+ A mapping of agent id to agent name.
191
+ name_suffix : str
192
+ The suffix to use for the function name.
193
+ Returns
194
+ -------
195
+ Tuple[str, str]
196
+ The after work string and the additional methods string.
197
+ """
198
+ if not chat.after_work:
199
+ return "AFTER_WORK(AfterWorkOption.TERMINATE)", ""
200
+ additional_methods = ""
201
+ after_work_string, function_content = chat.after_work.get_recipient(
202
+ agent_names=agent_names,
203
+ name_suffix=name_suffix,
204
+ )
205
+ if chat.after_work.recipient_type == "callable" and function_content:
206
+ additional_methods = "\n" + f"{function_content}" + "\n"
207
+ return after_work_string, additional_methods
@@ -1,5 +1,7 @@
1
- """Export the entire flow to string."""
1
+ # SPDX-License-Identifier: Apache-2.0.
2
+ # Copyright (c) 2024 - 2025 Waldiez and contributors.
3
+ """Flow exporter."""
2
4
 
3
- from .flow import export_flow
5
+ from .flow_exporter import FlowExporter
4
6
 
5
- __all__ = ["export_flow"]
7
+ __all__ = ["FlowExporter"]