AI Agent Checkpoint: Resume Tasks Without Restarting
Your agent is processing 50 documents. Forty minutes in, 43 done, and at step 44 the LLM API returns a 503. Without checkpoints, you restart from scratch: 43 LLM calls, 43 tool executions, 43 database writes — all repeated.
With checkpoints, the agent picks up from step 44. Nothing is reprocessed.
This isn't an edge case. Any agent that processes a batch of records, analyzes a set of files, or runs a sequence of actions lasting more than 30 seconds will hit this in production. The question isn't whether it will fail — it's whether it will know where to continue.
Why Retries Don't Solve This
Most teams implement retries for transient errors. That's correct, but it solves a different problem.
A retry handles the failure of a single operation: if the LLM call fails, retry up to three times before propagating. The scope is one request.
A checkpoint handles the failure of an entire process: if the agent dies halfway through a 50-item loop, it knows which item to resume from when relaunched. The scope is the whole task.
They're complementary, not interchangeable. An agent with retries but no checkpoints still loses all accumulated work when the process fails permanently. And in production, processes do fail permanently: Vercel function timeouts at 5 minutes, container restarts, network outages that don't self-recover.
What a Checkpoint Needs
A useful checkpoint has three pieces:
- Task identifier: which specific task is running (to avoid mixing state from different executions)
- Progress record: which items have been successfully processed
- Partial results: what the agent produced up to that point
You save the checkpoint after each completed unit of work. When the process relaunches, it loads the last checkpoint and skips already-processed items.
Basic TypeScript Implementation
interface AgentCheckpoint {
taskId: string;
processedIds: string[];
results: Record<string, unknown>;
savedAt: string;
}
interface CheckpointStorage {
get(key: string): Promise<AgentCheckpoint | null>;
set(key: string, value: AgentCheckpoint): Promise<void>;
del(key: string): Promise<void>;
}
class CheckpointManager {
constructor(private storage: CheckpointStorage) {}
async load(taskId: string): Promise<AgentCheckpoint | null> {
return this.storage.get(`ckpt:${taskId}`);
}
async save(taskId: string, processedIds: string[], results: Record<string, unknown>): Promise<void> {
await this.storage.set(`ckpt:${taskId}`, {
taskId,
processedIds,
results,
savedAt: new Date().toISOString(),
});
}
async clear(taskId: string): Promise<void> {
await this.storage.del(`ckpt:${taskId}`);
}
}
And the agent loop with checkpoint logic:
async function processItemsWithCheckpoint(
taskId: string,
items: Array<{ id: string; payload: unknown }>,
processor: (item: { id: string; payload: unknown }) => Promise<unknown>,
checkpoints: CheckpointManager
) {
const saved = await checkpoints.load(taskId);
const doneIds = new Set(saved?.processedIds ?? []);
const results: Record<string, unknown> = saved?.results ?? {};
for (const item of items) {
if (doneIds.has(item.id)) continue; // already done, skip
results[item.id] = await processor(item);
doneIds.add(item.id);
await checkpoints.save(taskId, [...doneIds], results);
}
await checkpoints.clear(taskId);
return results;
}
When the process relaunches with the same taskId, it loads the previous checkpoint and skips all items that already have a result. No work is repeated.
The Bug That Breaks Checkpoints: Non-Atomic Writes
The most common failure mode: the agent successfully processes an item but the checkpoint save fails before completing. Result: the item is "processed" in memory but not in the checkpoint. On relaunch, it gets reprocessed.
If your storage is Redis, use MULTI/EXEC for atomic writes. If it's a relational database, wrap the result write and checkpoint write in the same transaction.
// With Redis (ioredis)
async save(taskId: string, processedIds: string[], results: Record<string, unknown>) {
const pipeline = this.redis.multi();
pipeline.set(`ckpt:${taskId}`, JSON.stringify({ taskId, processedIds, results }));
pipeline.expire(`ckpt:${taskId}`, 86400); // 24h TTL
await pipeline.exec();
}
If atomic writes aren't possible, write the checkpoint before marking the item as done in memory. Worst case, you process the same item twice — which is acceptable if your tools are idempotent.
What This Changes in Production
This pattern isn't an optimization — it's resilience. What we've seen in AI agent integration projects:
- A nightly document ingestion agent processing 200 PDFs. Without a checkpoint, a timeout midway through the night restarted the whole batch. With checkpoints, the process resumed from where it left off and finished before business hours.
- A CRM-to-billing sync agent. Without a checkpoint, a mid-sync failure left the database in an inconsistent state. With a checkpoint plus transaction, intermediate state never reached the database.
The difference isn't in the agent code itself — it's in the orchestration layer around it. That's exactly the work we handle through AI agents and process automation: the part that doesn't show up in demos but determines whether the system holds up in production.
Questions Before You Implement
A few things to decide before adding checkpoints to your agent:
- What's the minimum unit of work? Saving a checkpoint after every single item is safe but expensive if items are tiny. Consider batching if it makes sense.
- Are your tools idempotent? If processing the same item twice has side effects (sending a duplicate email, creating two records), you need idempotency at the tool level too, not just at the checkpoint level.
- How long should a checkpoint live? Add a TTL. A checkpoint from a task that never completed shouldn't sit in Redis indefinitely.
If you're building this kind of system and don't want to solve each of these points from scratch, tell us what you're processing and how long it runs. In a 30-minute call we'll tell you what it would take — and what it wouldn't.