Skip to content
中文

ToolLifecycleRegistry ​

KIT · class · Runtime value

Registry of tools whose lifecycle, protocols and context contributions the App declares.

Registration is only possible before seal(); afterwards the catalog is read-only, so a run cannot change which tools exist. Every hook is optional and is applied in registration order, which is why registerAll preserves iteration order.

Import ​

ts
import { ToolLifecycleRegistry } from '@jangts/agent-core/kits/tools';
js
import { ToolLifecycleRegistry } from '@jangts/agent-core/kits/tools';

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

Definition ​

ts
class ToolLifecycleRegistry<Types, Declaration>

Type parameters ​

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

Constructor ​

ts
new ToolLifecycleRegistry<Types extends ToolRuntimeTypes, Declaration extends ToolRegistration<Types> = ToolRegistration<Types>>(options: ToolsOptions<Types, Declaration>): ToolLifecycleRegistry<Types, Declaration>
ParameterTypePassingDescription
optionsToolsOptions<Types, Declaration>Required—
Fields of options
FieldTypeRequiredDescription
receiver(() => Types["receiver"]) | undefinedOptionalRead-only. Supplies the receiver handed to the finalizer.
executionExecutionOptions | undefinedOptionalRead-only. Execution defaults (signal and diagnostics) applied to invocations.
errorsPick<ToolRegistryPorts, "unavailable" | "errorCode"> | undefinedOptionalRead-only. Error factories shared by the registry.
registrationPolicy<Declaration>RequiredRead-only. Registration policy for every tool.
invocationId(decision: Types["decision"]) => stringRequiredRead-only. Maps a decision to the invocation id that should handle it.
outputs() => Iterable<readonly [string, ToolProtocol<Declaration>]>RequiredRead-only. Output protocols by id, used to validate invocation outputs.
modelOutputs((context: Types["context"]) => Iterable<readonly [string, ToolProtocol<Declaration>]>) | undefinedOptionalRead-only. Optional context-dependent output protocols, exposed alongside outputs.
unavailableInvocation((invocationId: string) => Error) | undefinedOptionalRead-only. Builds the error for an invocation id with no registered tool.
forbidden(() => Error) | undefinedOptionalRead-only. Builds the error for a tool that is currently unavailable.
contextFragment(tool: Declaration, field: ToolModelField<Types["placement"]>) => ContextFragmentRequiredRead-only. Renders a model field into a context fragment.
goalIds() => readonly string[]RequiredRead-only. Current goal ids, used to validate goalIds: 'all' availability.
logger((context: Types["context"]) => import("../debug.js").SubFlowLogger | undefined) | undefinedOptionalRead-only. Explicit recorder selected for this invocation only.
diagnostics((context: Types["context"]) => import("../diagnostics.js").DiagnosticContext | undefined) | undefinedOptionalRead-only. Diagnostic scope; omitted disables recording for this tool.
signal((context: Types["context"]) => AbortSignal | undefined) | undefinedOptionalRead-only. Extra cancellation; must not replace the tool execution signal.
journal((context: Types["context"]) => ToolJournal | undefined) | undefinedOptionalRead-only. Journal receiving begin/finish receipts.
checkpoint((context: Types["context"]) => unknown) | undefinedOptionalRead-only. Extracts the domain checkpoint recorded with the receipt.
receipt((context: Types["context"], checkpoint: unknown) => unknown) | undefinedOptionalRead-only. Builds the domain receipt from a checkpoint after execution.
receiptError((error: unknown) => unknown) | undefinedOptionalRead-only. Converts an error into the receipt's replacement value.

Returns: ToolLifecycleRegistry<Types, Declaration>.

Instance properties ​

FieldTypeRequiredDescription
eventsreadonly Readonly<ToolExecutionEvent<PreparedTool<Types, Declaration>["kind"]>>[]RequiredRead-only. Core tool events, forwarded unchanged.
definitionsreadonly Readonly<Omit<Readonly<Tool<Types> & RegistrationData<Declaration> & Pick<Declaration, Extract<keyof Declaration, keyof Tool<Types>>>>, "goalIds" | "lifecycle"> & { lifecycle?: RegisteredLifecycle<Types, Declaration["lifecycle"]> | undefined; goalIds: Readonly<Declaration["goalIds"]>; }>[]RequiredRead-only. Registered tools in registration order.

Member index ​

