Skip to content

ExecuteToolContext

Defined in: src/middleware/stages.ts:116

Context passed to tool-stage middleware. Contains everything needed to understand and potentially modify the tool call.

readonly agent: LocalAgent;

Defined in: src/middleware/stages.ts:118

The agent instance (escape hatch for advanced use cases).


readonly tool: Tool;

Defined in: src/middleware/stages.ts:120

The resolved tool implementation, or undefined if not found.


readonly toolUse: ToolUseData;

Defined in: src/middleware/stages.ts:122

The tool use request (name, toolUseId, input).


readonly invocationState: InvocationState;

Defined in: src/middleware/stages.ts:124

Per-invocation state. Shared by reference — mutations are visible to hooks, tools, and AgentResult.


readonly cancelSignal: AbortSignal;

Defined in: src/middleware/stages.ts:126

Executor-owned cancellation signal for this tool call; middleware can observe but cannot replace it.

interrupt<T>(params): MiddlewareInterruptResult<T>;

Defined in: src/middleware/stages.ts:50

Request a human-in-the-loop interrupt.

On first execution (no prior response), throws InterruptError to halt the agent. On resume (after the user provides a response), returns the response wrapped in MiddlewareInterruptResult.

Type ParameterDefault type
TJSONValue
ParameterTypeDescription
paramsInterruptParamsInterrupt parameters (name, optional reason, optional preemptive response)

MiddlewareInterruptResult<T>

The user’s response wrapped in { response: T }

InterruptError when no response has been provided yet

MiddlewareInterruptible.interrupt