waldiez 0.2.1__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.
- waldiez/__init__.py +2 -0
- waldiez/__main__.py +2 -0
- waldiez/_version.py +3 -1
- waldiez/cli.py +13 -3
- waldiez/cli_extras.py +25 -27
- waldiez/conflict_checker.py +4 -3
- waldiez/exporter.py +28 -105
- waldiez/exporting/__init__.py +8 -9
- waldiez/exporting/agent/__init__.py +7 -0
- waldiez/exporting/agent/agent_exporter.py +279 -0
- waldiez/exporting/agent/utils/__init__.py +23 -0
- waldiez/exporting/agent/utils/agent_class_name.py +34 -0
- waldiez/exporting/agent/utils/agent_imports.py +50 -0
- waldiez/exporting/{agents → agent/utils}/code_execution.py +9 -11
- waldiez/exporting/{agents → agent/utils}/group_manager.py +47 -35
- waldiez/exporting/{agents → agent/utils}/rag_user/__init__.py +2 -0
- waldiez/exporting/{agents → agent/utils}/rag_user/chroma_utils.py +22 -17
- waldiez/exporting/{agents → agent/utils}/rag_user/mongo_utils.py +14 -10
- waldiez/exporting/{agents → agent/utils}/rag_user/pgvector_utils.py +12 -8
- waldiez/exporting/{agents → agent/utils}/rag_user/qdrant_utils.py +11 -8
- waldiez/exporting/{agents → agent/utils}/rag_user/rag_user.py +78 -55
- waldiez/exporting/{agents → agent/utils}/rag_user/vector_db.py +10 -8
- waldiez/exporting/agent/utils/swarm_agent.py +463 -0
- waldiez/exporting/{agents → agent/utils}/teachability.py +10 -6
- waldiez/exporting/{agents → agent/utils}/termination_message.py +7 -8
- waldiez/exporting/base/__init__.py +25 -0
- waldiez/exporting/base/agent_position.py +75 -0
- waldiez/exporting/base/base_exporter.py +118 -0
- waldiez/exporting/base/export_position.py +48 -0
- waldiez/exporting/base/import_position.py +23 -0
- waldiez/exporting/base/mixin.py +134 -0
- waldiez/exporting/base/utils/__init__.py +18 -0
- waldiez/exporting/{utils → base/utils}/comments.py +12 -55
- waldiez/exporting/{utils → base/utils}/naming.py +14 -4
- waldiez/exporting/base/utils/path_check.py +68 -0
- waldiez/exporting/{utils/object_string.py → base/utils/to_string.py} +21 -20
- waldiez/exporting/chats/__init__.py +5 -12
- waldiez/exporting/chats/chats_exporter.py +240 -0
- waldiez/exporting/chats/utils/__init__.py +15 -0
- waldiez/exporting/chats/utils/common.py +81 -0
- waldiez/exporting/chats/{nested.py → utils/nested.py} +125 -86
- waldiez/exporting/chats/utils/sequential.py +244 -0
- waldiez/exporting/chats/utils/single_chat.py +313 -0
- waldiez/exporting/chats/utils/swarm.py +207 -0
- waldiez/exporting/flow/__init__.py +5 -3
- waldiez/exporting/flow/flow_exporter.py +503 -0
- waldiez/exporting/flow/utils/__init__.py +47 -0
- waldiez/exporting/flow/utils/agent_utils.py +204 -0
- waldiez/exporting/flow/utils/chat_utils.py +71 -0
- waldiez/exporting/flow/utils/def_main.py +62 -0
- waldiez/exporting/flow/utils/flow_content.py +112 -0
- waldiez/exporting/flow/utils/flow_names.py +115 -0
- waldiez/exporting/flow/utils/importing_utils.py +179 -0
- waldiez/exporting/{utils → flow/utils}/logging_utils.py +34 -31
- waldiez/exporting/models/__init__.py +7 -242
- waldiez/exporting/models/models_exporter.py +192 -0
- waldiez/exporting/models/utils.py +166 -0
- waldiez/exporting/skills/__init__.py +7 -161
- waldiez/exporting/skills/skills_exporter.py +169 -0
- waldiez/exporting/skills/utils.py +281 -0
- waldiez/models/__init__.py +25 -7
- waldiez/models/agents/__init__.py +70 -0
- waldiez/models/agents/agent/__init__.py +11 -1
- waldiez/models/agents/agent/agent.py +9 -4
- waldiez/models/agents/agent/agent_data.py +3 -1
- waldiez/models/agents/agent/code_execution.py +2 -0
- waldiez/models/agents/agent/linked_skill.py +2 -0
- waldiez/models/agents/agent/nested_chat.py +2 -0
- waldiez/models/agents/agent/teachability.py +2 -0
- waldiez/models/agents/agent/termination_message.py +49 -13
- waldiez/models/agents/agents.py +15 -3
- waldiez/models/agents/assistant/__init__.py +2 -0
- waldiez/models/agents/assistant/assistant.py +2 -0
- waldiez/models/agents/assistant/assistant_data.py +2 -0
- waldiez/models/agents/group_manager/__init__.py +9 -1
- waldiez/models/agents/group_manager/group_manager.py +2 -0
- waldiez/models/agents/group_manager/group_manager_data.py +2 -0
- waldiez/models/agents/group_manager/speakers.py +49 -13
- waldiez/models/agents/rag_user/__init__.py +21 -4
- waldiez/models/agents/rag_user/rag_user.py +3 -1
- waldiez/models/agents/rag_user/rag_user_data.py +2 -0
- waldiez/models/agents/rag_user/retrieve_config.py +268 -17
- waldiez/models/agents/rag_user/vector_db_config.py +5 -3
- waldiez/models/agents/swarm_agent/__init__.py +49 -0
- waldiez/models/agents/swarm_agent/after_work.py +178 -0
- waldiez/models/agents/swarm_agent/on_condition.py +103 -0
- waldiez/models/agents/swarm_agent/on_condition_available.py +140 -0
- waldiez/models/agents/swarm_agent/on_condition_target.py +40 -0
- waldiez/models/agents/swarm_agent/swarm_agent.py +107 -0
- waldiez/models/agents/swarm_agent/swarm_agent_data.py +125 -0
- waldiez/models/agents/swarm_agent/update_system_message.py +144 -0
- waldiez/models/agents/user_proxy/__init__.py +2 -0
- waldiez/models/agents/user_proxy/user_proxy.py +2 -0
- waldiez/models/agents/user_proxy/user_proxy_data.py +2 -0
- waldiez/models/chat/__init__.py +21 -3
- waldiez/models/chat/chat.py +241 -7
- waldiez/models/chat/chat_data.py +192 -48
- waldiez/models/chat/chat_message.py +153 -144
- waldiez/models/chat/chat_nested.py +33 -53
- waldiez/models/chat/chat_summary.py +2 -0
- waldiez/models/common/__init__.py +6 -6
- waldiez/models/common/base.py +4 -1
- waldiez/models/common/method_utils.py +163 -83
- waldiez/models/flow/__init__.py +2 -0
- waldiez/models/flow/flow.py +176 -40
- waldiez/models/flow/flow_data.py +63 -2
- waldiez/models/flow/utils.py +172 -0
- waldiez/models/model/__init__.py +2 -0
- waldiez/models/model/model.py +25 -6
- waldiez/models/model/model_data.py +3 -1
- waldiez/models/skill/__init__.py +4 -1
- waldiez/models/skill/skill.py +30 -2
- waldiez/models/skill/skill_data.py +2 -0
- waldiez/models/waldiez.py +28 -4
- waldiez/runner.py +142 -228
- waldiez/running/__init__.py +33 -0
- waldiez/running/environment.py +83 -0
- waldiez/running/gen_seq_diagram.py +185 -0
- waldiez/running/running.py +300 -0
- {waldiez-0.2.1.dist-info → waldiez-0.3.0.dist-info}/METADATA +36 -30
- waldiez-0.3.0.dist-info/RECORD +125 -0
- waldiez-0.3.0.dist-info/licenses/LICENSE +201 -0
- waldiez/exporting/agents/__init__.py +0 -5
- waldiez/exporting/agents/agent.py +0 -236
- waldiez/exporting/agents/agent_skills.py +0 -67
- waldiez/exporting/agents/llm_config.py +0 -53
- waldiez/exporting/chats/chats.py +0 -46
- waldiez/exporting/chats/helpers.py +0 -420
- waldiez/exporting/flow/def_main.py +0 -32
- waldiez/exporting/flow/flow.py +0 -189
- waldiez/exporting/utils/__init__.py +0 -36
- waldiez/exporting/utils/importing.py +0 -265
- waldiez/exporting/utils/method_utils.py +0 -35
- waldiez/exporting/utils/path_check.py +0 -51
- waldiez-0.2.1.dist-info/RECORD +0 -92
- waldiez-0.2.1.dist-info/licenses/LICENSE +0 -21
- {waldiez-0.2.1.dist-info → waldiez-0.3.0.dist-info}/WHEEL +0 -0
- {waldiez-0.2.1.dist-info → waldiez-0.3.0.dist-info}/entry_points.txt +0 -0
|
@@ -0,0 +1,279 @@
|
|
|
1
|
+
# SPDX-License-Identifier: Apache-2.0.
|
|
2
|
+
# Copyright (c) 2024 - 2025 Waldiez and contributors.
|
|
3
|
+
# pylint: disable=too-many-return-statements,too-many-instance-attributes
|
|
4
|
+
"""Export agents."""
|
|
5
|
+
|
|
6
|
+
from pathlib import Path
|
|
7
|
+
from typing import Callable, Dict, List, Optional, Tuple, Union
|
|
8
|
+
|
|
9
|
+
from waldiez.models import WaldiezAgent, WaldiezChat
|
|
10
|
+
|
|
11
|
+
from ..base import (
|
|
12
|
+
AgentPosition,
|
|
13
|
+
AgentPositions,
|
|
14
|
+
BaseExporter,
|
|
15
|
+
ExporterMixin,
|
|
16
|
+
ExporterReturnType,
|
|
17
|
+
ExportPosition,
|
|
18
|
+
ImportPosition,
|
|
19
|
+
)
|
|
20
|
+
from .utils import (
|
|
21
|
+
get_agent_class_name,
|
|
22
|
+
get_agent_code_execution_config,
|
|
23
|
+
get_agent_imports,
|
|
24
|
+
get_group_manager_extras,
|
|
25
|
+
get_is_termination_message,
|
|
26
|
+
get_rag_user_extras,
|
|
27
|
+
get_swarm_extras,
|
|
28
|
+
)
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
class AgentExporter(BaseExporter, ExporterMixin):
|
|
32
|
+
"""Agents exporter."""
|
|
33
|
+
|
|
34
|
+
def __init__(
|
|
35
|
+
self,
|
|
36
|
+
agent: WaldiezAgent,
|
|
37
|
+
agent_names: Dict[str, str],
|
|
38
|
+
model_names: Dict[str, str],
|
|
39
|
+
skill_names: Dict[str, str],
|
|
40
|
+
chats: Tuple[List[WaldiezChat], Dict[str, str]],
|
|
41
|
+
is_async: bool,
|
|
42
|
+
group_chat_members: List[WaldiezAgent],
|
|
43
|
+
for_notebook: bool,
|
|
44
|
+
arguments_resolver: Callable[[WaldiezAgent], List[str]],
|
|
45
|
+
output_dir: Optional[Union[str, Path]] = None,
|
|
46
|
+
) -> None:
|
|
47
|
+
"""Initialize the agents exporter.
|
|
48
|
+
|
|
49
|
+
Parameters
|
|
50
|
+
----------
|
|
51
|
+
agent : WaldiezAgent
|
|
52
|
+
The agent to export.
|
|
53
|
+
agent_names : Dict[str, str]
|
|
54
|
+
The agent ids to names mapping.
|
|
55
|
+
model_names : Dict[str, str]
|
|
56
|
+
The model ids to names mapping.
|
|
57
|
+
skill_names : Dict[str, str]
|
|
58
|
+
The skill ids to names mapping.
|
|
59
|
+
all_chats : List[WaldiezChat]
|
|
60
|
+
All the chats in the flow.
|
|
61
|
+
chat_names : Dict[str, str]
|
|
62
|
+
The chat ids to names mapping.
|
|
63
|
+
is_async : bool
|
|
64
|
+
Whether the whole flow is async.
|
|
65
|
+
for_notebook : bool
|
|
66
|
+
Whether the exporter is for a notebook.
|
|
67
|
+
output_dir : Optional[Union[str, Path]], optional
|
|
68
|
+
The output directory, by default None
|
|
69
|
+
"""
|
|
70
|
+
self.for_notebook = for_notebook
|
|
71
|
+
self.agent = agent
|
|
72
|
+
self.agent_names = agent_names
|
|
73
|
+
if output_dir is not None and not isinstance(output_dir, Path):
|
|
74
|
+
output_dir = Path(output_dir)
|
|
75
|
+
self.output_dir = output_dir
|
|
76
|
+
self.model_names = model_names
|
|
77
|
+
self.skill_names = skill_names
|
|
78
|
+
self.arguments_resolver = arguments_resolver
|
|
79
|
+
self.group_chat_members = group_chat_members
|
|
80
|
+
self.chats = chats
|
|
81
|
+
self.is_async = is_async
|
|
82
|
+
self._agent_name = agent_names[agent.id]
|
|
83
|
+
self._agent_class = get_agent_class_name(self.agent)
|
|
84
|
+
# content, argument, import
|
|
85
|
+
self._code_execution = get_agent_code_execution_config(
|
|
86
|
+
agent=self.agent,
|
|
87
|
+
agent_name=self._agent_name,
|
|
88
|
+
skill_names=self.skill_names,
|
|
89
|
+
)
|
|
90
|
+
# before_rag, retrieve_arg, rag_imports
|
|
91
|
+
self._rag = get_rag_user_extras(
|
|
92
|
+
agent=self.agent,
|
|
93
|
+
agent_name=self._agent_name,
|
|
94
|
+
model_names=self.model_names,
|
|
95
|
+
path_resolver=self.path_resolver,
|
|
96
|
+
serializer=self.serializer,
|
|
97
|
+
)
|
|
98
|
+
# before_manager, group_chat_arg
|
|
99
|
+
self._group_chat = get_group_manager_extras(
|
|
100
|
+
agent=self.agent,
|
|
101
|
+
agent_names=self.agent_names,
|
|
102
|
+
group_chat_members=self.group_chat_members,
|
|
103
|
+
serializer=self.serializer,
|
|
104
|
+
)
|
|
105
|
+
# before_agent, extra args, handoff_registrations
|
|
106
|
+
self._swarm = get_swarm_extras(
|
|
107
|
+
agent=self.agent,
|
|
108
|
+
agent_names=self.agent_names,
|
|
109
|
+
skill_names=self.skill_names,
|
|
110
|
+
chats=self.chats,
|
|
111
|
+
is_async=self.is_async,
|
|
112
|
+
serializer=self.serializer,
|
|
113
|
+
string_escape=self.string_escape,
|
|
114
|
+
)
|
|
115
|
+
# before_agent, termination_arg
|
|
116
|
+
self._termination = get_is_termination_message(
|
|
117
|
+
agent=self.agent, agent_name=self._agent_name
|
|
118
|
+
)
|
|
119
|
+
|
|
120
|
+
def get_imports(self) -> Optional[List[Tuple[str, ImportPosition]]]:
|
|
121
|
+
"""Get the imports.
|
|
122
|
+
|
|
123
|
+
Returns
|
|
124
|
+
-------
|
|
125
|
+
Optional[Tuple[str, ImportPosition]]
|
|
126
|
+
The imports.
|
|
127
|
+
"""
|
|
128
|
+
position = ImportPosition.THIRD_PARTY
|
|
129
|
+
# default imports based on the agent class.
|
|
130
|
+
agent_imports = get_agent_imports(self._agent_class)
|
|
131
|
+
# if code execution is enabled, update the imports.
|
|
132
|
+
if self._code_execution[2]:
|
|
133
|
+
agent_imports.add(self._code_execution[2])
|
|
134
|
+
# if RAG is enabled, update the imports.
|
|
135
|
+
if self._rag[2]:
|
|
136
|
+
agent_imports.update(self._rag[2])
|
|
137
|
+
# if the agent has skills, add the register_function import.
|
|
138
|
+
if self.agent.data.skills:
|
|
139
|
+
agent_imports.add("from autogen import register_function")
|
|
140
|
+
return [(import_string, position) for import_string in agent_imports]
|
|
141
|
+
|
|
142
|
+
def get_system_message_arg(self) -> str:
|
|
143
|
+
"""Get the system message argument.
|
|
144
|
+
|
|
145
|
+
Returns
|
|
146
|
+
-------
|
|
147
|
+
str
|
|
148
|
+
The system message argument.
|
|
149
|
+
"""
|
|
150
|
+
if not self.agent.data.system_message:
|
|
151
|
+
return ""
|
|
152
|
+
system_message = self.string_escape(self.agent.data.system_message)
|
|
153
|
+
return ",\n system_message=" + f'"{system_message}"'
|
|
154
|
+
|
|
155
|
+
def get_before_export(
|
|
156
|
+
self,
|
|
157
|
+
) -> Optional[List[Tuple[str, Union[ExportPosition, AgentPosition]]]]:
|
|
158
|
+
"""Generate the content before the main export.
|
|
159
|
+
|
|
160
|
+
Returns
|
|
161
|
+
-------
|
|
162
|
+
Optional[List[Tuple[str, Union[ExportPosition, AgentPosition]]]]
|
|
163
|
+
The exported content before the main export and its position.
|
|
164
|
+
"""
|
|
165
|
+
before_agent_string = ""
|
|
166
|
+
if self._code_execution[0] and self._code_execution[2]:
|
|
167
|
+
before_agent_string += self._code_execution[0]
|
|
168
|
+
if self._termination[1]:
|
|
169
|
+
before_agent_string += self._termination[1]
|
|
170
|
+
if self._group_chat[0]:
|
|
171
|
+
before_agent_string += self._group_chat[0]
|
|
172
|
+
if self._rag[0]:
|
|
173
|
+
before_agent_string += self._rag[0]
|
|
174
|
+
if self._swarm[0]:
|
|
175
|
+
before_agent_string += self._swarm[0]
|
|
176
|
+
if before_agent_string:
|
|
177
|
+
return [
|
|
178
|
+
(
|
|
179
|
+
before_agent_string,
|
|
180
|
+
AgentPosition(self.agent, AgentPositions.BEFORE),
|
|
181
|
+
)
|
|
182
|
+
]
|
|
183
|
+
return None
|
|
184
|
+
|
|
185
|
+
def get_after_export(
|
|
186
|
+
self,
|
|
187
|
+
) -> Optional[List[Tuple[str, Union[ExportPosition, AgentPosition]]]]:
|
|
188
|
+
"""Generate the content after the main export.
|
|
189
|
+
|
|
190
|
+
Returns
|
|
191
|
+
-------
|
|
192
|
+
Optional[List[Tuple[str, Union[ExportPosition, AgentPosition]]]]
|
|
193
|
+
The exported content after the main export and its position.
|
|
194
|
+
"""
|
|
195
|
+
after_agent_string = ""
|
|
196
|
+
if self._swarm[2]:
|
|
197
|
+
after_agent_string += self._swarm[2]
|
|
198
|
+
if after_agent_string:
|
|
199
|
+
return [
|
|
200
|
+
(
|
|
201
|
+
after_agent_string,
|
|
202
|
+
AgentPosition(self.agent, AgentPositions.AFTER_ALL),
|
|
203
|
+
)
|
|
204
|
+
]
|
|
205
|
+
return None
|
|
206
|
+
|
|
207
|
+
def generate(self) -> Optional[str]:
|
|
208
|
+
"""Generate the exported agent.
|
|
209
|
+
|
|
210
|
+
Returns
|
|
211
|
+
-------
|
|
212
|
+
Optional[str]
|
|
213
|
+
The exported agent.
|
|
214
|
+
"""
|
|
215
|
+
agent = self.agent
|
|
216
|
+
agent_name = self._agent_name
|
|
217
|
+
agent_class = self._agent_class
|
|
218
|
+
retrieve_arg = self._rag[1]
|
|
219
|
+
group_chat_arg = self._group_chat[1]
|
|
220
|
+
is_termination = self._termination[0]
|
|
221
|
+
code_execution_arg = self._code_execution[1]
|
|
222
|
+
system_message_arg = self.get_system_message_arg()
|
|
223
|
+
default_auto_reply: str = "None"
|
|
224
|
+
if agent.data.agent_default_auto_reply:
|
|
225
|
+
default_auto_reply = (
|
|
226
|
+
f'"{self.string_escape(agent.data.agent_default_auto_reply)}"'
|
|
227
|
+
)
|
|
228
|
+
agent_str = f"""{agent_name} = {agent_class}(
|
|
229
|
+
name="{agent_name}",
|
|
230
|
+
description="{agent.description}"{system_message_arg},
|
|
231
|
+
human_input_mode="{agent.data.human_input_mode}",
|
|
232
|
+
max_consecutive_auto_reply={agent.data.max_consecutive_auto_reply},
|
|
233
|
+
default_auto_reply={default_auto_reply},
|
|
234
|
+
code_execution_config={code_execution_arg},
|
|
235
|
+
is_termination_msg={is_termination},{group_chat_arg}{retrieve_arg}
|
|
236
|
+
"""
|
|
237
|
+
if self._swarm[1]:
|
|
238
|
+
agent_str += self._swarm[1]
|
|
239
|
+
# e.g. llm_config=...
|
|
240
|
+
other_args = self.arguments_resolver(agent)
|
|
241
|
+
if other_args:
|
|
242
|
+
agent_str += ",\n".join(other_args)
|
|
243
|
+
if not agent_str.endswith("\n"):
|
|
244
|
+
agent_str += "\n"
|
|
245
|
+
agent_str += ")"
|
|
246
|
+
return agent_str
|
|
247
|
+
|
|
248
|
+
def export(self) -> ExporterReturnType:
|
|
249
|
+
"""Export the agent.
|
|
250
|
+
|
|
251
|
+
Returns
|
|
252
|
+
-------
|
|
253
|
+
ExporterReturnType
|
|
254
|
+
The exported agent.
|
|
255
|
+
"""
|
|
256
|
+
agent_string = self.generate() or ""
|
|
257
|
+
is_group_manager = self.agent.agent_type == "group_manager"
|
|
258
|
+
after_export = self.get_after_export() or []
|
|
259
|
+
content: Optional[str] = agent_string
|
|
260
|
+
if is_group_manager and agent_string:
|
|
261
|
+
content = None
|
|
262
|
+
# make sure the group manager is defined
|
|
263
|
+
# after the rest of the agents.
|
|
264
|
+
# to avoid issues with (for example):
|
|
265
|
+
# 'group_manager_group_chat = GroupChat(
|
|
266
|
+
# # assistant and rag_user should be defined first
|
|
267
|
+
# ' agents=[assistant, rag_user],
|
|
268
|
+
# ' enable_clear_history=True,
|
|
269
|
+
# ...
|
|
270
|
+
after_export.append(
|
|
271
|
+
(agent_string, AgentPosition(None, AgentPositions.AFTER_ALL, 0))
|
|
272
|
+
)
|
|
273
|
+
return {
|
|
274
|
+
"content": content,
|
|
275
|
+
"imports": self.get_imports(),
|
|
276
|
+
"environment_variables": [],
|
|
277
|
+
"before_export": self.get_before_export(),
|
|
278
|
+
"after_export": after_export,
|
|
279
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
# SPDX-License-Identifier: Apache-2.0.
|
|
2
|
+
# Copyright (c) 2024 - 2025 Waldiez and contributors.
|
|
3
|
+
"""Utility functions for generating agent related strings."""
|
|
4
|
+
|
|
5
|
+
from .agent_class_name import get_agent_class_name
|
|
6
|
+
from .agent_imports import get_agent_imports
|
|
7
|
+
from .code_execution import get_agent_code_execution_config
|
|
8
|
+
from .group_manager import get_group_manager_extras
|
|
9
|
+
from .rag_user import get_rag_user_extras
|
|
10
|
+
from .swarm_agent import get_swarm_extras
|
|
11
|
+
from .teachability import get_agent_teachability_string
|
|
12
|
+
from .termination_message import get_is_termination_message
|
|
13
|
+
|
|
14
|
+
__all__ = [
|
|
15
|
+
"get_agent_class_name",
|
|
16
|
+
"get_agent_imports",
|
|
17
|
+
"get_agent_code_execution_config",
|
|
18
|
+
"get_agent_teachability_string",
|
|
19
|
+
"get_group_manager_extras",
|
|
20
|
+
"get_is_termination_message",
|
|
21
|
+
"get_rag_user_extras",
|
|
22
|
+
"get_swarm_extras",
|
|
23
|
+
]
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
# SPDX-License-Identifier: Apache-2.0.
|
|
2
|
+
# Copyright (c) 2024 - 2025 Waldiez and contributors.
|
|
3
|
+
"""Get the agent class name."""
|
|
4
|
+
|
|
5
|
+
from waldiez.models import WaldiezAgent
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
# pylint: disable=too-many-return-statements
|
|
9
|
+
def get_agent_class_name(agent: WaldiezAgent) -> str:
|
|
10
|
+
"""Get the agent class name.
|
|
11
|
+
|
|
12
|
+
Parameters
|
|
13
|
+
----------
|
|
14
|
+
agent : WaldiezAgent
|
|
15
|
+
The agent.
|
|
16
|
+
|
|
17
|
+
Returns
|
|
18
|
+
-------
|
|
19
|
+
str
|
|
20
|
+
The agent class name.
|
|
21
|
+
"""
|
|
22
|
+
if agent.data.is_multimodal:
|
|
23
|
+
return "MultimodalConversableAgent"
|
|
24
|
+
if agent.agent_type == "assistant":
|
|
25
|
+
return "AssistantAgent"
|
|
26
|
+
if agent.agent_type == "user":
|
|
27
|
+
return "UserProxyAgent"
|
|
28
|
+
if agent.agent_type == "manager":
|
|
29
|
+
return "GroupChatManager"
|
|
30
|
+
if agent.agent_type == "rag_user":
|
|
31
|
+
return "RetrieveUserProxyAgent"
|
|
32
|
+
if agent.agent_type == "swarm":
|
|
33
|
+
return "SwarmAgent"
|
|
34
|
+
return "ConversableAgent" # pragma: no cover
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
# SPDX-License-Identifier: Apache-2.0.
|
|
2
|
+
# Copyright (c) 2024 - 2025 Waldiez and contributors.
|
|
3
|
+
"""Get the imports needed for the agent."""
|
|
4
|
+
|
|
5
|
+
from typing import Set
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
def get_agent_imports(agent_class: str) -> Set[str]:
|
|
9
|
+
"""Get the imports needed for the agent.
|
|
10
|
+
|
|
11
|
+
Parameters
|
|
12
|
+
----------
|
|
13
|
+
agent_class : str
|
|
14
|
+
The agent class name.
|
|
15
|
+
|
|
16
|
+
Returns
|
|
17
|
+
-------
|
|
18
|
+
Set[str]
|
|
19
|
+
The imports needed for the agent.
|
|
20
|
+
"""
|
|
21
|
+
imports = set(["import autogen"])
|
|
22
|
+
if agent_class == "AssistantAgent":
|
|
23
|
+
imports.add("from autogen import AssistantAgent")
|
|
24
|
+
elif agent_class == "UserProxyAgent":
|
|
25
|
+
imports.add("from autogen import UserProxyAgent")
|
|
26
|
+
elif agent_class == "GroupChatManager":
|
|
27
|
+
imports.add("from autogen import GroupChatManager")
|
|
28
|
+
elif agent_class == "RetrieveUserProxyAgent":
|
|
29
|
+
imports.add(
|
|
30
|
+
"from autogen.agentchat.contrib.retrieve_user_proxy_agent "
|
|
31
|
+
"import RetrieveUserProxyAgent"
|
|
32
|
+
)
|
|
33
|
+
elif agent_class == "MultimodalConversableAgent":
|
|
34
|
+
imports.add(
|
|
35
|
+
"from autogen.agentchat.contrib.multimodal_conversable_agent "
|
|
36
|
+
"import MultimodalConversableAgent"
|
|
37
|
+
)
|
|
38
|
+
elif agent_class == "SwarmAgent":
|
|
39
|
+
imports.add(
|
|
40
|
+
"from autogen import "
|
|
41
|
+
"AFTER_WORK, "
|
|
42
|
+
"ON_CONDITION, "
|
|
43
|
+
"UPDATE_SYSTEM_MESSAGE, "
|
|
44
|
+
"AfterWorkOption, "
|
|
45
|
+
"SwarmAgent, "
|
|
46
|
+
"SwarmResult"
|
|
47
|
+
)
|
|
48
|
+
else:
|
|
49
|
+
imports.add("from autogen import ConversableAgent")
|
|
50
|
+
return imports
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
# SPDX-License-Identifier: Apache-2.0.
|
|
2
|
+
# Copyright (c) 2024 - 2025 Waldiez and contributors.
|
|
1
3
|
"""Code execution related functions for exporting agents."""
|
|
2
4
|
|
|
3
5
|
from typing import Dict, Tuple
|
|
@@ -36,15 +38,15 @@ def get_agent_code_execution_config(
|
|
|
36
38
|
if use_docker
|
|
37
39
|
else "LocalCommandLineCodeExecutor"
|
|
38
40
|
)
|
|
39
|
-
executor_content = f"{agent_name}_executor = {executor_class_name}(\n"
|
|
41
|
+
executor_content = f"{agent_name}_executor = {executor_class_name}(" + "\n"
|
|
40
42
|
if agent.data.code_execution_config.work_dir:
|
|
41
43
|
wok_dir = agent.data.code_execution_config.work_dir.replace(
|
|
42
44
|
'"', '\\"'
|
|
43
45
|
).replace("\n", "\\n")
|
|
44
|
-
executor_content += f' work_dir="{wok_dir}"
|
|
46
|
+
executor_content += f' work_dir="{wok_dir}",' + "\n"
|
|
45
47
|
if agent.data.code_execution_config.timeout:
|
|
46
48
|
executor_content += (
|
|
47
|
-
f" timeout={agent.data.code_execution_config.timeout}
|
|
49
|
+
f" timeout={agent.data.code_execution_config.timeout}," + "\n"
|
|
48
50
|
)
|
|
49
51
|
if use_docker is False and agent.data.code_execution_config.functions:
|
|
50
52
|
function_names = []
|
|
@@ -53,15 +55,11 @@ def get_agent_code_execution_config(
|
|
|
53
55
|
function_names.append(skill_name)
|
|
54
56
|
if function_names:
|
|
55
57
|
# pylint: disable=inconsistent-quotes
|
|
58
|
+
function_names_string = ", ".join(function_names)
|
|
56
59
|
executor_content += (
|
|
57
|
-
f" functions=[{
|
|
60
|
+
f" functions=[{function_names_string}]," + "\n"
|
|
58
61
|
)
|
|
59
62
|
executor_content += ")\n\n"
|
|
60
|
-
# if (
|
|
61
|
-
# executor_content
|
|
62
|
-
# == f"{agent_name}_executor = {executor_class_name}(\n)\n\n"
|
|
63
|
-
# ):
|
|
64
|
-
# # empty executor?
|
|
65
|
-
# return "", "False", ""
|
|
66
63
|
executor_arg = f'{{"executor": {agent_name}_executor}}'
|
|
67
|
-
|
|
64
|
+
the_import = f"from autogen.coding import {executor_class_name}"
|
|
65
|
+
return executor_content, executor_arg, the_import
|
|
@@ -1,16 +1,17 @@
|
|
|
1
|
-
|
|
1
|
+
# SPDX-License-Identifier: Apache-2.0.
|
|
2
|
+
# Copyright (c) 2024 - 2025 Waldiez and contributors.
|
|
3
|
+
"""Export group manager and group chat to string."""
|
|
2
4
|
|
|
3
|
-
from typing import Dict, List, Optional, Tuple
|
|
5
|
+
from typing import Callable, Dict, List, Optional, Tuple
|
|
4
6
|
|
|
5
7
|
from waldiez.models import WaldiezAgent, WaldiezGroupManager
|
|
6
8
|
|
|
7
|
-
from ..utils import get_method_string, get_object_string
|
|
8
|
-
|
|
9
9
|
|
|
10
10
|
def get_group_manager_extras(
|
|
11
11
|
agent: WaldiezAgent,
|
|
12
12
|
group_chat_members: List[WaldiezAgent],
|
|
13
13
|
agent_names: Dict[str, str],
|
|
14
|
+
serializer: Callable[..., str],
|
|
14
15
|
) -> Tuple[str, str]:
|
|
15
16
|
"""Get the group manager extra string and custom selection method if any.
|
|
16
17
|
|
|
@@ -22,6 +23,8 @@ def get_group_manager_extras(
|
|
|
22
23
|
The group members.
|
|
23
24
|
agent_names : Dict[str, str]
|
|
24
25
|
The agent names.
|
|
26
|
+
serializer : Callable[..., str]
|
|
27
|
+
The serializer function.
|
|
25
28
|
|
|
26
29
|
Returns
|
|
27
30
|
-------
|
|
@@ -34,12 +37,17 @@ def get_group_manager_extras(
|
|
|
34
37
|
custom_speaker_selection: Optional[str] = None
|
|
35
38
|
if agent.agent_type == "manager" and isinstance(agent, WaldiezGroupManager):
|
|
36
39
|
group_chat_string, group_chat_name, custom_speaker_selection = (
|
|
37
|
-
_get_group_manager_extras(
|
|
40
|
+
_get_group_manager_extras(
|
|
41
|
+
agent=agent,
|
|
42
|
+
group_members=group_chat_members,
|
|
43
|
+
agent_names=agent_names,
|
|
44
|
+
serializer=serializer,
|
|
45
|
+
)
|
|
38
46
|
)
|
|
39
47
|
if group_chat_name:
|
|
40
|
-
group_chat_arg =
|
|
48
|
+
group_chat_arg = "\n" + f" groupchat={group_chat_name},"
|
|
41
49
|
if custom_speaker_selection:
|
|
42
|
-
before_agent_string += f"{custom_speaker_selection}\n
|
|
50
|
+
before_agent_string += f"{custom_speaker_selection}" + "\n"
|
|
43
51
|
if group_chat_string:
|
|
44
52
|
before_agent_string += group_chat_string
|
|
45
53
|
return before_agent_string, group_chat_arg
|
|
@@ -49,6 +57,7 @@ def _get_group_manager_extras(
|
|
|
49
57
|
agent: WaldiezGroupManager,
|
|
50
58
|
group_members: List[WaldiezAgent],
|
|
51
59
|
agent_names: Dict[str, str],
|
|
60
|
+
serializer: Callable[..., str],
|
|
52
61
|
) -> Tuple[str, str, Optional[str]]:
|
|
53
62
|
"""Get the group manager extra string and custom selection method if any.
|
|
54
63
|
|
|
@@ -60,6 +69,8 @@ def _get_group_manager_extras(
|
|
|
60
69
|
The group members.
|
|
61
70
|
agent_names : Dict[str, str]
|
|
62
71
|
The agent names.
|
|
72
|
+
serializer : Callable[..., str]
|
|
73
|
+
The serializer function.
|
|
63
74
|
|
|
64
75
|
Returns
|
|
65
76
|
-------
|
|
@@ -88,25 +99,19 @@ def _get_group_manager_extras(
|
|
|
88
99
|
group_chat_string += f" max_round={agent.data.max_round}," + "\n"
|
|
89
100
|
if agent.data.admin_name:
|
|
90
101
|
group_chat_string += f' admin_name="{agent.data.admin_name}",' + "\n"
|
|
91
|
-
extra_group_chat_string,
|
|
92
|
-
_get_group_chat_speakers_string(agent, agent_names)
|
|
102
|
+
extra_group_chat_string, custom_selection_method = (
|
|
103
|
+
_get_group_chat_speakers_string(agent, agent_names, serializer)
|
|
93
104
|
)
|
|
94
|
-
custom_selection_method: Optional[str] = None
|
|
95
105
|
group_chat_string += extra_group_chat_string
|
|
96
106
|
group_chat_string += ")\n\n"
|
|
97
|
-
if method_name_and_content:
|
|
98
|
-
method_name, method_content = method_name_and_content
|
|
99
|
-
custom_selection_method = get_method_string(
|
|
100
|
-
"custom_speaker_selection",
|
|
101
|
-
method_name,
|
|
102
|
-
method_content,
|
|
103
|
-
)
|
|
104
107
|
return group_chat_string, group_chat_name, custom_selection_method
|
|
105
108
|
|
|
106
109
|
|
|
107
110
|
def _get_group_chat_speakers_string(
|
|
108
|
-
agent: WaldiezGroupManager,
|
|
109
|
-
|
|
111
|
+
agent: WaldiezGroupManager,
|
|
112
|
+
agent_names: Dict[str, str],
|
|
113
|
+
serializer: Callable[..., str],
|
|
114
|
+
) -> Tuple[str, Optional[str]]:
|
|
110
115
|
"""Get the group chat speakers string.
|
|
111
116
|
|
|
112
117
|
Parameters
|
|
@@ -115,16 +120,18 @@ def _get_group_chat_speakers_string(
|
|
|
115
120
|
The agent.
|
|
116
121
|
agent_names : Dict[str, str]
|
|
117
122
|
The agent names.
|
|
123
|
+
serializer : Callable[..., str]
|
|
124
|
+
The serializer function.
|
|
118
125
|
|
|
119
126
|
Returns
|
|
120
127
|
-------
|
|
121
128
|
str
|
|
122
129
|
The group chat speakers string.
|
|
123
|
-
Optional[
|
|
124
|
-
The custom
|
|
130
|
+
Optional[str]
|
|
131
|
+
The custom custom for speaker selection if any.
|
|
125
132
|
"""
|
|
126
133
|
speakers_string = ""
|
|
127
|
-
|
|
134
|
+
function_content: Optional[str] = None
|
|
128
135
|
if agent.data.speakers.max_retries_for_selecting is not None:
|
|
129
136
|
speakers_string += (
|
|
130
137
|
" max_retries_for_selecting_speaker="
|
|
@@ -139,12 +146,14 @@ def _get_group_chat_speakers_string(
|
|
|
139
146
|
)
|
|
140
147
|
else:
|
|
141
148
|
agent_name = agent_names[agent.id]
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
149
|
+
function_content, function_name = (
|
|
150
|
+
agent.data.speakers.get_custom_method_function(
|
|
151
|
+
name_suffix=agent_name
|
|
152
|
+
)
|
|
153
|
+
)
|
|
154
|
+
speakers_string += (
|
|
155
|
+
f" speaker_selection_method={function_name}," + "\n"
|
|
146
156
|
)
|
|
147
|
-
speakers_string += f" speaker_selection_method={method_name}," "\n"
|
|
148
157
|
# selection_mode == "repeat":
|
|
149
158
|
if agent.data.speakers.selection_mode == "repeat":
|
|
150
159
|
speakers_string += _get_speakers_selection_repeat_string(
|
|
@@ -156,10 +165,12 @@ def _get_group_chat_speakers_string(
|
|
|
156
165
|
and agent.data.speakers.allowed_or_disallowed_transitions
|
|
157
166
|
):
|
|
158
167
|
speakers_string += _get_speakers_selection_transition_string(
|
|
159
|
-
agent,
|
|
168
|
+
agent=agent,
|
|
169
|
+
agent_names=agent_names,
|
|
170
|
+
serializer=serializer,
|
|
160
171
|
)
|
|
161
172
|
speakers_string = speakers_string.replace('"None"', "None")
|
|
162
|
-
return speakers_string,
|
|
173
|
+
return speakers_string, function_content
|
|
163
174
|
|
|
164
175
|
|
|
165
176
|
def _get_speakers_selection_repeat_string(
|
|
@@ -168,9 +179,8 @@ def _get_speakers_selection_repeat_string(
|
|
|
168
179
|
speakers_string = ""
|
|
169
180
|
if isinstance(agent.data.speakers.allow_repeat, bool):
|
|
170
181
|
speakers_string += (
|
|
171
|
-
" allow_repeat_speaker="
|
|
172
|
-
|
|
173
|
-
"\n"
|
|
182
|
+
f" allow_repeat_speaker={agent.data.speakers.allow_repeat},"
|
|
183
|
+
+ "\n"
|
|
174
184
|
)
|
|
175
185
|
elif isinstance(agent.data.speakers.allow_repeat, list):
|
|
176
186
|
# get the names of the agents
|
|
@@ -178,12 +188,14 @@ def _get_speakers_selection_repeat_string(
|
|
|
178
188
|
agent_names[agent_id]
|
|
179
189
|
for agent_id in agent.data.speakers.allow_repeat
|
|
180
190
|
)
|
|
181
|
-
speakers_string += f" allow_repeat=[{allow_repeat}]," "\n"
|
|
191
|
+
speakers_string += f" allow_repeat=[{allow_repeat}]," + "\n"
|
|
182
192
|
return speakers_string
|
|
183
193
|
|
|
184
194
|
|
|
185
195
|
def _get_speakers_selection_transition_string(
|
|
186
|
-
agent: WaldiezGroupManager,
|
|
196
|
+
agent: WaldiezGroupManager,
|
|
197
|
+
agent_names: Dict[str, str],
|
|
198
|
+
serializer: Callable[..., str],
|
|
187
199
|
) -> str:
|
|
188
200
|
speakers_string = ""
|
|
189
201
|
allowed_or_disallowed_speaker_transitions = {}
|
|
@@ -194,7 +206,7 @@ def _get_speakers_selection_transition_string(
|
|
|
194
206
|
allowed_or_disallowed_speaker_transitions[agent_names[agent_id]] = [
|
|
195
207
|
agent_names[transition] for transition in transitions
|
|
196
208
|
]
|
|
197
|
-
transitions_string =
|
|
209
|
+
transitions_string = serializer(
|
|
198
210
|
allowed_or_disallowed_speaker_transitions, 1
|
|
199
211
|
)
|
|
200
212
|
transitions_string = transitions_string.replace('"', "").replace("'", "")
|