Skip to content
中文

RegisteredToolDefinition ​

KIT · type · Type contract

Registered snapshot with frozen goal ids and projected hooks.

Import ​

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

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: RegisteredToolDefinition<Types, Declaration>

Type expression
ts
type RegisteredToolDefinition<Types extends ToolRuntimeTypes, Declaration extends ToolRegistration<Types> = ToolRegistration<Types>> = Readonly<
  Omit<RegistrationProjection<Declaration, Tool<Types>>, 'lifecycle' | 'goalIds'> & {
    lifecycle?: RegisteredLifecycle<Types, Declaration['lifecycle']>;
    goalIds: Readonly<Declaration['goalIds']>;
  }
>;

Type parameters ​

Type parameterConstraintDefault type
TypesToolRuntimeTypes—
DeclarationToolRegistration<Types>ToolRegistration<Types>

Field structure ​

FieldTypeRequiredDescription
id(Omit<Readonly<Tool<Types> & RegistrationData<Declaration> & Pick<Declaration, Extract<keyof Declaration, keyof Tool<Types>>>>, "goalIds" | "lifecycle"> & { lifecycle?: RegisteredLifecycle<Types, Declaration["lifecycle"]>; goalIds: Readonly<Declaration["goalIds"]>; })["id"]RequiredRead-only. See the type definition and usage context.
description(Omit<Readonly<Tool<Types> & RegistrationData<Declaration> & Pick<Declaration, Extract<keyof Declaration, keyof Tool<Types>>>>, "goalIds" | "lifecycle"> & { lifecycle?: RegisteredLifecycle<Types, Declaration["lifecycle"]>; goalIds: Readonly<Declaration["goalIds"]>; })["description"]RequiredRead-only. See the type definition and usage context.
resolve(Omit<Readonly<Tool<Types> & RegistrationData<Declaration> & Pick<Declaration, Extract<keyof Declaration, keyof Tool<Types>>>>, "goalIds" | "lifecycle"> & { lifecycle?: RegisteredLifecycle<Types, Declaration["lifecycle"]>; goalIds: Readonly<Declaration["goalIds"]>; })["resolve"]RequiredConverts validated arguments into the value handed back to the caller. Runs inside the model call, so it must return synchronously; throwing rejects the selection.
inputSchema(Omit<Readonly<Tool<Types> & RegistrationData<Declaration> & Pick<Declaration, Extract<keyof Declaration, keyof Tool<Types>>>>, "goalIds" | "lifecycle"> & { lifecycle?: RegisteredLifecycle<Types, Declaration["lifecycle"]>; goalIds: Readonly<Declaration["goalIds"]>; })["inputSchema"]RequiredRead-only. Schema describing the arguments; must be an object schema.
active(Omit<Readonly<Tool<Types> & RegistrationData<Declaration> & Pick<Declaration, Extract<keyof Declaration, keyof Tool<Types>>>>, "goalIds" | "lifecycle"> & { lifecycle?: RegisteredLifecycle<Types, Declaration["lifecycle"]>; goalIds: Readonly<Declaration["goalIds"]>; })["active"] | undefinedOptionalRead-only. Omitted means active. Authorization remains a separate execution boundary.
asIntent(Omit<Readonly<Tool<Types> & RegistrationData<Declaration> & Pick<Declaration, Extract<keyof Declaration, keyof Tool<Types>>>>, "goalIds" | "lifecycle"> & { lifecycle?: RegisteredLifecycle<Types, Declaration["lifecycle"]>; goalIds: Readonly<Declaration["goalIds"]>; })["asIntent"] | undefinedOptionalRead-only. Omitted means this tool is not advertised by withIntent().
kind(Omit<Readonly<Tool<Types> & RegistrationData<Declaration> & Pick<Declaration, Extract<keyof Declaration, keyof Tool<Types>>>>, "goalIds" | "lifecycle"> & { lifecycle?: RegisteredLifecycle<Types, Declaration["lifecycle"]>; goalIds: Readonly<Declaration["goalIds"]>; })["kind"]RequiredRead-only. See the type definition and usage context.
execute(Omit<Readonly<Tool<Types> & RegistrationData<Declaration> & Pick<Declaration, Extract<keyof Declaration, keyof Tool<Types>>>>, "goalIds" | "lifecycle"> & { lifecycle?: RegisteredLifecycle<Types, Declaration["lifecycle"]>; goalIds: Readonly<Declaration["goalIds"]>; })["execute"]RequiredSee the type definition and usage context.
debugSteps(Omit<Readonly<Tool<Types> & RegistrationData<Declaration> & Pick<Declaration, Extract<keyof Declaration, keyof Tool<Types>>>>, "goalIds" | "lifecycle"> & { lifecycle?: RegisteredLifecycle<Types, Declaration["lifecycle"]>; goalIds: Readonly<Declaration["goalIds"]>; })["debugSteps"] | undefinedOptionalRead-only. See the type definition and usage context.
parseOutput(Omit<Readonly<Tool<Types> & RegistrationData<Declaration> & Pick<Declaration, Extract<keyof Declaration, keyof Tool<Types>>>>, "goalIds" | "lifecycle"> & { lifecycle?: RegisteredLifecycle<Types, Declaration["lifecycle"]>; goalIds: Readonly<Declaration["goalIds"]>; })["parseOutput"]RequiredSee the type definition and usage context.
parseInput(Omit<Readonly<Tool<Types> & RegistrationData<Declaration> & Pick<Declaration, Extract<keyof Declaration, keyof Tool<Types>>>>, "goalIds" | "lifecycle"> & { lifecycle?: RegisteredLifecycle<Types, Declaration["lifecycle"]>; goalIds: Readonly<Declaration["goalIds"]>; })["parseInput"]RequiredSee the type definition and usage context.
audience(Omit<Readonly<Tool<Types> & RegistrationData<Declaration> & Pick<Declaration, Extract<keyof Declaration, keyof Tool<Types>>>>, "goalIds" | "lifecycle"> & { lifecycle?: RegisteredLifecycle<Types, Declaration["lifecycle"]>; goalIds: Readonly<Declaration["goalIds"]>; })["audience"]RequiredRead-only. Audience this tool is described to; validated against the registry policy.
effect(Omit<Readonly<Tool<Types> & RegistrationData<Declaration> & Pick<Declaration, Extract<keyof Declaration, keyof Tool<Types>>>>, "goalIds" | "lifecycle"> & { lifecycle?: RegisteredLifecycle<Types, Declaration["lifecycle"]>; goalIds: Readonly<Declaration["goalIds"]>; })["effect"]RequiredRead-only. Declared effect class, for example read-only or mutating.
delegate(Omit<Readonly<Tool<Types> & RegistrationData<Declaration> & Pick<Declaration, Extract<keyof Declaration, keyof Tool<Types>>>>, "goalIds" | "lifecycle"> & { lifecycle?: RegisteredLifecycle<Types, Declaration["lifecycle"]>; goalIds: Readonly<Declaration["goalIds"]>; })["delegate"] | undefinedOptionalRead-only. Delegate id this tool answers, when a node delegates execution by name.
lifecycle(Omit<Readonly<Tool<Types> & RegistrationData<Declaration> & Pick<Declaration, Extract<keyof Declaration, keyof Tool<Types>>>>, "goalIds" | "lifecycle"> & { lifecycle?: RegisteredLifecycle<Types, Declaration["lifecycle"]>; goalIds: Readonly<Declaration["goalIds"]>; })["lifecycle"] | undefinedOptionalSee the type definition and usage context.
goalIds(Omit<Readonly<Tool<Types> & RegistrationData<Declaration> & Pick<Declaration, Extract<keyof Declaration, keyof Tool<Types>>>>, "goalIds" | "lifecycle"> & { lifecycle?: RegisteredLifecycle<Types, Declaration["lifecycle"]>; goalIds: Readonly<Declaration["goalIds"]>; })["goalIds"]RequiredSee the type definition and usage context.

Member index ​

MemberPurpose
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.
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 ​

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
RegisteredToolDefinition.resolve(input: unknown, context: Readonly<{ stageId: string; }>): unknown

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
inputunknownRequired—
contextReadonly<{ stageId: string; }>Required—
Fields of context
FieldTypeRequiredDescription
stageIdstringRequiredSee the type definition and usage context.

Returns: unknown.

execute ​

ts
RegisteredToolDefinition.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
RegisteredToolDefinition.parseOutput(value: unknown): unknown
ParameterTypePassingDescription
valueunknownRequired—

Returns: unknown.

parseInput ​

ts
RegisteredToolDefinition.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.