agent-patterns

checkpoint-resume

flowchart TD
    Start([Task input]) --> LoadCP{Checkpoint\nexists?}
    LoadCP -- yes --> Resume[Resume from last step]
    LoadCP -- no --> S1[Step 1: Analyze]
    Resume --> Sx[Continue from step N]
    S1 --> CP1[(Checkpoint 1)]
    CP1 --> S2[Step 2: Plan]
    S2 --> CP2[(Checkpoint 2)]
    CP2 --> S3[Step 3: Implement]
    S3 --> CP3[(Checkpoint 3)]
    CP3 --> Done([Result])

The pipeline persists its state after each step. On failure or restart, it resumes from the last saved checkpoint rather than restarting from scratch.

How it works

  1. Before starting, the pipeline checks for an existing checkpoint file.
  2. If found, it skips all completed steps and resumes from the next one.
  3. After each step completes, the full accumulated state is written to disk.
  4. On successful completion, the checkpoint is cleared.

Where it came from

When to use

When not to use

Trade-offs

   
Pro Crash recovery is free — restart the process and it continues
Pro Easy to inspect intermediate state for debugging
Con Stale checkpoints produce wrong results if the task input changes between runs
Con Disk I/O on every step adds latency; on large state objects this matters

Failure modes