Long-running agents
An agent that finishes in eight seconds is a request. An agent that runs for six hours is a workflow, and everything about it changes: it must survive a restart, be cancellable mid-flight, and never repeat the step it already completed.
How it works
- Persist state after every step, not at the end.
- Make each step resumable: given the state, the next step is deterministic.
- Give every run a cancel switch that is checked between steps.
- Report progress in terms a human understands, not step numbers.
- Decide what a partial result is worth, because that is what a cancellation produces.
Optional: load a real model
See it work
When it pays, and when it does not
| Use it when | Skip it when |
|---|---|
| Runs outlive a request timeout | Everything finishes in seconds |
| Steps write to other systems | Everything is read-only, where a restart just wastes time |
| A restart during a run is likely | Runs are short enough that a restart means retrying from scratch |
| Humans approve steps mid-run | No human interaction until the end |
How it fails
No cancellation
A wrong agent running for six hours with no stop button is the story that ends a pilot.
Progress in step numbers
Step 14 of unknown means nothing. Say what it is doing and what is left.
Resuming into a changed world
The state it saved is stale after an hour. Re-verify preconditions on resume rather than trusting the checkpoint.
What it costs
| Engineering | Substantially more than a simple loop. Only pay it when the duration forces it. |
|---|---|
| Infrastructure | A queue, a state store, and a worker. This is a real system. |
| Debugging | Easier than a long loop, because the state at every checkpoint is inspectable. |
Checkpoint after every step or accept duplicates. There is no third option, and the systems that pretend otherwise discover it during their first restart.
Related: Retries and idempotency · Budgets and limits · Tracing · all patterns · agent jobs
Related: Retries and idempotency · Budgets and limits · Tracing · all patterns · agent jobs
Free from AI School - no signup, everything runs in your browser.