Predicate controlling whether a given tool call triggers an interrupt.
Receives a ToolCallRequest and returns true to interrupt or false
to auto-approve the tool call.
The request is constructed with tool set to undefined and runtime set to
the node-level Runtime, so it reflects the batch (afterModel) context
rather than a per-call tool execution. In "per_call" mode the predicate runs
in wrapToolCall and receives the real request, with tool set.
In both modes the predicate runs again when the run resumes, so it must return
the same answer for the same call. If it returns false on resume, the
reviewer's answer is skipped and the tool runs, even if they rejected it.
WhenPredicate: z.infer<typeof WhenFunctionSchema>import { type WhenPredicate } from "langchain";
// Only interrupt delete_file calls targeting /etc
const when: WhenPredicate = (request) =>
String(request.toolCall.args.path ?? "").startsWith("/etc");