Skip to content

BeforeToolsEvent

Defined in: src/hooks/events.ts:688

Event triggered before executing tools. Fired when the model returns tool use blocks that need to be executed. Hook callbacks can set cancel to prevent all tools from executing.

  • Interruptible
new BeforeToolsEvent(data): BeforeToolsEvent;

Defined in: src/hooks/events.ts:701

ParameterType
data{ agent: LocalAgent; message: Message; invocationState: InvocationState; }
data.agentLocalAgent
data.messageMessage
data.invocationStateInvocationState

BeforeToolsEvent

HookableEvent.constructor

readonly type: "beforeToolsEvent";

Defined in: src/hooks/events.ts:689


readonly agent: LocalAgent;

Defined in: src/hooks/events.ts:690


readonly message: Message;

Defined in: src/hooks/events.ts:691


readonly invocationState: InvocationState;

Defined in: src/hooks/events.ts:692


cancel: string | boolean = false;

Defined in: src/hooks/events.ts:699

Set by hook callbacks to cancel all tool calls. When set to true, a default cancel message is used. When set to a string, that string is used as the tool result error message.

interrupt<T>(params): T;

Defined in: src/hooks/events.ts:716

Raises an interrupt for human-in-the-loop workflows. If a response is available (from a previous resume), returns it immediately. Otherwise, throws an InterruptError to halt agent execution.

Type ParameterDefault type
TJSONValue
ParameterTypeDescription
paramsInterruptParamsInterrupt parameters including name and optional reason

T

The user’s response when resuming from an interrupt

Interruptible.interrupt

toJSON(): Pick<BeforeToolsEvent, "type" | "message">;

Defined in: src/hooks/events.ts:724

Serializes for wire transport, excluding the agent reference, invocationState, and mutable cancel flag. Called automatically by JSON.stringify().

Pick<BeforeToolsEvent, "type" | "message">