MemberPurpose
setDiagnosticsSwap the diagnostics sink for later invocations; the Core registry is updated as well.
registerRegister and freeze one tool definition. Handlers are bound to the original object; authorization, inspection and finalization hooks must return void synchronously, while the remaining handlers are checked for accidental thenables only.
registerAllRegister every tool in iteration order.
invokeInvoke one Core tool by its already-validated request. When the request carries no diagnostics, the currently active one is used, so a call made from inside a tool inherits that tool's diagnostic context.
idsRegistered tool ids, delegated to the Core registry.
entriesIterate [id, tool] pairs.
getRegistered tool for id, or undefined when it is absent.
requireRegistered tool for id.
hasWhether a tool id is registered.
valuesIterate the registered tools.
hasDelegateWhether a delegate id is claimed by a registered tool.
registerNormalizerInstall the single normalization handler.
normalizeApply the installed normalizer, or return the value unchanged when none exists.
registerFinalizerInstall the single reply finalizer.
finishRun the installed finalizer over a decision.
callRun the invocation that answers one decision next. Delegation is the App's choice; this method only executes the tool that claimed the id, so a purely programmatic node, a model choice and a mixed pipeline all dispatch the same way. Diagnostics are swapped to the invocation's own sink for the duration of the call and restored afterwards, so nested tool calls report under the innermost scope.
protocolsOutput protocols plus one protocol per registered invocation.
modelProtocolsProtocols exposed to the model: output protocols plus invocations whose audience is model and which are currently available in context.
isTerminalWhether the protocol registered for this invocation is declared terminal.
assertDecisionRun inspect for every registered tool in registration order. inspect belongs to the all-tools group, so the selected tool participates exactly once through the same loop rather than through a second selected-only pass.
authorizeRun the selected invocation's authorization hook, if any.
resumeWhether the selected invocation should resume rather than start fresh; defaults to false.
completeLet the selected invocation rewrite the decision on completion, if it declares a hook.
projectContextFold every tool's context projection over the value, in registration order.
visibleTextFold every tool's visible-text transform over the text.
reviewDraftFold every tool's review transform over the draft.
recoveryContextCollected recovery context values; undefined results are omitted.
compositionThe single output template that owns this delivery.
finalizeRun every tool's finalize hook for the given phase.
missingInteractionAllowedWhether any tool permits the interaction to be missing.
taskRulesTask rules ordered by their declared order, joined into one prompt block.
contextFieldsModel-context fragments for one placement, ordered by each field's order.
modelFieldsMerged model-context values for one placement; later fragments win per key.
supportsGoalA tool may veto a goal by returning false; silence means support.
describeDescribe registered tools, optionally limited by audience and availability. A tool with an available predicate is only listed when a context is supplied and the predicate holds, so a caller that omits the context sees just the unconditional tools.
copyToReinstall every registered tool, plus the finalizer and normalizer, into another registry. The original definitions are reused rather than the compiled views, so the target applies its own policy checks and binding exactly as it would for a first registration.
sealFreeze the registry: no further registration, normalizer or finalizer is accepted.

Member details ​

setDiagnostics ​

Instance method.

Swap the diagnostics sink for later invocations; the Core registry is updated as well.

ts
setDiagnostics(value: ToolRegistryPorts["diagnostics"]): void

Swap the diagnostics sink for later invocations; the Core registry is updated as well.

ParameterTypePassingDescription
valueDiagnosticContext | undefinedRequired—

Optional shapes of Parameter value: choose one shape; required fields for each branch are listed separately.

Branch 1

undefined

Branch 2
FieldTypeRequiredDescription
identityReadonly<DiagnosticIdentity> | undefinedOptionalRead-only. Identity of the current scope, when the scope is bound to an execution.
enabled(event: CoreEventName, content?: "metadata" | "content") => booleanRequiredCheap pre-check so callers can skip building expensive payloads.
emit<K extends CoreEventName>(event: K, payload: () => CoreEventPayloads[K], debug?: DebugStepsOutput) => voidRequiredRecords one fact.
deliver<K extends CoreEventName>(event: K, payload: () => CoreEventPayloads[K], sink: (event: Extract<CoreEvent, { type: K; }>) => void | Promise<void>) => Promise<void>RequiredOrdered content delivery uses the same fact, while consumer failures propagate.
child(spanId: string, fields?: Readonly<DiagnosticSpanFields>) => DiagnosticContextRequiredDerives a child span; fields fills values the child knows but the parent does not.
withObserver(observer: import("./execution/events.js").ExecutionObserver) => DiagnosticContextRequiredBind live observation without changing the log destination or request identity.

