ExecutableTool
CORE · interface · Type contract
One registered tool, typed by its input, output, host context and id literal.
Import
import type { ExecutableTool } from '@jangts/agent-core/types';/** @typedef {import('@jangts/agent-core/types').ExecutableTool} ExecutableTool */Other public entry points:@jangts/agent-core/types, @jangts/agent-core/structs.
Definition
interface ExecutableTool<Input, Output, App, Id>Extends or implements: ModelTool<Input, ToolProposal, App>.
Type parameters
| Type parameter | Constraint | Default type |
|---|---|---|
Input | — | unknown |
Output | — | unknown |
App | — | unknown |
Id | string | string |
Field structure
| Field | Type | Required | Description |
|---|---|---|---|
id | Id | Required | Read-only. Stable id; also the name the model calls. |
kind | string | Required | Read-only. Declared grouping used by registries and documentation; not an authorization boundary. |
description | string | Required | Read-only. Model-visible explanation of when to call the tool. |
inputSchema | SchemaAdapter<Input> | Required | Read-only. Schema applied to raw model arguments before authorize and execute. |
authorize | (input: Input, context: OperationContext<App>) => MaybePromise<void> | Required | Host permission check. Runs before execution and may be asynchronous. |
execute | (input: Input, context: OperationContext<App> & import("../debug.js").NodeReportingContext) => MaybePromise<Output> | Required | Executes the already-authorized input; must not repeat authorization decisions. |
debugSteps | ((result: Output, context: import("../debug.js").NodeReportingContext) => void) | undefined | Optional | Optional result hook; writes through context.createSubFlowLogger() are recorded immediately. |
parseOutput | (value: unknown) => Output | Required | Validates untrusted output (for example a cached replay) before it is returned. |
active | ToolCondition<App> | undefined | Optional | Read-only. Omitted means active. Authorization remains a separate execution boundary. |
asIntent | AsIntent<App> | undefined | Optional | Read-only. Omitted means this tool is not advertised by withIntent(). |
resolve | (input: Input, context: Readonly<{ stageId: string; }>) => ToolProposal | Required | Converts validated arguments into the value handed back to the caller. Runs inside the model call, so it must return synchronously; throwing rejects the selection. |
Member index
| Member | Purpose |
|---|---|
authorize | Host permission check. Runs before execution and may be asynchronous. |
execute | Executes the already-authorized input; must not repeat authorization decisions. |
parseOutput | Validates untrusted output (for example a cached replay) before it is returned. |
resolve | Converts validated arguments into the value handed back to the caller. Runs inside the model call, so it must return synchronously; throwing rejects the selection. |
Member details
authorize
Host permission check. Runs before execution and may be asynchronous.
ExecutableTool.authorize(input: Input, context: OperationContext<App>): MaybePromise<void>Host permission check. Runs before execution and may be asynchronous.
| Parameter | Type | Passing | Description |
|---|---|---|---|
input | Input | Required | — |
context | OperationContext<App> | Required | — |
Fields of context
| Field | Type | Required | Description |
|---|---|---|---|
app | unknown extends App ? App : Readonly<App> | Required | Read-only. See the type definition and usage context. |
logger | SubFlowLog | undefined | Optional | Read-only. Explicit optional recorder for this operation; never inferred from diagnostics. |
signal | AbortSignal | Required | Read-only. Non-optional cancellation signal; never undefined once execution has started. |
diagnostics | DiagnosticContext | undefined | Optional | Read-only. Diagnostic scope of the enclosing call, when recording is enabled. |
Returns: MaybePromise<void>.
Awaited value: void.
execute
Executes the already-authorized input; must not repeat authorization decisions.
ExecutableTool.execute(input: Input, context: OperationContext<App> & import("../debug.js").NodeReportingContext): MaybePromise<Output>Executes the already-authorized input; must not repeat authorization decisions.
| Parameter | Type | Passing | Description |
|---|---|---|---|
input | Input | Required | — |
context | OperationContext<App> & NodeReportingContext | Required | — |
Fields of context
| Field | Type | Required | Description |
|---|---|---|---|
app | unknown extends App ? App : Readonly<App> | Required | Read-only. See the type definition and usage context. |
logger | SubFlowLog | undefined | Optional | Read-only. Explicit optional recorder for this operation; never inferred from diagnostics. |
signal | AbortSignal | Required | Read-only. Non-optional cancellation signal; never undefined once execution has started. |
diagnostics | DiagnosticContext | undefined | Optional | Read-only. Diagnostic scope of the enclosing call, when recording is enabled. |
report | (update: import("./execution/workflow.js").WorkflowNodeReport) => void | Required | Reports progress for the active node; Core supplies the execution identity. |
createSubFlowLogger | () => SubFlowLogger | Required | Bound to this context and owned by runtime; repeated calls in one visit return the same instance. |
Returns: MaybePromise<Output>.
Awaited value: Awaited<Output>.
parseOutput
Validates untrusted output (for example a cached replay) before it is returned.
ExecutableTool.parseOutput(value: unknown): OutputValidates untrusted output (for example a cached replay) before it is returned.
| Parameter | Type | Passing | Description |
|---|---|---|---|
value | unknown | Required | — |
Returns: Output.
Awaited value: Awaited<Output>.
resolve
Converts validated arguments into the value handed back to the caller.
Runs inside the model call, so it must return synchronously; throwing rejects the selection.
ExecutableTool.resolve(input: Input, context: Readonly<{ stageId: string; }>): ToolProposalConverts validated arguments into the value handed back to the caller.
Runs inside the model call, so it must return synchronously; throwing rejects the selection.
| Parameter | Type | Passing | Description |
|---|---|---|---|
input | Input | Required | — |
context | Readonly<{ stageId: string; }> | Required | — |
Fields of context
| Field | Type | Required | Description |
|---|---|---|---|
stageId | string | Required | See the type definition and usage context. |
Returns: ToolProposal.
Return value structure
| Field | Type | Required | Description |
|---|---|---|---|
toolId | string | Required | Read-only. See the type definition and usage context. |
input | unknown | Required | Read-only. See the type definition and usage context. |
Examples
- Real tool invocation and in-request runtime: Core registers and executes real tools and returns receipts carrying an invocation; business authorization is owned by the implementation registered by the App.
Minimal local read-only tool
Beginner · Node.js
import { ToolRegistry } from '@jangts/agent-core/tools';
const tools = new ToolRegistry().register({
id: 'get_status', kind: 'read', description: '读取演示服务状态',
parseInput(value: unknown) { if (!value || typeof value !== 'object' || Array.isArray(value)) throw new TypeError('需要对象'); return {}; },
execute: () => '服务运行正常',
parseOutput(value: unknown) { if (typeof value !== 'string') throw new TypeError('需要文本'); return value; },
}).seal();
const result = tools.invoke({ toolId: 'get_status', input: {} });
console.log(result.value, result.invocation.invocationId);import { ToolRegistry } from '@jangts/agent-core/tools';
const tools = new ToolRegistry().register({
id: 'get_status', kind: 'read', description: '读取演示服务状态',
parseInput(value) { if (!value || typeof value !== 'object' || Array.isArray(value))
throw new TypeError('需要对象'); return {}; },
execute: () => '服务运行正常',
parseOutput(value) { if (typeof value !== 'string')
throw new TypeError('需要文本'); return value; },
}).seal();
const result = tools.invoke({ toolId: 'get_status', input: {} });
console.log(result.value, result.invocation.invocationId);Bind in advance so nodes no longer inject tools repeatedly
Configuration · Node.js
The first example validates external input strictly; the second only shows the binding relationship, and real business code should use the appropriate Schema and authorization.
import { AgentCoreEngine, defineWorkflow, route } from '@jangts/agent-core/engine';
import { ToolRegistry } from '@jangts/agent-core/tools';
type State = { answer?: unknown };
const tools = new ToolRegistry().register({ id: 'get_status', kind: 'read',
parseInput: () => ({}), execute: async () => '服务运行正常', parseOutput: value => value,
}).seal();
const workflow = defineWorkflow<State, unknown>({ id: 'status', nodes: [{
id: 'read', description: '读取状态', startsRound: true,
async run(_state, { tools }) { const { value } = await tools.invoke({ toolId: 'get_status', input: {} }); return { answer: value }; },
routes: [route.deliver('answer')],
}] });
const agent = new AgentCoreEngine({ workflow }).bindToolRuntime(tools);
console.log(await agent.run({}));import { AgentCoreEngine, defineWorkflow, route } from '@jangts/agent-core/engine';
import { ToolRegistry } from '@jangts/agent-core/tools';
const tools = new ToolRegistry().register({ id: 'get_status', kind: 'read',
parseInput: () => ({}), execute: async () => '服务运行正常', parseOutput: value => value,
}).seal();
const workflow = defineWorkflow({ id: 'status', nodes: [{
id: 'read', description: '读取状态', startsRound: true,
async run(_state, { tools }) { const { value } = await tools.invoke({ toolId: 'get_status', input: {} }); return { answer: value }; },
routes: [route.deliver('answer')],
}] });
const agent = new AgentCoreEngine({ workflow }).bindToolRuntime(tools);
console.log(await agent.run({}));