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,281 @@
|
|
|
1
|
+
# SPDX-License-Identifier: Apache-2.0.
|
|
2
|
+
# Copyright (c) 2024 - 2025 Waldiez and contributors.
|
|
3
|
+
"""Skills/tools related string generation functions.
|
|
4
|
+
|
|
5
|
+
Functions
|
|
6
|
+
---------
|
|
7
|
+
get_agent_skill_registration
|
|
8
|
+
Get an agent's skill registration string.
|
|
9
|
+
export_skills
|
|
10
|
+
Get the skills content and secrets.
|
|
11
|
+
"""
|
|
12
|
+
|
|
13
|
+
from pathlib import Path
|
|
14
|
+
from typing import Callable, Dict, List, Optional, Tuple, Union
|
|
15
|
+
|
|
16
|
+
from waldiez.models import WaldiezAgent, WaldiezSkill
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
def get_agent_skill_registration(
|
|
20
|
+
caller_name: str,
|
|
21
|
+
executor_name: str,
|
|
22
|
+
skill_name: str,
|
|
23
|
+
skill_description: str,
|
|
24
|
+
string_escape: Callable[[str], str],
|
|
25
|
+
) -> str:
|
|
26
|
+
"""Get the agent skill string and secrets.
|
|
27
|
+
|
|
28
|
+
Parameters
|
|
29
|
+
----------
|
|
30
|
+
caller_name : str
|
|
31
|
+
The name of the caller (agent).
|
|
32
|
+
executor_name : str
|
|
33
|
+
The name of the executor (agent).
|
|
34
|
+
skill_name : str
|
|
35
|
+
The name of the skill.
|
|
36
|
+
skill_description : str
|
|
37
|
+
The skill description.
|
|
38
|
+
string_escape : Callable[[str], str]
|
|
39
|
+
The string escape function.
|
|
40
|
+
Returns
|
|
41
|
+
-------
|
|
42
|
+
str
|
|
43
|
+
The agent skill string.
|
|
44
|
+
|
|
45
|
+
Example
|
|
46
|
+
-------
|
|
47
|
+
```python
|
|
48
|
+
>>> get_agent_skill_registration(
|
|
49
|
+
... caller_name="agent1",
|
|
50
|
+
... executor_name="agent2",
|
|
51
|
+
... skill_name="skill1",
|
|
52
|
+
... skill_description="A skill that does something.",
|
|
53
|
+
... string_escape=lambda x: x.replace('"', '\\"').replace("\\n", "\\n"),
|
|
54
|
+
... )
|
|
55
|
+
register_function(
|
|
56
|
+
skill1,
|
|
57
|
+
caller=agent1,
|
|
58
|
+
executor=agent2,
|
|
59
|
+
name="skill1",
|
|
60
|
+
description="A skill that does something.",
|
|
61
|
+
)
|
|
62
|
+
```
|
|
63
|
+
"""
|
|
64
|
+
skill_description = string_escape(skill_description)
|
|
65
|
+
content = f"""register_function(
|
|
66
|
+
{skill_name},
|
|
67
|
+
caller={caller_name},
|
|
68
|
+
executor={executor_name},
|
|
69
|
+
name="{skill_name}",
|
|
70
|
+
description="{skill_description}",
|
|
71
|
+
)
|
|
72
|
+
"""
|
|
73
|
+
return content
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
def _write_skill_secrets(
|
|
77
|
+
flow_name: str,
|
|
78
|
+
skill: WaldiezSkill,
|
|
79
|
+
skill_name: str,
|
|
80
|
+
output_dir: Optional[Union[str, Path]],
|
|
81
|
+
) -> None:
|
|
82
|
+
"""Write the skill secrets to a file.
|
|
83
|
+
|
|
84
|
+
Parameters
|
|
85
|
+
----------
|
|
86
|
+
skill : WaldiezSkill
|
|
87
|
+
The skill.
|
|
88
|
+
skill_name : str
|
|
89
|
+
The name of the skill.
|
|
90
|
+
output_dir : Optional[Union[str, Path]]
|
|
91
|
+
The output directory to save the secrets to.
|
|
92
|
+
"""
|
|
93
|
+
if not skill.secrets or not output_dir:
|
|
94
|
+
return
|
|
95
|
+
if not isinstance(output_dir, Path):
|
|
96
|
+
output_dir = Path(output_dir)
|
|
97
|
+
secrets_file = output_dir / f"{flow_name}_{skill_name}_secrets.py"
|
|
98
|
+
first_line = f'"""Secrets for the skill: {skill_name}."""' + "\n"
|
|
99
|
+
with secrets_file.open("w", encoding="utf-8", newline="\n") as f:
|
|
100
|
+
f.write(first_line)
|
|
101
|
+
f.write("import os\n\n")
|
|
102
|
+
for key, value in skill.secrets.items():
|
|
103
|
+
f.write(f'os.environ["{key}"] = "{value}"' + "\n")
|
|
104
|
+
|
|
105
|
+
|
|
106
|
+
def export_skills(
|
|
107
|
+
flow_name: str,
|
|
108
|
+
skills: List[WaldiezSkill],
|
|
109
|
+
skill_names: Dict[str, str],
|
|
110
|
+
output_dir: Optional[Union[str, Path]] = None,
|
|
111
|
+
) -> Tuple[List[str], List[Tuple[str, str]], str]:
|
|
112
|
+
"""Get the skills' contents and secrets.
|
|
113
|
+
|
|
114
|
+
If `output_dir` is provided, the contents are saved to that directory.
|
|
115
|
+
|
|
116
|
+
Parameters
|
|
117
|
+
----------
|
|
118
|
+
flow_name : str
|
|
119
|
+
The name of the flow.
|
|
120
|
+
skills : List[WaldiezSkill]
|
|
121
|
+
The skills.
|
|
122
|
+
skill_names : Dict[str, str]
|
|
123
|
+
The skill names.
|
|
124
|
+
output_dir : Optional[Union[str, Path]]
|
|
125
|
+
The output directory to save the skills to.
|
|
126
|
+
|
|
127
|
+
Returns
|
|
128
|
+
-------
|
|
129
|
+
Tuple[Set[str], Set[Tuple[str, str]], str]
|
|
130
|
+
- The skill imports to use in the main file.
|
|
131
|
+
- The skill secrets to set as environment variables.
|
|
132
|
+
- The skills contents.
|
|
133
|
+
"""
|
|
134
|
+
skill_imports: List[str] = []
|
|
135
|
+
skill_secrets: List[Tuple[str, str]] = []
|
|
136
|
+
skill_contents: str = ""
|
|
137
|
+
# if the skill.is_shared,
|
|
138
|
+
# its contents must be first (before the other skills)
|
|
139
|
+
shared_skill_contents = ""
|
|
140
|
+
for skill in skills:
|
|
141
|
+
skill_imports.append(get_skill_imports(flow_name, skill))
|
|
142
|
+
for key, value in skill.secrets.items():
|
|
143
|
+
skill_secrets.append((key, value))
|
|
144
|
+
_write_skill_secrets(
|
|
145
|
+
flow_name=flow_name,
|
|
146
|
+
skill=skill,
|
|
147
|
+
skill_name=skill_names[skill.id],
|
|
148
|
+
output_dir=output_dir,
|
|
149
|
+
)
|
|
150
|
+
skill_content = skill.get_content()
|
|
151
|
+
if not skill_content:
|
|
152
|
+
continue
|
|
153
|
+
if skill.is_shared:
|
|
154
|
+
shared_skill_contents += skill_content + "\n\n"
|
|
155
|
+
else:
|
|
156
|
+
skill_contents += skill_content + "\n\n"
|
|
157
|
+
skill_contents = shared_skill_contents + skill_contents
|
|
158
|
+
return (
|
|
159
|
+
skill_imports,
|
|
160
|
+
skill_secrets,
|
|
161
|
+
skill_contents.replace("\n\n\n", "\n\n"),
|
|
162
|
+
)
|
|
163
|
+
|
|
164
|
+
|
|
165
|
+
def get_skill_imports(flow_name: str, skill: WaldiezSkill) -> str:
|
|
166
|
+
"""Get the skill imports string.
|
|
167
|
+
|
|
168
|
+
Parameters
|
|
169
|
+
----------
|
|
170
|
+
flow_name : str
|
|
171
|
+
The name of the flow.
|
|
172
|
+
skill : WaldiezSkill
|
|
173
|
+
The skill.
|
|
174
|
+
Returns
|
|
175
|
+
-------
|
|
176
|
+
str
|
|
177
|
+
The skill imports string.
|
|
178
|
+
"""
|
|
179
|
+
if not skill.secrets:
|
|
180
|
+
return ""
|
|
181
|
+
# fmt: on
|
|
182
|
+
module_name = f"{flow_name}_{skill.name}"
|
|
183
|
+
ignore_noqa = " # type: ignore # noqa"
|
|
184
|
+
return f"import {module_name}_secrets{ignore_noqa}" + "\n"
|
|
185
|
+
|
|
186
|
+
|
|
187
|
+
def get_agent_skill_registrations(
|
|
188
|
+
agent: WaldiezAgent,
|
|
189
|
+
agent_names: Dict[str, str],
|
|
190
|
+
all_skills: List[WaldiezSkill],
|
|
191
|
+
skill_names: Dict[str, str],
|
|
192
|
+
string_escape: Callable[[str], str],
|
|
193
|
+
) -> str:
|
|
194
|
+
"""Get the agent skill registrations.
|
|
195
|
+
|
|
196
|
+
example output:
|
|
197
|
+
|
|
198
|
+
```python
|
|
199
|
+
>>> string_escape = lambda x: x.replace('"', '\\"').replace("\\n", "\\n")
|
|
200
|
+
>>> agent = WaldiezAgent(
|
|
201
|
+
... id="wa-1",
|
|
202
|
+
... name="agent1",
|
|
203
|
+
... description="An agent that does something.",
|
|
204
|
+
... ...,
|
|
205
|
+
... skills=[
|
|
206
|
+
... WaldiezSkillLink(id="ws-1", executor_id="wa-2", ...),
|
|
207
|
+
... WaldiezSkillLink(id="ws-2", executor_id="wa-3", ...),
|
|
208
|
+
... ],
|
|
209
|
+
... )
|
|
210
|
+
>>> agent_names = {"wa-1": "agent1", "wa-2": "agent2", "wa-3": "agent3"}
|
|
211
|
+
>>> all_skills = [
|
|
212
|
+
... WaldiezSkill(id="ws-1", ...),
|
|
213
|
+
... WaldiezSkill(id="ws-2", ...),
|
|
214
|
+
... WaldiezSkill(id="ws-3", ...),
|
|
215
|
+
... ]
|
|
216
|
+
>>> skill_names = {"ws-1": "skill1", "ws-2": "skill2", "ws-3": "skill3"}
|
|
217
|
+
>>> get_agent_skill_registrations(
|
|
218
|
+
... agent=agent,
|
|
219
|
+
... agent_names=agent_names,
|
|
220
|
+
... all_skills=all_skills,
|
|
221
|
+
... skill_names=skill_names,
|
|
222
|
+
... string_escape=string_escape,
|
|
223
|
+
... )
|
|
224
|
+
|
|
225
|
+
register_function(
|
|
226
|
+
skill1,
|
|
227
|
+
caller=agent1,
|
|
228
|
+
executor=agent2,
|
|
229
|
+
name="skill1",
|
|
230
|
+
description="A skill that does something.",
|
|
231
|
+
)
|
|
232
|
+
register_function(
|
|
233
|
+
skill2,
|
|
234
|
+
caller=agent1,
|
|
235
|
+
executor=agent3,
|
|
236
|
+
name="skill2",
|
|
237
|
+
description="A skill that does something.",
|
|
238
|
+
)
|
|
239
|
+
```
|
|
240
|
+
|
|
241
|
+
Parameters
|
|
242
|
+
----------
|
|
243
|
+
agent : WaldiezAgent
|
|
244
|
+
The agent.
|
|
245
|
+
agent_names : Dict[str, str]
|
|
246
|
+
A mapping of agent id to agent name.
|
|
247
|
+
all_skills : List[WaldiezSkill]
|
|
248
|
+
All the skills in the flow.
|
|
249
|
+
skill_names : Dict[str, str]
|
|
250
|
+
A mapping of skill id to skill name.
|
|
251
|
+
string_escape : Callable[[str], str]
|
|
252
|
+
The string escape function.
|
|
253
|
+
Returns
|
|
254
|
+
-------
|
|
255
|
+
str
|
|
256
|
+
The agent skill registrations.
|
|
257
|
+
"""
|
|
258
|
+
if not agent.data.skills or not all_skills:
|
|
259
|
+
return ""
|
|
260
|
+
content = "\n"
|
|
261
|
+
for linked_skill in agent.data.skills:
|
|
262
|
+
waldiez_skill = next(
|
|
263
|
+
skill for skill in all_skills if skill.id == linked_skill.id
|
|
264
|
+
)
|
|
265
|
+
skill_name = skill_names[linked_skill.id]
|
|
266
|
+
skill_description = (
|
|
267
|
+
waldiez_skill.description or f"Description of {skill_name}"
|
|
268
|
+
)
|
|
269
|
+
caller_name = agent_names[agent.id]
|
|
270
|
+
executor_name = agent_names[linked_skill.executor_id]
|
|
271
|
+
content += (
|
|
272
|
+
get_agent_skill_registration(
|
|
273
|
+
caller_name=caller_name,
|
|
274
|
+
executor_name=executor_name,
|
|
275
|
+
skill_name=skill_name,
|
|
276
|
+
skill_description=skill_description,
|
|
277
|
+
string_escape=string_escape,
|
|
278
|
+
)
|
|
279
|
+
+ "\n"
|
|
280
|
+
)
|
|
281
|
+
return content.replace("\n\n\n", "\n\n")
|
waldiez/models/__init__.py
CHANGED
|
@@ -1,10 +1,13 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
# SPDX-License-Identifier: Apache-2.0.
|
|
2
|
+
# Copyright (c) 2024 - 2025 Waldiez and contributors.
|
|
3
|
+
"""Waldiez models.
|
|
3
4
|
- Agents (Users, Assistants, Group Managers, etc.).
|
|
4
5
|
- Chat (Messages, Summaries, etc.).
|
|
5
6
|
- Model (LLM config, API type, etc.).
|
|
6
7
|
- Skill (Skills/Tools to be registered).
|
|
7
8
|
- Flow (Flow of the conversation).
|
|
9
|
+
- Methods (Method names, arguments, hints, etc.).
|
|
10
|
+
- Waldiez (Main class to hold the flow).
|
|
8
11
|
"""
|
|
9
12
|
|
|
10
13
|
from .agents import (
|
|
@@ -34,6 +37,15 @@ from .agents import (
|
|
|
34
37
|
WaldiezRagUserTask,
|
|
35
38
|
WaldiezRagUserVectorDb,
|
|
36
39
|
WaldiezRagUserVectorDbConfig,
|
|
40
|
+
WaldiezSwarmAfterWork,
|
|
41
|
+
WaldiezSwarmAfterWorkOption,
|
|
42
|
+
WaldiezSwarmAfterWorkRecipientType,
|
|
43
|
+
WaldiezSwarmAgent,
|
|
44
|
+
WaldiezSwarmAgentData,
|
|
45
|
+
WaldiezSwarmOnCondition,
|
|
46
|
+
WaldiezSwarmOnConditionAvailable,
|
|
47
|
+
WaldiezSwarmOnConditionTarget,
|
|
48
|
+
WaldiezSwarmUpdateSystemMessage,
|
|
37
49
|
WaldiezUserProxy,
|
|
38
50
|
WaldiezUserProxyData,
|
|
39
51
|
)
|
|
@@ -45,7 +57,6 @@ from .chat import (
|
|
|
45
57
|
WaldiezChatSummary,
|
|
46
58
|
WaldiezChatSummaryMethod,
|
|
47
59
|
)
|
|
48
|
-
from .common import METHOD_ARGS, METHOD_TYPE_HINTS, WaldiezMethodName
|
|
49
60
|
from .flow import WaldiezFlow, WaldiezFlowData
|
|
50
61
|
from .model import (
|
|
51
62
|
WaldiezModel,
|
|
@@ -53,14 +64,12 @@ from .model import (
|
|
|
53
64
|
WaldiezModelData,
|
|
54
65
|
WaldiezModelPrice,
|
|
55
66
|
)
|
|
56
|
-
from .skill import WaldiezSkill, WaldiezSkillData
|
|
67
|
+
from .skill import SHARED_SKILL_NAME, WaldiezSkill, WaldiezSkillData
|
|
57
68
|
from .waldiez import Waldiez
|
|
58
69
|
|
|
59
70
|
# pylint: disable=duplicate-code
|
|
60
71
|
__all__ = [
|
|
61
|
-
"
|
|
62
|
-
"METHOD_TYPE_HINTS",
|
|
63
|
-
"WaldiezMethodName",
|
|
72
|
+
"SHARED_SKILL_NAME",
|
|
64
73
|
"Waldiez",
|
|
65
74
|
"WaldiezAgent",
|
|
66
75
|
"WaldiezAgentCodeExecutionConfig",
|
|
@@ -104,4 +113,13 @@ __all__ = [
|
|
|
104
113
|
"WaldiezRagUserVectorDb",
|
|
105
114
|
"WaldiezRagUserVectorDbConfig",
|
|
106
115
|
"WaldiezRagUserModels",
|
|
116
|
+
"WaldiezSwarmAgent",
|
|
117
|
+
"WaldiezSwarmAfterWork",
|
|
118
|
+
"WaldiezSwarmAfterWorkOption",
|
|
119
|
+
"WaldiezSwarmAfterWorkRecipientType",
|
|
120
|
+
"WaldiezSwarmAgentData",
|
|
121
|
+
"WaldiezSwarmOnCondition",
|
|
122
|
+
"WaldiezSwarmOnConditionTarget",
|
|
123
|
+
"WaldiezSwarmOnConditionAvailable",
|
|
124
|
+
"WaldiezSwarmUpdateSystemMessage",
|
|
107
125
|
]
|
|
@@ -1,6 +1,11 @@
|
|
|
1
|
+
# SPDX-License-Identifier: Apache-2.0.
|
|
2
|
+
# Copyright (c) 2024 - 2025 Waldiez and contributors.
|
|
1
3
|
"""Agent models."""
|
|
2
4
|
|
|
3
5
|
from .agent import (
|
|
6
|
+
IS_TERMINATION_MESSAGE,
|
|
7
|
+
IS_TERMINATION_MESSAGE_ARGS,
|
|
8
|
+
IS_TERMINATION_MESSAGE_TYPES,
|
|
4
9
|
WaldiezAgent,
|
|
5
10
|
WaldiezAgentCodeExecutionConfig,
|
|
6
11
|
WaldiezAgentData,
|
|
@@ -14,6 +19,9 @@ from .agent import (
|
|
|
14
19
|
from .agents import WaldiezAgents
|
|
15
20
|
from .assistant import WaldiezAssistant, WaldiezAssistantData
|
|
16
21
|
from .group_manager import (
|
|
22
|
+
CUSTOM_SPEAKER_SELECTION,
|
|
23
|
+
CUSTOM_SPEAKER_SELECTION_ARGS,
|
|
24
|
+
CUSTOM_SPEAKER_SELECTION_TYPES,
|
|
17
25
|
WaldiezGroupManager,
|
|
18
26
|
WaldiezGroupManagerData,
|
|
19
27
|
WaldiezGroupManagerSpeakers,
|
|
@@ -22,6 +30,15 @@ from .group_manager import (
|
|
|
22
30
|
WaldiezGroupManagerSpeakersTransitionsType,
|
|
23
31
|
)
|
|
24
32
|
from .rag_user import (
|
|
33
|
+
CUSTOM_EMBEDDING_FUNCTION,
|
|
34
|
+
CUSTOM_EMBEDDING_FUNCTION_ARGS,
|
|
35
|
+
CUSTOM_EMBEDDING_FUNCTION_TYPES,
|
|
36
|
+
CUSTOM_TEXT_SPLIT_FUNCTION,
|
|
37
|
+
CUSTOM_TEXT_SPLIT_FUNCTION_ARGS,
|
|
38
|
+
CUSTOM_TEXT_SPLIT_FUNCTION_TYPES,
|
|
39
|
+
CUSTOM_TOKEN_COUNT_FUNCTION,
|
|
40
|
+
CUSTOM_TOKEN_COUNT_FUNCTION_ARGS,
|
|
41
|
+
CUSTOM_TOKEN_COUNT_FUNCTION_TYPES,
|
|
25
42
|
WaldiezRagUser,
|
|
26
43
|
WaldiezRagUserChunkMode,
|
|
27
44
|
WaldiezRagUserData,
|
|
@@ -31,9 +48,53 @@ from .rag_user import (
|
|
|
31
48
|
WaldiezRagUserVectorDb,
|
|
32
49
|
WaldiezRagUserVectorDbConfig,
|
|
33
50
|
)
|
|
51
|
+
from .swarm_agent import (
|
|
52
|
+
CUSTOM_AFTER_WORK,
|
|
53
|
+
CUSTOM_AFTER_WORK_ARGS,
|
|
54
|
+
CUSTOM_AFTER_WORK_TYPES,
|
|
55
|
+
CUSTOM_ON_CONDITION_AVAILABLE,
|
|
56
|
+
CUSTOM_ON_CONDITION_AVAILABLE_ARGS,
|
|
57
|
+
CUSTOM_ON_CONDITION_AVAILABLE_TYPES,
|
|
58
|
+
CUSTOM_UPDATE_SYSTEM_MESSAGE,
|
|
59
|
+
CUSTOM_UPDATE_SYSTEM_MESSAGE_ARGS,
|
|
60
|
+
CUSTOM_UPDATE_SYSTEM_MESSAGE_TYPES,
|
|
61
|
+
WaldiezSwarmAfterWork,
|
|
62
|
+
WaldiezSwarmAfterWorkOption,
|
|
63
|
+
WaldiezSwarmAfterWorkRecipientType,
|
|
64
|
+
WaldiezSwarmAgent,
|
|
65
|
+
WaldiezSwarmAgentData,
|
|
66
|
+
WaldiezSwarmOnCondition,
|
|
67
|
+
WaldiezSwarmOnConditionAvailable,
|
|
68
|
+
WaldiezSwarmOnConditionTarget,
|
|
69
|
+
WaldiezSwarmUpdateSystemMessage,
|
|
70
|
+
)
|
|
34
71
|
from .user_proxy import WaldiezUserProxy, WaldiezUserProxyData
|
|
35
72
|
|
|
36
73
|
__all__ = [
|
|
74
|
+
"IS_TERMINATION_MESSAGE",
|
|
75
|
+
"IS_TERMINATION_MESSAGE_ARGS",
|
|
76
|
+
"IS_TERMINATION_MESSAGE_TYPES",
|
|
77
|
+
"CUSTOM_AFTER_WORK",
|
|
78
|
+
"CUSTOM_AFTER_WORK_ARGS",
|
|
79
|
+
"CUSTOM_AFTER_WORK_TYPES",
|
|
80
|
+
"CUSTOM_EMBEDDING_FUNCTION",
|
|
81
|
+
"CUSTOM_EMBEDDING_FUNCTION_ARGS",
|
|
82
|
+
"CUSTOM_EMBEDDING_FUNCTION_TYPES",
|
|
83
|
+
"CUSTOM_ON_CONDITION_AVAILABLE",
|
|
84
|
+
"CUSTOM_ON_CONDITION_AVAILABLE_ARGS",
|
|
85
|
+
"CUSTOM_ON_CONDITION_AVAILABLE_TYPES",
|
|
86
|
+
"CUSTOM_SPEAKER_SELECTION",
|
|
87
|
+
"CUSTOM_SPEAKER_SELECTION_ARGS",
|
|
88
|
+
"CUSTOM_SPEAKER_SELECTION_TYPES",
|
|
89
|
+
"CUSTOM_TEXT_SPLIT_FUNCTION",
|
|
90
|
+
"CUSTOM_TEXT_SPLIT_FUNCTION_ARGS",
|
|
91
|
+
"CUSTOM_TEXT_SPLIT_FUNCTION_TYPES",
|
|
92
|
+
"CUSTOM_TOKEN_COUNT_FUNCTION",
|
|
93
|
+
"CUSTOM_TOKEN_COUNT_FUNCTION_ARGS",
|
|
94
|
+
"CUSTOM_TOKEN_COUNT_FUNCTION_TYPES",
|
|
95
|
+
"CUSTOM_UPDATE_SYSTEM_MESSAGE",
|
|
96
|
+
"CUSTOM_UPDATE_SYSTEM_MESSAGE_ARGS",
|
|
97
|
+
"CUSTOM_UPDATE_SYSTEM_MESSAGE_TYPES",
|
|
37
98
|
"WaldiezAgent",
|
|
38
99
|
"WaldiezAgentType",
|
|
39
100
|
"WaldiezAgents",
|
|
@@ -62,4 +123,13 @@ __all__ = [
|
|
|
62
123
|
"WaldiezRagUserChunkMode",
|
|
63
124
|
"WaldiezRagUserVectorDb",
|
|
64
125
|
"WaldiezRagUserVectorDbConfig",
|
|
126
|
+
"WaldiezSwarmAgent",
|
|
127
|
+
"WaldiezSwarmAgentData",
|
|
128
|
+
"WaldiezSwarmAfterWork",
|
|
129
|
+
"WaldiezSwarmAfterWorkOption",
|
|
130
|
+
"WaldiezSwarmAfterWorkRecipientType",
|
|
131
|
+
"WaldiezSwarmOnCondition",
|
|
132
|
+
"WaldiezSwarmOnConditionTarget",
|
|
133
|
+
"WaldiezSwarmOnConditionAvailable",
|
|
134
|
+
"WaldiezSwarmUpdateSystemMessage",
|
|
65
135
|
]
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
# SPDX-License-Identifier: Apache-2.0.
|
|
2
|
+
# Copyright (c) 2024 - 2025 Waldiez and contributors.
|
|
1
3
|
"""Base agent class to be inherited by all other agents."""
|
|
2
4
|
|
|
3
5
|
from .agent import WaldiezAgent, WaldiezAgentType
|
|
@@ -6,9 +8,17 @@ from .code_execution import WaldiezAgentCodeExecutionConfig
|
|
|
6
8
|
from .linked_skill import WaldiezAgentLinkedSkill
|
|
7
9
|
from .nested_chat import WaldiezAgentNestedChat, WaldiezAgentNestedChatMessage
|
|
8
10
|
from .teachability import WaldiezAgentTeachability
|
|
9
|
-
from .termination_message import
|
|
11
|
+
from .termination_message import (
|
|
12
|
+
IS_TERMINATION_MESSAGE,
|
|
13
|
+
IS_TERMINATION_MESSAGE_ARGS,
|
|
14
|
+
IS_TERMINATION_MESSAGE_TYPES,
|
|
15
|
+
WaldiezAgentTerminationMessage,
|
|
16
|
+
)
|
|
10
17
|
|
|
11
18
|
__all__ = [
|
|
19
|
+
"IS_TERMINATION_MESSAGE",
|
|
20
|
+
"IS_TERMINATION_MESSAGE_ARGS",
|
|
21
|
+
"IS_TERMINATION_MESSAGE_TYPES",
|
|
12
22
|
"WaldiezAgent",
|
|
13
23
|
"WaldiezAgentCodeExecutionConfig",
|
|
14
24
|
"WaldiezAgentData",
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
# SPDX-License-Identifier: Apache-2.0.
|
|
2
|
+
# Copyright (c) 2024 - 2025 Waldiez and contributors.
|
|
1
3
|
"""Base agent class to be inherited by all agents."""
|
|
2
4
|
|
|
3
5
|
from typing import List
|
|
@@ -9,7 +11,7 @@ from ...common import WaldiezBase, now
|
|
|
9
11
|
from .agent_data import WaldiezAgentData
|
|
10
12
|
from .code_execution import WaldiezAgentCodeExecutionConfig
|
|
11
13
|
|
|
12
|
-
WaldiezAgentType = Literal["user", "assistant", "manager", "rag_user"]
|
|
14
|
+
WaldiezAgentType = Literal["user", "assistant", "manager", "rag_user", "swarm"]
|
|
13
15
|
|
|
14
16
|
|
|
15
17
|
class WaldiezAgent(WaldiezBase):
|
|
@@ -21,7 +23,7 @@ class WaldiezAgent(WaldiezBase):
|
|
|
21
23
|
The ID of the agent.
|
|
22
24
|
type : Literal["agent"]
|
|
23
25
|
The type of the "node" in a graph: "agent"
|
|
24
|
-
agent_type : Literal["user", "assistant", "manager", "rag_user"]
|
|
26
|
+
agent_type : Literal["user", "assistant", "manager", "rag_user", "swarm"]
|
|
25
27
|
The type of the agent
|
|
26
28
|
name: str
|
|
27
29
|
The name of the agent.
|
|
@@ -59,11 +61,14 @@ class WaldiezAgent(WaldiezBase):
|
|
|
59
61
|
),
|
|
60
62
|
]
|
|
61
63
|
agent_type: Annotated[
|
|
62
|
-
Literal["user", "assistant", "manager", "rag_user"],
|
|
64
|
+
Literal["user", "assistant", "manager", "rag_user", "swarm"],
|
|
63
65
|
Field(
|
|
64
66
|
...,
|
|
65
67
|
title="Agent type",
|
|
66
|
-
description=
|
|
68
|
+
description=(
|
|
69
|
+
"The type of the agent: user, assistant, group manager, "
|
|
70
|
+
"rag_user, or swarm"
|
|
71
|
+
),
|
|
67
72
|
),
|
|
68
73
|
]
|
|
69
74
|
name: Annotated[
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
# SPDX-License-Identifier: Apache-2.0.
|
|
2
|
+
# Copyright (c) 2024 - 2025 Waldiez and contributors.
|
|
1
3
|
"""Common data structures for agents."""
|
|
2
4
|
|
|
3
5
|
from typing import List, Optional, Union
|
|
@@ -117,7 +119,7 @@ class WaldiezAgentData(WaldiezBase):
|
|
|
117
119
|
),
|
|
118
120
|
]
|
|
119
121
|
teachability: Annotated[
|
|
120
|
-
WaldiezAgentTeachability,
|
|
122
|
+
Optional[WaldiezAgentTeachability],
|
|
121
123
|
Field(
|
|
122
124
|
title="Teachability",
|
|
123
125
|
description="The agent teachability configuration.",
|
|
@@ -1,12 +1,20 @@
|
|
|
1
|
+
# SPDX-License-Identifier: Apache-2.0.
|
|
2
|
+
# Copyright (c) 2024 - 2025 Waldiez and contributors.
|
|
1
3
|
"""Waldiez Agent Termination Message Check."""
|
|
2
4
|
|
|
3
|
-
from typing import List, Optional
|
|
5
|
+
from typing import List, Optional, Tuple
|
|
4
6
|
|
|
5
|
-
from pydantic import
|
|
6
|
-
from pydantic.alias_generators import to_camel
|
|
7
|
+
from pydantic import Field, model_validator
|
|
7
8
|
from typing_extensions import Annotated, Literal, Self
|
|
8
9
|
|
|
9
|
-
from ...common import WaldiezBase,
|
|
10
|
+
from ...common import WaldiezBase, check_function, generate_function
|
|
11
|
+
|
|
12
|
+
IS_TERMINATION_MESSAGE = "is_termination_message"
|
|
13
|
+
IS_TERMINATION_MESSAGE_ARGS = ["message"]
|
|
14
|
+
IS_TERMINATION_MESSAGE_TYPES = (
|
|
15
|
+
["Dict[str, Any]"],
|
|
16
|
+
"bool",
|
|
17
|
+
)
|
|
10
18
|
|
|
11
19
|
|
|
12
20
|
class WaldiezAgentTerminationMessage(WaldiezBase):
|
|
@@ -34,13 +42,6 @@ class WaldiezAgentTerminationMessage(WaldiezBase):
|
|
|
34
42
|
Validate the termination message configuration.
|
|
35
43
|
"""
|
|
36
44
|
|
|
37
|
-
model_config = ConfigDict(
|
|
38
|
-
extra="forbid",
|
|
39
|
-
alias_generator=to_camel,
|
|
40
|
-
populate_by_name=True,
|
|
41
|
-
frozen=False,
|
|
42
|
-
)
|
|
43
|
-
|
|
44
45
|
type: Annotated[
|
|
45
46
|
Literal["none", "keyword", "method"],
|
|
46
47
|
Field(
|
|
@@ -90,6 +91,40 @@ class WaldiezAgentTerminationMessage(WaldiezBase):
|
|
|
90
91
|
|
|
91
92
|
_string: str = "None"
|
|
92
93
|
|
|
94
|
+
def get_termination_function(
|
|
95
|
+
self,
|
|
96
|
+
name_prefix: Optional[str] = None,
|
|
97
|
+
name_suffix: Optional[str] = None,
|
|
98
|
+
) -> Tuple[str, str]:
|
|
99
|
+
"""Get the termination function.
|
|
100
|
+
|
|
101
|
+
Parameters
|
|
102
|
+
----------
|
|
103
|
+
name_prefix : str
|
|
104
|
+
The function name prefix.
|
|
105
|
+
name_suffix : str
|
|
106
|
+
The function name suffix.
|
|
107
|
+
|
|
108
|
+
Returns
|
|
109
|
+
-------
|
|
110
|
+
Tuple[str, str]
|
|
111
|
+
The termination function and the function name.
|
|
112
|
+
"""
|
|
113
|
+
function_name = "is_termination_message"
|
|
114
|
+
if name_prefix:
|
|
115
|
+
function_name = f"{name_prefix}_{function_name}"
|
|
116
|
+
if name_suffix:
|
|
117
|
+
function_name = f"{function_name}_{name_suffix}"
|
|
118
|
+
return (
|
|
119
|
+
generate_function(
|
|
120
|
+
function_name=function_name,
|
|
121
|
+
function_args=IS_TERMINATION_MESSAGE_ARGS,
|
|
122
|
+
function_types=IS_TERMINATION_MESSAGE_TYPES,
|
|
123
|
+
function_body=self.string,
|
|
124
|
+
),
|
|
125
|
+
function_name,
|
|
126
|
+
)
|
|
127
|
+
|
|
93
128
|
@property
|
|
94
129
|
def string(self) -> str:
|
|
95
130
|
"""Get the value of the termination message.
|
|
@@ -112,9 +147,10 @@ class WaldiezAgentTerminationMessage(WaldiezBase):
|
|
|
112
147
|
raise ValueError(
|
|
113
148
|
"Method content is required for method termination."
|
|
114
149
|
)
|
|
115
|
-
expected_function_name: WaldiezMethodName = "is_termination_message"
|
|
116
150
|
valid, error_or_content = check_function(
|
|
117
|
-
self.method_content,
|
|
151
|
+
self.method_content,
|
|
152
|
+
function_name=IS_TERMINATION_MESSAGE,
|
|
153
|
+
function_args=IS_TERMINATION_MESSAGE_ARGS,
|
|
118
154
|
)
|
|
119
155
|
if not valid:
|
|
120
156
|
raise ValueError(error_or_content)
|