Returns: void.

register ​

Instance method.

Register and freeze one tool definition.

Handlers are bound to the original object; authorization, inspection and finalization hooks must return void synchronously, while the remaining handlers are checked for accidental thenables only.

ts
register(input: Declaration): ToolLifecycleRegistry<Types, Declaration>

Register and freeze one tool definition.

Handlers are bound to the original object; authorization, inspection and finalization hooks must return void synchronously, while the remaining handlers are checked for accidental thenables only.

ParameterTypePassingDescription
inputDeclarationRequired—

Returns: ToolLifecycleRegistry<Types, Declaration>.

registerAll ​

Instance method.

Register every tool in iteration order.

ts
registerAll(tools: Iterable<Declaration>): ToolLifecycleRegistry<Types, Declaration>

Register every tool in iteration order.

ParameterTypePassingDescription
toolsIterable<Declaration>Required—

Returns: ToolLifecycleRegistry<Types, Declaration>.

invoke ​

Instance method.

Invoke one Core tool by its already-validated request.

When the request carries no diagnostics, the currently active one is used, so a call made from inside a tool inherits that tool's diagnostic context.

ts
invoke(request: ToolInvocationRequest): ToolResult<unknown>

Invoke one Core tool by its already-validated request.

When the request carries no diagnostics, the currently active one is used, so a call made from inside a tool inherits that tool's diagnostic context.

ParameterTypePassingDescription
requestToolInvocationRequest<string>Required—
Fields of request
FieldTypeRequiredDescription
loggerSubFlowLogger | undefinedOptionalRead-only. Explicit recorder for this call, also available to its handler for deliberate use.
toolIdstringRequiredRead-only. See the type definition and usage context.
inputunknownRequiredRead-only. Raw model arguments; parsed by the tool's input schema before authorization.
signalAbortSignal | undefinedOptionalRead-only. Per-call cancellation; can only shorten the surrounding execution lifetime.
diagnosticsDiagnosticContext | undefinedOptionalRead-only. See the type definition and usage context.

Returns: ToolResult<unknown>.

Return value structure
FieldTypeRequiredDescription
valueunknownRequiredRead-only. See the type definition and usage context.
invocationReadonly<ToolCallRecord>RequiredRead-only. See the type definition and usage context.

ids ​

Instance method.

Registered tool ids, delegated to the Core registry.

ts
ids(): readonly string[]

Registered tool ids, delegated to the Core registry.

No call parameters.

Returns: readonly string[].

entries ​

Instance method.

Iterate [id, tool] pairs.

ts
entries(): IterableIterator<[string, RegisteredToolDefinition<Types, Declaration>]>

Iterate [id, tool] pairs.

No call parameters.

Returns: IterableIterator<[string, Readonly<Omit<Readonly<Tool<Types> & RegistrationData<Declaration> & Pick<Declaration, Extract<keyof Declaration, keyof Tool<Types>>>>, "goalIds" \| "lifecycle"> & { lifecycle?: RegisteredLifecycle<Types, Declaration["lifecycle"]> \| undefined; goalIds: Readonly<Declaration["goalIds"]>; }>]>.

get ​

Instance method.

Registered tool for id, or undefined when it is absent.

ts
get(id: string): RegisteredToolDefinition<Types, Declaration> | undefined

Registered tool for id, or undefined when it is absent.

ParameterTypePassingDescription
idstringRequired—

Returns: Readonly<Omit<Readonly<Tool<Types> & RegistrationData<Declaration> & Pick<Declaration, Extract<keyof Declaration, keyof Tool<Types>>>>, "goalIds" \| "lifecycle"> & { lifecycle?: RegisteredLifecycle<Types, Declaration["lifecycle"]> \| undefined; goalIds: Readonly<Declaration["goalIds"]>; }> \| undefined.

Optional shapes of Return value: choose one shape; required fields for each branch are listed separately.

Branch 1

undefined

Branch 2
FieldTypeRequiredDescription
id(Omit<Readonly<Tool<Types> & RegistrationData<Declaration> & Pick<Declaration, Extract<keyof Declaration, keyof Tool<Types>>>>, "goalIds" | "lifecycle"> & { lifecycle?: RegisteredLifecycle<Types, Declaration["lifecycle"]> | undefined; 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"]> | undefined; 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"]> | undefined; 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"]> | undefined; 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"]> | undefined; 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"]> | undefined; 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"]> | undefined; 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"]> | undefined; 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"]> | undefined; 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"]> | undefined; 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"]> | undefined; 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"]> | undefined; 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"]> | undefined; 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"]> | undefined; 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"]> | undefined; 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"]> | undefined; goalIds: Readonly<Declaration["goalIds"]>; })["goalIds"]RequiredSee the type definition and usage context.

