InvocationHandler
CORE · interface · 类型合同
A named handler invoked by a tool lifecycle step.
导入
ts
import type { InvocationHandler } from '@jangts/agent-core/tools';js
/** @typedef {import('@jangts/agent-core/tools').InvocationHandler} InvocationHandler */其他公开入口:@jangts/agent-core、@jangts/agent-core/types、@jangts/agent-core/structs、@jangts/agent-core/tools。
定义
ts
interface InvocationHandler<Input, Context>泛型参数
| 类型参数 | 约束 | 默认类型 |
|---|---|---|
Input | — | — |
Context | — | — |
字段结构
| 字段 | 类型 | 必需 | 说明 |
|---|---|---|---|
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. |
成员目录
| 成员 | 用途 |
|---|---|
call | Runs the handler. The return value is ignored, so handlers report outcomes through the tool value or journal. |
成员详情
call
Runs the handler.
The return value is ignored, so handlers report outcomes through the tool value or journal.
ts
InvocationHandler.call(input: Input, context: Context, execution: import("./tools.js").ToolExecutionContext): voidRuns the handler.
The return value is ignored, so handlers report outcomes through the tool value or journal.
| 参数 | 类型 | 传递 | 说明 |
|---|---|---|---|
input | Input | 必需 | — |
context | Context | 必需 | — |
execution | ToolExecutionContext | 必需 | — |
execution 的字段
| 字段 | 类型 | 必需 | 说明 |
|---|---|---|---|
logger | ScopedSubFlowLogger | undefined | 可省略 | 只读。Delegate bound by Core to this actual invocation. |
diagnostics | DiagnosticContext | undefined | 可省略 | 只读。Diagnostic scope of the invocation, when recording is enabled. |
mode | "sync" | "async" | 必需 | 只读。Declared execution discipline; mirrors whether the registry accepted an async tool. |
invocationId | string | 必需 | 只读。Opaque invocation id shared by receipt, events and diagnostics. |
signal | AbortSignal | 必需 | 只读。Non-optional cancellation for this invocation. |
report | (update: import("./execution/workflow.js").WorkflowNodeReport) => void | 必需 | Reports progress for the active node; Core supplies the execution identity. |
createSubFlowLogger | () => SubFlowLogger | 必需 | Bound to this context and owned by runtime; repeated calls in one visit return the same instance. |
返回: 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());