Skip to content
中文

ToolInvocationRequest ​

CORE · interface · Type contract

One invocation request; the registry supplies signal and diagnostics when omitted.

Import ​

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

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

Definition ​

ts
interface ToolInvocationRequest<Id>

Type parameters ​

Type parameterConstraintDefault type
Idstringstring

Field structure ​

FieldTypeRequiredDescription
loggerSubFlowLogger | undefinedOptionalRead-only. Explicit recorder for this call, also available to its handler for deliberate use.
toolIdIdRequiredRead-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.

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.