Interrupts and Resuming
🎯 Introduction
An article that passes automated review may still need an editor's approval before delivery. A workflow that immediately continues cannot wait for that input. LangGraph interrupts pause tasks at nodes requiring external input, save execution state, and continue after a user decision. This article implements human review with interrupt() and Command and explains how nodes behave when resumed.
🧱 Add Human Review to the Workflow
The LangChain course used middleware to pause selected tools. Here, we will create an independent review node in a custom workflow instead of intercepting tool calls. A reviewer can approve the article or reject delivery.
interrupt() pauses the graph run and returns control to its caller, so the application does not need to keep a model request waiting. The checkpointer saves task state, and the application can resume it later with the same task ID.
🛠 Pause a Task with interrupt
Create 08.interrupts.mjs:
import { StateGraph, StateSchema, START, END, MemorySaver, interrupt, Command } from '@langchain/langgraph';
import { z } from 'zod';
const ArticleState = new StateSchema({
draft: z.string(),
approved: z.boolean().default(false),
status: z.string().default('pending'),
});
Human approval and final delivery status are stored separately. Start with the review node:
function humanReview(state) {
// Pause the workflow and return the content for review to the application
const approved = interrupt({
question: 'Approve this article?',
draft: state.draft,
});
return { approved: approved === true };
}
The first time execution reaches interrupt(), the workflow pauses without executing the following return. After external input arrives and execution resumes, interrupt() receives the value supplied by the application.
Add the subsequent nodes and routing function:
function routeAfterReview(state) {
if (state.approved) {
return 'deliver';
}
return 'reject';
}
function deliver() {
return { status: 'ready' };
}
function reject() {
return { status: 'rejected' };
}
deliver only marks the article as ready for delivery. It does not write files or publish to a website, keeping the example focused on execution control.
Continue by creating the workflow:
const graph = new StateGraph(ArticleState)
.addNode('humanReview', humanReview)
.addNode('deliver', deliver)
.addNode('reject', reject)
.addEdge(START, 'humanReview')
.addConditionalEdges('humanReview', routeAfterReview, ['deliver', 'reject'])
.addEdge('deliver', END)
.addEdge('reject', END)
.compile({ checkpointer: new MemorySaver() });
Interrupts and resuming require a checkpointer. This example uses in-memory storage to avoid a database dependency. For recovery across processes, use the PostgreSQL checkpointer from the previous article.
🧱 Observe the Paused Task
Append the following:
const config = {
configurable: { thread_id: 'review-001' },
};
const pending = await graph.invoke({
draft: 'For example: organize an article review workflow with LangGraph.',
}, config);
const interrupts = pending.__interrupt__ ?? [];
if (interrupts.length !== 1) {
throw new Error('Expected exactly one human review request');
}
const request = interrupts[0].value;
console.log('Review request:', request.question);
console.log('Article for review:', request.draft);
console.log('Current status:', pending.status);
Run:
node 08.interrupts.mjs
Expected output:
Review request: Approve this article?
Article for review: For example: organize an article review workflow with LangGraph.
Current status: pending
invoke() returns the current result when the workflow pauses. __interrupt__ contains information about the external input being requested. Its value is the object passed to interrupt().
Neither deliver nor reject has run yet. A frontend can use this data to display a review dialog.
🧱 Collect a Human Decision and Resume
Collect the Decision
To simulate human review in the terminal, add this import at the top:
import { createInterface } from 'node:readline/promises';
Append a function that reads user input:
async function askApproval() {
const rl = createInterface({
input: process.stdin,
output: process.stdout,
});
try {
const answer = await rl.question('Enter yes to approve; anything else rejects: ');
return answer.trim().toLowerCase() === 'yes';
} finally {
rl.close();
}
}
const approved = await askApproval();
askApproval() is a terminal interaction function, not part of LangGraph. A real application could submit a boolean from a frontend button to the backend. Do not automatically supply true without user approval.
Resume Workflow Execution
The first invoke() created the task and paused it at review. Now we will send the decision to that paused workflow rather than start a new task.
Append the following:
// Create a resume command carrying the human decision
const command = new Command({
resume: approved,
});
// Continue with the original task ID
const result = await graph.invoke(command, config);
console.log('Final status:', result.status);
resume supplies input to the paused node. If the user enters yes, approved is true, and interrupt() returns true after resuming. Unlike the LangChain human approval middleware, this example defines its own interrupt payload, so a boolean can be passed directly without a decisions array.
| Operation | Purpose |
|---|---|
graph.invoke({ draft: ... }, config) | Start a new task |
new Command({ resume: approved }) | Create a resume command carrying the external decision |
graph.invoke(command, config) | Resume the original task using the same thread_id |
After resuming, the review node receives approved from interrupt() and writes it to state. Routing uses that state to choose deliver or reject.
Run it again:
node 08.interrupts.mjs
Expected output when you enter yes:
Review request: Approve this article?
Article for review: For example: organize an article review workflow with LangGraph.
Current status: pending
Enter yes to approve; anything else rejects: yes
Final status: ready
Run the script again and enter no. Expected output:
Review request: Approve this article?
Article for review: For example: organize an article review workflow with LangGraph.
Current status: pending
Enter yes to approve; anything else rejects: no
Final status: rejected
This example uses MemorySaver, so both invoke() calls must run in the same process. Every new script run creates a fresh in-memory checkpointer.
⚠️ Nodes Restart When Resumed
When a workflow resumes, LangGraph re-enters the interrupted node from the beginning of its function. At the previous interrupt, it consumes the supplied resume value and continues. It does not simply skip the first part of the function.
Temporarily add a log before interrupt() in humanReview():
console.log('Entering human review node');
Run the script again and enter yes. The key output should be:
Entering human review node
Review request: Approve this article?
Article for review: For example: organize an article review workflow with LangGraph.
Current status: pending
Enter yes to approve; anything else rejects: yes
Entering human review node
Final status: ready
The review node is entered twice. Do not perform non-repeatable actions such as publishing or charging before interrupt(). Put them in separate nodes after approval and enforce idempotency in the application.
interrupt() uses a special control-flow exception to pause execution. Do not swallow it with an ordinary try...catch. The terminal interaction's try...finally is unrelated.
Reference: Interrupts.
❓ Questions and Answers
Q1: Why must thread_id stay the same when resuming?
The checkpointer uses the task ID to locate saved state. A different ID cannot locate the paused task. A real system must also verify that the current user is authorized to review it.
🧪 Exercise
Change askApproval() to request edited article text and return the input string. Change humanReview() to return { draft: editedDraft, approved: true }, where editedDraft is the resumed return value of interrupt(). Print result.draft from the final state and confirm that it matches the input. This demonstrates human-provided data rather than the original approval or rejection flow.
🎉 Congratulations! You can now pause custom workflows, collect human input, and resume execution.
