waldiez 0.4.6__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.6.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.6.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.6.dist-info → waldiez-0.4.8.dist-info}/WHEEL +0 -0
- {waldiez-0.4.6.dist-info → waldiez-0.4.8.dist-info}/entry_points.txt +0 -0
- {waldiez-0.4.6.dist-info → waldiez-0.4.8.dist-info}/licenses/LICENSE +0 -0
- {waldiez-0.4.6.dist-info → waldiez-0.4.8.dist-info}/licenses/NOTICE.md +0 -0
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
# SPDX-License-Identifier: Apache-2.0.
|
|
2
2
|
# Copyright (c) 2024 - 2025 Waldiez and contributors.
|
|
3
|
-
"""Waldiez
|
|
3
|
+
"""Waldiez Tool model."""
|
|
4
4
|
|
|
5
5
|
import json
|
|
6
6
|
import re
|
|
7
7
|
from pathlib import Path
|
|
8
|
-
from typing import Any,
|
|
8
|
+
from typing import Any, Union
|
|
9
9
|
|
|
10
10
|
from pydantic import Field, model_validator
|
|
11
11
|
from typing_extensions import Annotated, Literal, Self
|
|
@@ -17,85 +17,85 @@ from ..common import (
|
|
|
17
17
|
now,
|
|
18
18
|
parse_code_string,
|
|
19
19
|
)
|
|
20
|
-
from .
|
|
21
|
-
from .
|
|
20
|
+
from .tool_data import WaldiezToolData
|
|
21
|
+
from .tool_type import WaldiezToolType
|
|
22
22
|
|
|
23
|
-
|
|
23
|
+
SHARED_TOOL_NAME = "waldiez_shared"
|
|
24
24
|
|
|
25
25
|
|
|
26
|
-
class
|
|
27
|
-
"""Waldiez
|
|
26
|
+
class WaldiezTool(WaldiezBase):
|
|
27
|
+
"""Waldiez Tool.
|
|
28
28
|
|
|
29
29
|
Attributes
|
|
30
30
|
----------
|
|
31
31
|
id : str
|
|
32
|
-
The ID of the
|
|
33
|
-
type : Literal["
|
|
34
|
-
The type of the "node" in a graph: "
|
|
32
|
+
The ID of the tool.
|
|
33
|
+
type : Literal["tool"]
|
|
34
|
+
The type of the "node" in a graph: "tool".
|
|
35
35
|
name : str
|
|
36
|
-
The name of the
|
|
36
|
+
The name of the tool.
|
|
37
37
|
description : str
|
|
38
|
-
The description of the
|
|
39
|
-
tags :
|
|
40
|
-
The tags of the
|
|
41
|
-
requirements :
|
|
42
|
-
The requirements of the
|
|
38
|
+
The description of the tool.
|
|
39
|
+
tags : list[str]
|
|
40
|
+
The tags of the tool.
|
|
41
|
+
requirements : list[str]
|
|
42
|
+
The requirements of the tool.
|
|
43
43
|
created_at : str
|
|
44
|
-
The date and time when the
|
|
44
|
+
The date and time when the tool was created.
|
|
45
45
|
updated_at : str
|
|
46
|
-
The date and time when the
|
|
47
|
-
data :
|
|
48
|
-
The data of the
|
|
46
|
+
The date and time when the tool was last updated.
|
|
47
|
+
data : WaldiezToolData
|
|
48
|
+
The data of the tool. See `WaldiezToolData`.
|
|
49
49
|
"""
|
|
50
50
|
|
|
51
51
|
id: Annotated[
|
|
52
|
-
str, Field(..., title="ID", description="The ID of the
|
|
52
|
+
str, Field(..., title="ID", description="The ID of the tool.")
|
|
53
53
|
]
|
|
54
54
|
type: Annotated[
|
|
55
|
-
Literal["
|
|
55
|
+
Literal["tool"],
|
|
56
56
|
Field(
|
|
57
|
-
default="
|
|
57
|
+
default="tool",
|
|
58
58
|
title="Type",
|
|
59
59
|
description="The type of the 'node' in a graph.",
|
|
60
60
|
),
|
|
61
61
|
]
|
|
62
62
|
name: Annotated[
|
|
63
|
-
str, Field(..., title="Name", description="The name of the
|
|
63
|
+
str, Field(..., title="Name", description="The name of the tool.")
|
|
64
64
|
]
|
|
65
65
|
description: Annotated[
|
|
66
66
|
str,
|
|
67
67
|
Field(
|
|
68
68
|
...,
|
|
69
69
|
title="Description",
|
|
70
|
-
description="The description of the
|
|
70
|
+
description="The description of the tool.",
|
|
71
71
|
),
|
|
72
72
|
]
|
|
73
73
|
tags: Annotated[
|
|
74
|
-
|
|
74
|
+
list[str],
|
|
75
75
|
Field(
|
|
76
76
|
title="Tags",
|
|
77
|
-
description="The tags of the
|
|
77
|
+
description="The tags of the tool.",
|
|
78
78
|
default_factory=list,
|
|
79
79
|
),
|
|
80
80
|
]
|
|
81
81
|
requirements: Annotated[
|
|
82
|
-
|
|
82
|
+
list[str],
|
|
83
83
|
Field(
|
|
84
84
|
title="Requirements",
|
|
85
|
-
description="The requirements of the
|
|
85
|
+
description="The requirements of the tool.",
|
|
86
86
|
default_factory=list,
|
|
87
87
|
),
|
|
88
88
|
]
|
|
89
89
|
data: Annotated[
|
|
90
|
-
|
|
91
|
-
Field(..., title="Data", description="The data of the
|
|
90
|
+
WaldiezToolData,
|
|
91
|
+
Field(..., title="Data", description="The data of the tool."),
|
|
92
92
|
]
|
|
93
93
|
created_at: Annotated[
|
|
94
94
|
str,
|
|
95
95
|
Field(
|
|
96
96
|
default_factory=now,
|
|
97
97
|
title="Created At",
|
|
98
|
-
description="The date and time when the
|
|
98
|
+
description="The date and time when the tool was created.",
|
|
99
99
|
),
|
|
100
100
|
]
|
|
101
101
|
updated_at: Annotated[
|
|
@@ -103,23 +103,23 @@ class WaldiezSkill(WaldiezBase):
|
|
|
103
103
|
Field(
|
|
104
104
|
default_factory=now,
|
|
105
105
|
title="Updated At",
|
|
106
|
-
description="The date and time when the
|
|
106
|
+
description="The date and time when the tool was last updated.",
|
|
107
107
|
),
|
|
108
108
|
]
|
|
109
109
|
|
|
110
110
|
@staticmethod
|
|
111
|
-
def load(data_or_path: Union[str, Path,
|
|
112
|
-
"""Load a
|
|
111
|
+
def load(data_or_path: Union[str, Path, dict[str, Any]]) -> "WaldiezTool":
|
|
112
|
+
"""Load a tool from a read-only file.
|
|
113
113
|
|
|
114
114
|
Parameters
|
|
115
115
|
----------
|
|
116
|
-
data_or_path : Union[str, Path,
|
|
116
|
+
data_or_path : Union[str, Path, dict[str, Any]]
|
|
117
117
|
The path to the read-only file or the loaded data.
|
|
118
118
|
|
|
119
119
|
Returns
|
|
120
120
|
-------
|
|
121
|
-
|
|
122
|
-
The
|
|
121
|
+
WaldiezTool
|
|
122
|
+
The tool.
|
|
123
123
|
|
|
124
124
|
Raises
|
|
125
125
|
------
|
|
@@ -129,7 +129,7 @@ class WaldiezSkill(WaldiezBase):
|
|
|
129
129
|
If the JSON is invalid or the data is invalid.
|
|
130
130
|
"""
|
|
131
131
|
if isinstance(data_or_path, dict):
|
|
132
|
-
return
|
|
132
|
+
return WaldiezTool.model_validate(data_or_path)
|
|
133
133
|
if not isinstance(data_or_path, Path):
|
|
134
134
|
data_or_path = Path(data_or_path)
|
|
135
135
|
resolved = data_or_path.resolve()
|
|
@@ -140,88 +140,88 @@ class WaldiezSkill(WaldiezBase):
|
|
|
140
140
|
try:
|
|
141
141
|
data_dict = json.loads(data_string)
|
|
142
142
|
except BaseException as exc: # pylint: disable=broad-except
|
|
143
|
-
raise ValueError(f"Invalid
|
|
144
|
-
return
|
|
143
|
+
raise ValueError(f"Invalid WaldiezTool/JSON: {exc}") from exc
|
|
144
|
+
return WaldiezTool.model_validate(data_dict)
|
|
145
145
|
|
|
146
146
|
@property
|
|
147
|
-
def
|
|
148
|
-
"""Get the
|
|
147
|
+
def tool_type(self) -> WaldiezToolType:
|
|
148
|
+
"""Get the tool type.
|
|
149
149
|
|
|
150
150
|
Returns
|
|
151
151
|
-------
|
|
152
|
-
|
|
153
|
-
The type of the
|
|
152
|
+
WaldiezToolType
|
|
153
|
+
The type of the tool:
|
|
154
154
|
[shared, custom, langchain, crewai].
|
|
155
155
|
"""
|
|
156
|
-
return self.data.
|
|
156
|
+
return self.data.tool_type
|
|
157
157
|
|
|
158
|
-
|
|
158
|
+
_tool_imports: tuple[list[str], list[str]] = ([], [])
|
|
159
159
|
|
|
160
|
-
def get_imports(self) ->
|
|
161
|
-
"""Get the
|
|
160
|
+
def get_imports(self) -> tuple[list[str], list[str]]:
|
|
161
|
+
"""Get the tool imports.
|
|
162
162
|
|
|
163
163
|
Returns
|
|
164
164
|
-------
|
|
165
|
-
|
|
165
|
+
tuple[list[str], list[str]]
|
|
166
166
|
The builtin and external imports.
|
|
167
167
|
"""
|
|
168
|
-
return self.
|
|
168
|
+
return self._tool_imports
|
|
169
169
|
|
|
170
170
|
@property
|
|
171
171
|
def is_shared(self) -> bool:
|
|
172
|
-
"""Check if the
|
|
172
|
+
"""Check if the tool is shared.
|
|
173
173
|
|
|
174
174
|
Returns
|
|
175
175
|
-------
|
|
176
176
|
bool
|
|
177
|
-
True if the
|
|
177
|
+
True if the tool is shared, False otherwise.
|
|
178
178
|
"""
|
|
179
|
-
return self.
|
|
179
|
+
return self.tool_type == "shared" or self.name == SHARED_TOOL_NAME
|
|
180
180
|
|
|
181
181
|
@property
|
|
182
182
|
def is_interop(self) -> bool:
|
|
183
|
-
"""Check if the
|
|
183
|
+
"""Check if the tool is interoperability.
|
|
184
184
|
|
|
185
185
|
Returns
|
|
186
186
|
-------
|
|
187
187
|
bool
|
|
188
|
-
True if the
|
|
188
|
+
True if the tool is interoperability, False otherwise.
|
|
189
189
|
"""
|
|
190
|
-
return self.
|
|
190
|
+
return self.tool_type in ("langchain", "crewai")
|
|
191
191
|
|
|
192
192
|
def get_content(self) -> str:
|
|
193
|
-
"""Get the content of the
|
|
193
|
+
"""Get the content of the tool.
|
|
194
194
|
|
|
195
195
|
Returns
|
|
196
196
|
-------
|
|
197
197
|
str
|
|
198
|
-
The content of the
|
|
198
|
+
The content of the tool.
|
|
199
199
|
"""
|
|
200
200
|
if self.is_shared or self.is_interop:
|
|
201
201
|
return self.data.content
|
|
202
202
|
# if custom, only the function content
|
|
203
203
|
return get_function(self.data.content, self.name)
|
|
204
204
|
|
|
205
|
-
def
|
|
206
|
-
"""Validate the interoperability
|
|
205
|
+
def _validate_interop_tool(self) -> None:
|
|
206
|
+
"""Validate the interoperability tool.
|
|
207
207
|
|
|
208
208
|
Raises
|
|
209
209
|
------
|
|
210
210
|
ValueError
|
|
211
|
-
If the
|
|
211
|
+
If the tool name is not in the content.
|
|
212
212
|
"""
|
|
213
213
|
if self.is_interop:
|
|
214
214
|
# we expect sth like:
|
|
215
|
-
# with single or double quotes for type={
|
|
216
|
-
# {
|
|
215
|
+
# with single or double quotes for type={tool_type}
|
|
216
|
+
# {tool_name} = *.convert_tool(..., type="{tool_type}", ...)
|
|
217
217
|
if f"{self.name} = " not in self.data.content:
|
|
218
218
|
raise ValueError(
|
|
219
|
-
f"The
|
|
219
|
+
f"The tool name '{self.name}' is not in the content."
|
|
220
220
|
)
|
|
221
221
|
# we don't want the conversion to ag2 tool (we do it internally)
|
|
222
|
-
# or the
|
|
223
|
-
# so no
|
|
224
|
-
# or
|
|
222
|
+
# or the tool registration (we do it after having the agent names)
|
|
223
|
+
# so no `.convert_tool(... type="...")`
|
|
224
|
+
# or `.register_for_llm(...)`, `.register_for_execution(...)`
|
|
225
225
|
to_exclude = [
|
|
226
226
|
r".convert_tool\(.+?type=",
|
|
227
227
|
rf"{self.name}.register_for_llm\(",
|
|
@@ -230,27 +230,27 @@ class WaldiezSkill(WaldiezBase):
|
|
|
230
230
|
for exclude in to_exclude:
|
|
231
231
|
if re.search(exclude, self.data.content):
|
|
232
232
|
raise ValueError(
|
|
233
|
-
f"Invalid
|
|
233
|
+
f"Invalid tool content: '{exclude}' is not allowed."
|
|
234
234
|
)
|
|
235
235
|
|
|
236
|
-
def
|
|
237
|
-
"""Validate a custom
|
|
236
|
+
def _validate_custom_tool(self) -> None:
|
|
237
|
+
"""Validate a custom tool.
|
|
238
238
|
|
|
239
239
|
Raises
|
|
240
240
|
------
|
|
241
241
|
ValueError
|
|
242
|
-
If the
|
|
243
|
-
If the
|
|
242
|
+
If the tool name is not in the content.
|
|
243
|
+
If the tool content is invalid.
|
|
244
244
|
"""
|
|
245
245
|
search = f"def {self.name}("
|
|
246
|
-
if self.
|
|
246
|
+
if self.tool_type == "custom" and not self.is_shared:
|
|
247
247
|
if search not in self.data.content:
|
|
248
248
|
raise ValueError(
|
|
249
|
-
f"The
|
|
249
|
+
f"The tool name '{self.name}' is not in the content."
|
|
250
250
|
)
|
|
251
251
|
error, tree = parse_code_string(self.data.content)
|
|
252
252
|
if error is not None or tree is None:
|
|
253
|
-
raise ValueError(f"Invalid
|
|
253
|
+
raise ValueError(f"Invalid tool content: {error}")
|
|
254
254
|
|
|
255
255
|
@model_validator(mode="after")
|
|
256
256
|
def validate_data(self) -> Self:
|
|
@@ -258,23 +258,23 @@ class WaldiezSkill(WaldiezBase):
|
|
|
258
258
|
|
|
259
259
|
Returns
|
|
260
260
|
-------
|
|
261
|
-
|
|
262
|
-
The
|
|
261
|
+
WaldiezTool
|
|
262
|
+
The tool.
|
|
263
263
|
|
|
264
264
|
Raises
|
|
265
265
|
------
|
|
266
266
|
ValueError
|
|
267
|
-
If the
|
|
268
|
-
If the
|
|
267
|
+
If the tool name is not in the content.
|
|
268
|
+
If the tool content is invalid.
|
|
269
269
|
"""
|
|
270
|
-
self.
|
|
271
|
-
self.
|
|
272
|
-
self.
|
|
270
|
+
self._validate_custom_tool()
|
|
271
|
+
self._validate_interop_tool()
|
|
272
|
+
self._tool_imports = gather_code_imports(
|
|
273
273
|
self.data.content, self.is_interop
|
|
274
274
|
)
|
|
275
275
|
# remove the imports from the content
|
|
276
|
-
# we
|
|
277
|
-
all_imports = self.
|
|
276
|
+
# we will place them at the top of the file
|
|
277
|
+
all_imports = self._tool_imports[0] + self._tool_imports[1]
|
|
278
278
|
code_lines = self.data.content.splitlines()
|
|
279
279
|
valid_lines = [
|
|
280
280
|
line
|
|
@@ -292,10 +292,10 @@ class WaldiezSkill(WaldiezBase):
|
|
|
292
292
|
|
|
293
293
|
@property
|
|
294
294
|
def content(self) -> str:
|
|
295
|
-
"""Get the content (source) of the
|
|
295
|
+
"""Get the content (source) of the tool."""
|
|
296
296
|
return self.data.content
|
|
297
297
|
|
|
298
298
|
@property
|
|
299
|
-
def secrets(self) ->
|
|
300
|
-
"""Get the secrets (environment variables) of the
|
|
299
|
+
def secrets(self) -> dict[str, str]:
|
|
300
|
+
"""Get the secrets (environment variables) of the tool."""
|
|
301
301
|
return self.data.secrets or {}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
# SPDX-License-Identifier: Apache-2.0.
|
|
2
|
+
# Copyright (c) 2024 - 2025 Waldiez and contributors.
|
|
3
|
+
"""Waldiez Tool model."""
|
|
4
|
+
|
|
5
|
+
from pydantic import Field
|
|
6
|
+
from typing_extensions import Annotated
|
|
7
|
+
|
|
8
|
+
from ..common import WaldiezBase
|
|
9
|
+
from .tool_type import WaldiezToolType
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
class WaldiezToolData(WaldiezBase):
|
|
13
|
+
"""Waldiez Tool Data.
|
|
14
|
+
|
|
15
|
+
Attributes
|
|
16
|
+
----------
|
|
17
|
+
tool_type : WaldiezToolType
|
|
18
|
+
The type of the tool: shared, custom, langchain, crewai.
|
|
19
|
+
content : str
|
|
20
|
+
The content (source code) of the tool.
|
|
21
|
+
secrets : dict[str, str]
|
|
22
|
+
The secrets (environment variables) of the tool.
|
|
23
|
+
"""
|
|
24
|
+
|
|
25
|
+
tool_type: Annotated[
|
|
26
|
+
WaldiezToolType,
|
|
27
|
+
Field(
|
|
28
|
+
"custom",
|
|
29
|
+
alias="toolType",
|
|
30
|
+
title="Tool Type",
|
|
31
|
+
description=(
|
|
32
|
+
"The type of the tool: shared, custom, langchain, crewai."
|
|
33
|
+
),
|
|
34
|
+
),
|
|
35
|
+
] = "custom"
|
|
36
|
+
content: Annotated[
|
|
37
|
+
str,
|
|
38
|
+
Field(
|
|
39
|
+
...,
|
|
40
|
+
title="Content",
|
|
41
|
+
description="The content (source code) of the tool.",
|
|
42
|
+
),
|
|
43
|
+
]
|
|
44
|
+
secrets: Annotated[
|
|
45
|
+
dict[str, str],
|
|
46
|
+
Field(
|
|
47
|
+
default_factory=dict,
|
|
48
|
+
title="Secrets",
|
|
49
|
+
description="The secrets (environment variables) of the tool.",
|
|
50
|
+
),
|
|
51
|
+
]
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
# SPDX-License-Identifier: Apache-2.0.
|
|
2
|
+
# Copyright (c) 2024 - 2025 Waldiez and contributors.
|
|
3
|
+
"""Waldiez Tool types."""
|
|
4
|
+
|
|
5
|
+
from typing_extensions import Literal
|
|
6
|
+
|
|
7
|
+
WaldiezToolType = Literal["shared", "custom", "langchain", "crewai"]
|
|
8
|
+
"""Possible types of a Waldiez Tool."""
|