require ​

Instance method.

Registered tool for id.

ts
require(id: string): RegisteredToolDefinition<Types, Declaration>

Registered tool for id.

ParameterTypePassingDescription
idstringRequired—

Returns: Readonly<Omit<Readonly<Tool<Types> & RegistrationData<Declaration> & Pick<Declaration, Extract<keyof Declaration, keyof Tool<Types>>>>, "goalIds" \| "lifecycle"> & { lifecycle?: RegisteredLifecycle<Types, Declaration["lifecycle"]> \| undefined; goalIds: Readonly<Declaration["goalIds"]>; }>.

Return value structure
FieldTypeRequiredDescription
id(Omit<Readonly<Tool<Types> & RegistrationData<Declaration> & Pick<Declaration, Extract<keyof Declaration, keyof Tool<Types>>>>, "goalIds" | "lifecycle"> & { lifecycle?: RegisteredLifecycle<Types, Declaration["lifecycle"]> | undefined; 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"]> | undefined; 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"]> | undefined; 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"]> | undefined; 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"]> | undefined; 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"]> | undefined; 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"]> | undefined; 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"]> | undefined; 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"]> | undefined; 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"]> | undefined; 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"]> | undefined; 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"]> | undefined; 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"]> | undefined; 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"]> | undefined; 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"]> | undefined; 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"]> | undefined; goalIds: Readonly<Declaration["goalIds"]>; })["goalIds"]RequiredSee the type definition and usage context.

has ​

Instance method.

Whether a tool id is registered.

ts
has(name: string): boolean

Whether a tool id is registered.

ParameterTypePassingDescription
namestringRequired—

Returns: boolean.

values ​

Instance method.

Iterate the registered tools.

ts
values(): IterableIterator<RegisteredToolDefinition<Types, Declaration>>

Iterate the registered tools.

No call parameters.

Returns: IterableIterator<Readonly<Omit<Readonly<Tool<Types> & RegistrationData<Declaration> & Pick<Declaration, Extract<keyof Declaration, keyof Tool<Types>>>>, "goalIds" \| "lifecycle"> & { lifecycle?: RegisteredLifecycle<Types, Declaration["lifecycle"]> \| undefined; goalIds: Readonly<Declaration["goalIds"]>; }>>.

hasDelegate ​

Instance method.

Whether a delegate id is claimed by a registered tool.

ts
hasDelegate(id: string): boolean

Whether a delegate id is claimed by a registered tool.

ParameterTypePassingDescription
idstringRequired—

Returns: boolean.

registerNormalizer ​

Instance method.

Install the single normalization handler.

ts
registerNormalizer(handler: ToolNormalizer<Types>): void

Install the single normalization handler.

ParameterTypePassingDescription
handlerToolNormalizer<Types>Required—

Returns: void.

normalize ​

Instance method.

Apply the installed normalizer, or return the value unchanged when none exists.

ts
normalize(value: unknown, ...args: Types["normalizerArgs"]): unknown

Apply the installed normalizer, or return the value unchanged when none exists.

ParameterTypePassingDescription
valueunknownRequired—
argsTypes["normalizerArgs"]Rest parameter—

Returns: unknown.

registerFinalizer ​

Instance method.

Install the single reply finalizer.

ts
registerFinalizer(handler: ToolFinalizer<Types>): void

Install the single reply finalizer.

ParameterTypePassingDescription
handlerToolFinalizer<Types>Required—

Returns: void.

finish ​

Instance method.

Run the installed finalizer over a decision.

ts
finish(receiver: Types["receiver"], decision: Types["decision"], context: Types["context"]): Types["result"]

Run the installed finalizer over a decision.

ParameterTypePassingDescription
receiverTypes["receiver"]Required—
decisionTypes["decision"]Required—
contextTypes["context"]Required—

Returns: Types["result"].

Awaited value: Awaited<Types["result"]>.

call ​

Instance method.

Run the invocation that answers one decision next.

Delegation is the App's choice; this method only executes the tool that claimed the id, so a purely programmatic node, a model choice and a mixed pipeline all dispatch the same way.

Diagnostics are swapped to the invocation's own sink for the duration of the call and restored afterwards, so nested tool calls report under the innermost scope.

