forge-tool 0.1.0__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.
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ https://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, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright 2026 X-ERA
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ https://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
@@ -0,0 +1,443 @@
1
+ Metadata-Version: 2.4
2
+ Name: forge-tool
3
+ Version: 0.1.0
4
+ Summary: Typed endpoint contracts for Forge query, action, and session tools.
5
+ Author: X-ERA
6
+ License-Expression: Apache-2.0
7
+ License-File: LICENSE
8
+ Requires-Dist: forge-msgs>=1.2.0,<2 ; extra == 'dora'
9
+ Requires-Python: >=3.12
10
+ Provides-Extra: dora
11
+ Description-Content-Type: text/markdown
12
+
13
+ # forge-tool
14
+
15
+ `forge-tool` is the dependency-free Python implementation of the provider-side Forge
16
+ ToolEndpoint contracts and logical Wire protocol
17
+ `forge.tool.endpoint/v1alpha1`.
18
+
19
+ It provides:
20
+
21
+ - validated endpoint descriptors, requests, results, status, control, events, and errors;
22
+ - async Query, Action, and Session ToolEndpoint SPI;
23
+ - strict logical envelopes, typed payload codecs, complete factories, and correlation
24
+ validators;
25
+ - a transport-independent Query/Action `ToolEndpointHandler`; and
26
+ - an optional in-memory Arrow binding for embedding the handler in a Dora Operator or
27
+ Adapter node.
28
+
29
+ It does **not** provide the caller-facing Tool Runtime, a Gateway, a Dora `Node`, or a
30
+ persistent execution service.
31
+
32
+ ## Capability status
33
+
34
+ | Capability | Query | Action | Session |
35
+ | --- | --- | --- | --- |
36
+ | Models, descriptor, and SPI | Implemented | Implemented | Implemented |
37
+ | Logical Wire messages | Implemented | Implemented | Implemented |
38
+ | `ToolEndpointHandler` execution | Implemented | Implemented | **Not implemented** |
39
+ | Optional Arrow/Dora binding | Implemented | Implemented | **Not implemented** |
40
+
41
+ “Session implemented” currently means its model, descriptor semantics, structural SPI,
42
+ and generic Wire shapes exist. `ToolEndpointHandler.dispatch()` does not execute a
43
+ Session operation yet.
44
+
45
+ The sibling Gateway integration is currently Query-only. Provider-side Action handling
46
+ therefore does not imply a complete caller-to-provider Action system.
47
+
48
+ ## Installation
49
+
50
+ Python 3.12 or newer is required. Install Tool `0.1.0` from PyPI:
51
+
52
+ ```bash
53
+ pip install forge-tool
54
+ ```
55
+
56
+ Install the optional Arrow carrier integration when embedding an endpoint in a
57
+ Dora-capable Operator or Adapter node:
58
+
59
+ ```bash
60
+ pip install 'forge-tool[dora]'
61
+ ```
62
+
63
+ From a Forge source checkout, run code through the repository workspace instead of
64
+ syncing the package subproject in isolation:
65
+
66
+ ```bash
67
+ uv run python your_endpoint.py
68
+ ```
69
+
70
+ The base package has no runtime dependencies. `import forge_tool` does not import
71
+ `forge_msgs` or PyArrow. The optional extra adds the carrier stack, not `dora-rs`; the
72
+ concrete node package remains responsible for its Dora dependency.
73
+
74
+ ## Query quickstart
75
+
76
+ A Query returns one authoritative terminal `ToolResult`.
77
+
78
+ ```python
79
+ import asyncio
80
+
81
+ from forge_tool import (
82
+ TOOL_ENDPOINT_PROTOCOL,
83
+ ToolContext,
84
+ ToolEndpointDescriptor,
85
+ ToolEndpointHandler,
86
+ ToolExecutionKey,
87
+ ToolOperationDescriptor,
88
+ ToolRequest,
89
+ ToolResult,
90
+ invoke_response_from_payload,
91
+ make_invoke_request_envelope,
92
+ )
93
+
94
+
95
+ class DetectQuery:
96
+ async def query(
97
+ self,
98
+ request: ToolRequest,
99
+ context: ToolContext,
100
+ ) -> ToolResult:
101
+ return ToolResult(
102
+ status="succeeded",
103
+ outputs={"requested_class": request.arguments.get("class")},
104
+ )
105
+
106
+
107
+ async def main() -> None:
108
+ descriptor = ToolEndpointDescriptor(
109
+ protocol_version=TOOL_ENDPOINT_PROTOCOL,
110
+ endpoint_id="vision.detector",
111
+ operations=(
112
+ ToolOperationDescriptor(name="detect", semantics="query"),
113
+ ),
114
+ )
115
+ handler = ToolEndpointHandler(
116
+ descriptor,
117
+ endpoint_instance_id="detector-process-1",
118
+ operations={"detect": DetectQuery()},
119
+ )
120
+
121
+ context = ToolContext(
122
+ execution_key=ToolExecutionKey("invocation-1", "attempt-1"),
123
+ tool_id="vision.detect",
124
+ implementation_id="detector.primary",
125
+ endpoint_id="vision.detector",
126
+ operation="detect",
127
+ )
128
+ request = make_invoke_request_envelope(
129
+ ToolRequest(arguments={"class": "cube"}),
130
+ context,
131
+ request_id="request-1",
132
+ endpoint_instance_id="detector-process-1",
133
+ )
134
+
135
+ response = await handler.handle_invoke(request)
136
+ result = invoke_response_from_payload(response.payload)
137
+ assert isinstance(result, ToolResult)
138
+ print(result.outputs)
139
+
140
+
141
+ asyncio.run(main())
142
+ ```
143
+
144
+ `handle_invoke()` is intentionally Query-only. It validates the concrete provider route,
145
+ decodes the typed request, calls `query()`, and builds a correlated
146
+ `tool.invoke.response`.
147
+
148
+ Use `ToolEndpointError(ToolError(...))` only to reject a request **before** execution is
149
+ accepted or side effects begin. Once execution has begun, represent a Query failure as a
150
+ terminal `ToolResult(status="failed", error=...)`.
151
+
152
+ ## Action endpoints
153
+
154
+ An Action normally admits work with `ToolAccepted`, then exposes authoritative status and
155
+ result, optional cancellation, and low-rate events. It may instead return an initial
156
+ terminal `ToolResult` when completion was established during `start()`, including terminal
157
+ `unknown` when dispatch may have begun but acceptance cannot be established.
158
+
159
+ ```python
160
+ from forge_tool import (
161
+ ToolAccepted,
162
+ ToolContext,
163
+ ToolControlResponse,
164
+ ToolEvent,
165
+ ToolEventEmitter,
166
+ ToolExecutionKey,
167
+ ToolExecutionStatus,
168
+ ToolRequest,
169
+ ToolResultResponse,
170
+ )
171
+
172
+
173
+ class MoveAction:
174
+ async def start(
175
+ self,
176
+ request: ToolRequest,
177
+ context: ToolContext,
178
+ events: ToolEventEmitter,
179
+ ) -> ToolAccepted:
180
+ await events.emit(ToolEvent(type="progress", data={"fraction": 0.0}))
181
+ # Start the business executor here and retain its private handle by
182
+ # context.execution_key.
183
+ return ToolAccepted(details={"executor": "arm"})
184
+
185
+ async def cancel(
186
+ self,
187
+ key: ToolExecutionKey,
188
+ reason: str | None = None,
189
+ ) -> ToolControlResponse:
190
+ return ToolControlResponse(command="cancel", status="accepted")
191
+
192
+ async def status(self, key: ToolExecutionKey) -> ToolExecutionStatus:
193
+ return ToolExecutionStatus(phase="running")
194
+
195
+ async def result(self, key: ToolExecutionKey) -> ToolResultResponse:
196
+ return ToolResultResponse(status="pending")
197
+ ```
198
+
199
+ Declare it with Action semantics and call it from an async transport loop. This fragment
200
+ assumes the `MoveAction` class above and receives an already constructed request:
201
+
202
+ ```python
203
+ from forge_tool import (
204
+ TOOL_ENDPOINT_PROTOCOL,
205
+ ToolEndpointDescriptor,
206
+ ToolEndpointHandler,
207
+ ToolEnvelope,
208
+ ToolOperationDescriptor,
209
+ )
210
+
211
+ operation = ToolOperationDescriptor(
212
+ name="move",
213
+ semantics="action",
214
+ cancellable=True,
215
+ status_supported=True,
216
+ max_concurrency=4,
217
+ )
218
+ descriptor = ToolEndpointDescriptor(
219
+ protocol_version=TOOL_ENDPOINT_PROTOCOL,
220
+ endpoint_id="motion.arm",
221
+ operations=(operation,),
222
+ )
223
+ handler = ToolEndpointHandler(
224
+ descriptor,
225
+ endpoint_instance_id="arm-process-1",
226
+ operations={"move": MoveAction()},
227
+ )
228
+
229
+ published_events: list[ToolEnvelope] = []
230
+
231
+
232
+ async def collect_event(event: ToolEnvelope) -> None:
233
+ # Suitable for in-memory inspection. A transport publisher needs the
234
+ # response-publication gate described below.
235
+ published_events.append(event)
236
+
237
+
238
+ async def dispatch_action(request: ToolEnvelope) -> tuple[ToolEnvelope, ...]:
239
+ messages = await handler.dispatch(request, event_sink=collect_event)
240
+ # messages[0] is the correlated response; events emitted during start()
241
+ # follow it in strict sequence order.
242
+ return messages
243
+ ```
244
+
245
+ The returned tuple establishes logical response-first ordering for events buffered during
246
+ `start()`. Once acceptance is established, the asynchronous event sink may run before a
247
+ direct transport has physically published `messages[0]`. A transport integration must gate
248
+ that sink until response publication succeeds; `DoraToolEndpointBinding` provides this
249
+ acknowledged publication barrier.
250
+
251
+ The provider remains authoritative for business status, result, and control decisions.
252
+
253
+ ### Action handler guarantees
254
+
255
+ The current Python handler provides provider-side lifecycle and logical-ordering guarantees:
256
+
257
+ - descriptor operation names and implementation mapping must match exactly;
258
+ - `max_concurrency` is enforced per Action operation;
259
+ - the invoke response is first in the returned tuple, before events buffered during
260
+ `start()`;
261
+ - an asynchronous event sink preserves sequence order, while its transport integration
262
+ remains responsible for gating physical publication until the response succeeds;
263
+ - events are assigned sequence numbers from `0` in emission order;
264
+ - a terminal phase/event is not exposed until a matching authoritative result is
265
+ available;
266
+ - terminal status and result are retained and immutable while the record is retained;
267
+ - an unrecoverable failure after dispatch may have started a side effect converges to
268
+ terminal `unknown` and is not retried;
269
+ - a duplicate `ToolExecutionKey` does not restart the provider while its record remains
270
+ in the bounded ledger.
271
+
272
+ These are **not** persistent idempotency or exactly-once guarantees. The ledger is
273
+ process-local and bounded; eviction or restart ends duplicate protection. Duplicate
274
+ requests are keyed by `invocation_id + attempt_id` and are not compared by arguments or
275
+ context fingerprint.
276
+
277
+ The handler currently enforces descriptor `max_concurrency` only for Action admission.
278
+ It also validates but does not enforce `ToolContext.deadline_ms`; timeout ownership
279
+ belongs to the provider or future Runtime/Gateway policy.
280
+
281
+ ## Handler entry points
282
+
283
+ | API | Supported behavior |
284
+ | --- | --- |
285
+ | `handle_invoke(request)` | Legacy single-response Query invoke only. Rejects Action without starting it. |
286
+ | `dispatch(request, event_sink=...)` | Query invoke and Action invoke/status/result/control. Response is first in the returned tuple. Session is not implemented. |
287
+ | `handle_status(request)` | Convenience wrapper for Action status dispatch. |
288
+ | `handle_result(request)` | Convenience wrapper for Action result dispatch. |
289
+ | `handle_control(request)` | Convenience wrapper for Action control dispatch. |
290
+
291
+ Action uses `cancel`; `stop` is returned as `unsupported`. Session will use `stop` when
292
+ its handler path is implemented.
293
+
294
+ ## Optional Arrow/Dora binding
295
+
296
+ Import the optional module explicitly. The following embedding fragment assumes the
297
+ provider Operator/Adapter supplies an existing `handler` and async
298
+ `publish_arrow_value` function:
299
+
300
+ ```python
301
+ from forge_tool.dora import DoraToolEndpointBinding
302
+
303
+ binding = DoraToolEndpointBinding(
304
+ handler,
305
+ max_message_bytes=1_048_576,
306
+ max_carrier_bytes=1_114_112,
307
+ event_sink=publish_arrow_value,
308
+ )
309
+ ```
310
+
311
+ The binding accepts one exact `forge_msgs.ToolMessage` in-memory Arrow carrier:
312
+
313
+ - a one-row `pyarrow.RecordBatch`;
314
+ - a single-batch `pyarrow.Table`; or
315
+ - a `pyarrow.StructArray` accepted by `forge_msgs.ToolMessage`.
316
+
317
+ It rejects raw Arrow IPC bytes. Framing, compression, decompression, and bounded IPC
318
+ decoding belong to the upstream transport.
319
+
320
+ ### Query
321
+
322
+ ```python
323
+ async def handle_query_input(input_arrow_value):
324
+ return await binding.handle_input(input_arrow_value)
325
+ ```
326
+
327
+ `handle_input()` preserves the Query-only single-response API and returns one
328
+ `RecordBatch`. It rejects an Action before calling `start()`.
329
+
330
+ ### Action
331
+
332
+ ```python
333
+ async def handle_action_input(action_input_arrow_value) -> None:
334
+ await binding.dispatch_input(action_input_arrow_value)
335
+ ```
336
+
337
+ For an Action invoke, the configured async `event_sink` is the acknowledged publisher
338
+ for **both** the invoke response and subsequent events. The binding waits for physical
339
+ response publication before opening the event gate, serializes events in sequence order,
340
+ and returns `()` after publication.
341
+
342
+ Other request types use the response-first returned-tuple form. A late-event encoding or
343
+ publication failure is raised from `ToolEventEmitter.emit()`. A buffered early-event
344
+ failure is raised from `dispatch_input()` after the accepted response may already have
345
+ been published. Neither path fabricates a second request-correlated error.
346
+
347
+ The binding does not:
348
+
349
+ - create or import a Dora `Node`;
350
+ - choose input/output IDs;
351
+ - own the event loop or call `asyncio.run()`;
352
+ - inspect or rewrite Dora event metadata;
353
+ - perform registration, route authorization, or Gateway resolution.
354
+
355
+ ## Validation layers
356
+
357
+ A common source of integration bugs is assuming one layer validates everything.
358
+
359
+ | Layer | Responsibility |
360
+ | --- | --- |
361
+ | `forge_msgs.ToolMessage` | Exact Arrow schema, one row, generic identity/nullability rules, strict object-valued `payload_json`. |
362
+ | `ToolEnvelope` | Protocol/message type and generic logical header matrix; JSON-compatible payload object. |
363
+ | `validate_message_envelope`, codec, and factories | Message-specific closed payload schema and complete logical construction. |
364
+ | `ToolEndpointHandler` | Concrete provider route, descriptor operation semantics, SPI dispatch, and Action lifecycle. |
365
+ | `DoraToolEndpointBinding` | Carrier/raw payload/logical size boundaries and bounded correlated error conversion after route trust. |
366
+
367
+ Outbound conversion validates the typed payload. Inbound carrier conversion first
368
+ establishes the generic envelope; after route trust, handler validation can return a
369
+ correlated `tool.error` for an invalid typed payload.
370
+
371
+ Failures before route trust—wrong carrier, oversized raw carrier, invalid generic
372
+ headers, or route mismatch—may be raised without a response. Once the route is trusted,
373
+ the binding attempts to return a bounded correlated error for invalid requests,
374
+ provider exceptions, and invalid or oversized responses.
375
+
376
+ ## Current Python defaults
377
+
378
+ These are implementation defaults, not cross-language Wire constants.
379
+
380
+ | Resource | Default |
381
+ | --- | ---: |
382
+ | Logical encoded message | 1 MiB (`1_048_576` bytes) |
383
+ | Accepted binding request | logical maximum minus 512 bytes of correlated-error headroom |
384
+ | In-memory Arrow carrier | logical maximum plus 64 KiB of framing overhead |
385
+ | Early Action events | 32 events |
386
+ | Retained Action execution records | 1,024 records |
387
+ | JSON nesting | 64 levels |
388
+ | Interoperable JSON integer | `±(2^53-1)` |
389
+
390
+ `max_message_bytes` for `DoraToolEndpointBinding` must be at least 1 KiB, and
391
+ `max_carrier_bytes` must be at least `max_message_bytes`.
392
+
393
+ ## Public API map
394
+
395
+ ### Endpoint contracts and models
396
+
397
+ - SPI: `QueryToolEndpoint`, `ActionToolEndpoint`, `SessionToolEndpoint`,
398
+ `ToolEventEmitter`
399
+ - descriptors: `ToolEndpointDescriptor`, `ToolOperationDescriptor`
400
+ - identity/context: `ToolExecutionKey`, `ToolContext`, `ToolRequest`
401
+ - outcomes: `ToolAccepted`, `ToolResult`, `ToolResultResponse`
402
+ - observation/control: `ToolExecutionStatus`, `ToolControlResponse`, `ToolEvent`
403
+ - errors/management: `ToolError`, `ToolEndpointError`, `EndpointStatus`,
404
+ `EndpointRegistryResponse`
405
+
406
+ ### Logical Wire
407
+
408
+ - `ToolEnvelope`, `ToolMessageType`, `TOOL_ENDPOINT_PROTOCOL`
409
+ - `encode_envelope`, `decode_envelope`
410
+ - `make_*_envelope` factories
411
+ - typed `*_to_payload` / `*_from_payload` adapters
412
+ - `validate_message_envelope`, `validate_response_correlation`,
413
+ `validate_management_response_correlation`
414
+
415
+ Prefer complete `make_*_envelope` factories over manually assembling an envelope.
416
+ Response factories take the originating request and copy its correlation identities.
417
+
418
+ ### Optional carrier API
419
+
420
+ Explicitly import from `forge_tool.dora`:
421
+
422
+ - `DoraToolEndpointBinding`
423
+ - `tool_message_to_envelope`
424
+ - `tool_envelope_to_message`
425
+
426
+ ## Protocol documentation
427
+
428
+ - [Tool documentation index](https://github.com/Forgelab-Robotics/forge/blob/forge-tool-v0.1.0/interfaces/forge_tool/README.md)
429
+ - [Architecture](https://github.com/Forgelab-Robotics/forge/blob/forge-tool-v0.1.0/interfaces/forge_tool/ARCHITECTURE.md)
430
+ - [ToolEndpoint Wire protocol](https://github.com/Forgelab-Robotics/forge/blob/forge-tool-v0.1.0/interfaces/forge_tool/PROTOCOL.md)
431
+ - [Canonical `ToolMessage` Arrow schema](https://github.com/Forgelab-Robotics/forge/blob/forge-msgs-v1.2.0/interfaces/forge_msgs/tool.v1.yaml)
432
+
433
+ ## Development
434
+
435
+ From the Forge repository root:
436
+
437
+ ```bash
438
+ uv run pytest packages/tool/tests
439
+ ```
440
+
441
+ ## License
442
+
443
+ Apache-2.0. See the release [LICENSE](https://github.com/Forgelab-Robotics/forge/blob/forge-tool-v0.1.0/LICENSE).