How should a long-running agent task persist state so it can resume after a crash or deployment?
Checkpoint after every state-mutating step to a durable store keyed by task id, with full message history, step index, and tool results, so any worker can resume.
Imagine writing a long story in chapters. Every time you finish a chapter, you save the whole story so far to a folder on a server, not just on your laptop. If your laptop dies, you can pick up any other laptop, open the folder, see exactly where you left off, and write the next chapter. An agent task is the same. After every step it takes, it writes down the entire story so far, the step number it is on, what tools it called and what they returned, and what it plans to do next. The notes live in a database that survives any single computer crashing. Any worker can pick up any task by reading the notes and continuing.
Detailed answer & concept explanation~8 min readEverything you need to truly understand this topic: intuition, mechanics, step by step explanation, code, formulas, and worked example. Click to expand.
Everything you need to truly understand this topic: intuition, mechanics, step by step explanation, code, formulas, and worked example. Click to expand.
Everything you need to truly understand this topic: intuition, mechanics, step by step explanation, code, formulas, and worked example.
Everything important, quickly.
Start with why in-memory fails: pod lifetime is minutes, agent task is 30 minutes. State the canonical pattern: durable checkpoint after every state-mutating step keyed by task id, payload is messages plus step index plus tool results plus next action. Name LangGraph plus Postgres as the reference stack. Cover idempotent tool calls, then contrast plain checkpointing with workflow engines like Temporal and Inngest for cases where the agent is one node in a longer pipeline.
Real products, models, and research that use this idea.
- LangGraph ships a `Checkpointer` interface with Postgres, SQLite, and in-memory backends; Postgres is the canonical production choice for long-running agent tasks.
- Temporal's durable workflow engine is widely used as the orchestration layer for multi-step agent pipelines at scale, providing exactly-once semantics on tool calls.
- Inngest provides a similar durable-workflow primitive aimed specifically at LLM agents, with built-in retries and step-level state persistence.
- Anthropic's documentation on building effective agents calls out durable state as a precondition for production multi-step tasks, recommending Postgres or equivalent over in-memory storage.
What an interviewer would ask next. Try answering before peeking at the approach.
QWhere exactly do you write the checkpoint: before the tool call, after the tool call, or both?
QHow do you handle a checkpoint that has been poisoned by a bad reasoning step five steps ago?
Don't say thisRed flags and common mistakes that signal junior thinking. Click to expand.
Red flags and common mistakes that signal junior thinking. Click to expand.
Holding agent state in process memory or on local disk, so any pod restart, deployment, or crash loses progress and forces the task to start over.
The night-before-the-interview bullets. Scan these on the way to the call.
Primary sources. Skim if you want the original framing.
Same topic, related formats. Practice these next.