How do you build agents that survive long-horizon tasks - hours or days of execution?
Type it the way you would explain it to an interviewer. A few sentences is enough; you can't break anything.
Model answer: the part to lead with
Assume everything fails mid-flight - process restarts, rate limits, tool outages, deploys - and design for resumability rather than praying for uptime. The pieces:
- Externalised, checkpointed state. The run's truth must live outside the process: message history, plan/todo state, and accumulated artifacts persisted at every loop boundary (a natural checkpoint is "after tool results are appended"). On restart, rehydrate and continue. LangGraph's checkpointer abstraction is a framework example of exactly this; you can equally do it with a table keyed by run ID.
- Durable-execution semantics. The orchestration layer should treat the agent loop like a workflow engine treats activities: each step journaled, replays skip completed steps, retries with backoff for transient failures. Some teams literally run agent loops on Temporal or similar engines to inherit this machinery instead of reinventing it.
- Idempotent side effects. Crash-then-retry means every side-effectful tool can execute twice. Idempotency keys, upserts, and "check-then-act" tool designs make retries safe - without this, durability machinery causes incidents rather than preventing them.
- Context lifecycle management. A multi-day run cannot keep one ever-growing context. The pattern is compaction plus agent-maintained notes: progress files, decision logs, todo lists in the workspace. On resume (or context reset), a fresh context reads the notes and continues - the notes, not the token history, are the real long-term memory. Anthropic's context-engineering guidance describes exactly this note-taking pattern for hours-long sessions.
- Progress accountability. Long runs fail silently - an agent can burn a day looping politely. Emit heartbeats and progress metrics (steps completed vs plan, budget consumed), alert on stall, and support human inspection mid-run: pause, review trajectory, redirect, resume.
- Budget and blast-radius scaling. Longer autonomy means bigger accumulated error potential: escalating checkpoint-review gates (human sign-off at phase boundaries) and hard spend caps per phase, not just per call.
Full worked answer with diagram
Assume everything fails mid-flight - process restarts, rate limits, tool outages, deploys - and design for resumability rather than praying for uptime. The pieces:
- Externalised, checkpointed state. The run's truth must live outside the process: message history, plan/todo state, and accumulated artifacts persisted at every loop boundary (a natural checkpoint is "after tool results are appended"). On restart, rehydrate and continue. LangGraph's checkpointer abstraction is a framework example of exactly this; you can equally do it with a table keyed by run ID.
- Durable-execution semantics. The orchestration layer should treat the agent loop like a workflow engine treats activities: each step journaled, replays skip completed steps, retries with backoff for transient failures. Some teams literally run agent loops on Temporal or similar engines to inherit this machinery instead of reinventing it.
- Idempotent side effects. Crash-then-retry means every side-effectful tool can execute twice. Idempotency keys, upserts, and "check-then-act" tool designs make retries safe - without this, durability machinery causes incidents rather than preventing them.
- Context lifecycle management. A multi-day run cannot keep one ever-growing context. The pattern is compaction plus agent-maintained notes: progress files, decision logs, todo lists in the workspace. On resume (or context reset), a fresh context reads the notes and continues - the notes, not the token history, are the real long-term memory. Anthropic's context-engineering guidance describes exactly this note-taking pattern for hours-long sessions.
- Progress accountability. Long runs fail silently - an agent can burn a day looping politely. Emit heartbeats and progress metrics (steps completed vs plan, budget consumed), alert on stall, and support human inspection mid-run: pause, review trajectory, redirect, resume.
- Budget and blast-radius scaling. Longer autonomy means bigger accumulated error potential: escalating checkpoint-review gates (human sign-off at phase boundaries) and hard spend caps per phase, not just per call.
Worth sketching. The crash edge re-entering the loop is the point: resumability is a property of where state lives, not of uptime.
flowchart LR
A["Loop step"] --> B["Execute tool<br/>with an idempotency key"]
B --> C["Append result, checkpoint<br/>state keyed by run id"]
C --> D{"Process still alive?"}
D -->|"yes"| A
D -->|"crash, deploy, rate limit"| E["Rehydrate from checkpoint<br/>plus the notes file"]
E --> A
C --> F["Notes file:<br/>progress, decisions, todo"]
F --> E
What a good answer covers
- Assume everything fails mid-flight - process restarts, rate limits, tool outages, deploys - and design…
- Externalised, checkpointed state
- Durable-execution semantics
- Idempotent side effects
- Context lifecycle management
Key terms: resumability · Externalised, checkpointed state · Durable-execution semantics · Idempotent side effects · Context lifecycle management · agent-maintained notes · Progress accountability · Budget and blast-radius scaling
In the glossary: Workflow · Compaction · Idempotency key
Interviewer follow-ups to expect
What exactly goes into the checkpoint - full message array or summarised state - and what are the tradeoffs on resume?
How do you handle a tool version change mid-run?
Worked answer from AI-Engineer-Interview-Questions by Om (MIT), reformatted for LLM Prep · answer text last updated 6 November 2026 · scoring and review schedule by LLM Prep