Skip to content
中文

ToolInvocationPorts ​

CORE · interface · Type contract

Optional tools the lifecycle resolves from the host context for one invocation.

Import ​

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

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

Definition ​

ts
interface ToolInvocationPorts<Context>

Type parameters ​

Type parameterConstraintDefault type
Context——

Field structure ​

FieldTypeRequiredDescription
logger((context: Context) => import("../debug.js").SubFlowLogger | undefined) | undefinedOptionalRead-only. Explicit recorder selected for this invocation only.
diagnostics((context: Context) => import("../diagnostics.js").DiagnosticContext | undefined) | undefinedOptionalRead-only. Diagnostic scope; omitted disables recording for this tool.
signal((context: Context) => AbortSignal | undefined) | undefinedOptionalRead-only. Extra cancellation; must not replace the tool execution signal.
journal((context: Context) => ToolJournal | undefined) | undefinedOptionalRead-only. Journal receiving begin/finish receipts.
checkpoint((context: Context) => unknown) | undefinedOptionalRead-only. Extracts the domain checkpoint recorded with the receipt.
receipt((context: 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.

Examples ​

Execute a local invocation the App has already selected ​

Beginner · Node.js

ts
import { executeInvocation } from '@jangts/agent-core/tools';
const state = { status: '' };
executeInvocation({ id: 'read-status', call(_input: {}, context: typeof state) {
  context.status = '服务正常';
} }, {}, state);
console.log(state.status);
js
import { executeInvocation } from '@jangts/agent-core/tools';
const state = { status: '' };
executeInvocation({ id: 'read-status', call(_input, context) {
        context.status = '服务正常';
    } }, {}, state);
console.log(state.status);

Connect the same request journal and cancellation signal ​

Configuration · Node.js

ts
import { executeInvocation } from '@jangts/agent-core/tools';
import { ContextJournal } from '@jangts/agent-core/journal';
const state = { status: '', journal: new ContextJournal(), signal: new AbortController().signal };
executeInvocation({ id: 'read-status', call(_input: {}, context: typeof state) { context.status = '服务正常'; } }, {}, state, {
  signal: context => context.signal,
  journal: context => context.journal,
  receipt: context => context.status,
});
console.log(state.journal.snapshot());
js
import { executeInvocation } from '@jangts/agent-core/tools';
import { ContextJournal } from '@jangts/agent-core/journal';
const state = { status: '', journal: new ContextJournal(), signal: new AbortController().signal };
executeInvocation({ id: 'read-status', call(_input, context) { context.status = '服务正常'; } }, {}, state, {
    signal: context => context.signal,
    journal: context => context.journal,
    receipt: context => context.status,
});
console.log(state.journal.snapshot());

API reference, usage examples and developer guides.