Durable and Asynchronous Agent Work
Language AI HandbookAll chapters Checkpoints, resumability, queues, idempotency, retries, deadlines, and state across long-running workflows.
You can finish three tool calls and crash before writing the fourth result. The next worker needs to know which steps are safe to run again and which external operations still have an unknown outcome. We will build a small runner that keeps those questions separate.
We will use a local SQLite runner to model recovery across crashes, expired claims, and retries. It replays a committed trace and rejects stale workers’ updates to task events and task state. The result cache is stored separately from that guarded transition. A worker can cache a result even if its subsequent task update is rejected.
- The checkpointer: how the agent's memory of "where I am" is persisted.
- The queue/lease layer: how work is dispatched to workers and reclaimed when a worker disappears.
- The external side-effect boundary handles operations outside the local task-state transaction. An external service may have its own transaction or idempotency contract.
An agent loop can stop between any two steps. Use an event record to resume work from the last committed step and account for any operation that may have run outside that record. Agent Architectures: Control Loops, State & Planning describes the underlying loop.
The plan:
- Motivate why long-running agent work needs explicit durability primitives.
- Build the concepts: the event log, checkpoints, leases, idempotency keys, retries with backoff, deadlines, and compensation.
- Walk a concrete worked example of a crash and a duplicate.
- Implement a local SQLite fixture for replay, lease expiry, retry budgets, idempotency, and reconciliation while the store remains open.
- Explain when retries can repeat an effect and which guarantees require cooperation from the service performing it.
Comments
Add to the conversation
A question, a correction, or an example from your own work.
No comments yet. Be the first to share your thoughts!