swarmauri_toolkit_runtime 0.1.1.dev2__tar.gz → 0.11.0.dev4__tar.gz
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.
- {swarmauri_toolkit_runtime-0.1.1.dev2 → swarmauri_toolkit_runtime-0.11.0.dev4}/PKG-INFO +35 -18
- {swarmauri_toolkit_runtime-0.1.1.dev2 → swarmauri_toolkit_runtime-0.11.0.dev4}/README.md +22 -12
- {swarmauri_toolkit_runtime-0.1.1.dev2 → swarmauri_toolkit_runtime-0.11.0.dev4}/pyproject.toml +19 -14
- swarmauri_toolkit_runtime-0.11.0.dev4/swarmauri_toolkit_runtime/InspectRuntimeTool.py +3 -0
- swarmauri_toolkit_runtime-0.11.0.dev4/swarmauri_toolkit_runtime/ListRuntimeTools.py +3 -0
- swarmauri_toolkit_runtime-0.11.0.dev4/swarmauri_toolkit_runtime/RecipeTool.py +47 -0
- swarmauri_toolkit_runtime-0.11.0.dev4/swarmauri_toolkit_runtime/RegisterRuntimeTool.py +3 -0
- swarmauri_toolkit_runtime-0.11.0.dev4/swarmauri_toolkit_runtime/ReplaceRuntimeTool.py +3 -0
- swarmauri_toolkit_runtime-0.11.0.dev4/swarmauri_toolkit_runtime/RuntimeToolkit.py +75 -0
- swarmauri_toolkit_runtime-0.11.0.dev4/swarmauri_toolkit_runtime/UnregisterRuntimeTool.py +3 -0
- swarmauri_toolkit_runtime-0.11.0.dev4/swarmauri_toolkit_runtime/_dynamic_runtime_tool.py +3 -0
- swarmauri_toolkit_runtime-0.11.0.dev4/swarmauri_toolkit_runtime/_tool_factory.py +3 -0
- swarmauri_toolkit_runtime-0.1.1.dev2/swarmauri_toolkit_runtime/InspectRuntimeTool.py +0 -38
- swarmauri_toolkit_runtime-0.1.1.dev2/swarmauri_toolkit_runtime/ListRuntimeTools.py +0 -31
- swarmauri_toolkit_runtime-0.1.1.dev2/swarmauri_toolkit_runtime/RegisterRuntimeTool.py +0 -53
- swarmauri_toolkit_runtime-0.1.1.dev2/swarmauri_toolkit_runtime/ReplaceRuntimeTool.py +0 -68
- swarmauri_toolkit_runtime-0.1.1.dev2/swarmauri_toolkit_runtime/RuntimeToolkit.py +0 -43
- swarmauri_toolkit_runtime-0.1.1.dev2/swarmauri_toolkit_runtime/UnregisterRuntimeTool.py +0 -43
- swarmauri_toolkit_runtime-0.1.1.dev2/swarmauri_toolkit_runtime/_tool_factory.py +0 -49
- {swarmauri_toolkit_runtime-0.1.1.dev2 → swarmauri_toolkit_runtime-0.11.0.dev4}/LICENSE +0 -0
- {swarmauri_toolkit_runtime-0.1.1.dev2 → swarmauri_toolkit_runtime-0.11.0.dev4}/swarmauri_toolkit_runtime/__init__.py +0 -0
|
@@ -1,31 +1,38 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: swarmauri_toolkit_runtime
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.11.0.dev4
|
|
4
4
|
Summary: Runtime toolkit for explicit-parameter registration, inspection, replacement, listing, and removal of Swarmauri tools during agent execution.
|
|
5
5
|
License-Expression: Apache-2.0
|
|
6
6
|
License-File: LICENSE
|
|
7
7
|
Keywords: swarmauri,sdk,standards,toolkit,runtime,agent-runtime,tool-management,tool-registration,tool-inspection,tool-replacement,tool-removal,tool-schema,explicit-parameters,runtime-governance,agent,crud,runtime-tools
|
|
8
8
|
Author: Jacob Stewart
|
|
9
9
|
Author-email: jacob@swarmauri.com
|
|
10
|
-
Requires-Python: >=3.10,<3.
|
|
10
|
+
Requires-Python: >=3.10,<3.15
|
|
11
11
|
Classifier: Development Status :: 1 - Planning
|
|
12
12
|
Classifier: Intended Audience :: Developers
|
|
13
13
|
Classifier: License :: OSI Approved :: Apache Software License
|
|
14
14
|
Classifier: Natural Language :: English
|
|
15
|
+
Classifier: Topic :: Software Development :: Libraries :: Application Frameworks
|
|
15
16
|
Classifier: Programming Language :: Python
|
|
16
17
|
Classifier: Programming Language :: Python :: 3
|
|
17
18
|
Classifier: Programming Language :: Python :: 3 :: Only
|
|
18
19
|
Classifier: Programming Language :: Python :: 3.10
|
|
19
20
|
Classifier: Programming Language :: Python :: 3.11
|
|
20
21
|
Classifier: Programming Language :: Python :: 3.12
|
|
21
|
-
Classifier:
|
|
22
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
23
|
+
Classifier: Programming Language :: Python :: 3.14
|
|
22
24
|
Requires-Dist: pydantic
|
|
23
|
-
Requires-Dist: swarmauri_base
|
|
24
|
-
Requires-Dist: swarmauri_core
|
|
25
|
-
Requires-Dist: swarmauri_standard
|
|
25
|
+
Requires-Dist: swarmauri_base (>=0.11.0.dev6,<0.12)
|
|
26
|
+
Requires-Dist: swarmauri_core (>=0.11.0.dev6,<0.12)
|
|
27
|
+
Requires-Dist: swarmauri_standard (>=0.11.0.dev8,<0.12)
|
|
28
|
+
Requires-Dist: swarmauri_tool_inspectruntimetool (>=0.1.0,<0.2)
|
|
29
|
+
Requires-Dist: swarmauri_tool_listruntimetools (>=0.1.0,<0.2)
|
|
30
|
+
Requires-Dist: swarmauri_tool_registerruntimetool (>=0.1.0,<0.2)
|
|
31
|
+
Requires-Dist: swarmauri_tool_replaceruntimetool (>=0.1.0,<0.2)
|
|
32
|
+
Requires-Dist: swarmauri_tool_unregisterruntimetool (>=0.1.0,<0.2)
|
|
26
33
|
Description-Content-Type: text/markdown
|
|
27
34
|
|
|
28
|
-

