Wake an agent after a timeout
Schedule a timeout for an agent run waiting on human input. The handler resumes the run if approval doesn't arrive.
Use this to
- Resume an agent run if a human reviewer doesn't approve a step within 24 hours
- Time out an agent waiting on a tool call that may never return
- Fail over a long-running agent task that has been idle past its deadline
- Wake a paused agent at a specific future time without holding a worker
Code
Schedule the timeout when the agent pauses
// agent run pauses, waiting on human approval await dk.schedule("agent-timeout", { key: "run_789", delay: "24h", });
Cancel when approval arrives
await dk.unschedule("agent-timeout", "run_789");
When the time comes, resume the run
dk.handle("agent-timeout", async ({ key }) => { const run = await db.runs.find(key); if (run.status !== "awaiting_approval") return; // already resolved await agents.resume(key, { outcome: "timed_out" }); });
npm install delaykit
bun add delaykit