ts
call(next: { type: string; }, context: Types["context"]): void

Run the invocation that answers one decision next.

Delegation is the App's choice; this method only executes the tool that claimed the id, so a purely programmatic node, a model choice and a mixed pipeline all dispatch the same way.

Diagnostics are swapped to the invocation's own sink for the duration of the call and restored afterwards, so nested tool calls report under the innermost scope.

ParameterTypePassingDescription
next{ type: string; }Required—
contextTypes["context"]Required—
Fields of next
FieldTypeRequiredDescription
typestringRequiredSee the type definition and usage context.

Returns: void.

protocols ​

Instance method.

Output protocols plus one protocol per registered invocation.

ts
protocols(): ProtocolRegistry<ToolProtocol<Declaration>>

Output protocols plus one protocol per registered invocation.

No call parameters.

Returns: ProtocolRegistry<ToolProtocol<Declaration>>.

modelProtocols ​

Instance method.

Protocols exposed to the model: output protocols plus invocations whose audience is model and which are currently available in context.

ts
modelProtocols(context: Types["context"]): ProtocolRegistry<ToolProtocol<Declaration>>

Protocols exposed to the model: output protocols plus invocations whose audience is model and which are currently available in context.

ParameterTypePassingDescription
contextTypes["context"]Required—

Returns: ProtocolRegistry<ToolProtocol<Declaration>>.

isTerminal ​

Instance method.

Whether the protocol registered for this invocation is declared terminal.

ts
isTerminal(next: { type: string; }): boolean

Whether the protocol registered for this invocation is declared terminal.

ParameterTypePassingDescription
next{ type: string; }Required—
Fields of next
FieldTypeRequiredDescription
typestringRequiredSee the type definition and usage context.

Returns: boolean.

assertDecision ​

Instance method.

Run inspect for every registered tool in registration order.

inspect belongs to the all-tools group, so the selected tool participates exactly once through the same loop rather than through a second selected-only pass.

ts
assertDecision(decision: Types["decision"], context: Types["context"]): void

Run inspect for every registered tool in registration order.

inspect belongs to the all-tools group, so the selected tool participates exactly once through the same loop rather than through a second selected-only pass.

ParameterTypePassingDescription
decisionTypes["decision"]Required—
contextTypes["context"]Required—

Returns: void.

authorize ​

Instance method.

Run the selected invocation's authorization hook, if any.

ts
authorize(decision: Types["decision"], context: Types["context"]): void

Run the selected invocation's authorization hook, if any.

ParameterTypePassingDescription
decisionTypes["decision"]Required—
contextTypes["context"]Required—

Returns: void.

resume ​

Instance method.

Whether the selected invocation should resume rather than start fresh; defaults to false.

ts
resume(decision: Types["decision"], context: Types["context"]): boolean

Whether the selected invocation should resume rather than start fresh; defaults to false.

ParameterTypePassingDescription
decisionTypes["decision"]Required—
contextTypes["context"]Required—

Returns: boolean.

complete ​

Instance method.

Let the selected invocation rewrite the decision on completion, if it declares a hook.

ts
complete(decision: Types["decision"], context: Types["context"]): Types["decision"] | undefined

Let the selected invocation rewrite the decision on completion, if it declares a hook.

ParameterTypePassingDescription
decisionTypes["decision"]Required—
contextTypes["context"]Required—

Returns: Types["decision"] \| undefined.

Awaited value: Awaited<Types["decision"]> \| undefined.

projectContext ​

Instance method.

Fold every tool's context projection over the value, in registration order.

ts
projectContext(value: unknown): unknown

Fold every tool's context projection over the value, in registration order.

ParameterTypePassingDescription
valueunknownRequired—

Returns: unknown.

visibleText ​

Instance method.

Fold every tool's visible-text transform over the text.

ts
visibleText(text: string, context: Types["context"]): string

Fold every tool's visible-text transform over the text.

ParameterTypePassingDescription
textstringRequired—
contextTypes["context"]Required—

Returns: string.

reviewDraft ​

Instance method.

Fold every tool's review transform over the draft.

ts
reviewDraft(draft: unknown, context: Types["context"]): unknown

Fold every tool's review transform over the draft.

ParameterTypePassingDescription
draftunknownRequired—
contextTypes["context"]Required—

Returns: unknown.

recoveryContext ​

Instance method.

Collected recovery context values; undefined results are omitted.

