Skip to content
中文

ToolRegistration ​

KIT · type · Type contract

Declaration form; the registry derives the ModelTool projection from existing handlers.

Import ​

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

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

Definition ​

Type: ToolRegistration<Types>

Type expression
ts
type ToolRegistration<Types extends ToolRuntimeTypes> = Omit<
  Tool<Types>,
  'inputSchema' | 'resolve'
> &
  Partial<Pick<Tool<Types>, 'inputSchema' | 'resolve'>>;

Type parameters ​

Type parameterConstraintDefault type
TypesToolRuntimeTypes—

Field structure ​

FieldTypeRequiredDescription
idstringRequiredRead-only. See the type definition and usage context.
descriptionstringRequiredRead-only. See the type definition and usage context.
activeToolCondition<Types["context"]> | undefinedOptionalRead-only. Omitted means active. Authorization remains a separate execution boundary.
asIntentAsIntent<Types["context"]> | undefinedOptionalRead-only. Omitted means this tool is not advertised by withIntent().
kindstringRequiredRead-only. See the type definition and usage context.
execute(input: unknown, context: ToolExecutionContext) => unknownRequiredSee the type definition and usage context.
debugSteps((result: unknown, context: NodeReportingContext) => void) | undefinedOptionalRead-only. See the type definition and usage context.
parseOutput(value: unknown) => unknownRequiredSee the type definition and usage context.
parseInput(value: unknown) => unknownRequiredSee the type definition and usage context.
goalIdsreadonly string[] | "all"RequiredRead-only. Goal ids this tool serves, or 'all' when it is always available.
audiencestringRequiredRead-only. Audience this tool is described to; validated against the registry policy.
effectstringRequiredRead-only. Declared effect class, for example read-only or mutating.
delegatestring | undefinedOptionalRead-only. Delegate id this tool answers, when a node delegates execution by name.
lifecycleLifecycleHooks<Types, LifecycleProtocol> | undefinedOptionalRead-only. Lifecycle hooks this tool declares for a request.
resolve((input: unknown, context: Readonly<{ stageId: string; }>) => unknown) | undefinedOptionalConverts validated arguments into the value handed back to the caller. Runs inside the model call, so it must return synchronously; throwing rejects the selection.
inputSchemaSchemaAdapter<unknown> | undefinedOptionalRead-only. Schema describing the arguments; must be an object schema.

Member index ​

MemberPurpose
executeSee the overload below for full inputs and outputs.
parseOutputSee the overload below for full inputs and outputs.
parseInputSee the overload below for full inputs and outputs.

Member details ​

execute ​

ts
ToolRegistration.execute(input: unknown, context: ToolExecutionContext): unknown
ParameterTypePassingDescription
inputunknownRequired—
contextToolExecutionContextRequired—
Fields of context
FieldTypeRequiredDescription
loggerScopedSubFlowLogger | undefinedOptionalRead-only. Delegate bound by Core to this actual invocation.
diagnosticsDiagnosticContext | undefinedOptionalRead-only. Diagnostic scope of the invocation, when recording is enabled.
mode"sync" | "async"RequiredRead-only. Declared execution discipline; mirrors whether the registry accepted an async tool.
invocationIdstringRequiredRead-only. Opaque invocation id shared by receipt, events and diagnostics.
signalAbortSignalRequiredRead-only. Non-optional cancellation for this invocation.
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: unknown.

parseOutput ​

ts
ToolRegistration.parseOutput(value: unknown): unknown
ParameterTypePassingDescription
valueunknownRequired—

Returns: unknown.

parseInput ​

ts
ToolRegistration.parseInput(value: unknown): unknown
ParameterTypePassingDescription
valueunknownRequired—

Returns: unknown.

Examples ​

Register one read-only tool for an existing App ​

Beginner · Node.js

