ToolCallRecord
CORE · interface · Type contract
Receipt of a tool call that returned successfully.
Import
ts
import type { ToolCallRecord } from '@jangts/agent-core';js
/** @typedef {import('@jangts/agent-core').ToolCallRecord} ToolCallRecord */Other public entry points:@jangts/agent-core, @jangts/agent-core/types, @jangts/agent-core/structs.
Definition
ts
interface ToolCallRecordExtends or implements: InvocationMetadata.
Field structure
| Field | Type | Required | Description |
|---|---|---|---|
status | "success" | Required | Read-only. Records are only emitted for successful calls; failures are thrown instead. |
toolId | string | Required | Read-only. Registered tool that produced the value. |
runId | string | undefined | Optional | Read-only. Root run this invocation belongs to, when the host runs inside a diagnostics scope. |
spanId | string | undefined | Optional | Read-only. Diagnostics span of this invocation. |
parentSpanId | string | undefined | Optional | Read-only. Span that caused this invocation; absent for a root invocation. |
parentInvocationId | string | undefined | Optional | Read-only. Enclosing invocation when one call triggers another. |
invocationId | string | Required | Read-only. Opaque per-invocation id shared by receipt, events and diagnostic records. |
startedAtMs | number | Required | Read-only. Start instant in epoch milliseconds. |
durationMs | number | Required | Read-only. Elapsed milliseconds from start to completion. |
Examples
- Real tool invocation and in-request runtime: Core registers and executes real tools and returns receipts carrying an invocation; business authorization is owned by the implementation registered by the App.
- Tool best practice: one definition generates the model tool and execution runtime: Register Schema, authorization, execution, and output validation once, and bind the App per request instead of maintaining two tool lists.
- Tools: App tool lifecycle and content contribution: Register tool invocations, output rules, context contribution, and delivery handling for existing complex App tools in one place.
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({}));Related policy source
- Check order for tool input, execution, output, and late results
- Authorization and model tool projection come from the same definition
- Registration policy, lifecycle binding, and content projection