Topic 2 of 5 · 5 min read
Pausing and resuming agent runs
Goal: Design the state an agent saves at an interrupt so it resumes after human input without repeating side effects.
A run that waits for a person must save its state to storage, stop, and later continue from that state, without redoing steps that already had side effects. A process that just blocks on a prompt will not survive a deploy, a timeout or a person who answers tomorrow.
Check yourself · 1 of 3
Why should an agent run that waits for a person save its state to storage?
Why it matters
People answer in minutes, hours or days. A web request cannot wait that long, and a server process can be restarted at any time. If the agent holds its progress only in memory, a restart loses it, and a naive retry may repeat steps: a second email, a second charge.
How it works
Frameworks such as LangGraph give this as a feature. A node calls an interrupt with a payload (the question for the person). The framework saves a checkpoint, the full state of the run, under a thread id, and the run stops. Later, you resume the same thread id with the person's answer, and the run continues from where it paused.
The saved state needs four things:
- The conversation and plan so far, so the agent knows what it was doing.
- The pending action, with exact arguments, so what the person approved is what runs.
- A record of side effects already done, each with an idempotency key.
- A run id and a status:
waiting,approved,rejected,expired.
Resume without repeating work
When a run resumes, the code before the interrupt may run again. In LangGraph the node restarts from its beginning, so anything before the interrupt call must be safe to repeat. Put side effects after the interrupt, or give each one an idempotency key so a repeat is a no-op:
def refund_node(state):
decision = interrupt({"action": "refund", "order": state["order_id"], "amount": state["amount"]})
if decision == "approve":
payments.refund(
order_id=state["order_id"],
amount=state["amount"],
idempotency_key=f"{state['run_id']}:refund",
)
return {"status": decision}
Here the question comes first and the payment second, and the key means a retry cannot pay twice.
Before and after
Weak: the agent calls input() in a worker and waits. The deploy at 3 a.m. kills the worker, and the pending refund vanishes.
Better: the run is saved to a database under a thread id, a notification goes to the approver, and any worker can pick the thread up when the answer arrives.
What goes wrong
- Side effects before the interrupt. The step re-runs on resume and sends the email twice.
- Approving one thing, running another. If the agent re-plans after resume, the executed call may differ from the approved one. Execute the stored arguments.
- No expiry. A request approved three weeks later may no longer be true. Set a time limit and re-check the facts on resume.
- State that cannot be saved. Open connections and file handles do not serialize. Store ids and rebuild them.
Examples
State saved at the interrupt
{
"run_id": "run_7f3a",
"status": "waiting",
"expires_at": "2026-12-03T09:00:00Z",
"pending_action": {"tool": "send_email", "to": "billing@acme.test", "subject": "Invoice 5521 correction"},
"done": [{"tool": "create_draft", "key": "run_7f3a:draft"}]
}
A worker that loads this knows what is pending, what already ran, and when the request goes stale.
The double email
A node drafts a message, sends it, then calls the interrupt for approval of a follow-up. On resume the node starts again from the top and sends the first message a second time. The fix is to move the send after the interrupt, or to wrap it in a call with an idempotency key such as run_7f3a:send1.
Key points
- Persist the run state to storage at the interrupt, keyed by a thread or run id, so any worker can resume it.
- Save the pending action with exact arguments, so the resumed run executes what the person approved.
- Code before an interrupt may run again on resume, so put side effects after it or protect them with idempotency keys.
- Record completed side effects in the state so a retry skips them.
- Give waiting runs an expiry and re-check key facts on resume.
Common mistakes
- Blocking a worker on a prompt, so a restart or timeout loses the run.
- Running side effects before the interrupt call in the same step, then repeating them on resume.
- Letting the agent re-plan after approval and then running different arguments than the person saw.
- Leaving waiting runs open forever with no expiry or re-check.
Check yourself · 2 of 3
A node sends an email and then calls an interrupt for approval of a later step. The node restarts from its top on resume. What is the likely result?
Check yourself · 3 of 3
What should the saved state hold so the resumed run executes what the person approved?
Practice items, not counted towards your mastery.
Start here
- Interrupts (LangGraph docs) (opens in a new tab)DocsFree
How an interrupt pauses a graph, stores state and resumes with the human's answer.
- Persistence (LangGraph docs) (opens in a new tab)DocsFree
Checkpoints and threads: the saved state that makes pause and resume possible.
- Configure permissions (Claude Code) (opens in a new tab)DocsFree
A working example of allow, ask and deny rules for an agent's tools.