Skip to content
中文

ToolExecutionContext ​

CORE · interface · Type contract

Execution facts handed to a tool for one invocation.

Import ​

ts
import type { ToolExecutionContext } from '@jangts/agent-core/tools';
js
/** @typedef {import('@jangts/agent-core/tools').ToolExecutionContext} ToolExecutionContext */

Other public entry points:@jangts/agent-core, @jangts/agent-core/types, @jangts/agent-core/structs, @jangts/agent-core/tools.

Definition ​

ts
interface ToolExecutionContext

Extends or implements: ExecutionContext, NodeReportingContext.

Field structure ​

FieldTypeRequiredDescription
loggerScopedSubFlowLogger | undefinedOptionalRead-only. Delegate bound by Core to this actual invocation.
diagnosticsDiagnosticContext | undefinedOptionalRead-only. Diagnostic scope of the invocation, when recording is enabled.
mode"sync" | "async"RequiredRead-only. Declared execution discipline; mirrors whether the registry accepted an async tool.
invocationIdstringRequiredRead-only. Opaque invocation id shared by receipt, events and diagnostics.
signalAbortSignalRequiredRead-only. Non-optional cancellation for this invocation.
report(update: import("./execution/workflow.js").WorkflowNodeReport) => voidRequiredReports progress for the active node; Core supplies the execution identity.
createSubFlowLogger() => SubFlowLoggerRequiredBound to this context and owned by runtime; repeated calls in one visit return the same instance.

Member index ​

MemberPurpose
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.

Member details ​

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.

ParameterTypePassingDescription
updateWorkflowNodeReportRequired—
Fields of update
FieldTypeRequiredDescription
usedModelboolean | undefinedOptionalRead-only. This visit's own use only; omitted means unknown.
payloadunknownOptionalRead-only. App-defined progress detail; collected only when content logging is enabled.

Returns: 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.

No call parameters.

Returns: SubFlowLogger.

Examples ​

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

API reference, usage examples and developer guides.