Intermediate level · Module 6: Agent State Management · Lesson 3 of 3
Persistence, Checkpoints and Resuming
Learners save state after each step to SQLite so that tasks can resume after a crash, a power cut or a lost connection, and make steps idempotent.
In this lesson you will
- Persist state and resume interrupted tasks
- Make steps idempotent
Key concepts
checkpointserialisation (model_dump_json)resumeidempotencytask ID
The lesson
Save the state as JSON (state.model_dump_json()) to a SQLite table keyed by task ID after every step. If the program stops, reload the latest checkpoint and continue from its status instead of starting again, which saves time and tokens.
A step is idempotent if running it twice gives the same result without side effects. Read-only steps usually are; any future write step must check whether it has already been done before acting.
Checkpoints matter in places where power and connectivity are unreliable, and they also form a durable history of each task.
Step by step
- Add a checkpoints table and save state after each step.
- Stop the program in the middle of a task.
- Resume from the checkpoint and finish.
- Show that rerunning a completed step changes nothing.
Practice activity
Add checkpointing and resume to the project agent.
Expected result: Tasks that resume correctly after interruption without repeating completed work.
Check your understanding
-
What is an idempotent step?
Show answer
A step that gives the same result when run twice, without extra side effects.
-
Why checkpoint agent state?
Show answer
To resume after interruptions and keep a durable history.
Further learning
Taught live by an instructor — online or in person. Free course lessons are for self-study and do not lead to a certificate — see registration options.