Skip to content
English

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。

字段结构 ​

字段类型必需说明
loggerScopedSubFlowLogger | undefined可省略只读。Delegate bound by Core to this actual invocation.
diagnosticsDiagnosticContext | undefined可省略只读。Diagnostic scope of the invocation, when recording is enabled.
mode"sync" | "async"必需只读。Declared execution discipline; mirrors whether the registry accepted an async tool.
invocationIdstring必需只读。Opaque invocation id shared by receipt, events and diagnostics.
signalAbortSignal必需只读。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.

成员目录 ​

成员用途
reportReports progress for the active node; Core supplies the execution identity.
createSubFlowLoggerBound 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): void

Reports progress for the active node; Core supplies the execution identity.

参数类型传递说明
updateWorkflowNodeReport必需—
update 的字段
字段类型必需说明
usedModelboolean | undefined可省略只读。This visit's own use only; omitted means unknown.
payloadunknown可省略只读。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(): SubFlowLogger

Bound to this context and owned by runtime; repeated calls in one visit return the same instance.

无调用参数。

返回: SubFlowLogger。

使用示例 ​

执行 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());

相关策略源码 ​

相关定义 ​

接口参考、使用示例与开发指南。