ts
recoveryContext(context: Types["context"]): unknown[]

Collected recovery context values; undefined results are omitted.

ParameterTypePassingDescription
contextTypes["context"]Required—

Returns: unknown[].

composition ​

Instance method.

The single output template that owns this delivery.

ts
composition(context: Types["context"]): Types["composition"] | undefined

The single output template that owns this delivery.

ParameterTypePassingDescription
contextTypes["context"]Required—

Returns: Types["composition"] \| undefined.

Awaited value: Awaited<Types["composition"]> \| undefined.

finalize ​

Instance method.

Run every tool's finalize hook for the given phase.

ts
finalize(decision: Types["decision"], context: Types["context"], phase: Types["phase"]): void

Run every tool's finalize hook for the given phase.

ParameterTypePassingDescription
decisionTypes["decision"]Required—
contextTypes["context"]Required—
phaseTypes["phase"]Required—

Returns: void.

missingInteractionAllowed ​

Instance method.

Whether any tool permits the interaction to be missing.

ts
missingInteractionAllowed(decision: Types["decision"], context: Types["context"]): boolean

Whether any tool permits the interaction to be missing.

ParameterTypePassingDescription
decisionTypes["decision"]Required—
contextTypes["context"]Required—

Returns: boolean.

taskRules ​

Instance method.

Task rules ordered by their declared order, joined into one prompt block.

ts
taskRules(context: Types["context"]): string

Task rules ordered by their declared order, joined into one prompt block.

ParameterTypePassingDescription
contextTypes["context"]Required—

Returns: string.

contextFields ​

Instance method.

Model-context fragments for one placement, ordered by each field's order.

ts
contextFields(context: Types["context"], placement: Types["placement"]): ContextFragment[]

Model-context fragments for one placement, ordered by each field's order.

ParameterTypePassingDescription
contextTypes["context"]Required—
placementTypes["placement"]Required—

Returns: ContextFragment[].

modelFields ​

Instance method.

Merged model-context values for one placement; later fragments win per key.

ts
modelFields(context: Types["context"], placement: Types["placement"]): Record<string, unknown>

Merged model-context values for one placement; later fragments win per key.

ParameterTypePassingDescription
contextTypes["context"]Required—
placementTypes["placement"]Required—

Returns: Record<string, unknown>.

supportsGoal ​

Instance method.

A tool may veto a goal by returning false; silence means support.

ts
supportsGoal(intentId: string, context: Types["context"]): boolean

A tool may veto a goal by returning false; silence means support.

ParameterTypePassingDescription
intentIdstringRequired—
contextTypes["context"]Required—

Returns: boolean.

describe ​

Instance method.

Describe registered tools, optionally limited by audience and availability.

A tool with an available predicate is only listed when a context is supplied and the predicate holds, so a caller that omits the context sees just the unconditional tools.

ts
describe(audience?: string, context?: Types["context"]): { id: Declaration["id"]; kind: Declaration["kind"]; description: Declaration["description"]; audience: Declaration["audience"]; effect: Declaration["effect"]; goalIds: string[]; }[]

Describe registered tools, optionally limited by audience and availability.

A tool with an available predicate is only listed when a context is supplied and the predicate holds, so a caller that omits the context sees just the unconditional tools.

ParameterTypePassingDescription
audiencestring | undefinedOptional—
contextTypes["context"] | undefinedOptional—

Returns: { id: Declaration["id"]; kind: Declaration["kind"]; description: Declaration["description"]; audience: Declaration["audience"]; effect: Declaration["effect"]; goalIds: string[]; }[].

copyTo ​

Instance method.

Reinstall every registered tool, plus the finalizer and normalizer, into another registry.

The original definitions are reused rather than the compiled views, so the target applies its own policy checks and binding exactly as it would for a first registration.

ts
copyTo(target: ToolLifecycleRegistry<Types, Declaration>): void

Reinstall every registered tool, plus the finalizer and normalizer, into another registry.

The original definitions are reused rather than the compiled views, so the target applies its own policy checks and binding exactly as it would for a first registration.

ParameterTypePassingDescription
targetToolLifecycleRegistry<Types, Declaration>Required—

Returns: void.

seal ​

Instance method.

Freeze the registry: no further registration, normalizer or finalizer is accepted.

ts
seal(): ToolLifecycleRegistry<Types, Declaration>

Freeze the registry: no further registration, normalizer or finalizer is accepted.

No call parameters.

Returns: ToolLifecycleRegistry<Types, Declaration>.

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.