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 parameter | Constraint | Default type |
|---|---|---|
Input | — | — |
Context | — | — |
Call
ts
executeInvocation<Input, Context>(invocation: InvocationHandler<Input, Context>, input: Input, context: Context, ports?: ToolInvocationPorts<Context>): voidRun one synchronous invocation and record its effects.
| Type parameter | Constraint | Default type |
|---|---|---|
Input | — | — |
Context | — | — |
| Parameter | Type | Passing | Description |
|---|---|---|---|
invocation | InvocationHandler<Input, Context> | Required | — |
input | Input | Required | — |
context | Context | Required | — |
ports | ToolInvocationPorts<Context> | Optional | — |
Fields of invocation
| Field | Type | Required | Description |
|---|---|---|---|
id | string | Required | Read-only. See the type definition and usage context. |
call | (input: Input, context: Context, execution: import("./tools.js").ToolExecutionContext) => void | Required | Runs the handler. The return value is ignored, so handlers report outcomes through the tool value or journal. |
Fields of ports
| Field | Type | Required | Description |
|---|---|---|---|
logger | ((context: Context) => import("../debug.js").SubFlowLogger | undefined) | undefined | Optional | Read-only. Explicit recorder selected for this invocation only. |
diagnostics | ((context: Context) => import("../diagnostics.js").DiagnosticContext | undefined) | undefined | Optional | Read-only. Diagnostic scope; omitted disables recording for this tool. |
signal | ((context: Context) => AbortSignal | undefined) | undefined | Optional | Read-only. Extra cancellation; must not replace the tool execution signal. |
journal | ((context: Context) => ToolJournal | undefined) | undefined | Optional | Read-only. Journal receiving begin/finish receipts. |
checkpoint | ((context: Context) => unknown) | undefined | Optional | Read-only. Extracts the domain checkpoint recorded with the receipt. |
receipt | ((context: Context, checkpoint: unknown) => unknown) | undefined | Optional | Read-only. Builds the domain receipt from a checkpoint after execution. |
receiptError | ((error: unknown) => unknown) | undefined | Optional | Read-only. Converts an error into the receipt's replacement value. |
Returns: void.
Examples
- Synchronous execution adapter for host-selected invocations: Record start, completion, and failure uniformly for synchronous invocations the host has already selected, without replacing tool selection or authorization.
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());