Pausing Execution with State Interrupts
Autonomous agents are powerful, but allowing them to execute high-risk actions (such as sending bank transfers or deleting database tables) without supervision is risky. LangGraph addresses this by introducing State Interrupts, which pause the graph's execution before entering designated nodes.
1. Interrupt Architecture
When compiling a graph, you can specify that it should pause immediately before executing a certain node. When the graph reaches that point, it halts, saves its state to a checkpointer, and yields control back to the runner application.
graph LR
A[Node: UserQuery] --> B[Node: CreatePlan]
B -->|Interrupt Pause| C[Node: HighRiskDBDelete]
C --> D[__end__]2. Configuring InterruptBefore inside a Graph
Here is how to configure an interrupt rule during compilation:
// src/services/interruptGraph.ts
import { StateGraph, Annotation, MemorySaver } from "@langchain/langgraph";
const AppStateAnnotation = Annotation.Root({
actionQuery: Annotation<string>(),
approvedByHuman: Annotation<boolean>(),
});
async function requestNode(state: typeof AppStateAnnotation.State) {
console.log("Analyzing request:", state.actionQuery);
return { approvedByHuman: false };
}
async function sensitiveActionNode(state: typeof AppStateAnnotation.State) {
console.log("Executing high risk database write...");
return {};
}
const workflow = new StateGraph(AppStateAnnotation)
.addNode("request", requestNode)
.addNode("sensitiveAction", sensitiveActionNode)
.setEntryPoint("request")
.addEdge("request", "sensitiveAction")
.addEdge("sensitiveAction", "__end__");
// 1. Create checkpointer to save paused states
const memoryStore = new MemorySaver();
// 2. Compile the graph with interrupt rules and checkpointers
export const compiledInterruptApp = workflow.compile({
checkpointer: memoryStore,
// Automatically pause before sensitiveAction runs
interruptBefore: ["sensitiveAction"],
});3. Running and Pausing
To trigger execution, you must supply a thread_id inside the configuration parameter. This ID maps the execution to a database checkpoint track:
const runConfig = { configurable: { thread_id: "user_session_45" } };
// Execution starts, runs the "request" node, and pauses before "sensitiveAction"
const executionStatus = await compiledInterruptApp.invoke({
actionQuery: "Format partition disk C",
}, runConfig);
console.log("Did execution finish?", executionStatus); // Graph stops and returns partial statePublished on Last updated: