defineDelegatingTool
@forge/monorepo / backend/src / defineDelegatingTool
Function: defineDelegatingTool()
defineDelegatingTool<
I,O>(deps,spec):Tool<O>
Defined in: backend/src/tools/delegating.ts:170
Build a Tool whose execute path is: authorise → validate → derive key → look up → preflight → shadow →
approval gate → delegate → store.
The lookup sits before the approval gate deliberately. A call whose result is already stored has already been approved and executed, so re-gating it would either block a legitimate replay or ask a human to approve one action twice.
The descriptor comes from defineTool and the error envelope from the same toPlatformError a
delegating tool's shape is the existing ToolResult by construction rather than by resemblance
(AC-5). The execute path is written out here rather than passed to defineTool, because the
idempotency key arrives on ToolExecutionInput and defineTool's execute(input, context) does not
carry it — bridging that with a side table keyed by context worked but read like a trick.
Type Parameters
I
I = unknown
O
O = unknown
Parameters
deps
spec
DelegatingToolSpec<I, O>
Returns
Tool<O>