executeInvocation
CORE · function · 运行时值
Run one synchronous invocation and record its effects.
导入
ts
import { executeInvocation } from '@jangts/agent-core/tools';js
import { executeInvocation } from '@jangts/agent-core/tools';其他公开入口:@jangts/agent-core、@jangts/agent-core/types、@jangts/agent-core/tools。
定义
泛型参数
| 类型参数 | 约束 | 默认类型 |
|---|---|---|
Input | — | — |
Context | — | — |
调用
ts
executeInvocation<Input, Context>(invocation: InvocationHandler<Input, Context>, input: Input, context: Context, ports?: ToolInvocationPorts<Context>): voidRun one synchronous invocation and record its effects.
| 类型参数 | 约束 | 默认类型 |
|---|---|---|
Input | — | — |
Context | — | — |
| 参数 | 类型 | 传递 | 说明 |
|---|---|---|---|
invocation | InvocationHandler<Input, Context> | 必需 | — |
input | Input | 必需 | — |
context | Context | 必需 | — |
ports | ToolInvocationPorts<Context> | 可省略 | — |
invocation 的字段
| 字段 | 类型 | 必需 | 说明 |
|---|---|---|---|
id | string | 必需 | 只读。见类型定义及调用场景。 |
call | (input: Input, context: Context, execution: import("./tools.js").ToolExecutionContext) => void | 必需 | Runs the handler. The return value is ignored, so handlers report outcomes through the tool value or journal. |
ports 的字段
| 字段 | 类型 | 必需 | 说明 |
|---|---|---|---|
logger | ((context: Context) => import("../debug.js").SubFlowLogger | undefined) | undefined | 可省略 | 只读。Explicit recorder selected for this invocation only. |
diagnostics | ((context: Context) => import("../diagnostics.js").DiagnosticContext | undefined) | undefined | 可省略 | 只读。Diagnostic scope; omitted disables recording for this tool. |
signal | ((context: Context) => AbortSignal | undefined) | undefined | 可省略 | 只读。Extra cancellation; must not replace the tool execution signal. |
journal | ((context: Context) => ToolJournal | undefined) | undefined | 可省略 | 只读。Journal receiving begin/finish receipts. |
checkpoint | ((context: Context) => unknown) | undefined | 可省略 | 只读。Extracts the domain checkpoint recorded with the receipt. |
receipt | ((context: Context, checkpoint: unknown) => unknown) | undefined | 可省略 | 只读。Builds the domain receipt from a checkpoint after execution. |
receiptError | ((error: unknown) => unknown) | undefined | 可省略 | 只读。Converts an error into the receipt's replacement value. |
返回: void。
使用示例
- 宿主已选定调用的同步执行适配:为宿主已经选定的同步调用统一记录开始、完成和失败,不替代选工具与授权。
执行 App 已选定的本地调用
入门 · 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);接入同一请求 journal 和取消信号
配置 · 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());