Skip to content
中文

ExecutableTool ​

CORE · interface · Type contract

One registered tool, typed by its input, output, host context and id literal.

Import ​

ts
import type { ExecutableTool } from '@jangts/agent-core/types';
js
/** @typedef {import('@jangts/agent-core/types').ExecutableTool} ExecutableTool */

Other public entry points:@jangts/agent-core/types, @jangts/agent-core/structs.

Definition ​

ts
interface ExecutableTool<Input, Output, App, Id>

Extends or implements: ModelTool<Input, ToolProposal, App>.

Type parameters ​

Type parameterConstraintDefault type
Input—unknown
Output—unknown
App—unknown
Idstringstring

Field structure ​

FieldTypeRequiredDescription
idIdRequiredRead-only. Stable id; also the name the model calls.
kindstringRequiredRead-only. Declared grouping used by registries and documentation; not an authorization boundary.
descriptionstringRequiredRead-only. Model-visible explanation of when to call the tool.
inputSchemaSchemaAdapter<Input>RequiredRead-only. Schema applied to raw model arguments before authorize and execute.
authorize(input: Input, context: OperationContext<App>) => MaybePromise<void>RequiredHost permission check. Runs before execution and may be asynchronous.
execute(input: Input, context: OperationContext<App> & import("../debug.js").NodeReportingContext) => MaybePromise<Output>RequiredExecutes the already-authorized input; must not repeat authorization decisions.
debugSteps((result: Output, context: import("../debug.js").NodeReportingContext) => void) | undefinedOptionalOptional result hook; writes through context.createSubFlowLogger() are recorded immediately.
parseOutput(value: unknown) => OutputRequiredValidates untrusted output (for example a cached replay) before it is returned.
activeToolCondition<App> | undefinedOptionalRead-only. Omitted means active. Authorization remains a separate execution boundary.
asIntentAsIntent<App> | undefinedOptionalRead-only. Omitted means this tool is not advertised by withIntent().
resolve(input: Input, context: Readonly<{ stageId: string; }>) => ToolProposalRequiredConverts 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 ​

MemberPurpose
authorizeHost permission check. Runs before execution and may be asynchronous.
executeExecutes the already-authorized input; must not repeat authorization decisions.
parseOutputValidates untrusted output (for example a cached replay) before it is returned.
resolveConverts 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.

ts
ExecutableTool.authorize(input: Input, context: OperationContext<App>): MaybePromise<void>

Host permission check. Runs before execution and may be asynchronous.

ParameterTypePassingDescription
inputInputRequired—
contextOperationContext<App>Required—
Fields of context
FieldTypeRequiredDescription
appunknown extends App ? App : Readonly<App>RequiredRead-only. See the type definition and usage context.
loggerSubFlowLog | undefinedOptionalRead-only. Explicit optional recorder for this operation; never inferred from diagnostics.
signalAbortSignalRequiredRead-only. Non-optional cancellation signal; never undefined once execution has started.
diagnosticsDiagnosticContext | undefinedOptionalRead-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.

ts
ExecutableTool.execute(input: Input, context: OperationContext<App> & import("../debug.js").NodeReportingContext): MaybePromise<Output>

Executes the already-authorized input; must not repeat authorization decisions.

ParameterTypePassingDescription
inputInputRequired—
contextOperationContext<App> & NodeReportingContextRequired—
Fields of context
FieldTypeRequiredDescription
appunknown extends App ? App : Readonly<App>RequiredRead-only. See the type definition and usage context.
loggerSubFlowLog | undefinedOptionalRead-only. Explicit optional recorder for this operation; never inferred from diagnostics.
signalAbortSignalRequiredRead-only. Non-optional cancellation signal; never undefined once execution has started.
diagnosticsDiagnosticContext | undefinedOptionalRead-only. Diagnostic scope of the enclosing call, when recording is enabled.
report(update: import("./execution/workflow.js").WorkflowNodeReport) => voidRequiredReports progress for the active node; Core supplies the execution identity.
createSubFlowLogger() => SubFlowLoggerRequiredBound 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.

ts
ExecutableTool.parseOutput(value: unknown): Output

Validates untrusted output (for example a cached replay) before it is returned.

ParameterTypePassingDescription
valueunknownRequired—

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.

ts
ExecutableTool.resolve(input: Input, context: Readonly<{ stageId: string; }>): ToolProposal

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.

ParameterTypePassingDescription
inputInputRequired—
contextReadonly<{ stageId: string; }>Required—
Fields of context
FieldTypeRequiredDescription
stageIdstringRequiredSee the type definition and usage context.

Returns: ToolProposal.

Return value structure
FieldTypeRequiredDescription
toolIdstringRequiredRead-only. See the type definition and usage context.
inputunknownRequiredRead-only. See the type definition and usage context.

Examples ​

Minimal local read-only tool ​

Beginner · Node.js

ts
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);
js
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.

ts
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({}));
js
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({}));

API reference, usage examples and developer guides.