Skip to content
中文

executeInvocation ​

CORE · function · Runtime value

Run one synchronous invocation and record its effects.

Import ​

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

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

Definition ​

Type parameters ​

Type parameterConstraintDefault type
Input——
Context——

Call ​

ts
executeInvocation<Input, Context>(invocation: InvocationHandler<Input, Context>, input: Input, context: Context, ports?: ToolInvocationPorts<Context>): void

Run one synchronous invocation and record its effects.

Type parameterConstraintDefault type
Input——
Context——
ParameterTypePassingDescription
invocationInvocationHandler<Input, Context>Required—
inputInputRequired—
contextContextRequired—
portsToolInvocationPorts<Context>Optional—
Fields of invocation
FieldTypeRequiredDescription
idstringRequiredRead-only. See the type definition and usage context.
call(input: Input, context: Context, execution: import("./tools.js").ToolExecutionContext) => voidRequiredRuns the handler. The return value is ignored, so handlers report outcomes through the tool value or journal.
Fields of ports
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.

Returns: void.

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.