ts
import { Tools } from '@jangts/agent-core/kits/tools';
type Runtime = { decision: { type: string }; context: { canRead: boolean }; composition: string; phase: string; placement: string; normalizerArgs: []; result: string; receiver: undefined };
const tools = new Tools<Runtime>({
  registration: { kinds: ['read'], audiences: ['model'], effects: ['read'], isValidId: tool => !!tool.id, goalExists: id => id === 'explain' },
  invocationId: decision => decision.type, outputs: () => [], goalIds: () => ['explain'],
  contextFragment() { throw new Error('这个工具没有登记上下文字段'); },
});
tools.registerAll([{ id: 'read-source', kind: 'read', description: '读取已允许说明', audience: 'model', effect: 'read', goalIds: ['explain'], parseInput: value => value, parseOutput: value => value, execute: () => '接口说明' }]).seal();
console.log(tools.invoke({ toolId: 'read-source', input: {} }).value);
console.log(tools.describe('model', { canRead: true }));
js
import { Tools } from '@jangts/agent-core/kits/tools';
const tools = new Tools({
    registration: { kinds: ['read'], audiences: ['model'], effects: ['read'], isValidId: tool => !!tool.id, goalExists: id => id === 'explain' },
    invocationId: decision => decision.type, outputs: () => [], goalIds: () => ['explain'],
    contextFragment() { throw new Error('这个工具没有登记上下文字段'); },
});
tools.registerAll([{ id: 'read-source', kind: 'read', description: '读取已允许说明', audience: 'model', effect: 'read', goalIds: ['explain'], parseInput: value => value, parseOutput: value => value, execute: () => '接口说明' }]).seal();
console.log(tools.invoke({ toolId: 'read-source', input: {} }).value);
console.log(tools.describe('model', { canRead: true }));

Add App rules and presentation contribution to the same registration ​

Configuration · Node.js

active affects real tool availability and description; business authorization must still verify server-side identity at the actual invocation boundary.

ts
import { Tools } from '@jangts/agent-core/kits/tools';
type Runtime = { decision: { type: string }; context: { canRead: boolean }; composition: string; phase: string; placement: string; normalizerArgs: []; result: string; receiver: undefined };
const tools = new Tools<Runtime>({
  registration: { kinds: ['read'], audiences: ['model'], effects: ['read'], isValidId: tool => !!tool.id, goalExists: id => id === 'explain' },
  invocationId: decision => decision.type, outputs: () => [], goalIds: () => ['explain'],
  contextFragment() { throw new Error('这个工具没有登记上下文字段'); },
});
tools.registerAll([{ id: 'read-source', kind: 'read', description: '读取已允许说明', audience: 'model', effect: 'read', goalIds: ['explain'], active: app => app.canRead,
  parseInput: value => value, parseOutput: value => value, execute: () => '接口说明',
  lifecycle: { rules: () => [{ order: 10, text: '只根据真实读取结果回答。' }], visibleText: text => text.trim() },
}]).seal();
console.log(tools.taskRules({ canRead: true }));
console.log(tools.visibleText(' 已确认说明 ', { canRead: true }));
console.log(tools.describe('model', { canRead: false }));
js
import { Tools } from '@jangts/agent-core/kits/tools';
const tools = new Tools({
    registration: { kinds: ['read'], audiences: ['model'], effects: ['read'], isValidId: tool => !!tool.id, goalExists: id => id === 'explain' },
    invocationId: decision => decision.type, outputs: () => [], goalIds: () => ['explain'],
    contextFragment() { throw new Error('这个工具没有登记上下文字段'); },
});
tools.registerAll([{ id: 'read-source', kind: 'read', description: '读取已允许说明', audience: 'model', effect: 'read', goalIds: ['explain'], active: app => app.canRead,
        parseInput: value => value, parseOutput: value => value, execute: () => '接口说明',
        lifecycle: { rules: () => [{ order: 10, text: '只根据真实读取结果回答。' }], visibleText: text => text.trim() },
    }]).seal();
console.log(tools.taskRules({ canRead: true }));
console.log(tools.visibleText(' 已确认说明 ', { canRead: true }));
console.log(tools.describe('model', { canRead: false }));

API reference, usage examples and developer guides.