ovos-PHAL-plugin-tools 0.0.1a1__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.
- ovos_phal_plugin_tools-0.0.1a1/LICENSE +107 -0
- ovos_phal_plugin_tools-0.0.1a1/PKG-INFO +314 -0
- ovos_phal_plugin_tools-0.0.1a1/README.md +294 -0
- ovos_phal_plugin_tools-0.0.1a1/ovos_PHAL_plugin_tools.egg-info/PKG-INFO +314 -0
- ovos_phal_plugin_tools-0.0.1a1/ovos_PHAL_plugin_tools.egg-info/SOURCES.txt +14 -0
- ovos_phal_plugin_tools-0.0.1a1/ovos_PHAL_plugin_tools.egg-info/dependency_links.txt +1 -0
- ovos_phal_plugin_tools-0.0.1a1/ovos_PHAL_plugin_tools.egg-info/entry_points.txt +2 -0
- ovos_phal_plugin_tools-0.0.1a1/ovos_PHAL_plugin_tools.egg-info/requires.txt +8 -0
- ovos_phal_plugin_tools-0.0.1a1/ovos_PHAL_plugin_tools.egg-info/top_level.txt +1 -0
- ovos_phal_plugin_tools-0.0.1a1/ovos_phal_plugin_tools/__init__.py +220 -0
- ovos_phal_plugin_tools-0.0.1a1/ovos_phal_plugin_tools/version.py +17 -0
- ovos_phal_plugin_tools-0.0.1a1/pyproject.toml +35 -0
- ovos_phal_plugin_tools-0.0.1a1/setup.cfg +4 -0
- ovos_phal_plugin_tools-0.0.1a1/test/test_e2e.py +162 -0
- ovos_phal_plugin_tools-0.0.1a1/test/test_extended.py +417 -0
- ovos_phal_plugin_tools-0.0.1a1/test/test_unit.py +277 -0
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship made available under
|
|
36
|
+
the License, as indicated by a copyright notice that is included in
|
|
37
|
+
or attached to the work (an example is provided in the Appendix below).
|
|
38
|
+
|
|
39
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
40
|
+
form, that is based on (or derived from) the Work and for which the
|
|
41
|
+
editorial revisions, annotations, elaborations, or other transformations
|
|
42
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
43
|
+
of this License, Derivative Works shall not include works that remain
|
|
44
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
45
|
+
the Work and Derivative Works thereof.
|
|
46
|
+
|
|
47
|
+
"Contribution" shall mean, as submitted to the Licensor for inclusion
|
|
48
|
+
in the Work by the copyright owner or by an individual or Legal Entity
|
|
49
|
+
authorized to submit on behalf of the copyright owner. For the purposes
|
|
50
|
+
of this definition, "submitted" means any form of electronic, verbal,
|
|
51
|
+
or written communication sent to the Licensor or its representatives,
|
|
52
|
+
including but not limited to communication on electronic mailing lists,
|
|
53
|
+
source code control systems, and issue tracking systems that are managed
|
|
54
|
+
by, or on behalf of, the Licensor for the purpose of documenting and
|
|
55
|
+
discussing improvements to the Work, but excluding communication that is
|
|
56
|
+
conspicured and/or labeled by the copyright owner as "Not a Contribution."
|
|
57
|
+
|
|
58
|
+
"Contributor" shall mean Licensor and any Legal Entity on behalf of
|
|
59
|
+
whom a Contribution has been received by the Licensor and included
|
|
60
|
+
within the Work.
|
|
61
|
+
|
|
62
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
63
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
64
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
65
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
66
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
67
|
+
Work and such Derivative Works in Source or Object form.
|
|
68
|
+
|
|
69
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
70
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
71
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
72
|
+
(except as stated in this section) patent license to make, have made,
|
|
73
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
74
|
+
where such license applies only to those Contributions necessary to
|
|
75
|
+
make, use, or sell their Contribution(s).
|
|
76
|
+
|
|
77
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
78
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
79
|
+
modifications, and in Source or Object form, provided that You
|
|
80
|
+
meet the following conditions:
|
|
81
|
+
|
|
82
|
+
(a) You must give any other recipients of the Work or Derivative
|
|
83
|
+
Works a copy of this License; and
|
|
84
|
+
|
|
85
|
+
(b) You must cause any modified files to carry prominent notices
|
|
86
|
+
stating that You changed the files; and
|
|
87
|
+
|
|
88
|
+
(c) You must retain, in all the Source form of any Derivative
|
|
89
|
+
Works that You distribute, all copyright, patent, trademark,
|
|
90
|
+
and attribution notices from the Source form of the Work,
|
|
91
|
+
excluding those notices that do not pertain to any part of
|
|
92
|
+
the Derivative Works; and
|
|
93
|
+
|
|
94
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
95
|
+
distribution, You must include a readable copy of the
|
|
96
|
+
attribution notices contained within such NOTICE file, in
|
|
97
|
+
at least one of the following places: within a NOTICE text
|
|
98
|
+
file distributed as part of the Derivative Works; within
|
|
99
|
+
the Source form or documentation, if provided along with the
|
|
100
|
+
Derivative Works; or, within a display generated by the
|
|
101
|
+
Derivative Works, if and wherever such third-party notices
|
|
102
|
+
normally appear.
|
|
103
|
+
|
|
104
|
+
DISCLAIMER OF WARRANTIES. The Work is provided "AS IS", WITHOUT
|
|
105
|
+
WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
106
|
+
See the License for the specific language governing permissions
|
|
107
|
+
and limitations under the License.
|
|
@@ -0,0 +1,314 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: ovos-PHAL-plugin-tools
|
|
3
|
+
Version: 0.0.1a1
|
|
4
|
+
Summary: PHAL service provider exposing OVOS tool plugins over the messagebus
|
|
5
|
+
Author-email: JarbasAi <jarbasai@mailfence.com>
|
|
6
|
+
License-Expression: Apache-2.0
|
|
7
|
+
Project-URL: Homepage, https://github.com/TigreGotico/ovos-PHAL-plugin-tools
|
|
8
|
+
Project-URL: Repository, https://github.com/TigreGotico/ovos-PHAL-plugin-tools
|
|
9
|
+
Requires-Python: >=3.10
|
|
10
|
+
Description-Content-Type: text/markdown
|
|
11
|
+
License-File: LICENSE
|
|
12
|
+
Requires-Dist: ovos-plugin-manager<3.0.0,>=2.3.0a1
|
|
13
|
+
Requires-Dist: ovos-utils<1.0.0,>=0.1.0
|
|
14
|
+
Requires-Dist: ovos-bus-client<2.0.0,>=0.0.8
|
|
15
|
+
Requires-Dist: pydantic>=2.0.0
|
|
16
|
+
Provides-Extra: test
|
|
17
|
+
Requires-Dist: pytest; extra == "test"
|
|
18
|
+
Requires-Dist: pytest-cov; extra == "test"
|
|
19
|
+
Dynamic: license-file
|
|
20
|
+
|
|
21
|
+
# ovos-PHAL-plugin-tools
|
|
22
|
+
|
|
23
|
+
A PHAL (Platform / Hardware Abstraction Layer) service provider that exposes all
|
|
24
|
+
installed OPM **ToolBox** plugins (`opm.agents.toolbox` entry-point group) as a
|
|
25
|
+
unified bus API.
|
|
26
|
+
|
|
27
|
+
Any skill, agent, or external client connected to the OVOS messagebus can:
|
|
28
|
+
|
|
29
|
+
- enumerate every available tool and its JSON Schema
|
|
30
|
+
- fetch a single tool's full schema
|
|
31
|
+
- invoke a tool by name with keyword arguments
|
|
32
|
+
|
|
33
|
+
---
|
|
34
|
+
|
|
35
|
+
## Bus API reference
|
|
36
|
+
|
|
37
|
+
All events follow the request → response pattern. The response event name is the
|
|
38
|
+
request event name suffixed with `.response`.
|
|
39
|
+
|
|
40
|
+
### `ovos.tools.list`
|
|
41
|
+
|
|
42
|
+
Enumerate all tools registered across every loaded toolbox.
|
|
43
|
+
|
|
44
|
+
| Field | Type | Required | Description |
|
|
45
|
+
|-------|------|----------|-------------|
|
|
46
|
+
| *(no payload fields)* | | | |
|
|
47
|
+
|
|
48
|
+
**Response: `ovos.tools.list.response`**
|
|
49
|
+
|
|
50
|
+
| Field | Type | Description |
|
|
51
|
+
|-------|------|-------------|
|
|
52
|
+
| `tools` | `list[ToolEntry]` | All discovered tools |
|
|
53
|
+
|
|
54
|
+
**ToolEntry fields:**
|
|
55
|
+
|
|
56
|
+
| Field | Type | Description |
|
|
57
|
+
|-------|------|-------------|
|
|
58
|
+
| `name` | `str` | Unique tool name (snake_case) |
|
|
59
|
+
| `description` | `str` | Natural-language description |
|
|
60
|
+
| `argument_schema` | `dict` | JSON Schema for call arguments |
|
|
61
|
+
| `output_schema` | `dict` | JSON Schema for the return value |
|
|
62
|
+
| `toolbox_id` | `str` | Originating toolbox entry-point name |
|
|
63
|
+
|
|
64
|
+
**Example response payload:**
|
|
65
|
+
|
|
66
|
+
```json
|
|
67
|
+
{
|
|
68
|
+
"tools": [
|
|
69
|
+
{
|
|
70
|
+
"name": "add",
|
|
71
|
+
"description": "Add two integers.",
|
|
72
|
+
"argument_schema": {
|
|
73
|
+
"title": "AddArgs",
|
|
74
|
+
"type": "object",
|
|
75
|
+
"properties": {
|
|
76
|
+
"a": {"title": "A", "type": "integer"},
|
|
77
|
+
"b": {"title": "B", "type": "integer"}
|
|
78
|
+
},
|
|
79
|
+
"required": ["a", "b"]
|
|
80
|
+
},
|
|
81
|
+
"output_schema": {
|
|
82
|
+
"title": "AddOutput",
|
|
83
|
+
"type": "object",
|
|
84
|
+
"properties": {
|
|
85
|
+
"result": {"title": "Result", "type": "integer"}
|
|
86
|
+
},
|
|
87
|
+
"required": ["result"]
|
|
88
|
+
},
|
|
89
|
+
"toolbox_id": "math_tools"
|
|
90
|
+
}
|
|
91
|
+
]
|
|
92
|
+
}
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
---
|
|
96
|
+
|
|
97
|
+
### `ovos.tools.get`
|
|
98
|
+
|
|
99
|
+
Retrieve the full schema of a single named tool.
|
|
100
|
+
|
|
101
|
+
**Request payload:**
|
|
102
|
+
|
|
103
|
+
| Field | Type | Required | Description |
|
|
104
|
+
|-------|------|----------|-------------|
|
|
105
|
+
| `name` | `str` | yes | The snake_case tool name |
|
|
106
|
+
|
|
107
|
+
**Response: `ovos.tools.get.response`**
|
|
108
|
+
|
|
109
|
+
Success:
|
|
110
|
+
|
|
111
|
+
| Field | Type | Description |
|
|
112
|
+
|-------|------|-------------|
|
|
113
|
+
| `name` | `str` | Tool name |
|
|
114
|
+
| `description` | `str` | Natural-language description |
|
|
115
|
+
| `argument_schema` | `dict` | JSON Schema for call arguments |
|
|
116
|
+
| `output_schema` | `dict` | JSON Schema for return value |
|
|
117
|
+
| `toolbox_id` | `str` | Originating toolbox |
|
|
118
|
+
|
|
119
|
+
Error (unknown tool or missing `name`):
|
|
120
|
+
|
|
121
|
+
| Field | Type | Description |
|
|
122
|
+
|-------|------|-------------|
|
|
123
|
+
| `error` | `str` | Human-readable error message |
|
|
124
|
+
|
|
125
|
+
**Example:**
|
|
126
|
+
|
|
127
|
+
```json
|
|
128
|
+
// request
|
|
129
|
+
{"name": "add"}
|
|
130
|
+
|
|
131
|
+
// response (success)
|
|
132
|
+
{
|
|
133
|
+
"name": "add",
|
|
134
|
+
"description": "Add two integers.",
|
|
135
|
+
"argument_schema": { ... },
|
|
136
|
+
"output_schema": { ... },
|
|
137
|
+
"toolbox_id": "math_tools"
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
// response (error)
|
|
141
|
+
{"error": "Unknown tool: 'nonexistent'"}
|
|
142
|
+
```
|
|
143
|
+
|
|
144
|
+
---
|
|
145
|
+
|
|
146
|
+
### `ovos.tools.invoke`
|
|
147
|
+
|
|
148
|
+
Execute a tool synchronously and receive its result.
|
|
149
|
+
|
|
150
|
+
**Request payload:**
|
|
151
|
+
|
|
152
|
+
| Field | Type | Required | Description |
|
|
153
|
+
|-------|------|----------|-------------|
|
|
154
|
+
| `name` | `str` | yes | The snake_case tool name |
|
|
155
|
+
| `args` | `dict` | yes | Keyword arguments matching the tool's `argument_schema` |
|
|
156
|
+
|
|
157
|
+
**Response: `ovos.tools.invoke.response`**
|
|
158
|
+
|
|
159
|
+
Success:
|
|
160
|
+
|
|
161
|
+
| Field | Type | Description |
|
|
162
|
+
|-------|------|-------------|
|
|
163
|
+
| `name` | `str` | Tool name (echoed) |
|
|
164
|
+
| `result` | `dict` | Tool output, matching `output_schema` |
|
|
165
|
+
|
|
166
|
+
Error:
|
|
167
|
+
|
|
168
|
+
| Field | Type | Description |
|
|
169
|
+
|-------|------|-------------|
|
|
170
|
+
| `name` | `str` | Tool name (echoed) |
|
|
171
|
+
| `error` | `str` | `ExceptionType: message` |
|
|
172
|
+
|
|
173
|
+
**Example:**
|
|
174
|
+
|
|
175
|
+
```json
|
|
176
|
+
// request
|
|
177
|
+
{"name": "add", "args": {"a": 3, "b": 4}}
|
|
178
|
+
|
|
179
|
+
// response (success)
|
|
180
|
+
{"name": "add", "result": {"result": 7}}
|
|
181
|
+
|
|
182
|
+
// response (error — bad args)
|
|
183
|
+
{"name": "add", "error": "ValueError: Tool input validation failed for 'add' ..."}
|
|
184
|
+
|
|
185
|
+
// response (error — unknown tool)
|
|
186
|
+
{"name": "nope", "error": "Unknown tool: 'nope'"}
|
|
187
|
+
```
|
|
188
|
+
|
|
189
|
+
---
|
|
190
|
+
|
|
191
|
+
### `ovos.tools.reload`
|
|
192
|
+
|
|
193
|
+
Hot-reload the toolbox registry without restarting OVOS. Useful after
|
|
194
|
+
installing new toolbox plugins at runtime.
|
|
195
|
+
|
|
196
|
+
**Request payload:** *(none)*
|
|
197
|
+
|
|
198
|
+
**Response: `ovos.tools.reload.response`**
|
|
199
|
+
|
|
200
|
+
| Field | Type | Description |
|
|
201
|
+
|-------|------|-------------|
|
|
202
|
+
| `loaded` | `list[str]` | Toolbox entry-point names now loaded |
|
|
203
|
+
| `total_tools` | `int` | Total number of tools across all toolboxes |
|
|
204
|
+
|
|
205
|
+
---
|
|
206
|
+
|
|
207
|
+
## Third-party usage example
|
|
208
|
+
|
|
209
|
+
```python
|
|
210
|
+
from ovos_bus_client import MessageBusClient, Message
|
|
211
|
+
|
|
212
|
+
bus = MessageBusClient()
|
|
213
|
+
bus.run_in_thread()
|
|
214
|
+
|
|
215
|
+
# --- list all tools ---
|
|
216
|
+
response = bus.wait_for_response(Message("ovos.tools.list"))
|
|
217
|
+
for tool in response.data["tools"]:
|
|
218
|
+
print(tool["name"], "—", tool["description"])
|
|
219
|
+
|
|
220
|
+
# --- get schema for one tool ---
|
|
221
|
+
response = bus.wait_for_response(
|
|
222
|
+
Message("ovos.tools.get", {"name": "add"})
|
|
223
|
+
)
|
|
224
|
+
print(response.data)
|
|
225
|
+
|
|
226
|
+
# --- invoke a tool ---
|
|
227
|
+
response = bus.wait_for_response(
|
|
228
|
+
Message("ovos.tools.invoke", {"name": "add", "args": {"a": 10, "b": 32}})
|
|
229
|
+
)
|
|
230
|
+
if "error" in response.data:
|
|
231
|
+
print("Error:", response.data["error"])
|
|
232
|
+
else:
|
|
233
|
+
print("Result:", response.data["result"])
|
|
234
|
+
```
|
|
235
|
+
|
|
236
|
+
---
|
|
237
|
+
|
|
238
|
+
## Installation
|
|
239
|
+
|
|
240
|
+
```bash
|
|
241
|
+
pip install ovos-PHAL-plugin-tools
|
|
242
|
+
```
|
|
243
|
+
|
|
244
|
+
Enable in your OVOS config (`mycroft.conf`):
|
|
245
|
+
|
|
246
|
+
```json
|
|
247
|
+
{
|
|
248
|
+
"PHAL": {
|
|
249
|
+
"ovos-phal-plugin-tools": {
|
|
250
|
+
"enabled": true
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
```
|
|
255
|
+
|
|
256
|
+
Install one or more toolbox plugins (entry-point group `opm.agents.toolbox`) and
|
|
257
|
+
the service will discover them automatically at startup. Call
|
|
258
|
+
`ovos.tools.reload` if you install plugins while OVOS is already running.
|
|
259
|
+
|
|
260
|
+
---
|
|
261
|
+
|
|
262
|
+
## Writing a ToolBox plugin
|
|
263
|
+
|
|
264
|
+
Implement `ovos_plugin_manager.templates.agent_tools.ToolBox` and register under
|
|
265
|
+
the `opm.agents.toolbox` entry-point group in your package's `pyproject.toml`:
|
|
266
|
+
|
|
267
|
+
```toml
|
|
268
|
+
[project.entry-points."opm.agents.toolbox"]
|
|
269
|
+
my-math-tools = "my_package.toolbox:MyMathToolBox"
|
|
270
|
+
```
|
|
271
|
+
|
|
272
|
+
```python
|
|
273
|
+
from typing import List
|
|
274
|
+
from pydantic import Field
|
|
275
|
+
from ovos_plugin_manager.templates.agent_tools import (
|
|
276
|
+
AgentTool, ToolArguments, ToolOutput, ToolBox,
|
|
277
|
+
)
|
|
278
|
+
|
|
279
|
+
|
|
280
|
+
class AddArgs(ToolArguments):
|
|
281
|
+
a: int = Field(..., description="First operand")
|
|
282
|
+
b: int = Field(..., description="Second operand")
|
|
283
|
+
|
|
284
|
+
|
|
285
|
+
class AddOutput(ToolOutput):
|
|
286
|
+
result: int = Field(..., description="Sum")
|
|
287
|
+
|
|
288
|
+
|
|
289
|
+
class MyMathToolBox(ToolBox):
|
|
290
|
+
def discover_tools(self) -> List[AgentTool]:
|
|
291
|
+
return [
|
|
292
|
+
AgentTool(
|
|
293
|
+
name="add",
|
|
294
|
+
description="Add two integers.",
|
|
295
|
+
argument_schema=AddArgs,
|
|
296
|
+
output_schema=AddOutput,
|
|
297
|
+
tool_call=lambda args: AddOutput(result=args.a + args.b),
|
|
298
|
+
)
|
|
299
|
+
]
|
|
300
|
+
```
|
|
301
|
+
|
|
302
|
+
---
|
|
303
|
+
|
|
304
|
+
## License
|
|
305
|
+
|
|
306
|
+
Apache 2.0 — see [LICENSE](LICENSE).
|
|
307
|
+
|
|
308
|
+
## Credits
|
|
309
|
+
|
|
310
|
+
Developed by [TigreGotico](https://tigregotico.pt) for [OpenVoiceOS](https://openvoiceos.org).
|
|
311
|
+
|
|
312
|
+
Funded by [NGI0 Commons Fund](https://nlnet.nl/project/OpenVoiceOS) / [NLnet](https://nlnet.nl)
|
|
313
|
+
under grant agreement No [101135429](https://cordis.europa.eu/project/id/101135429),
|
|
314
|
+
through the European Commission's [Next Generation Internet](https://ngi.eu) programme.
|
|
@@ -0,0 +1,294 @@
|
|
|
1
|
+
# ovos-PHAL-plugin-tools
|
|
2
|
+
|
|
3
|
+
A PHAL (Platform / Hardware Abstraction Layer) service provider that exposes all
|
|
4
|
+
installed OPM **ToolBox** plugins (`opm.agents.toolbox` entry-point group) as a
|
|
5
|
+
unified bus API.
|
|
6
|
+
|
|
7
|
+
Any skill, agent, or external client connected to the OVOS messagebus can:
|
|
8
|
+
|
|
9
|
+
- enumerate every available tool and its JSON Schema
|
|
10
|
+
- fetch a single tool's full schema
|
|
11
|
+
- invoke a tool by name with keyword arguments
|
|
12
|
+
|
|
13
|
+
---
|
|
14
|
+
|
|
15
|
+
## Bus API reference
|
|
16
|
+
|
|
17
|
+
All events follow the request → response pattern. The response event name is the
|
|
18
|
+
request event name suffixed with `.response`.
|
|
19
|
+
|
|
20
|
+
### `ovos.tools.list`
|
|
21
|
+
|
|
22
|
+
Enumerate all tools registered across every loaded toolbox.
|
|
23
|
+
|
|
24
|
+
| Field | Type | Required | Description |
|
|
25
|
+
|-------|------|----------|-------------|
|
|
26
|
+
| *(no payload fields)* | | | |
|
|
27
|
+
|
|
28
|
+
**Response: `ovos.tools.list.response`**
|
|
29
|
+
|
|
30
|
+
| Field | Type | Description |
|
|
31
|
+
|-------|------|-------------|
|
|
32
|
+
| `tools` | `list[ToolEntry]` | All discovered tools |
|
|
33
|
+
|
|
34
|
+
**ToolEntry fields:**
|
|
35
|
+
|
|
36
|
+
| Field | Type | Description |
|
|
37
|
+
|-------|------|-------------|
|
|
38
|
+
| `name` | `str` | Unique tool name (snake_case) |
|
|
39
|
+
| `description` | `str` | Natural-language description |
|
|
40
|
+
| `argument_schema` | `dict` | JSON Schema for call arguments |
|
|
41
|
+
| `output_schema` | `dict` | JSON Schema for the return value |
|
|
42
|
+
| `toolbox_id` | `str` | Originating toolbox entry-point name |
|
|
43
|
+
|
|
44
|
+
**Example response payload:**
|
|
45
|
+
|
|
46
|
+
```json
|
|
47
|
+
{
|
|
48
|
+
"tools": [
|
|
49
|
+
{
|
|
50
|
+
"name": "add",
|
|
51
|
+
"description": "Add two integers.",
|
|
52
|
+
"argument_schema": {
|
|
53
|
+
"title": "AddArgs",
|
|
54
|
+
"type": "object",
|
|
55
|
+
"properties": {
|
|
56
|
+
"a": {"title": "A", "type": "integer"},
|
|
57
|
+
"b": {"title": "B", "type": "integer"}
|
|
58
|
+
},
|
|
59
|
+
"required": ["a", "b"]
|
|
60
|
+
},
|
|
61
|
+
"output_schema": {
|
|
62
|
+
"title": "AddOutput",
|
|
63
|
+
"type": "object",
|
|
64
|
+
"properties": {
|
|
65
|
+
"result": {"title": "Result", "type": "integer"}
|
|
66
|
+
},
|
|
67
|
+
"required": ["result"]
|
|
68
|
+
},
|
|
69
|
+
"toolbox_id": "math_tools"
|
|
70
|
+
}
|
|
71
|
+
]
|
|
72
|
+
}
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
---
|
|
76
|
+
|
|
77
|
+
### `ovos.tools.get`
|
|
78
|
+
|
|
79
|
+
Retrieve the full schema of a single named tool.
|
|
80
|
+
|
|
81
|
+
**Request payload:**
|
|
82
|
+
|
|
83
|
+
| Field | Type | Required | Description |
|
|
84
|
+
|-------|------|----------|-------------|
|
|
85
|
+
| `name` | `str` | yes | The snake_case tool name |
|
|
86
|
+
|
|
87
|
+
**Response: `ovos.tools.get.response`**
|
|
88
|
+
|
|
89
|
+
Success:
|
|
90
|
+
|
|
91
|
+
| Field | Type | Description |
|
|
92
|
+
|-------|------|-------------|
|
|
93
|
+
| `name` | `str` | Tool name |
|
|
94
|
+
| `description` | `str` | Natural-language description |
|
|
95
|
+
| `argument_schema` | `dict` | JSON Schema for call arguments |
|
|
96
|
+
| `output_schema` | `dict` | JSON Schema for return value |
|
|
97
|
+
| `toolbox_id` | `str` | Originating toolbox |
|
|
98
|
+
|
|
99
|
+
Error (unknown tool or missing `name`):
|
|
100
|
+
|
|
101
|
+
| Field | Type | Description |
|
|
102
|
+
|-------|------|-------------|
|
|
103
|
+
| `error` | `str` | Human-readable error message |
|
|
104
|
+
|
|
105
|
+
**Example:**
|
|
106
|
+
|
|
107
|
+
```json
|
|
108
|
+
// request
|
|
109
|
+
{"name": "add"}
|
|
110
|
+
|
|
111
|
+
// response (success)
|
|
112
|
+
{
|
|
113
|
+
"name": "add",
|
|
114
|
+
"description": "Add two integers.",
|
|
115
|
+
"argument_schema": { ... },
|
|
116
|
+
"output_schema": { ... },
|
|
117
|
+
"toolbox_id": "math_tools"
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
// response (error)
|
|
121
|
+
{"error": "Unknown tool: 'nonexistent'"}
|
|
122
|
+
```
|
|
123
|
+
|
|
124
|
+
---
|
|
125
|
+
|
|
126
|
+
### `ovos.tools.invoke`
|
|
127
|
+
|
|
128
|
+
Execute a tool synchronously and receive its result.
|
|
129
|
+
|
|
130
|
+
**Request payload:**
|
|
131
|
+
|
|
132
|
+
| Field | Type | Required | Description |
|
|
133
|
+
|-------|------|----------|-------------|
|
|
134
|
+
| `name` | `str` | yes | The snake_case tool name |
|
|
135
|
+
| `args` | `dict` | yes | Keyword arguments matching the tool's `argument_schema` |
|
|
136
|
+
|
|
137
|
+
**Response: `ovos.tools.invoke.response`**
|
|
138
|
+
|
|
139
|
+
Success:
|
|
140
|
+
|
|
141
|
+
| Field | Type | Description |
|
|
142
|
+
|-------|------|-------------|
|
|
143
|
+
| `name` | `str` | Tool name (echoed) |
|
|
144
|
+
| `result` | `dict` | Tool output, matching `output_schema` |
|
|
145
|
+
|
|
146
|
+
Error:
|
|
147
|
+
|
|
148
|
+
| Field | Type | Description |
|
|
149
|
+
|-------|------|-------------|
|
|
150
|
+
| `name` | `str` | Tool name (echoed) |
|
|
151
|
+
| `error` | `str` | `ExceptionType: message` |
|
|
152
|
+
|
|
153
|
+
**Example:**
|
|
154
|
+
|
|
155
|
+
```json
|
|
156
|
+
// request
|
|
157
|
+
{"name": "add", "args": {"a": 3, "b": 4}}
|
|
158
|
+
|
|
159
|
+
// response (success)
|
|
160
|
+
{"name": "add", "result": {"result": 7}}
|
|
161
|
+
|
|
162
|
+
// response (error — bad args)
|
|
163
|
+
{"name": "add", "error": "ValueError: Tool input validation failed for 'add' ..."}
|
|
164
|
+
|
|
165
|
+
// response (error — unknown tool)
|
|
166
|
+
{"name": "nope", "error": "Unknown tool: 'nope'"}
|
|
167
|
+
```
|
|
168
|
+
|
|
169
|
+
---
|
|
170
|
+
|
|
171
|
+
### `ovos.tools.reload`
|
|
172
|
+
|
|
173
|
+
Hot-reload the toolbox registry without restarting OVOS. Useful after
|
|
174
|
+
installing new toolbox plugins at runtime.
|
|
175
|
+
|
|
176
|
+
**Request payload:** *(none)*
|
|
177
|
+
|
|
178
|
+
**Response: `ovos.tools.reload.response`**
|
|
179
|
+
|
|
180
|
+
| Field | Type | Description |
|
|
181
|
+
|-------|------|-------------|
|
|
182
|
+
| `loaded` | `list[str]` | Toolbox entry-point names now loaded |
|
|
183
|
+
| `total_tools` | `int` | Total number of tools across all toolboxes |
|
|
184
|
+
|
|
185
|
+
---
|
|
186
|
+
|
|
187
|
+
## Third-party usage example
|
|
188
|
+
|
|
189
|
+
```python
|
|
190
|
+
from ovos_bus_client import MessageBusClient, Message
|
|
191
|
+
|
|
192
|
+
bus = MessageBusClient()
|
|
193
|
+
bus.run_in_thread()
|
|
194
|
+
|
|
195
|
+
# --- list all tools ---
|
|
196
|
+
response = bus.wait_for_response(Message("ovos.tools.list"))
|
|
197
|
+
for tool in response.data["tools"]:
|
|
198
|
+
print(tool["name"], "—", tool["description"])
|
|
199
|
+
|
|
200
|
+
# --- get schema for one tool ---
|
|
201
|
+
response = bus.wait_for_response(
|
|
202
|
+
Message("ovos.tools.get", {"name": "add"})
|
|
203
|
+
)
|
|
204
|
+
print(response.data)
|
|
205
|
+
|
|
206
|
+
# --- invoke a tool ---
|
|
207
|
+
response = bus.wait_for_response(
|
|
208
|
+
Message("ovos.tools.invoke", {"name": "add", "args": {"a": 10, "b": 32}})
|
|
209
|
+
)
|
|
210
|
+
if "error" in response.data:
|
|
211
|
+
print("Error:", response.data["error"])
|
|
212
|
+
else:
|
|
213
|
+
print("Result:", response.data["result"])
|
|
214
|
+
```
|
|
215
|
+
|
|
216
|
+
---
|
|
217
|
+
|
|
218
|
+
## Installation
|
|
219
|
+
|
|
220
|
+
```bash
|
|
221
|
+
pip install ovos-PHAL-plugin-tools
|
|
222
|
+
```
|
|
223
|
+
|
|
224
|
+
Enable in your OVOS config (`mycroft.conf`):
|
|
225
|
+
|
|
226
|
+
```json
|
|
227
|
+
{
|
|
228
|
+
"PHAL": {
|
|
229
|
+
"ovos-phal-plugin-tools": {
|
|
230
|
+
"enabled": true
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
```
|
|
235
|
+
|
|
236
|
+
Install one or more toolbox plugins (entry-point group `opm.agents.toolbox`) and
|
|
237
|
+
the service will discover them automatically at startup. Call
|
|
238
|
+
`ovos.tools.reload` if you install plugins while OVOS is already running.
|
|
239
|
+
|
|
240
|
+
---
|
|
241
|
+
|
|
242
|
+
## Writing a ToolBox plugin
|
|
243
|
+
|
|
244
|
+
Implement `ovos_plugin_manager.templates.agent_tools.ToolBox` and register under
|
|
245
|
+
the `opm.agents.toolbox` entry-point group in your package's `pyproject.toml`:
|
|
246
|
+
|
|
247
|
+
```toml
|
|
248
|
+
[project.entry-points."opm.agents.toolbox"]
|
|
249
|
+
my-math-tools = "my_package.toolbox:MyMathToolBox"
|
|
250
|
+
```
|
|
251
|
+
|
|
252
|
+
```python
|
|
253
|
+
from typing import List
|
|
254
|
+
from pydantic import Field
|
|
255
|
+
from ovos_plugin_manager.templates.agent_tools import (
|
|
256
|
+
AgentTool, ToolArguments, ToolOutput, ToolBox,
|
|
257
|
+
)
|
|
258
|
+
|
|
259
|
+
|
|
260
|
+
class AddArgs(ToolArguments):
|
|
261
|
+
a: int = Field(..., description="First operand")
|
|
262
|
+
b: int = Field(..., description="Second operand")
|
|
263
|
+
|
|
264
|
+
|
|
265
|
+
class AddOutput(ToolOutput):
|
|
266
|
+
result: int = Field(..., description="Sum")
|
|
267
|
+
|
|
268
|
+
|
|
269
|
+
class MyMathToolBox(ToolBox):
|
|
270
|
+
def discover_tools(self) -> List[AgentTool]:
|
|
271
|
+
return [
|
|
272
|
+
AgentTool(
|
|
273
|
+
name="add",
|
|
274
|
+
description="Add two integers.",
|
|
275
|
+
argument_schema=AddArgs,
|
|
276
|
+
output_schema=AddOutput,
|
|
277
|
+
tool_call=lambda args: AddOutput(result=args.a + args.b),
|
|
278
|
+
)
|
|
279
|
+
]
|
|
280
|
+
```
|
|
281
|
+
|
|
282
|
+
---
|
|
283
|
+
|
|
284
|
+
## License
|
|
285
|
+
|
|
286
|
+
Apache 2.0 — see [LICENSE](LICENSE).
|
|
287
|
+
|
|
288
|
+
## Credits
|
|
289
|
+
|
|
290
|
+
Developed by [TigreGotico](https://tigregotico.pt) for [OpenVoiceOS](https://openvoiceos.org).
|
|
291
|
+
|
|
292
|
+
Funded by [NGI0 Commons Fund](https://nlnet.nl/project/OpenVoiceOS) / [NLnet](https://nlnet.nl)
|
|
293
|
+
under grant agreement No [101135429](https://cordis.europa.eu/project/id/101135429),
|
|
294
|
+
through the European Commission's [Next Generation Internet](https://ngi.eu) programme.
|