Sub topic 3
Checking Saved State Against Reality
Assume you can read JSON and Markdown, write basic Python, and understand how an agent runs tool calls in a process. A checkpoint records what a task believes happened. It is not proof that the external result exists.
Verify Before Trust
After loading state, check important claims against reality. For example, if a checkpoint says a file was published, verify that the file exists and matches the expected checksum. If it says an API request succeeded, query the API or inspect its durable result.
import json
from pathlib import Path
def load_and_verify(checkpoint_path):
state = json.loads(Path(checkpoint_path).read_text())
for item in state.get("published_files", []):
path = Path(item["path"])
if not path.exists():
raise RuntimeError(f"Missing published file: {path}")
return stateThe verification rule should match the side effect. Existence checks are useful for files, but insufficient when contents, row counts, or remote status matter.
Handing Work to Another Agent or Person
A handoff transfers both state and intent. The next worker should not need the original conversation to understand what happened, what remains, or what could be dangerous to repeat.
What a Good Handoff Note Contains
Include:
- The goal and the definition of done.
- Completed work, with evidence and locations.
- Unverified claims and open problems.
- Decisions and their reasons.
- Actions that must not be repeated.
- One specific next action.
- Links to machine state, such as
checkpoint.json.
Avoiding Conflicting Writers
Only one process should update a checkpoint at a time. Use a lock, a single coordinator, or version checks that reject stale updates. Atomic replacement prevents partial files, but it does not prevent two valid writers from overwriting each other.
Common Failure Modes
- Stale state: the checkpoint describes an older directory or remote resource.
- Duplicated side effects: retrying an upload creates a second object.
- False completion: a step was marked complete before its result was durable.
- Conflicting writers: one agent silently replaces another agent’s progress.
Design Checklist
- Split work into small, repeatable steps.
- Save state after each durable step.
- Write checkpoints atomically.
- Verify important state against external evidence.
- Record decisions, risks, and the next action.
- Lock or serialize checkpoint updates.
- Make retries idempotent where possible.
Exercise
Why should a resume routine verify a completed step before skipping it?
Show answer
The checkpoint may be stale, corrupt, or written before the external side effect finished.