▶ Sign up free for the video, slides & prompts
The lesson below is open to all. Enter your email once to unlock every video, slide deck, prompt and code example on this device.
Checking…
AI Agents in Production · Lesson 12 of 14 · 2 min read · 5 min video
Deploying agents: queues, retries and timeouts
Run agents as background jobs that survive crashes, slow APIs and traffic spikes.
📄 Download slides (PDF)· free sign-upA web request that waits 45 seconds for an agent to finish will time out, and a server restart loses the run. Production agents run as background jobs that survive failures.
The shape of a deployment
- The user's request creates a task in the database and returns immediately ("We're on it")
- The task goes onto a queue (Redis, Cloud Tasks, SQS, or a Postgres table)
- Workers pick up tasks and run the agent loop, checkpointing after each step
- When done, the result is saved and the user is notified by WebSocket, push or WhatsApp
Need more capacity? Add more workers. Did a worker crash? Another one picks up the task from its last checkpoint.
Retries done right
Model APIs and tools fail sometimes: rate limits, timeouts, 500 errors.
- Retry with exponential backoff and a little randomness (1s, 2s, 4s…), up to a limit
- Retry only safe failures. Never blindly retry a payment unless it has an idempotency key
- After the last retry, mark the task failed with a clear reason, and alert someone
Timeouts everywhere
Set a timeout on every model call, every tool call and the whole task. Nothing in production should be able to wait forever.
Safe rollouts
- Keep prompts, tool definitions and model names in versioned config, so you know exactly what ran
- Release a new version to a small share of traffic first, compare its success and cost metrics, then roll out fully
- Keep a one-click way to roll back
In one line
Run agents as queued background jobs with checkpoints, safe retries with backoff, timeouts on everything, and versioned, gradual rollouts you can undo.
Share with a friend