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.
- waldiez/__init__.py +5 -5
- waldiez/_version.py +1 -1
- waldiez/cli.py +112 -73
- waldiez/exporter.py +61 -19
- waldiez/exporting/__init__.py +25 -6
- waldiez/exporting/agent/__init__.py +7 -3
- waldiez/exporting/agent/code_execution.py +114 -0
- waldiez/exporting/agent/exporter.py +354 -0
- waldiez/exporting/agent/extras/__init__.py +15 -0
- waldiez/exporting/agent/extras/captain_agent_extras.py +315 -0
- waldiez/exporting/agent/extras/group/target.py +178 -0
- waldiez/exporting/agent/extras/group_manager_agent_extas.py +500 -0
- waldiez/exporting/agent/extras/group_member_extras.py +181 -0
- waldiez/exporting/agent/extras/handoffs/__init__.py +19 -0
- waldiez/exporting/agent/extras/handoffs/after_work.py +78 -0
- waldiez/exporting/agent/extras/handoffs/available.py +74 -0
- waldiez/exporting/agent/extras/handoffs/condition.py +158 -0
- waldiez/exporting/agent/extras/handoffs/handoff.py +171 -0
- waldiez/exporting/agent/extras/handoffs/target.py +189 -0
- waldiez/exporting/agent/extras/rag/__init__.py +10 -0
- waldiez/exporting/agent/{utils/rag_user/chroma_utils.py → extras/rag/chroma_extras.py} +16 -15
- waldiez/exporting/agent/{utils/rag_user/mongo_utils.py → extras/rag/mongo_extras.py} +10 -10
- waldiez/exporting/agent/{utils/rag_user/pgvector_utils.py → extras/rag/pgvector_extras.py} +13 -13
- waldiez/exporting/agent/{utils/rag_user/qdrant_utils.py → extras/rag/qdrant_extras.py} +13 -13
- waldiez/exporting/agent/{utils/rag_user/vector_db.py → extras/rag/vector_db_extras.py} +59 -46
- waldiez/exporting/agent/extras/rag_user_proxy_agent_extras.py +245 -0
- waldiez/exporting/agent/extras/reasoning_agent_extras.py +88 -0
- waldiez/exporting/agent/factory.py +95 -0
- waldiez/exporting/agent/processor.py +150 -0
- waldiez/exporting/agent/system_message.py +36 -0
- waldiez/exporting/agent/termination.py +50 -0
- waldiez/exporting/chats/__init__.py +7 -3
- waldiez/exporting/chats/exporter.py +97 -0
- waldiez/exporting/chats/factory.py +65 -0
- waldiez/exporting/chats/processor.py +226 -0
- waldiez/exporting/chats/utils/__init__.py +6 -5
- waldiez/exporting/chats/utils/common.py +11 -45
- waldiez/exporting/chats/utils/group.py +55 -0
- waldiez/exporting/chats/utils/nested.py +37 -52
- waldiez/exporting/chats/utils/sequential.py +72 -61
- waldiez/exporting/chats/utils/{single_chat.py → single.py} +48 -50
- waldiez/exporting/core/__init__.py +196 -0
- waldiez/exporting/core/constants.py +17 -0
- waldiez/exporting/core/content.py +69 -0
- waldiez/exporting/core/context.py +244 -0
- waldiez/exporting/core/enums.py +89 -0
- waldiez/exporting/core/errors.py +19 -0
- waldiez/exporting/core/exporter.py +390 -0
- waldiez/exporting/core/exporters.py +67 -0
- waldiez/exporting/core/extras/__init__.py +39 -0
- waldiez/exporting/core/extras/agent_extras/__init__.py +27 -0
- waldiez/exporting/core/extras/agent_extras/captain_extras.py +57 -0
- waldiez/exporting/core/extras/agent_extras/group_manager_extras.py +102 -0
- waldiez/exporting/core/extras/agent_extras/rag_user_extras.py +53 -0
- waldiez/exporting/core/extras/agent_extras/reasoning_extras.py +68 -0
- waldiez/exporting/core/extras/agent_extras/standard_extras.py +263 -0
- waldiez/exporting/core/extras/base.py +241 -0
- waldiez/exporting/core/extras/chat_extras.py +118 -0
- waldiez/exporting/core/extras/flow_extras.py +70 -0
- waldiez/exporting/core/extras/model_extras.py +73 -0
- waldiez/exporting/core/extras/path_resolver.py +93 -0
- waldiez/exporting/core/extras/serializer.py +138 -0
- waldiez/exporting/core/extras/tool_extras.py +82 -0
- waldiez/exporting/core/protocols.py +259 -0
- waldiez/exporting/core/result.py +705 -0
- waldiez/exporting/core/types.py +329 -0
- waldiez/exporting/core/utils/__init__.py +11 -0
- waldiez/exporting/core/utils/comment.py +33 -0
- waldiez/exporting/core/utils/llm_config.py +117 -0
- waldiez/exporting/core/validation.py +96 -0
- waldiez/exporting/flow/__init__.py +6 -2
- waldiez/exporting/flow/execution_generator.py +193 -0
- waldiez/exporting/flow/exporter.py +107 -0
- waldiez/exporting/flow/factory.py +94 -0
- waldiez/exporting/flow/file_generator.py +214 -0
- waldiez/exporting/flow/merger.py +387 -0
- waldiez/exporting/flow/orchestrator.py +411 -0
- waldiez/exporting/flow/utils/__init__.py +9 -36
- waldiez/exporting/flow/utils/common.py +206 -0
- waldiez/exporting/flow/utils/importing.py +373 -0
- waldiez/exporting/flow/utils/linting.py +200 -0
- waldiez/exporting/flow/utils/{logging_utils.py → logging.py} +23 -9
- waldiez/exporting/models/__init__.py +3 -1
- waldiez/exporting/models/exporter.py +233 -0
- waldiez/exporting/models/factory.py +66 -0
- waldiez/exporting/models/processor.py +139 -0
- waldiez/exporting/tools/__init__.py +11 -0
- waldiez/exporting/tools/exporter.py +207 -0
- waldiez/exporting/tools/factory.py +57 -0
- waldiez/exporting/tools/processor.py +248 -0
- waldiez/exporting/tools/registration.py +133 -0
- waldiez/io/__init__.py +128 -0
- waldiez/io/_ws.py +199 -0
- waldiez/io/models/__init__.py +60 -0
- waldiez/io/models/base.py +66 -0
- waldiez/io/models/constants.py +78 -0
- waldiez/io/models/content/__init__.py +23 -0
- waldiez/io/models/content/audio.py +43 -0
- waldiez/io/models/content/base.py +45 -0
- waldiez/io/models/content/file.py +43 -0
- waldiez/io/models/content/image.py +96 -0
- waldiez/io/models/content/text.py +37 -0
- waldiez/io/models/content/video.py +43 -0
- waldiez/io/models/user_input.py +269 -0
- waldiez/io/models/user_response.py +215 -0
- waldiez/io/mqtt.py +681 -0
- waldiez/io/redis.py +782 -0
- waldiez/io/structured.py +419 -0
- waldiez/io/utils.py +184 -0
- waldiez/io/ws.py +298 -0
- waldiez/logger.py +481 -0
- waldiez/models/__init__.py +108 -51
- waldiez/models/agents/__init__.py +34 -70
- waldiez/models/agents/agent/__init__.py +10 -4
- waldiez/models/agents/agent/agent.py +466 -65
- waldiez/models/agents/agent/agent_data.py +119 -47
- waldiez/models/agents/agent/agent_type.py +13 -2
- waldiez/models/agents/agent/code_execution.py +12 -12
- waldiez/models/agents/agent/human_input_mode.py +8 -0
- waldiez/models/agents/agent/{linked_skill.py → linked_tool.py} +7 -7
- waldiez/models/agents/agent/nested_chat.py +35 -7
- waldiez/models/agents/agent/termination_message.py +30 -22
- waldiez/models/agents/{swarm_agent → agent}/update_system_message.py +22 -22
- waldiez/models/agents/agents.py +58 -63
- waldiez/models/agents/assistant/assistant.py +4 -4
- waldiez/models/agents/assistant/assistant_data.py +13 -1
- waldiez/models/agents/{captain_agent → captain}/captain_agent.py +5 -5
- waldiez/models/agents/{captain_agent → captain}/captain_agent_data.py +5 -5
- waldiez/models/agents/extra_requirements.py +11 -16
- waldiez/models/agents/group_manager/group_manager.py +103 -13
- waldiez/models/agents/group_manager/group_manager_data.py +36 -14
- waldiez/models/agents/group_manager/speakers.py +77 -24
- waldiez/models/agents/{rag_user → rag_user_proxy}/__init__.py +16 -16
- waldiez/models/agents/rag_user_proxy/rag_user_proxy.py +64 -0
- waldiez/models/agents/{rag_user/rag_user_data.py → rag_user_proxy/rag_user_proxy_data.py} +6 -5
- waldiez/models/agents/{rag_user → rag_user_proxy}/retrieve_config.py +182 -114
- waldiez/models/agents/{rag_user → rag_user_proxy}/vector_db_config.py +13 -13
- waldiez/models/agents/reasoning/reasoning_agent.py +6 -6
- waldiez/models/agents/reasoning/reasoning_agent_data.py +110 -63
- waldiez/models/agents/reasoning/reasoning_agent_reason_config.py +38 -10
- waldiez/models/agents/user_proxy/user_proxy.py +11 -7
- waldiez/models/agents/user_proxy/user_proxy_data.py +2 -2
- waldiez/models/chat/__init__.py +2 -1
- waldiez/models/chat/chat.py +166 -87
- waldiez/models/chat/chat_data.py +99 -136
- waldiez/models/chat/chat_message.py +33 -23
- waldiez/models/chat/chat_nested.py +31 -30
- waldiez/models/chat/chat_summary.py +10 -8
- waldiez/models/common/__init__.py +52 -2
- waldiez/models/common/ag2_version.py +1 -1
- waldiez/models/common/base.py +38 -7
- waldiez/models/common/dict_utils.py +42 -17
- waldiez/models/common/handoff.py +459 -0
- waldiez/models/common/id_generator.py +19 -0
- waldiez/models/common/method_utils.py +130 -68
- waldiez/{exporting/base/utils → models/common}/naming.py +38 -61
- waldiez/models/common/waldiez_version.py +37 -0
- waldiez/models/flow/__init__.py +9 -2
- waldiez/models/flow/connection.py +18 -0
- waldiez/models/flow/flow.py +311 -215
- waldiez/models/flow/flow_data.py +207 -40
- waldiez/models/flow/info.py +85 -0
- waldiez/models/flow/naming.py +131 -0
- waldiez/models/model/__init__.py +7 -1
- waldiez/models/model/extra_requirements.py +3 -12
- waldiez/models/model/model.py +76 -21
- waldiez/models/model/model_data.py +108 -20
- waldiez/models/tool/__init__.py +16 -0
- waldiez/models/tool/extra_requirements.py +36 -0
- waldiez/models/{skill/skill.py → tool/tool.py} +88 -88
- waldiez/models/tool/tool_data.py +51 -0
- waldiez/models/tool/tool_type.py +8 -0
- waldiez/models/waldiez.py +97 -80
- waldiez/runner.py +114 -49
- waldiez/running/__init__.py +1 -1
- waldiez/running/environment.py +49 -68
- waldiez/running/gen_seq_diagram.py +16 -14
- waldiez/running/running.py +53 -34
- waldiez/utils/__init__.py +0 -4
- waldiez/utils/cli_extras/jupyter.py +5 -3
- waldiez/utils/cli_extras/runner.py +6 -4
- waldiez/utils/cli_extras/studio.py +6 -4
- waldiez/utils/conflict_checker.py +15 -9
- waldiez/utils/flaml_warnings.py +5 -5
- {waldiez-0.4.7.dist-info → waldiez-0.4.8.dist-info}/METADATA +235 -91
- waldiez-0.4.8.dist-info/RECORD +200 -0
- waldiez/exporting/agent/agent_exporter.py +0 -297
- waldiez/exporting/agent/utils/__init__.py +0 -23
- waldiez/exporting/agent/utils/captain_agent.py +0 -263
- waldiez/exporting/agent/utils/code_execution.py +0 -65
- waldiez/exporting/agent/utils/group_manager.py +0 -220
- waldiez/exporting/agent/utils/rag_user/__init__.py +0 -7
- waldiez/exporting/agent/utils/rag_user/rag_user.py +0 -209
- waldiez/exporting/agent/utils/reasoning.py +0 -36
- waldiez/exporting/agent/utils/swarm_agent.py +0 -469
- waldiez/exporting/agent/utils/teachability.py +0 -41
- waldiez/exporting/agent/utils/termination_message.py +0 -44
- waldiez/exporting/base/__init__.py +0 -25
- waldiez/exporting/base/agent_position.py +0 -75
- waldiez/exporting/base/base_exporter.py +0 -118
- waldiez/exporting/base/export_position.py +0 -48
- waldiez/exporting/base/import_position.py +0 -23
- waldiez/exporting/base/mixin.py +0 -137
- waldiez/exporting/base/utils/__init__.py +0 -18
- waldiez/exporting/base/utils/comments.py +0 -96
- waldiez/exporting/base/utils/path_check.py +0 -68
- waldiez/exporting/base/utils/to_string.py +0 -84
- waldiez/exporting/chats/chats_exporter.py +0 -240
- waldiez/exporting/chats/utils/swarm.py +0 -210
- waldiez/exporting/flow/flow_exporter.py +0 -528
- waldiez/exporting/flow/utils/agent_utils.py +0 -204
- waldiez/exporting/flow/utils/chat_utils.py +0 -71
- waldiez/exporting/flow/utils/def_main.py +0 -77
- waldiez/exporting/flow/utils/flow_content.py +0 -202
- waldiez/exporting/flow/utils/flow_names.py +0 -116
- waldiez/exporting/flow/utils/importing_utils.py +0 -227
- waldiez/exporting/models/models_exporter.py +0 -199
- waldiez/exporting/models/utils.py +0 -174
- waldiez/exporting/skills/__init__.py +0 -9
- waldiez/exporting/skills/skills_exporter.py +0 -176
- waldiez/exporting/skills/utils.py +0 -369
- waldiez/models/agents/agent/teachability.py +0 -70
- waldiez/models/agents/rag_user/rag_user.py +0 -60
- waldiez/models/agents/swarm_agent/__init__.py +0 -50
- waldiez/models/agents/swarm_agent/after_work.py +0 -179
- waldiez/models/agents/swarm_agent/on_condition.py +0 -105
- waldiez/models/agents/swarm_agent/on_condition_available.py +0 -142
- waldiez/models/agents/swarm_agent/on_condition_target.py +0 -40
- waldiez/models/agents/swarm_agent/swarm_agent.py +0 -107
- waldiez/models/agents/swarm_agent/swarm_agent_data.py +0 -124
- waldiez/models/flow/utils.py +0 -232
- waldiez/models/skill/__init__.py +0 -16
- waldiez/models/skill/extra_requirements.py +0 -36
- waldiez/models/skill/skill_data.py +0 -53
- waldiez/models/skill/skill_type.py +0 -8
- waldiez/utils/pysqlite3_checker.py +0 -308
- waldiez/utils/rdps_checker.py +0 -122
- waldiez-0.4.7.dist-info/RECORD +0 -149
- /waldiez/models/agents/{captain_agent → captain}/__init__.py +0 -0
- /waldiez/models/agents/{captain_agent → captain}/captain_agent_lib_entry.py +0 -0
- {waldiez-0.4.7.dist-info → waldiez-0.4.8.dist-info}/WHEEL +0 -0
- {waldiez-0.4.7.dist-info → waldiez-0.4.8.dist-info}/entry_points.txt +0 -0
- {waldiez-0.4.7.dist-info → waldiez-0.4.8.dist-info}/licenses/LICENSE +0 -0
- {waldiez-0.4.7.dist-info → waldiez-0.4.8.dist-info}/licenses/NOTICE.md +0 -0
|
@@ -1,176 +0,0 @@
|
|
|
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 Dict, List, Optional, Tuple, Union
|
|
15
|
-
|
|
16
|
-
from waldiez.models import WaldiezAgent, WaldiezSkill
|
|
17
|
-
|
|
18
|
-
from ..base import (
|
|
19
|
-
AgentPosition,
|
|
20
|
-
AgentPositions,
|
|
21
|
-
BaseExporter,
|
|
22
|
-
ExporterMixin,
|
|
23
|
-
ExporterReturnType,
|
|
24
|
-
ExportPosition,
|
|
25
|
-
ImportPosition,
|
|
26
|
-
)
|
|
27
|
-
from .utils import export_skills, get_agent_skill_registrations
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
class SkillsExporter(BaseExporter, ExporterMixin):
|
|
31
|
-
"""Skill exporter."""
|
|
32
|
-
|
|
33
|
-
def __init__(
|
|
34
|
-
self,
|
|
35
|
-
flow_name: str,
|
|
36
|
-
agents: List[WaldiezAgent],
|
|
37
|
-
agent_names: Dict[str, str],
|
|
38
|
-
skills: List[WaldiezSkill],
|
|
39
|
-
skill_names: Dict[str, str],
|
|
40
|
-
output_dir: Optional[Union[str, Path]] = None,
|
|
41
|
-
) -> None:
|
|
42
|
-
"""Initialize the skill exporter.
|
|
43
|
-
|
|
44
|
-
Parameters
|
|
45
|
-
----------
|
|
46
|
-
flow_name : str
|
|
47
|
-
The name of the flow.
|
|
48
|
-
agents : List[WaldiezAgent]
|
|
49
|
-
The agents.
|
|
50
|
-
agent_names : Dict[str, str]
|
|
51
|
-
The agent names.
|
|
52
|
-
skills : List[WaldiezSkill]
|
|
53
|
-
The skills.
|
|
54
|
-
skill_names : Dict[str, str]
|
|
55
|
-
The skill names.
|
|
56
|
-
output_dir : Optional[Union[str, Path]], optional
|
|
57
|
-
The output directory if any, by default None
|
|
58
|
-
"""
|
|
59
|
-
self.flow_name = flow_name
|
|
60
|
-
self.agents = agents
|
|
61
|
-
self.agent_names = agent_names
|
|
62
|
-
self.skills = skills
|
|
63
|
-
self.skill_names = skill_names
|
|
64
|
-
self.output_dir = output_dir
|
|
65
|
-
self.skill_imports, self.skill_secrets, self.skills_contents = (
|
|
66
|
-
export_skills(
|
|
67
|
-
flow_name=flow_name,
|
|
68
|
-
skills=skills,
|
|
69
|
-
skill_names=skill_names,
|
|
70
|
-
output_dir=output_dir,
|
|
71
|
-
)
|
|
72
|
-
)
|
|
73
|
-
|
|
74
|
-
def get_environment_variables(self) -> List[Tuple[str, str]]:
|
|
75
|
-
"""Get the environment variables to set.
|
|
76
|
-
|
|
77
|
-
Returns
|
|
78
|
-
-------
|
|
79
|
-
List[Tuple[str, str]]
|
|
80
|
-
The environment variables to set.
|
|
81
|
-
"""
|
|
82
|
-
return self.skill_secrets
|
|
83
|
-
|
|
84
|
-
def get_imports(self) -> List[Tuple[str, ImportPosition]]:
|
|
85
|
-
"""Generate the imports string.
|
|
86
|
-
|
|
87
|
-
Returns
|
|
88
|
-
-------
|
|
89
|
-
Tuple[str, int]
|
|
90
|
-
The exported imports and the position of the imports.
|
|
91
|
-
"""
|
|
92
|
-
imports: List[Tuple[str, ImportPosition]] = []
|
|
93
|
-
if not self.skill_imports:
|
|
94
|
-
return imports
|
|
95
|
-
# standard imports
|
|
96
|
-
for import_statement in self.skill_imports[0]:
|
|
97
|
-
imports.append((import_statement, ImportPosition.BUILTINS))
|
|
98
|
-
# third party imports
|
|
99
|
-
for import_statement in self.skill_imports[1]:
|
|
100
|
-
imports.append((import_statement, ImportPosition.THIRD_PARTY))
|
|
101
|
-
# secrets/local imports
|
|
102
|
-
for import_statement in self.skill_imports[2]:
|
|
103
|
-
imports.append((import_statement, ImportPosition.LOCAL))
|
|
104
|
-
return imports
|
|
105
|
-
|
|
106
|
-
def get_before_export(
|
|
107
|
-
self,
|
|
108
|
-
) -> Optional[List[Tuple[str, Union[ExportPosition, AgentPosition]]]]:
|
|
109
|
-
"""Generate the content before the main export.
|
|
110
|
-
|
|
111
|
-
Returns
|
|
112
|
-
-------
|
|
113
|
-
Optional[List[Tuple[str, Union[ExportPosition, AgentPosition]]]]
|
|
114
|
-
The exported content before the main export and its position.
|
|
115
|
-
"""
|
|
116
|
-
|
|
117
|
-
def generate(self) -> Optional[str]:
|
|
118
|
-
"""Generate the main export.
|
|
119
|
-
|
|
120
|
-
Returns
|
|
121
|
-
-------
|
|
122
|
-
Optional[str]
|
|
123
|
-
The exported content.
|
|
124
|
-
"""
|
|
125
|
-
return self.skills_contents
|
|
126
|
-
|
|
127
|
-
def get_after_export(
|
|
128
|
-
self,
|
|
129
|
-
) -> Optional[List[Tuple[str, Union[ExportPosition, AgentPosition]]]]:
|
|
130
|
-
"""Generate the content after the main export.
|
|
131
|
-
|
|
132
|
-
Returns
|
|
133
|
-
-------
|
|
134
|
-
Optional[List[Tuple[str, Union[ExportPosition, AgentPosition]]]]
|
|
135
|
-
The exported content after the main export and its position.
|
|
136
|
-
"""
|
|
137
|
-
agent_registrations: List[
|
|
138
|
-
Tuple[str, Union[ExportPosition, AgentPosition]]
|
|
139
|
-
] = []
|
|
140
|
-
for agent in self.agents:
|
|
141
|
-
agent_registration = get_agent_skill_registrations(
|
|
142
|
-
agent=agent,
|
|
143
|
-
agent_names=self.agent_names,
|
|
144
|
-
all_skills=self.skills,
|
|
145
|
-
skill_names=self.skill_names,
|
|
146
|
-
string_escape=self.string_escape,
|
|
147
|
-
)
|
|
148
|
-
if agent_registration:
|
|
149
|
-
# after all agents since we use the executor
|
|
150
|
-
# (it might not yet be defined)
|
|
151
|
-
position = AgentPosition(None, AgentPositions.AFTER_ALL, 1)
|
|
152
|
-
agent_registrations.append((agent_registration, position))
|
|
153
|
-
return agent_registrations
|
|
154
|
-
|
|
155
|
-
def export(self) -> ExporterReturnType:
|
|
156
|
-
"""Export the skills.
|
|
157
|
-
|
|
158
|
-
Returns
|
|
159
|
-
-------
|
|
160
|
-
ExporterReturnType
|
|
161
|
-
The exported skills content, the imports,
|
|
162
|
-
the before export strings, the after export strings,
|
|
163
|
-
and the environment variables.
|
|
164
|
-
"""
|
|
165
|
-
content = self.generate()
|
|
166
|
-
imports = self.get_imports()
|
|
167
|
-
after_export = self.get_after_export()
|
|
168
|
-
environment_variables = self.get_environment_variables()
|
|
169
|
-
result: ExporterReturnType = {
|
|
170
|
-
"content": content,
|
|
171
|
-
"imports": imports,
|
|
172
|
-
"before_export": None,
|
|
173
|
-
"after_export": after_export,
|
|
174
|
-
"environment_variables": environment_variables,
|
|
175
|
-
}
|
|
176
|
-
return result
|
|
@@ -1,369 +0,0 @@
|
|
|
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
|
-
r"""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
|
-
|
|
41
|
-
Returns
|
|
42
|
-
-------
|
|
43
|
-
str
|
|
44
|
-
The agent skill string.
|
|
45
|
-
|
|
46
|
-
Example
|
|
47
|
-
-------
|
|
48
|
-
```python
|
|
49
|
-
>>> get_agent_skill_registration(
|
|
50
|
-
... caller_name="agent1",
|
|
51
|
-
... executor_name="agent2",
|
|
52
|
-
... skill_name="skill1",
|
|
53
|
-
... skill_description="A skill that does something.",
|
|
54
|
-
... string_escape=lambda x: x.replace('"', '\\"').replace("\\n", "\\n"),
|
|
55
|
-
... )
|
|
56
|
-
register_function(
|
|
57
|
-
skill1,
|
|
58
|
-
caller=agent1,
|
|
59
|
-
executor=agent2,
|
|
60
|
-
name="skill1",
|
|
61
|
-
description="A skill that does something.",
|
|
62
|
-
)
|
|
63
|
-
```
|
|
64
|
-
"""
|
|
65
|
-
skill_description = string_escape(skill_description)
|
|
66
|
-
content = f"""register_function(
|
|
67
|
-
{skill_name},
|
|
68
|
-
caller={caller_name},
|
|
69
|
-
executor={executor_name},
|
|
70
|
-
name="{skill_name}",
|
|
71
|
-
description="{skill_description}",
|
|
72
|
-
)
|
|
73
|
-
"""
|
|
74
|
-
return content
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
def _write_skill_secrets(
|
|
78
|
-
flow_name: str,
|
|
79
|
-
skill: WaldiezSkill,
|
|
80
|
-
skill_name: str,
|
|
81
|
-
output_dir: Optional[Union[str, Path]],
|
|
82
|
-
) -> None:
|
|
83
|
-
"""Write the skill secrets to a file.
|
|
84
|
-
|
|
85
|
-
Parameters
|
|
86
|
-
----------
|
|
87
|
-
skill : WaldiezSkill
|
|
88
|
-
The skill.
|
|
89
|
-
skill_name : str
|
|
90
|
-
The name of the skill.
|
|
91
|
-
output_dir : Optional[Union[str, Path]]
|
|
92
|
-
The output directory to save the secrets to.
|
|
93
|
-
"""
|
|
94
|
-
if not skill.secrets or not output_dir:
|
|
95
|
-
return
|
|
96
|
-
if not isinstance(output_dir, Path):
|
|
97
|
-
output_dir = Path(output_dir)
|
|
98
|
-
output_dir.mkdir(parents=True, exist_ok=True)
|
|
99
|
-
secrets_file = output_dir / f"{flow_name}_{skill_name}_secrets.py"
|
|
100
|
-
first_line = f'"""Secrets for the skill: {skill_name}."""' + "\n"
|
|
101
|
-
with secrets_file.open("w", encoding="utf-8", newline="\n") as f:
|
|
102
|
-
f.write(first_line)
|
|
103
|
-
f.write("import os\n\n")
|
|
104
|
-
for key, value in skill.secrets.items():
|
|
105
|
-
f.write(f'os.environ["{key}"] = "{value}"' + "\n")
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
def export_skills(
|
|
109
|
-
flow_name: str,
|
|
110
|
-
skills: List[WaldiezSkill],
|
|
111
|
-
skill_names: Dict[str, str],
|
|
112
|
-
output_dir: Optional[Union[str, Path]] = None,
|
|
113
|
-
) -> Tuple[Tuple[List[str], List[str], List[str]], List[Tuple[str, str]], str]:
|
|
114
|
-
"""Get the skills' contents and secrets.
|
|
115
|
-
|
|
116
|
-
If `output_dir` is provided, the contents are saved to that directory.
|
|
117
|
-
|
|
118
|
-
Parameters
|
|
119
|
-
----------
|
|
120
|
-
flow_name : str
|
|
121
|
-
The name of the flow.
|
|
122
|
-
skills : List[WaldiezSkill]
|
|
123
|
-
The skills.
|
|
124
|
-
skill_names : Dict[str, str]
|
|
125
|
-
The skill names.
|
|
126
|
-
output_dir : Optional[Union[str, Path]]
|
|
127
|
-
The output directory to save the skills to.
|
|
128
|
-
|
|
129
|
-
Returns
|
|
130
|
-
-------
|
|
131
|
-
Tuple[Tuple[List[str], List[str], List[str]], List[Tuple[str, str]], str]
|
|
132
|
-
- The skill imports to use in the main file.
|
|
133
|
-
- The skill secrets to set as environment variables.
|
|
134
|
-
- The skills contents.
|
|
135
|
-
"""
|
|
136
|
-
skill_imports: Tuple[List[str], List[str], List[str]] = ([], [], [])
|
|
137
|
-
skill_secrets: List[Tuple[str, str]] = []
|
|
138
|
-
skill_contents: str = ""
|
|
139
|
-
# if the skill.is_shared,
|
|
140
|
-
# its contents must be first (before the other skills)
|
|
141
|
-
shared_skill_contents = ""
|
|
142
|
-
for skill in skills:
|
|
143
|
-
standard_skill_imports, third_party_skill_imports = skill.get_imports()
|
|
144
|
-
if standard_skill_imports:
|
|
145
|
-
skill_imports[0].extend(standard_skill_imports)
|
|
146
|
-
if third_party_skill_imports:
|
|
147
|
-
skill_imports[1].extend(third_party_skill_imports)
|
|
148
|
-
secrets_import = get_skill_secrets_import(flow_name, skill)
|
|
149
|
-
if secrets_import:
|
|
150
|
-
skill_imports[2].append(secrets_import)
|
|
151
|
-
for key, value in skill.secrets.items():
|
|
152
|
-
skill_secrets.append((key, value))
|
|
153
|
-
_write_skill_secrets(
|
|
154
|
-
flow_name=flow_name,
|
|
155
|
-
skill=skill,
|
|
156
|
-
skill_name=skill_names[skill.id],
|
|
157
|
-
output_dir=output_dir,
|
|
158
|
-
)
|
|
159
|
-
skill_content = skill.get_content()
|
|
160
|
-
if not skill_content:
|
|
161
|
-
continue
|
|
162
|
-
if skill.is_shared:
|
|
163
|
-
shared_skill_contents += skill_content + "\n\n"
|
|
164
|
-
else:
|
|
165
|
-
if skill.is_interop:
|
|
166
|
-
skill_content += _add_interop_extras(
|
|
167
|
-
skill=skill, skill_names=skill_names
|
|
168
|
-
)
|
|
169
|
-
skill_contents += skill_content + "\n\n"
|
|
170
|
-
skill_contents = shared_skill_contents + skill_contents
|
|
171
|
-
# remove dupes from imports if any and sort them
|
|
172
|
-
skill_imports = _sort_imports(skill_imports)
|
|
173
|
-
return (
|
|
174
|
-
skill_imports,
|
|
175
|
-
skill_secrets,
|
|
176
|
-
skill_contents.replace("\n\n\n", "\n\n"),
|
|
177
|
-
)
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
def _add_interop_extras(
|
|
181
|
-
skill: WaldiezSkill,
|
|
182
|
-
skill_names: Dict[str, str],
|
|
183
|
-
) -> str:
|
|
184
|
-
"""Add the interop conversion.
|
|
185
|
-
|
|
186
|
-
Parameters
|
|
187
|
-
----------
|
|
188
|
-
skill : WaldiezSkill
|
|
189
|
-
The skill
|
|
190
|
-
skill_names : Dict[str, str]
|
|
191
|
-
The skill names.
|
|
192
|
-
|
|
193
|
-
Returns
|
|
194
|
-
-------
|
|
195
|
-
str
|
|
196
|
-
The extra content to convert the tool.
|
|
197
|
-
"""
|
|
198
|
-
skill_name = skill_names[skill.id]
|
|
199
|
-
interop_instance = f"ag2_{skill_name}_interop = Interoperability()" + "\n"
|
|
200
|
-
extra_content = (
|
|
201
|
-
f"ag2_{skill_name} = "
|
|
202
|
-
f"ag2_{skill_name}_interop.convert_tool("
|
|
203
|
-
f"tool={skill_name}, "
|
|
204
|
-
f'type="{skill.skill_type}")'
|
|
205
|
-
)
|
|
206
|
-
return "\n" + interop_instance + extra_content
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
def _sort_imports(
|
|
210
|
-
skill_imports: Tuple[List[str], List[str], List[str]],
|
|
211
|
-
) -> Tuple[List[str], List[str], List[str]]:
|
|
212
|
-
"""Sort the imports.
|
|
213
|
-
|
|
214
|
-
Parameters
|
|
215
|
-
----------
|
|
216
|
-
skill_imports : Tuple[List[str], List[str], List[str]]
|
|
217
|
-
The skill imports.
|
|
218
|
-
|
|
219
|
-
Returns
|
|
220
|
-
-------
|
|
221
|
-
Tuple[List[str], List[str], List[str]]
|
|
222
|
-
The sorted skill imports.
|
|
223
|
-
"""
|
|
224
|
-
# "from x import y" and "import z"
|
|
225
|
-
# the "import a" should be first (and sorted)
|
|
226
|
-
# then the "from b import c" (and sorted)
|
|
227
|
-
standard_lib_imports = skill_imports[0]
|
|
228
|
-
third_party_imports = skill_imports[1]
|
|
229
|
-
secrets_imports = skill_imports[2]
|
|
230
|
-
|
|
231
|
-
sorted_standard_lib_imports = sorted(
|
|
232
|
-
[imp for imp in standard_lib_imports if imp.startswith("import ")]
|
|
233
|
-
) + sorted([imp for imp in standard_lib_imports if imp.startswith("from ")])
|
|
234
|
-
|
|
235
|
-
sorted_third_party_imports = sorted(
|
|
236
|
-
[imp for imp in third_party_imports if imp.startswith("import ")]
|
|
237
|
-
) + sorted([imp for imp in third_party_imports if imp.startswith("from ")])
|
|
238
|
-
|
|
239
|
-
sorted_secrets_imports = sorted(secrets_imports)
|
|
240
|
-
|
|
241
|
-
return (
|
|
242
|
-
sorted_standard_lib_imports,
|
|
243
|
-
sorted_third_party_imports,
|
|
244
|
-
sorted_secrets_imports,
|
|
245
|
-
)
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
def get_skill_secrets_import(flow_name: str, skill: WaldiezSkill) -> str:
|
|
249
|
-
"""Get the skill secrets import string.
|
|
250
|
-
|
|
251
|
-
Parameters
|
|
252
|
-
----------
|
|
253
|
-
flow_name : str
|
|
254
|
-
The name of the flow.
|
|
255
|
-
skill : WaldiezSkill
|
|
256
|
-
The skill.
|
|
257
|
-
|
|
258
|
-
Returns
|
|
259
|
-
-------
|
|
260
|
-
str
|
|
261
|
-
The skill imports string.
|
|
262
|
-
"""
|
|
263
|
-
if not skill.secrets:
|
|
264
|
-
return ""
|
|
265
|
-
# fmt: on
|
|
266
|
-
module_name = f"{flow_name}_{skill.name}"
|
|
267
|
-
type_ignore_noqa = " # type: ignore # noqa"
|
|
268
|
-
return f"import {module_name}_secrets{type_ignore_noqa}" + "\n"
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
def get_agent_skill_registrations(
|
|
272
|
-
agent: WaldiezAgent,
|
|
273
|
-
agent_names: Dict[str, str],
|
|
274
|
-
all_skills: List[WaldiezSkill],
|
|
275
|
-
skill_names: Dict[str, str],
|
|
276
|
-
string_escape: Callable[[str], str],
|
|
277
|
-
) -> str:
|
|
278
|
-
r"""Get the agent skill registrations.
|
|
279
|
-
|
|
280
|
-
example output:
|
|
281
|
-
|
|
282
|
-
```python
|
|
283
|
-
>>> string_escape = lambda x: x.replace('"', '\\"').replace("\\n", "\\n")
|
|
284
|
-
>>> agent = WaldiezAgent(
|
|
285
|
-
... id="wa-1",
|
|
286
|
-
... name="agent1",
|
|
287
|
-
... description="An agent that does something.",
|
|
288
|
-
... ...,
|
|
289
|
-
... skills=[
|
|
290
|
-
... WaldiezSkillLink(id="ws-1", executor_id="wa-2", ...),
|
|
291
|
-
... WaldiezSkillLink(id="ws-2", executor_id="wa-3", ...),
|
|
292
|
-
... ],
|
|
293
|
-
... )
|
|
294
|
-
>>> agent_names = {"wa-1": "agent1", "wa-2": "agent2", "wa-3": "agent3"}
|
|
295
|
-
>>> all_skills = [
|
|
296
|
-
... WaldiezSkill(id="ws-1", ...),
|
|
297
|
-
... WaldiezSkill(id="ws-2", ...),
|
|
298
|
-
... WaldiezSkill(id="ws-3", ...),
|
|
299
|
-
... ]
|
|
300
|
-
>>> skill_names = {"ws-1": "skill1", "ws-2": "skill2", "ws-3": "skill3"}
|
|
301
|
-
>>> get_agent_skill_registrations(
|
|
302
|
-
... agent=agent,
|
|
303
|
-
... agent_names=agent_names,
|
|
304
|
-
... all_skills=all_skills,
|
|
305
|
-
... skill_names=skill_names,
|
|
306
|
-
... string_escape=string_escape,
|
|
307
|
-
... )
|
|
308
|
-
|
|
309
|
-
register_function(
|
|
310
|
-
skill1,
|
|
311
|
-
caller=agent1,
|
|
312
|
-
executor=agent2,
|
|
313
|
-
name="skill1",
|
|
314
|
-
description="A skill that does something.",
|
|
315
|
-
)
|
|
316
|
-
register_function(
|
|
317
|
-
skill2,
|
|
318
|
-
caller=agent1,
|
|
319
|
-
executor=agent3,
|
|
320
|
-
name="skill2",
|
|
321
|
-
description="A skill that does something.",
|
|
322
|
-
)
|
|
323
|
-
```
|
|
324
|
-
|
|
325
|
-
Parameters
|
|
326
|
-
----------
|
|
327
|
-
agent : WaldiezAgent
|
|
328
|
-
The agent.
|
|
329
|
-
agent_names : Dict[str, str]
|
|
330
|
-
A mapping of agent id to agent name.
|
|
331
|
-
all_skills : List[WaldiezSkill]
|
|
332
|
-
All the skills in the flow.
|
|
333
|
-
skill_names : Dict[str, str]
|
|
334
|
-
A mapping of skill id to skill name.
|
|
335
|
-
string_escape : Callable[[str], str]
|
|
336
|
-
The string escape function.
|
|
337
|
-
|
|
338
|
-
Returns
|
|
339
|
-
-------
|
|
340
|
-
str
|
|
341
|
-
The agent skill registrations.
|
|
342
|
-
"""
|
|
343
|
-
if not agent.data.skills or not all_skills:
|
|
344
|
-
return ""
|
|
345
|
-
content = "\n"
|
|
346
|
-
for linked_skill in agent.data.skills:
|
|
347
|
-
waldiez_skill = next(
|
|
348
|
-
skill for skill in all_skills if skill.id == linked_skill.id
|
|
349
|
-
)
|
|
350
|
-
skill_name = skill_names[linked_skill.id]
|
|
351
|
-
if waldiez_skill.is_interop:
|
|
352
|
-
# the name of the the converted to ag2 tool
|
|
353
|
-
skill_name = f"ag2_{skill_name}"
|
|
354
|
-
skill_description = (
|
|
355
|
-
waldiez_skill.description or f"Description of {skill_name}"
|
|
356
|
-
)
|
|
357
|
-
caller_name = agent_names[agent.id]
|
|
358
|
-
executor_name = agent_names[linked_skill.executor_id]
|
|
359
|
-
content += (
|
|
360
|
-
get_agent_skill_registration(
|
|
361
|
-
caller_name=caller_name,
|
|
362
|
-
executor_name=executor_name,
|
|
363
|
-
skill_name=skill_name,
|
|
364
|
-
skill_description=skill_description,
|
|
365
|
-
string_escape=string_escape,
|
|
366
|
-
)
|
|
367
|
-
+ "\n"
|
|
368
|
-
)
|
|
369
|
-
return content.replace("\n\n\n", "\n\n")
|
|
@@ -1,70 +0,0 @@
|
|
|
1
|
-
# SPDX-License-Identifier: Apache-2.0.
|
|
2
|
-
# Copyright (c) 2024 - 2025 Waldiez and contributors.
|
|
3
|
-
"""Waldiez Agent Teachability."""
|
|
4
|
-
|
|
5
|
-
from pydantic import Field
|
|
6
|
-
from typing_extensions import Annotated, Literal
|
|
7
|
-
|
|
8
|
-
from ...common import WaldiezBase
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
class WaldiezAgentTeachability(WaldiezBase):
|
|
12
|
-
"""Waldiez Agent Teachability.
|
|
13
|
-
|
|
14
|
-
Attributes
|
|
15
|
-
----------
|
|
16
|
-
enabled : bool
|
|
17
|
-
Whether the teachability is enabled.
|
|
18
|
-
verbosity : Literal[0, 1, 2, 3]
|
|
19
|
-
The verbosity level of the teachability. Default: 0
|
|
20
|
-
reset_db : bool
|
|
21
|
-
Whether to reset the database. Default: False
|
|
22
|
-
recall_threshold : float
|
|
23
|
-
The recall threshold. Default: 1.5
|
|
24
|
-
max_num_retrievals : int
|
|
25
|
-
The maximum number of retrievals. Default: 10
|
|
26
|
-
"""
|
|
27
|
-
|
|
28
|
-
enabled: Annotated[
|
|
29
|
-
bool,
|
|
30
|
-
Field(
|
|
31
|
-
False,
|
|
32
|
-
title="Enabled",
|
|
33
|
-
description="Whether the teachability is enabled.",
|
|
34
|
-
),
|
|
35
|
-
]
|
|
36
|
-
verbosity: Annotated[
|
|
37
|
-
Literal[0, 1, 2, 3],
|
|
38
|
-
Field(
|
|
39
|
-
0,
|
|
40
|
-
title="Verbosity",
|
|
41
|
-
description="The verbosity level of the teachability.",
|
|
42
|
-
),
|
|
43
|
-
]
|
|
44
|
-
reset_db: Annotated[
|
|
45
|
-
bool,
|
|
46
|
-
Field(
|
|
47
|
-
False,
|
|
48
|
-
title="Reset DB",
|
|
49
|
-
description="Whether to reset the database.",
|
|
50
|
-
alias="resetDb",
|
|
51
|
-
),
|
|
52
|
-
]
|
|
53
|
-
recall_threshold: Annotated[
|
|
54
|
-
float,
|
|
55
|
-
Field(
|
|
56
|
-
1.5,
|
|
57
|
-
title="Recall threshold",
|
|
58
|
-
description="The recall threshold.",
|
|
59
|
-
alias="recallThreshold",
|
|
60
|
-
),
|
|
61
|
-
]
|
|
62
|
-
max_num_retrievals: Annotated[
|
|
63
|
-
int,
|
|
64
|
-
Field(
|
|
65
|
-
10,
|
|
66
|
-
title="Max num retrievals",
|
|
67
|
-
description="The maximum number of retrievals.",
|
|
68
|
-
alias="maxMumRetrievals",
|
|
69
|
-
),
|
|
70
|
-
]
|
|
@@ -1,60 +0,0 @@
|
|
|
1
|
-
# SPDX-License-Identifier: Apache-2.0.
|
|
2
|
-
# Copyright (c) 2024 - 2025 Waldiez and contributors.
|
|
3
|
-
"""RAG user agent.
|
|
4
|
-
|
|
5
|
-
It extends a user agent and has RAG related parameters (`retrieve_config`).
|
|
6
|
-
"""
|
|
7
|
-
|
|
8
|
-
from pydantic import Field
|
|
9
|
-
from typing_extensions import Annotated, Literal
|
|
10
|
-
|
|
11
|
-
from ..agent import WaldiezAgent
|
|
12
|
-
from .rag_user_data import WaldiezRagUserData
|
|
13
|
-
from .retrieve_config import WaldiezRagUserRetrieveConfig
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
class WaldiezRagUser(WaldiezAgent):
|
|
17
|
-
"""RAG user agent.
|
|
18
|
-
|
|
19
|
-
It extends a user agent and has RAG related parameters.
|
|
20
|
-
|
|
21
|
-
Attributes
|
|
22
|
-
----------
|
|
23
|
-
agent_type : Literal["rag_user"]
|
|
24
|
-
The agent type: 'rag_user' for a RAG user agent.
|
|
25
|
-
data : WaldiezRagUserData
|
|
26
|
-
The RAG user agent's data.
|
|
27
|
-
See `WaldiezRagUserData` for more info.
|
|
28
|
-
retrieve_config : WaldiezRagUserRetrieveConfig
|
|
29
|
-
The RAG user agent's retrieve config.
|
|
30
|
-
"""
|
|
31
|
-
|
|
32
|
-
agent_type: Annotated[
|
|
33
|
-
Literal["rag_user"],
|
|
34
|
-
Field(
|
|
35
|
-
"rag_user",
|
|
36
|
-
title="Agent type",
|
|
37
|
-
description="The agent type: 'rag_user' for a RAG user agent",
|
|
38
|
-
alias="agentType",
|
|
39
|
-
),
|
|
40
|
-
]
|
|
41
|
-
|
|
42
|
-
data: Annotated[
|
|
43
|
-
WaldiezRagUserData,
|
|
44
|
-
Field(
|
|
45
|
-
title="Data",
|
|
46
|
-
description="The RAG user agent's data",
|
|
47
|
-
default_factory=WaldiezRagUserData,
|
|
48
|
-
),
|
|
49
|
-
]
|
|
50
|
-
|
|
51
|
-
@property
|
|
52
|
-
def retrieve_config(self) -> WaldiezRagUserRetrieveConfig:
|
|
53
|
-
"""Get the retrieve config.
|
|
54
|
-
|
|
55
|
-
Returns
|
|
56
|
-
-------
|
|
57
|
-
WaldiezRagUserRetrieveConfig
|
|
58
|
-
The RAG user agent's retrieve config.
|
|
59
|
-
"""
|
|
60
|
-
return self.data.retrieve_config
|