ToolExecutionContext
CORE · interface · 类型合同
Execution facts handed to a tool for one invocation.
导入
ts
import type { ToolExecutionContext } from '@jangts/agent-core/tools';js
/** @typedef {import('@jangts/agent-core/tools').ToolExecutionContext} ToolExecutionContext */其他公开入口:@jangts/agent-core、@jangts/agent-core/types、@jangts/agent-core/structs、@jangts/agent-core/tools。
定义
ts
interface ToolExecutionContext继承或实现: ExecutionContext、NodeReportingContext。
字段结构
| 字段 | 类型 | 必需 | 说明 |
|---|---|---|---|
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. |
成员目录
| 成员 | 用途 |
|---|---|
report | Reports progress for the active node; Core supplies the execution identity. |
createSubFlowLogger | Bound to this context and owned by runtime; repeated calls in one visit return the same instance. |
成员详情
report
Reports progress for the active node; Core supplies the execution identity.
ts
ToolExecutionContext.report(update: import("./execution/workflow.js").WorkflowNodeReport): voidReports progress for the active node; Core supplies the execution identity.
| 参数 | 类型 | 传递 | 说明 |
|---|---|---|---|
update | WorkflowNodeReport | 必需 | — |
update 的字段
| 字段 | 类型 | 必需 | 说明 |
|---|---|---|---|
usedModel | boolean | undefined | 可省略 | 只读。This visit's own use only; omitted means unknown. |
payload | unknown | 可省略 | 只读。App-defined progress detail; collected only when content logging is enabled. |
返回: void。
createSubFlowLogger
Bound to this context and owned by runtime; repeated calls in one visit return the same instance.
ts
ToolExecutionContext.createSubFlowLogger(): SubFlowLoggerBound to this context and owned by runtime; repeated calls in one visit return the same instance.
无调用参数。
返回: SubFlowLogger。
使用示例
- 宿主已选定调用的同步执行适配:为宿主已经选定的同步调用统一记录开始、完成和失败,不替代选工具与授权。
- 装饰器:处理类与已有实例方法:类装饰代办定义实例化,方法装饰绑定原对象;输出仍走原 define、构造和 bind。
执行 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());