|
|
29
36
|
|
|
30
37
|
<p align="center">
|
|
31
38
|
<a href="https://pepy.tech/project/swarmauri_toolkit_runtime/">
|
|
@@ -33,22 +40,24 @@ Description-Content-Type: text/markdown
|
|
|
33
40
|
<a href="https://hits.sh/github.com/swarmauri/swarmauri-sdk/tree/master/pkgs/standards/swarmauri_toolkit_runtime/">
|
|
34
41
|
<img alt="Hits" src="https://hits.sh/github.com/swarmauri/swarmauri-sdk/tree/master/pkgs/standards/swarmauri_toolkit_runtime.svg"/></a>
|
|
35
42
|
<a href="https://pypi.org/project/swarmauri_toolkit_runtime/">
|
|
36
|
-
<img src="https://img.shields.io/
|
|
43
|
+
<img src="https://img.shields.io/badge/python-3.10%20%7C%203.11%20%7C%203.12%20%7C%203.13%20%7C%203.14-blue" alt="PyPI - Python Version"/></a>
|
|
37
44
|
<a href="https://pypi.org/project/swarmauri_toolkit_runtime/">
|
|
38
45
|
<img src="https://img.shields.io/pypi/l/swarmauri_toolkit_runtime" alt="PyPI - License"/></a>
|
|
39
46
|
<a href="https://pypi.org/project/swarmauri_toolkit_runtime/">
|
|
40
47
|
<img src="https://img.shields.io/pypi/v/swarmauri_toolkit_runtime?label=swarmauri_toolkit_runtime&color=green" alt="PyPI - swarmauri_toolkit_runtime"/></a>
|
|
41
|
-
|
|
48
|
+
<a href="https://discord.gg/N4UpBuQv8T">
|
|
49
|
+
<img src="https://img.shields.io/badge/Discord-Join%20Chat-5865F2?logo=discord&logoColor=white" alt="Discord"/></a></p>
|
|
42
50
|
|
|
43
51
|
# Swarmauri Toolkit RuntimeToolkit
|
|
44
52
|
|
|
45
|
-
`RuntimeToolkit` is a Swarmauri runtime-management toolkit for agents that need to register, inspect, list, replace, and remove tools during execution. It keeps tool mutation inside the active toolkit instance and requires explicit parameter declarations when a new runtime tool is introduced.
|
|
53
|
+
`RuntimeToolkit` is a Swarmauri runtime-management toolkit for agents that need to register, inspect, list, replace, and remove tools during execution. It keeps tool mutation inside the active toolkit instance and requires both explicit parameter declarations and an explicit `__call__` implementation when a new runtime tool is introduced.
|
|
46
54
|
|
|
47
55
|
## Features
|
|
48
56
|
|
|
49
57
|
- Bundles agent-callable CRUD operations for toolkit members.
|
|
50
|
-
- Accepts serialized tool specs with `type`
|
|
51
|
-
- Enforces a non-empty declared `parameters` list for runtime tool registration and replacement.
|
|
58
|
+
- Accepts serialized runtime tool specs with `type`, `parameters`, and `__call__` fields.
|
|
59
|
+
- Enforces a non-empty declared `parameters` list and a non-empty `__call__` body for runtime tool registration and replacement.
|
|
60
|
+
- Evaluates runtime `__call__` bodies through a restricted expression rail rather than unrestricted Python execution.
|
|
52
61
|
- Returns agent-friendly dictionaries for reads, lists, and mutation results.
|
|
53
62
|
- Protects the toolkit's own management tools from accidental overwrite or removal.
|
|
54
63
|
- Supports Python 3.10 through 3.12.
|
|
@@ -78,7 +87,7 @@ pip install swarmauri_toolkit_runtime
|
|
|
78
87
|
Use `RuntimeToolkit` when an agent needs to mutate its own tool surface safely at runtime. The expected workflow is:
|
|
79
88
|
|
|
80
89
|
1. Start with the management toolkit.
|
|
81
|
-
2. Register a runtime tool using an explicit parameter contract.
|
|
90
|
+
2. Register a runtime tool using an explicit parameter contract and explicit callable body.
|
|
82
91
|
3. Inspect or list the available runtime tools.
|
|
83
92
|
4. Execute the registered tool.
|
|
84
93
|
5. Replace or unregister the tool when the runtime surface changes.
|
|
@@ -92,7 +101,7 @@ toolkit = RuntimeToolkit()
|
|
|
92
101
|
|
|
93
102
|
toolkit.get_tool_by_name("RegisterRuntimeTool")(
|
|
94
103
|
{
|
|
95
|
-
"type": "
|
|
104
|
+
"type": "RuntimeAdditionTool",
|
|
96
105
|
"name": "RuntimeAdditionTool",
|
|
97
106
|
"description": "Adds two integers during the active agent session.",
|
|
98
107
|
"parameters": [
|
|
@@ -109,6 +118,7 @@ toolkit.get_tool_by_name("RegisterRuntimeTool")(
|
|
|
109
118
|
"required": True,
|
|
110
119
|
},
|
|
111
120
|
],
|
|
121
|
+
"__call__": '{"sum": str(x + y)}',
|
|
112
122
|
}
|
|
113
123
|
)
|
|
114
124
|
|
|
@@ -128,14 +138,15 @@ print(result)
|
|
|
128
138
|
|
|
129
139
|
Mutation tools accept a serialized tool specification. At minimum, provide:
|
|
130
140
|
|
|
131
|
-
- a `type` field that
|
|
141
|
+
- a non-empty `type` field that names the runtime tool surface
|
|
132
142
|
- a non-empty `parameters` list that explicitly declares the runtime callable contract
|
|
143
|
+
- a non-empty `__call__` string that evaluates as a safe Python expression over the declared parameters and approved builtins
|
|
133
144
|
|
|
134
|
-
|
|
145
|
+
The runtime evaluator permits only a constrained expression subset and approved builtins such as `str`, `int`, `float`, `len`, `sum`, `min`, `max`, and `abs`. Imports, attribute traversal, and arbitrary function calls are rejected.
|
|
135
146
|
|
|
136
147
|
```python
|
|
137
148
|
{
|
|
138
|
-
"type": "
|
|
149
|
+
"type": "RuntimeAdditionTool",
|
|
139
150
|
"name": "RuntimeAdditionTool",
|
|
140
151
|
"description": "Adds two integers.",
|
|
141
152
|
"parameters": [
|
|
@@ -152,15 +163,19 @@ Resolution prefers the `swarmauri` facade when present and falls back to `swarma
|
|
|
152
163
|
"required": True,
|
|
153
164
|
},
|
|
154
165
|
],
|
|
166
|
+
"__call__": '{"sum": str(x + y)}',
|
|
155
167
|
}
|
|
156
168
|
```
|
|
157
169
|
|
|
158
|
-
|
|
170
|
+
The `__call__` value is evaluated against the declared parameter names. A body such as `{"sum": str(x + y)}` is valid. A body that tries to import modules, access attributes, or reference undeclared names is rejected.
|
|
159
171
|
|
|
160
172
|
## Failure Modes
|
|
161
173
|
|
|
162
174
|
- Registration fails when the tool spec omits `parameters`.
|
|
175
|
+
- Registration fails when the tool spec omits `__call__`.
|
|
176
|
+
- Registration fails when the `__call__` body uses unsafe syntax or disallowed names.
|
|
163
177
|
- Registration fails when the tool name collides with a protected management tool.
|
|
178
|
+
- Execution failures inside an accepted runtime tool return a structured error payload instead of propagating a hard exception or terminating the host process.
|
|
164
179
|
- Replacement fails when the target tool is missing, reserved, or renamed to an existing tool.
|
|
165
180
|
- Unregistration fails when the target is reserved or absent.
|
|
166
181
|
|
|
@@ -169,3 +184,5 @@ If the target tool defines extra fields, include them in the spec and the toolki
|
|
|
169
184
|
`swarmauri_toolkit_runtime` is released under the Apache 2.0 License. See `LICENSE` for details.
|
|
170
185
|
|
|
171
186
|
|
|
187
|
+
|
|
188
|
+
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-

|
|
2
2
|
|
|
3
3
|
<p align="center">
|
|
4
4
|
<a href="https://pepy.tech/project/swarmauri_toolkit_runtime/">
|
|
@@ -6,22 +6,24 @@
|
|
|
6
6
|
<a href="https://hits.sh/github.com/swarmauri/swarmauri-sdk/tree/master/pkgs/standards/swarmauri_toolkit_runtime/">
|
|
7
7
|
<img alt="Hits" src="https://hits.sh/github.com/swarmauri/swarmauri-sdk/tree/master/pkgs/standards/swarmauri_toolkit_runtime.svg"/></a>
|
|
8
8
|
<a href="https://pypi.org/project/swarmauri_toolkit_runtime/">
|
|
9
|
-
<img src="https://img.shields.io/
|
|
9
|
+
<img src="https://img.shields.io/badge/python-3.10%20%7C%203.11%20%7C%203.12%20%7C%203.13%20%7C%203.14-blue" alt="PyPI - Python Version"/></a>
|
|
10
10
|
<a href="https://pypi.org/project/swarmauri_toolkit_runtime/">
|
|
11
11
|
<img src="https://img.shields.io/pypi/l/swarmauri_toolkit_runtime" alt="PyPI - License"/></a>
|
|
12
12
|
<a href="https://pypi.org/project/swarmauri_toolkit_runtime/">
|
|
13
13
|
<img src="https://img.shields.io/pypi/v/swarmauri_toolkit_runtime?label=swarmauri_toolkit_runtime&color=green" alt="PyPI - swarmauri_toolkit_runtime"/></a>
|
|
14
|
-
|
|
14
|
+
<a href="https://discord.gg/N4UpBuQv8T">
|
|
15
|
+
<img src="https://img.shields.io/badge/Discord-Join%20Chat-5865F2?logo=discord&logoColor=white" alt="Discord"/></a></p>
|
|
15
16
|
|
|
16
17
|
# Swarmauri Toolkit RuntimeToolkit
|
|
17
18
|
|
|
18
|
-
`RuntimeToolkit` is a Swarmauri runtime-management toolkit for agents that need to register, inspect, list, replace, and remove tools during execution. It keeps tool mutation inside the active toolkit instance and requires explicit parameter declarations when a new runtime tool is introduced.
|
|
19
|
+
`RuntimeToolkit` is a Swarmauri runtime-management toolkit for agents that need to register, inspect, list, replace, and remove tools during execution. It keeps tool mutation inside the active toolkit instance and requires both explicit parameter declarations and an explicit `__call__` implementation when a new runtime tool is introduced.
|
|
19
20
|
|
|
20
21
|
## Features
|
|
21
22
|
|
|
22
23
|
- Bundles agent-callable CRUD operations for toolkit members.
|
|
23
|
-
- Accepts serialized tool specs with `type`
|
|
24
|
-
- Enforces a non-empty declared `parameters` list for runtime tool registration and replacement.
|
|
24
|
+
- Accepts serialized runtime tool specs with `type`, `parameters`, and `__call__` fields.
|
|
25
|
+
- Enforces a non-empty declared `parameters` list and a non-empty `__call__` body for runtime tool registration and replacement.
|
|
26
|
+
- Evaluates runtime `__call__` bodies through a restricted expression rail rather than unrestricted Python execution.
|
|
25
27
|
- Returns agent-friendly dictionaries for reads, lists, and mutation results.
|
|
26
28
|
- Protects the toolkit's own management tools from accidental overwrite or removal.
|
|
27
29
|
- Supports Python 3.10 through 3.12.
|
|
@@ -51,7 +53,7 @@ pip install swarmauri_toolkit_runtime
|
|
|
51
53
|
Use `RuntimeToolkit` when an agent needs to mutate its own tool surface safely at runtime. The expected workflow is:
|
|
52
54
|
|
|
53
55
|
1. Start with the management toolkit.
|
|
54
|
-
2. Register a runtime tool using an explicit parameter contract.
|
|
56
|
+
2. Register a runtime tool using an explicit parameter contract and explicit callable body.
|
|
55
57
|
3. Inspect or list the available runtime tools.
|
|
56
58
|
4. Execute the registered tool.
|
|
57
59
|
5. Replace or unregister the tool when the runtime surface changes.
|
|
@@ -65,7 +67,7 @@ toolkit = RuntimeToolkit()
|
|
|
65
67
|
|
|
66
68
|
toolkit.get_tool_by_name("RegisterRuntimeTool")(
|
|
67
69
|
{
|
|
68
|
-
"type": "
|
|
70
|
+
"type": "RuntimeAdditionTool",
|
|
69
71
|
"name": "RuntimeAdditionTool",
|
|
70
72
|
"description": "Adds two integers during the active agent session.",
|
|
71
73
|
"parameters": [
|
|
@@ -82,6 +84,7 @@ toolkit.get_tool_by_name("RegisterRuntimeTool")(
|
|
|
82
84
|
"required": True,
|
|
83
85
|
},
|
|
84
86
|
],
|
|
87
|
+
"__call__": '{"sum": str(x + y)}',
|
|
85
88
|
}
|
|
86
89
|
)
|
|
87
90
|
|
|
@@ -101,14 +104,15 @@ print(result)
|
|
|
101
104
|
|
|
102
105
|
Mutation tools accept a serialized tool specification. At minimum, provide:
|
|
103
106
|
|
|
104
|
-
- a `type` field that
|
|
107
|
+
- a non-empty `type` field that names the runtime tool surface
|
|
105
108
|
- a non-empty `parameters` list that explicitly declares the runtime callable contract
|
|
109
|
+
- a non-empty `__call__` string that evaluates as a safe Python expression over the declared parameters and approved builtins
|
|
106
110
|
|
|
107
|
-
|
|
111
|
+
The runtime evaluator permits only a constrained expression subset and approved builtins such as `str`, `int`, `float`, `len`, `sum`, `min`, `max`, and `abs`. Imports, attribute traversal, and arbitrary function calls are rejected.
|
|
108
112
|
|
|
109
113
|
```python
|
|
110
114
|
{
|
|
111
|
-
"type": "
|
|
115
|
+
"type": "RuntimeAdditionTool",
|
|
112
116
|
"name": "RuntimeAdditionTool",
|
|
113
117
|
"description": "Adds two integers.",
|
|
114
118
|
"parameters": [
|
|
@@ -125,15 +129,19 @@ Resolution prefers the `swarmauri` facade when present and falls back to `swarma
|
|
|
125
129
|
"required": True,
|
|
126
130
|
},
|
|
127
131
|
],
|
|
132
|
+
"__call__": '{"sum": str(x + y)}',
|
|
128
133
|
}
|
|
129
134
|
```
|
|
130
135
|
|
|
131
|
-
|
|
136
|
+
The `__call__` value is evaluated against the declared parameter names. A body such as `{"sum": str(x + y)}` is valid. A body that tries to import modules, access attributes, or reference undeclared names is rejected.
|
|
132
137
|
|
|
133
138
|
## Failure Modes
|
|
134
139
|
|
|
135
140
|
- Registration fails when the tool spec omits `parameters`.
|
|
141
|
+
- Registration fails when the tool spec omits `__call__`.
|
|
142
|
+
- Registration fails when the `__call__` body uses unsafe syntax or disallowed names.
|
|
136
143
|
- Registration fails when the tool name collides with a protected management tool.
|
|
144
|
+
- Execution failures inside an accepted runtime tool return a structured error payload instead of propagating a hard exception or terminating the host process.
|
|
137
145
|
- Replacement fails when the target tool is missing, reserved, or renamed to an existing tool.
|
|
138
146
|
- Unregistration fails when the target is reserved or absent.
|
|
139
147
|
|
|
@@ -141,3 +149,5 @@ If the target tool defines extra fields, include them in the spec and the toolki
|
|
|
141
149
|
|
|
142
150
|
`swarmauri_toolkit_runtime` is released under the Apache 2.0 License. See `LICENSE` for details.
|
|
143
151
|
|
|
152
|
+
|
|
153
|
+
|
{swarmauri_toolkit_runtime-0.1.1.dev2 → swarmauri_toolkit_runtime-0.11.0.dev4}/pyproject.toml
RENAMED
|
@@ -1,30 +1,37 @@
|
|
|
1
1
|
[project]
|
|
2
2
|
name = "swarmauri_toolkit_runtime"
|
|
3
|
-
version = "0.
|
|
3
|
+
version = "0.11.0.dev4"
|
|
4
4
|
description = "Runtime toolkit for explicit-parameter registration, inspection, replacement, listing, and removal of Swarmauri tools during agent execution."
|
|
5
5
|
license = "Apache-2.0"
|
|
6
6
|
readme = { file = "README.md", content-type = "text/markdown" }
|
|
7
7
|
repository = "http://github.com/swarmauri/swarmauri-sdk/tree/master/pkgs/standards/swarmauri_toolkit_runtime"
|
|
8
|
-
requires-python = ">=3.10,<3.
|
|
8
|
+
requires-python = ">=3.10,<3.15"
|
|
9
9
|
classifiers = [
|
|
10
10
|
"Development Status :: 1 - Planning",
|
|
11
11
|
"Intended Audience :: Developers",
|
|
12
12
|
"License :: OSI Approved :: Apache Software License",
|
|
13
13
|
"Natural Language :: English",
|
|
14
|
+
"Topic :: Software Development :: Libraries :: Application Frameworks",
|
|
14
15
|
"Programming Language :: Python",
|
|
15
16
|
"Programming Language :: Python :: 3",
|
|
16
17
|
"Programming Language :: Python :: 3 :: Only",
|
|
17
18
|
"Programming Language :: Python :: 3.10",
|
|
18
19
|
"Programming Language :: Python :: 3.11",
|
|
19
20
|
"Programming Language :: Python :: 3.12",
|
|
20
|
-
"
|
|
21
|
+
"Programming Language :: Python :: 3.13",
|
|
22
|
+
"Programming Language :: Python :: 3.14",
|
|
21
23
|
]
|
|
22
24
|
authors = [{ name = "Jacob Stewart", email = "jacob@swarmauri.com" }]
|
|
23
25
|
dependencies = [
|
|
26
|
+
"swarmauri_tool_registerruntimetool>=0.1.0,<0.2",
|
|
27
|
+
"swarmauri_tool_inspectruntimetool>=0.1.0,<0.2",
|
|
28
|
+
"swarmauri_tool_listruntimetools>=0.1.0,<0.2",
|
|
29
|
+
"swarmauri_tool_replaceruntimetool>=0.1.0,<0.2",
|
|
30
|
+
"swarmauri_tool_unregisterruntimetool>=0.1.0,<0.2",
|
|
24
31
|
"pydantic",
|
|
25
|
-
"swarmauri_core",
|
|
26
|
-
"swarmauri_base",
|
|
27
|
-
"swarmauri_standard",
|
|
32
|
+
"swarmauri_core>=0.11.0.dev6,<0.12",
|
|
33
|
+
"swarmauri_base>=0.11.0.dev6,<0.12",
|
|
34
|
+
"swarmauri_standard>=0.11.0.dev8,<0.12",
|
|
28
35
|
]
|
|
29
36
|
keywords = [
|
|
30
37
|
"swarmauri",
|
|
@@ -47,6 +54,11 @@ keywords = [
|
|
|
47
54
|
]
|
|
48
55
|
|
|
49
56
|
[tool.uv.sources]
|
|
57
|
+
swarmauri_tool_registerruntimetool = { workspace = true }
|
|
58
|
+
swarmauri_tool_inspectruntimetool = { workspace = true }
|
|
59
|
+
swarmauri_tool_listruntimetools = { workspace = true }
|
|
60
|
+
swarmauri_tool_replaceruntimetool = { workspace = true }
|
|
61
|
+
swarmauri_tool_unregisterruntimetool = { workspace = true }
|
|
50
62
|
swarmauri_core = { workspace = true }
|
|
51
63
|
swarmauri_base = { workspace = true }
|
|
52
64
|
swarmauri_standard = { workspace = true }
|
|
@@ -74,13 +86,6 @@ asyncio_default_fixture_loop_scope = "function"
|
|
|
74
86
|
[project.entry-points.'swarmauri.toolkits']
|
|
75
87
|
RuntimeToolkit = "swarmauri_toolkit_runtime:RuntimeToolkit"
|
|
76
88
|
|
|
77
|
-
[project.entry-points.'swarmauri.tools']
|
|
78
|
-
RegisterRuntimeTool = "swarmauri_toolkit_runtime:RegisterRuntimeTool"
|
|
79
|
-
InspectRuntimeTool = "swarmauri_toolkit_runtime:InspectRuntimeTool"
|
|
80
|
-
ListRuntimeTools = "swarmauri_toolkit_runtime:ListRuntimeTools"
|
|
81
|
-
UnregisterRuntimeTool = "swarmauri_toolkit_runtime:UnregisterRuntimeTool"
|
|
82
|
-
ReplaceRuntimeTool = "swarmauri_toolkit_runtime:ReplaceRuntimeTool"
|
|
83
|
-
|
|
84
89
|
[build-system]
|
|
85
90
|
requires = ["poetry-core>=1.0.0"]
|
|
86
91
|
build-backend = "poetry.core.masonry.api"
|
|
@@ -92,7 +97,7 @@ dev = [
|
|
|
92
97
|
"pytest-xdist>=3.6.1",
|
|
93
98
|
"pytest-json-report>=1.5.0",
|
|
94
99
|
"python-dotenv",
|
|
95
|
-
"
|
|
100
|
+
"httpx>=0.27",
|
|
96
101
|
"flake8>=7.0",
|
|
97
102
|
"pytest-timeout>=2.3.1",
|
|
98
103
|
"ruff>=0.9.9",
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
from collections.abc import Callable
|
|
2
|
+
from typing import Any, Literal
|
|
3
|
+
|
|
4
|
+
from pydantic import BaseModel, Field
|
|
5
|
+
from swarmauri_base.ComponentBase import ComponentBase
|
|
6
|
+
from swarmauri_base.tools.ToolBase import ToolBase
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
class RecipeStep(BaseModel):
|
|
10
|
+
"""Call one installed tool with literals or input references."""
|
|
11
|
+
|
|
12
|
+
tool: str
|
|
13
|
+
arguments: dict[str, Any] = Field(default_factory=dict)
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
@ComponentBase.register_type(ToolBase, "RecipeTool")
|
|
17
|
+
class RecipeTool(ToolBase):
|
|
18
|
+
"""Run a sequence of existing tool calls through a host dispatcher."""
|
|
19
|
+
|
|
20
|
+
type: Literal["RecipeTool"] = "RecipeTool"
|
|
21
|
+
steps: list[RecipeStep] = Field(min_length=1, max_length=32)
|
|
22
|
+
dispatch: Callable[[str, dict[str, Any]], dict[str, Any]] = Field(
|
|
23
|
+
exclude=True
|
|
24
|
+
)
|
|
25
|
+
|
|
26
|
+
def __call__(self, **inputs):
|
|
27
|
+
declared = {parameter.name for parameter in self.parameters}
|
|
28
|
+
required = {
|
|
29
|
+
parameter.name
|
|
30
|
+
for parameter in self.parameters
|
|
31
|
+
if parameter.required
|
|
32
|
+
}
|
|
33
|
+
if inputs.keys() - declared or required - inputs.keys():
|
|
34
|
+
raise ValueError("Recipe inputs do not match its parameters")
|
|
35
|
+
results = []
|
|
36
|
+
for step in self.steps:
|
|
37
|
+
arguments = {
|
|
38
|
+
key: inputs[value["input"]]
|
|
39
|
+
if isinstance(value, dict) and value.keys() == {"input"}
|
|
40
|
+
else value
|
|
41
|
+
for key, value in step.arguments.items()
|
|
42
|
+
}
|
|
43
|
+
result = self.dispatch(step.tool, arguments)
|
|
44
|
+
results.append(result)
|
|
45
|
+
if result.get("status") != "completed":
|
|
46
|
+
break
|
|
47
|
+
return {"steps": results}
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
from collections.abc import Callable, Mapping
|
|
2
|
+
from typing import Dict, Literal
|
|
3
|
+
|
|
4
|
+
from pydantic import Field, PrivateAttr
|
|
5
|
+
|
|
6
|
+
from swarmauri_base.ComponentBase import ComponentBase
|
|
7
|
+
from swarmauri_base.tools.ToolBase import ToolBase
|
|
8
|
+
from swarmauri_base.toolkits.ToolkitBase import ToolkitBase
|
|
9
|
+
|
|
10
|
+
from .RegisterRuntimeTool import RegisterRuntimeTool
|
|
11
|
+
from .InspectRuntimeTool import InspectRuntimeTool
|
|
12
|
+
from .ListRuntimeTools import ListRuntimeTools
|
|
13
|
+
from .UnregisterRuntimeTool import UnregisterRuntimeTool
|
|
14
|
+
from .ReplaceRuntimeTool import ReplaceRuntimeTool
|
|
15
|
+
from .RecipeTool import RecipeTool
|
|
16
|
+
from ._tool_factory import build_tool_from_spec
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
@ComponentBase.register_type(ToolkitBase, "RuntimeToolkit")
|
|
20
|
+
class RuntimeToolkit(ToolkitBase):
|
|
21
|
+
type: Literal["RuntimeToolkit"] = "RuntimeToolkit"
|
|
22
|
+
tools: Dict[str, ToolBase] = {}
|
|
23
|
+
revision: int = Field(default=0, ge=0)
|
|
24
|
+
_recipe_dispatch: Callable | None = PrivateAttr(default=None)
|
|
25
|
+
|
|
26
|
+
def __init__(self, **kwargs):
|
|
27
|
+
super().__init__(**kwargs)
|
|
28
|
+
self.tools = self._build_management_tools()
|
|
29
|
+
|
|
30
|
+
def _build_management_tools(self) -> Dict[str, ToolBase]:
|
|
31
|
+
protected_tool_names = {
|
|
32
|
+
"RegisterRuntimeTool",
|
|
33
|
+
"InspectRuntimeTool",
|
|
34
|
+
"ListRuntimeTools",
|
|
35
|
+
"UnregisterRuntimeTool",
|
|
36
|
+
"ReplaceRuntimeTool",
|
|
37
|
+
}
|
|
38
|
+
return {
|
|
39
|
+
"RegisterRuntimeTool": RegisterRuntimeTool(
|
|
40
|
+
toolkit=self,
|
|
41
|
+
protected_tool_names=protected_tool_names,
|
|
42
|
+
factory=self._build_tool,
|
|
43
|
+
),
|
|
44
|
+
"InspectRuntimeTool": InspectRuntimeTool(toolkit=self),
|
|
45
|
+
"ListRuntimeTools": ListRuntimeTools(toolkit=self),
|
|
46
|
+
"UnregisterRuntimeTool": UnregisterRuntimeTool(
|
|
47
|
+
toolkit=self, protected_tool_names=protected_tool_names
|
|
48
|
+
),
|
|
49
|
+
"ReplaceRuntimeTool": ReplaceRuntimeTool(
|
|
50
|
+
toolkit=self,
|
|
51
|
+
protected_tool_names=protected_tool_names,
|
|
52
|
+
factory=self._build_tool,
|
|
53
|
+
),
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
def bind_recipe_dispatch(self, dispatch: Callable) -> None:
|
|
57
|
+
"""Configure the application dispatcher for recipe steps."""
|
|
58
|
+
self._recipe_dispatch = dispatch
|
|
59
|
+
|
|
60
|
+
def _build_tool(self, spec):
|
|
61
|
+
if isinstance(spec, Mapping) and spec.get("type") == "RecipeTool":
|
|
62
|
+
if self._recipe_dispatch is None:
|
|
63
|
+
raise ValueError("Recipe dispatch is not configured")
|
|
64
|
+
return RecipeTool.model_validate(
|
|
65
|
+
{**spec, "dispatch": self._recipe_dispatch}
|
|
66
|
+
)
|
|
67
|
+
return build_tool_from_spec(spec)
|
|
68
|
+
|
|
69
|
+
def add_tool(self, tool):
|
|
70
|
+
super().add_tool(tool)
|
|
71
|
+
self.revision += 1
|
|
72
|
+
|
|
73
|
+
def remove_tool(self, tool_name):
|
|
74
|
+
super().remove_tool(tool_name)
|
|
75
|
+
self.revision += 1
|
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
from typing import Any, Dict, List, Literal
|
|
2
|
-
|
|
3
|
-
from pydantic import Field
|
|
4
|
-
|
|
5
|
-
from swarmauri_base.ComponentBase import ComponentBase
|
|
6
|
-
from swarmauri_base.tools.ToolBase import ToolBase
|
|
7
|
-
from swarmauri_base.toolkits.ToolkitBase import ToolkitBase
|
|
8
|
-
from swarmauri_standard.tools.Parameter import Parameter
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
@ComponentBase.register_type(ToolBase, "InspectRuntimeTool")
|
|
12
|
-
class InspectRuntimeTool(ToolBase):
|
|
13
|
-
version: str = "0.1.0"
|
|
14
|
-
name: str = "InspectRuntimeTool"
|
|
15
|
-
description: str = "Read one tool from the active toolkit by name."
|
|
16
|
-
type: Literal["InspectRuntimeTool"] = "InspectRuntimeTool"
|
|
17
|
-
toolkit: ToolkitBase | None = Field(default=None, exclude=True, repr=False)
|
|
18
|
-
parameters: List[Parameter] = Field(
|
|
19
|
-
default_factory=lambda: [
|
|
20
|
-
Parameter(
|
|
21
|
-
name="tool_name",
|
|
22
|
-
input_type="string",
|
|
23
|
-
description="Name of the tool to fetch from the toolkit.",
|
|
24
|
-
required=True,
|
|
25
|
-
)
|
|
26
|
-
]
|
|
27
|
-
)
|
|
28
|
-
|
|
29
|
-
def __call__(self, tool_name: str) -> Dict[str, Any]:
|
|
30
|
-
if self.toolkit is None:
|
|
31
|
-
raise ValueError("toolkit is not configured")
|
|
32
|
-
|
|
33
|
-
tool = self.toolkit.get_tool_by_name(tool_name)
|
|
34
|
-
return {
|
|
35
|
-
"tool_name": tool_name,
|
|
36
|
-
"tool_type": tool.type,
|
|
37
|
-
"tool": tool.model_dump(exclude_none=True),
|
|
38
|
-
}
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
from typing import Any, Dict, List, Literal
|
|
2
|
-
|
|
3
|
-
from pydantic import Field
|
|
4
|
-
|
|
5
|
-
from swarmauri_base.ComponentBase import ComponentBase
|
|
6
|
-
from swarmauri_base.tools.ToolBase import ToolBase
|
|
7
|
-
from swarmauri_base.toolkits.ToolkitBase import ToolkitBase
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
@ComponentBase.register_type(ToolBase, "ListRuntimeTools")
|
|
11
|
-
class ListRuntimeTools(ToolBase):
|
|
12
|
-
version: str = "0.1.0"
|
|
13
|
-
name: str = "ListRuntimeTools"
|
|
14
|
-
description: str = "List all tools currently available in the active toolkit."
|
|
15
|
-
type: Literal["ListRuntimeTools"] = "ListRuntimeTools"
|
|
16
|
-
toolkit: ToolkitBase | None = Field(default=None, exclude=True, repr=False)
|
|
17
|
-
parameters: List[Any] = Field(default_factory=list)
|
|
18
|
-
|
|
19
|
-
def __call__(self) -> Dict[str, Any]:
|
|
20
|
-
if self.toolkit is None:
|
|
21
|
-
raise ValueError("toolkit is not configured")
|
|
22
|
-
|
|
23
|
-
tools = {
|
|
24
|
-
name: tool.model_dump(exclude_none=True)
|
|
25
|
-
for name, tool in self.toolkit.tools.items()
|
|
26
|
-
}
|
|
27
|
-
return {
|
|
28
|
-
"tool_count": len(self.toolkit),
|
|
29
|
-
"tool_names": list(self.toolkit.tools.keys()),
|
|
30
|
-
"tools": tools,
|
|
31
|
-
}
|
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
from typing import Any, Dict, List, Literal, Mapping
|
|
2
|
-
|
|
3
|
-
from pydantic import Field
|
|
4
|
-
|
|
5
|
-
from swarmauri_base.ComponentBase import ComponentBase
|
|
6
|
-
from swarmauri_base.tools.ToolBase import ToolBase
|
|
7
|
-
from swarmauri_base.toolkits.ToolkitBase import ToolkitBase
|
|
8
|
-
from swarmauri_standard.tools.Parameter import Parameter
|
|
9
|
-
|
|
10
|
-
from ._tool_factory import build_tool_from_spec
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
@ComponentBase.register_type(ToolBase, "RegisterRuntimeTool")
|
|
14
|
-
class RegisterRuntimeTool(ToolBase):
|
|
15
|
-
version: str = "0.1.0"
|
|
16
|
-
name: str = "RegisterRuntimeTool"
|
|
17
|
-
description: str = (
|
|
18
|
-
"Create a tool from a serialized tool spec and add it to the active toolkit."
|
|
19
|
-
)
|
|
20
|
-
type: Literal["RegisterRuntimeTool"] = "RegisterRuntimeTool"
|
|
21
|
-
toolkit: ToolkitBase | None = Field(default=None, exclude=True, repr=False)
|
|
22
|
-
protected_tool_names: set[str] = Field(
|
|
23
|
-
default_factory=set, exclude=True, repr=False
|
|
24
|
-
)
|
|
25
|
-
parameters: List[Parameter] = Field(
|
|
26
|
-
default_factory=lambda: [
|
|
27
|
-
Parameter(
|
|
28
|
-
name="tool_spec",
|
|
29
|
-
input_type="object",
|
|
30
|
-
description="Serialized tool payload with at least a 'type' field.",
|
|
31
|
-
required=True,
|
|
32
|
-
)
|
|
33
|
-
]
|
|
34
|
-
)
|
|
35
|
-
|
|
36
|
-
def __call__(self, tool_spec: Mapping[str, Any] | ToolBase) -> Dict[str, Any]:
|
|
37
|
-
if self.toolkit is None:
|
|
38
|
-
raise ValueError("toolkit is not configured")
|
|
39
|
-
|
|
40
|
-
tool = build_tool_from_spec(tool_spec)
|
|
41
|
-
if tool.name in self.protected_tool_names:
|
|
42
|
-
raise ValueError(f"Tool '{tool.name}' is reserved by RuntimeToolkit")
|
|
43
|
-
if tool.name in self.toolkit.tools:
|
|
44
|
-
raise ValueError(f"Tool '{tool.name}' already exists in the toolkit")
|
|
45
|
-
|
|
46
|
-
self.toolkit.add_tool(tool)
|
|
47
|
-
return {
|
|
48
|
-
"status": "created",
|
|
49
|
-
"tool_name": tool.name,
|
|
50
|
-
"tool_type": tool.type,
|
|
51
|
-
"tool": tool.model_dump(exclude_none=True),
|
|
52
|
-
"tool_count": len(self.toolkit),
|
|
53
|
-
}
|
|
@@ -1,68 +0,0 @@
|
|
|
1
|
-
from typing import Any, Dict, List, Literal, Mapping
|
|
2
|
-
|
|
3
|
-
from pydantic import Field
|
|
4
|
-
|
|
5
|
-
from swarmauri_base.ComponentBase import ComponentBase
|
|
6
|
-
from swarmauri_base.tools.ToolBase import ToolBase
|
|
7
|
-
from swarmauri_base.toolkits.ToolkitBase import ToolkitBase
|
|
8
|
-
from swarmauri_standard.tools.Parameter import Parameter
|
|
9
|
-
|
|
10
|
-
from ._tool_factory import build_tool_from_spec
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
@ComponentBase.register_type(ToolBase, "ReplaceRuntimeTool")
|
|
14
|
-
class ReplaceRuntimeTool(ToolBase):
|
|
15
|
-
version: str = "0.1.0"
|
|
16
|
-
name: str = "ReplaceRuntimeTool"
|
|
17
|
-
description: str = "Replace an existing non-reserved tool in the active toolkit with a new serialized tool spec."
|
|
18
|
-
type: Literal["ReplaceRuntimeTool"] = "ReplaceRuntimeTool"
|
|
19
|
-
toolkit: ToolkitBase | None = Field(default=None, exclude=True, repr=False)
|
|
20
|
-
protected_tool_names: set[str] = Field(
|
|
21
|
-
default_factory=set, exclude=True, repr=False
|
|
22
|
-
)
|
|
23
|
-
parameters: List[Parameter] = Field(
|
|
24
|
-
default_factory=lambda: [
|
|
25
|
-
Parameter(
|
|
26
|
-
name="tool_name",
|
|
27
|
-
input_type="string",
|
|
28
|
-
description="Existing tool name to replace.",
|
|
29
|
-
required=True,
|
|
30
|
-
),
|
|
31
|
-
Parameter(
|
|
32
|
-
name="tool_spec",
|
|
33
|
-
input_type="object",
|
|
34
|
-
description="Serialized replacement tool payload with at least a 'type' field.",
|
|
35
|
-
required=True,
|
|
36
|
-
),
|
|
37
|
-
]
|
|
38
|
-
)
|
|
39
|
-
|
|
40
|
-
def __call__(
|
|
41
|
-
self, tool_name: str, tool_spec: Mapping[str, Any] | ToolBase
|
|
42
|
-
) -> Dict[str, Any]:
|
|
43
|
-
if self.toolkit is None:
|
|
44
|
-
raise ValueError("toolkit is not configured")
|
|
45
|
-
if tool_name in self.protected_tool_names:
|
|
46
|
-
raise ValueError(f"Tool '{tool_name}' is reserved by RuntimeToolkit")
|
|
47
|
-
if tool_name not in self.toolkit.tools:
|
|
48
|
-
raise ValueError(f"Tool '{tool_name}' not found in the toolkit")
|
|
49
|
-
|
|
50
|
-
replacement = build_tool_from_spec(tool_spec)
|
|
51
|
-
if (
|
|
52
|
-
replacement.name in self.protected_tool_names
|
|
53
|
-
and replacement.name != tool_name
|
|
54
|
-
):
|
|
55
|
-
raise ValueError(f"Tool '{replacement.name}' is reserved by RuntimeToolkit")
|
|
56
|
-
if replacement.name != tool_name and replacement.name in self.toolkit.tools:
|
|
57
|
-
raise ValueError(f"Tool '{replacement.name}' already exists in the toolkit")
|
|
58
|
-
|
|
59
|
-
self.toolkit.remove_tool(tool_name)
|
|
60
|
-
self.toolkit.add_tool(replacement)
|
|
61
|
-
return {
|
|
62
|
-
"status": "updated",
|
|
63
|
-
"previous_tool_name": tool_name,
|
|
64
|
-
"tool_name": replacement.name,
|
|
65
|
-
"tool_type": replacement.type,
|
|
66
|
-
"tool": replacement.model_dump(exclude_none=True),
|
|
67
|
-
"tool_count": len(self.toolkit),
|
|
68
|
-
}
|
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
from typing import Dict, Literal
|
|
2
|
-
|
|
3
|
-
from swarmauri_base.ComponentBase import ComponentBase, SubclassUnion
|
|
4
|
-
from swarmauri_base.tools.ToolBase import ToolBase
|
|
5
|
-
from swarmauri_base.toolkits.ToolkitBase import ToolkitBase
|
|
6
|
-
|
|
7
|
-
from .RegisterRuntimeTool import RegisterRuntimeTool
|
|
8
|
-
from .InspectRuntimeTool import InspectRuntimeTool
|
|
9
|
-
from .ListRuntimeTools import ListRuntimeTools
|
|
10
|
-
from .UnregisterRuntimeTool import UnregisterRuntimeTool
|
|
11
|
-
from .ReplaceRuntimeTool import ReplaceRuntimeTool
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
@ComponentBase.register_type(ToolkitBase, "RuntimeToolkit")
|
|
15
|
-
class RuntimeToolkit(ToolkitBase):
|
|
16
|
-
type: Literal["RuntimeToolkit"] = "RuntimeToolkit"
|
|
17
|
-
tools: Dict[str, SubclassUnion[ToolBase]] = {}
|
|
18
|
-
|
|
19
|
-
def __init__(self, **kwargs):
|
|
20
|
-
super().__init__(**kwargs)
|
|
21
|
-
self.tools = self._build_management_tools()
|
|
22
|
-
|
|
23
|
-
def _build_management_tools(self) -> Dict[str, SubclassUnion[ToolBase]]:
|
|
24
|
-
protected_tool_names = {
|
|
25
|
-
"RegisterRuntimeTool",
|
|
26
|
-
"InspectRuntimeTool",
|
|
27
|
-
"ListRuntimeTools",
|
|
28
|
-
"UnregisterRuntimeTool",
|
|
29
|
-
"ReplaceRuntimeTool",
|
|
30
|
-
}
|
|
31
|
-
return {
|
|
32
|
-
"RegisterRuntimeTool": RegisterRuntimeTool(
|
|
33
|
-
toolkit=self, protected_tool_names=protected_tool_names
|
|
34
|
-
),
|
|
35
|
-
"InspectRuntimeTool": InspectRuntimeTool(toolkit=self),
|
|
36
|
-
"ListRuntimeTools": ListRuntimeTools(toolkit=self),
|
|
37
|
-
"UnregisterRuntimeTool": UnregisterRuntimeTool(
|
|
38
|
-
toolkit=self, protected_tool_names=protected_tool_names
|
|
39
|
-
),
|
|
40
|
-
"ReplaceRuntimeTool": ReplaceRuntimeTool(
|
|
41
|
-
toolkit=self, protected_tool_names=protected_tool_names
|
|
42
|
-
),
|
|
43
|
-
}
|
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
from typing import Any, Dict, List, Literal
|
|
2
|
-
|
|
3
|
-
from pydantic import Field
|
|
4
|
-
|
|
5
|
-
from swarmauri_base.ComponentBase import ComponentBase
|
|
6
|
-
from swarmauri_base.tools.ToolBase import ToolBase
|
|
7
|
-
from swarmauri_base.toolkits.ToolkitBase import ToolkitBase
|
|
8
|
-
from swarmauri_standard.tools.Parameter import Parameter
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
@ComponentBase.register_type(ToolBase, "UnregisterRuntimeTool")
|
|
12
|
-
class UnregisterRuntimeTool(ToolBase):
|
|
13
|
-
version: str = "0.1.0"
|
|
14
|
-
name: str = "UnregisterRuntimeTool"
|
|
15
|
-
description: str = "Delete a non-reserved tool from the active toolkit."
|
|
16
|
-
type: Literal["UnregisterRuntimeTool"] = "UnregisterRuntimeTool"
|
|
17
|
-
toolkit: ToolkitBase | None = Field(default=None, exclude=True, repr=False)
|
|
18
|
-
protected_tool_names: set[str] = Field(
|
|
19
|
-
default_factory=set, exclude=True, repr=False
|
|
20
|
-
)
|
|
21
|
-
parameters: List[Parameter] = Field(
|
|
22
|
-
default_factory=lambda: [
|
|
23
|
-
Parameter(
|
|
24
|
-
name="tool_name",
|
|
25
|
-
input_type="string",
|
|
26
|
-
description="Name of the tool to remove from the toolkit.",
|
|
27
|
-
required=True,
|
|
28
|
-
)
|
|
29
|
-
]
|
|
30
|
-
)
|
|
31
|
-
|
|
32
|
-
def __call__(self, tool_name: str) -> Dict[str, Any]:
|
|
33
|
-
if self.toolkit is None:
|
|
34
|
-
raise ValueError("toolkit is not configured")
|
|
35
|
-
if tool_name in self.protected_tool_names:
|
|
36
|
-
raise ValueError(f"Tool '{tool_name}' is reserved by RuntimeToolkit")
|
|
37
|
-
|
|
38
|
-
self.toolkit.remove_tool(tool_name)
|
|
39
|
-
return {
|
|
40
|
-
"status": "deleted",
|
|
41
|
-
"tool_name": tool_name,
|
|
42
|
-
"tool_count": len(self.toolkit),
|
|
43
|
-
}
|
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
from importlib import import_module
|
|
2
|
-
from typing import Any, Mapping
|
|
3
|
-
|
|
4
|
-
from swarmauri_base.tools.ToolBase import ToolBase
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
def _resolve_tool_module(tool_type: str):
|
|
8
|
-
module_names = [
|
|
9
|
-
f"swarmauri.tools.{tool_type}",
|
|
10
|
-
f"swarmauri_standard.tools.{tool_type}",
|
|
11
|
-
]
|
|
12
|
-
last_error: ModuleNotFoundError | None = None
|
|
13
|
-
for module_name in module_names:
|
|
14
|
-
try:
|
|
15
|
-
return import_module(module_name)
|
|
16
|
-
except ModuleNotFoundError as exc:
|
|
17
|
-
last_error = exc
|
|
18
|
-
raise ValueError(f"Unable to resolve tool type '{tool_type}'") from last_error
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
def build_tool_from_spec(tool_spec: Mapping[str, Any] | ToolBase) -> ToolBase:
|
|
22
|
-
if isinstance(tool_spec, ToolBase):
|
|
23
|
-
if not tool_spec.parameters:
|
|
24
|
-
raise ValueError("Runtime tool registration requires declared parameters")
|
|
25
|
-
return tool_spec
|
|
26
|
-
if not isinstance(tool_spec, Mapping):
|
|
27
|
-
raise TypeError("tool_spec must be a mapping or ToolBase instance")
|
|
28
|
-
|
|
29
|
-
tool_data = dict(tool_spec)
|
|
30
|
-
tool_type = tool_data.get("type")
|
|
31
|
-
if not isinstance(tool_type, str) or not tool_type:
|
|
32
|
-
raise ValueError("tool_spec must include a non-empty string 'type' field")
|
|
33
|
-
declared_parameters = tool_data.get("parameters")
|
|
34
|
-
if not isinstance(declared_parameters, list) or not declared_parameters:
|
|
35
|
-
raise ValueError(
|
|
36
|
-
"Runtime tool registration requires a non-empty 'parameters' list"
|
|
37
|
-
)
|
|
38
|
-
|
|
39
|
-
module = _resolve_tool_module(tool_type)
|
|
40
|
-
|
|
41
|
-
tool_cls = getattr(module, tool_type, None)
|
|
42
|
-
if tool_cls is None:
|
|
43
|
-
raise ValueError(
|
|
44
|
-
f"Module for tool type '{tool_type}' does not expose that class"
|
|
45
|
-
)
|
|
46
|
-
if not issubclass(tool_cls, ToolBase):
|
|
47
|
-
raise TypeError(f"Resolved class '{tool_type}' is not a ToolBase subtype")
|
|
48
|
-
|
|
49
|
-
return tool_cls.model_validate(tool_data)
|
|
File without changes
|
|
File without changes
|