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 ToolExecutionContextExtends or implements: ExecutionContext, NodeReportingContext.
Field structure
| Field | Type | Required | Description |
|---|---|---|---|
logger | ScopedSubFlowLogger | undefined | Optional | Read-only. Delegate bound by Core to this actual invocation. |
diagnostics | DiagnosticContext | undefined | Optional | Read-only. Diagnostic scope of the invocation, when recording is enabled. |
mode | "sync" | "async" | Required | Read-only. Declared execution discipline; mirrors whether the registry accepted an async tool. |
invocationId | string | Required | Read-only. Opaque invocation id shared by receipt, events and diagnostics. |
signal | AbortSignal | Required | Read-only. Non-optional cancellation for this invocation. |
report | (update: import("./execution/workflow.js").WorkflowNodeReport) => void | Required | Reports progress for the active node; Core supplies the execution identity. |
createSubFlowLogger | () => SubFlowLogger | Required | Bound to this context and owned by runtime; repeated calls in one visit return the same instance. |
Member index
| Member | Purpose |
|---|---|
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. |
Member details
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.
| Parameter | Type | Passing | Description |
|---|---|---|---|
update | WorkflowNodeReport | Required | — |
Fields of update
| Field | Type | Required | Description |
|---|---|---|---|
usedModel | boolean | undefined | Optional | Read-only. This visit's own use only; omitted means unknown. |
payload | unknown | Optional | Read-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(): SubFlowLoggerBound to this context and owned by runtime; repeated calls in one visit return the same instance.
No call parameters.
Returns: SubFlowLogger.
Examples
- Synchronous execution adapter for host-selected invocations: Record start, completion, and failure uniformly for synchronous invocations the host has already selected, without replacing tool selection or authorization.
- Decorators: complete handlers and existing host methods: Classes construct definitions automatically; methods bind the real host. Outputs still use original define, constructor and bind contracts.
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());