Skip to main content
AI agents sometimes need to pause execution to schedule recurring or future actions, wait before retrying an operation (for rate limiting), or wait for external state to be available. Workflow DevKit’s sleep function enables agents to pause execution without consuming resources, and resume at a specified time, after a specified duration, or in response to an external event. Workflows that suspend survive restarts, new deploys, and infrastructure changes, whether the suspension takes seconds or months.
See the sleep() API Reference for the full list of supported duration formats and detailed API documentation.

Adding a Sleep Tool

Sleep is a built-in function in Workflow DevKit, so exposing it as a tool is as simple as wrapping it in a tool definition:
1

Define the Tool

Add a sleep tool to your tool definitions:
workflows/chat/steps/tools.ts
The sleep() function must be called from within a workflow context, not from within a step. This is why executeSleep does not have "use step" - it runs in the workflow context where sleep() is available.
2

Show Tool Status in the UI

Extend your chat UI to display the sleep tool call:
app/page.tsx
Now you can ask the agent to sleep, and the workflow will pause without consuming resources until the duration expires.

Duration Formats

sleep() supports multiple duration formats:
lineNumbers

Use Cases

Rate Limiting

When hitting API rate limits, use RetryableError with a delay:
workflows/chat/steps/tools.ts
Learn more in Errors and Retries.

Scheduled Tasks

Schedule future actions within your agent workflow:
lineNumbers

Polling External State

Poll an external service until a condition is met:
lineNumbers

Exponential Backoff

Implement custom retry logic with exponential backoff:
lineNumbers

Daily Reports

Schedule recurring daily tasks:
lineNumbers

Combining Sleep with Other Patterns

Sleep + Human-in-the-Loop

Implement timeouts for human approval:
lineNumbers

Sleep + Streaming Updates

Stream progress updates during a long sleep:
lineNumbers

Best Practices

Don’t Sleep in Steps

Always call sleep() from workflow-level code, not steps:
lineNumbers

Combine with Steps for I/O

Use steps for I/O operations around sleep:
lineNumbers

Handle Sleep Interruptions

Workflows can be cancelled during sleep:
lineNumbers