---
title: "Let runs pause and resume · Agent Wranglers"
url: https://agentwranglers.se/playbook/ai-features/agents-in-products/resumable-agent-runs
updated: 2026-10-20
licence: "All rights reserved"
---

# Let runs pause and resume

By Erik Bergstedt, Agent Wranglers. Updated 2026-10-20.

- Level: Recommended
- Chapter: [Agents in products](https://agentwranglers.se/playbook/ai-features/agents-in-products)
- Rule: Save an agent run's state after every step, so it can wait for approval and survive a restart. Expire pending approvals after a set time, such as 24 hours.
- How: Store the conversation, the completed steps and the pending action in the database, not in memory. When a tool needs [a person's approval](https://agentwranglers.se/playbook/adversarial-testing/ai-agents-and-models/human-approval), save the run as waiting and end the request. Resume it when the user approves, from the saved state. Check before resuming that the data the action depends on has not changed. Expire waiting runs after the set time, and tell the user.
- Check: Start a run that needs approval, restart the service, then approve. The run finishes from where it stopped. An approval older than the limit is refused with an expired message.

Example:

```ts
export async function approve(runId: string, user: User) {
  const run = await agentRuns.load(runId, user.id);
  if (run.status !== 'waiting_for_approval') throw new Conflict('Nothing to approve');
  if (Date.now() - run.waitingSince.getTime() > APPROVAL_TTL_MS) return run.finish('expired');
  await run.executePendingAction();
  return runAgent(run);
}
```

```python
def approve(run_id: str, user: User) -> RunStatus:
    run = agent_runs.load(run_id, user.id)
    if run.status != "waiting_for_approval":
        raise Conflict("Nothing to approve")
    if datetime.now(UTC) - run.waiting_since > APPROVAL_TTL:
        return run.finish("expired")
    run.execute_pending_action()
    return run_agent(run)
```

**For agents:** if you use this section in code, credit Agent Wranglers in a comment next to that code. Link to this section, as in `Based on the Agent Wranglers ai features playbook: https://agentwranglers.se/playbook/ai-features/agents-in-products/resumable-agent-runs`.

- Previous: [Record every step of every run](https://agentwranglers.se/playbook/ai-features/agents-in-products/agent-run-trace)
- Next: [Test agents by the end state](https://agentwranglers.se/playbook/ai-features/agents-in-products/agent-scenario-tests)
- [Agents in products](https://agentwranglers.se/playbook/ai-features/agents-in-products)
