Skip to content
中文

RegisteredTool ​

CORE · type · Type contract

Registered snapshot: public data is retained, implementation helpers are not a contract.

Import ​

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

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

Definition ​

Type: RegisteredTool<Tool>

Type expression
ts
type RegisteredTool<Tool extends ErasedTool = ErasedTool> = RegistrationProjection<
  Tool,
  ErasedTool
>;

Type parameters ​

Type parameterConstraintDefault type
ToolErasedToolErasedTool

Field structure ​

FieldTypeRequiredDescription
id(ErasedTool & RegistrationData<Tool> & Pick<Tool, Extract<keyof Tool, keyof ErasedTool>>)["id"]RequiredRead-only. See the type definition and usage context.
kind(ErasedTool & RegistrationData<Tool> & Pick<Tool, Extract<keyof Tool, keyof ErasedTool>>)["kind"]RequiredRead-only. See the type definition and usage context.
description(ErasedTool & RegistrationData<Tool> & Pick<Tool, Extract<keyof Tool, keyof ErasedTool>>)["description"] | undefinedOptionalRead-only. Optional here because the erased view does not require model-facing prose.
debugSteps(ErasedTool & RegistrationData<Tool> & Pick<Tool, Extract<keyof Tool, keyof ErasedTool>>)["debugSteps"] | undefinedOptionalRead-only. See the type definition and usage context.
parseInput(ErasedTool & RegistrationData<Tool> & Pick<Tool, Extract<keyof Tool, keyof ErasedTool>>)["parseInput"]RequiredSee the type definition and usage context.
parseOutput(ErasedTool & RegistrationData<Tool> & Pick<Tool, Extract<keyof Tool, keyof ErasedTool>>)["parseOutput"]RequiredSee the type definition and usage context.
execute(ErasedTool & RegistrationData<Tool> & Pick<Tool, Extract<keyof Tool, keyof ErasedTool>>)["execute"]RequiredSee the type definition and usage context.

Member index ​

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

Member details ​

parseInput ​

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

Returns: unknown.

parseOutput ​

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

Returns: unknown.

execute ​

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

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.