Vibe Engines
YouTube

Vibe Engines is free, interactive AI engineering & system design — runs in your browser. Pick a learning path

Handbooks  /  Long-Horizon Agents
Handbook~14 min readReliabilityworked math + runnable code
Handbook

Long-horizon
agents.

A ten-step task the agent nails every time. A hundred-step version of the same task, and it almost never finishes. Nothing got harder — the steps are identical. What changed is that reliability compounds: a small per-step failure rate, multiplied over a long chain, becomes near-certain failure. The fix isn't a smarter model; it's an engineered one — checkpoint the work, and retry the segment that broke instead of the whole run.

01

The wall: reliability compounds

If each step of a task succeeds with probability p, and the task needs k steps to all go right in a row, the chance of finishing clean is pk. That exponent is brutal. It's the same passk curve that agent evaluation measures — and it means length, not difficulty, is the enemy.

no-checkpoint success = pk  →  p=0.99, k=100 → 37%  ·  p=0.95, k=100 → 0.6%

A 95%-reliable step sounds great until you chain a hundred of them and land under 1%. The math of long horizons is unforgiving to any single-shot run.

The full treatment of measuring this — pass@k versus passk, and how reliability scores over many attempts — lives in the agent-evals handbook. This handbook picks up where measurement ends: given that pk collapses, how do you build an agent that survives it?

02

Checkpointing: don't restart from zero

The first move is to stop treating the task as one indivisible chain. Checkpointing saves the agent's state at intervals — completed subtasks, intermediate artifacts, verified progress — so a failure at step 87 doesn't throw away steps 1 through 86. Without checkpoints, one stumble anywhere means starting over; with them, a stumble costs only the work since the last save.

One long fragile chain vs saved segments
No checkpoint
■■■■✗ → restart ALL
success p^k
vs
Checkpointed
■■│■■✗ → retry last segment
failure is local

A good checkpoint is resumable state: enough that the agent can pick up exactly where it left off, not a vague summary that forces guesswork. The art is choosing what to persist — the durable artifacts and decisions, not the entire scratchpad — so resume is faithful and cheap.

03

Resume + retry: break the exponent

Checkpoints unlock the real win: retry the failed segment, not the whole task. Split the k steps into segments of length c. A segment succeeds with probability pc, and if you can retry a failed segment up to r times, its effective success rises to 1−(1−pc)r. The whole task is then those segments in series:

checkpointed success = [1 − (1 − pc)r]k/c  ≫  pk

Same model, same per-step p. At p=0.95, k=100: the naive run finishes 0.6% of the time; checkpoint every 10 steps with 3 retries per segment and it finishes ~51%. The exponent that was killing you now works segment-by-segment, where retries can beat it.

The key idea

You can't make pk survivable by nudging p — you'd need near-perfection. You make it survivable by shortening the chain that has to hold: small segments, cheap resume, and retries where a failure is local and recoverable. Reliability engineering, not model improvement.

Two dials fall out of the formula. Shorter segments (frequent checkpoints) make each segment more likely to pass on the first try; more retries per segment raise each segment's effective reliability. Both cost overhead, so you tune them against the horizon. The runnable model below lets you turn each dial.

04

The catch: real failures are silent and correlated

The retry math above makes two quiet assumptions: every failure is noticed, and every retry is an independent draw. Long-running agents break both. A step can fail while reporting success, with a test it skipped, a file it thinks it wrote, or "done" on a feature that doesn't work, and every later step builds on the mistake. A retry only fires on a failure somebody detected. And when the cause is the model's own misunderstanding, the retry tends to make the same mistake, because nothing about the second attempt is different.

success ceiling with unlimited retries = (1 − (1−p)·s)k  ·  s = share of failures that look like success

Illustrative, at p = 0.95 and k = 100. If 10% of failures are silent, the ceiling is about 61%; at 20% it's 37%; at 50% it's 8%. No number of retries moves it. Only detection does.

So the cheapest reliability work on a long-horizon agent is usually verification, not retries: a check after each step that can tell "claimed done" from "done". Anthropic's write-up on harnesses for long-running agents names exactly these failure modes in its coding agents: trying to one-shot the whole app and running out of context mid-implementation, a later session seeing progress and declaring the project finished, and marking features complete without end-to-end testing. Its fix for the last one was to have the agent use browser automation and "do all testing as a human user would." Correlated failures need a different kind of retry, one that changes something (the prompt, the context, the approach, or the model), so the next attempt isn't the same attempt again.

05

State outside the context window: compaction, progress files, git

A checkpoint is only as good as what it saves, and for an LLM agent the hard part is that the working state lives in the context window, which fills up and degrades. Anthropic's post on context engineering (September 2025) calls the degradation context rot and describes three ways to work past it:

TechniqueWhat it does
CompactionSummarize a conversation nearing the context limit and continue in a fresh window. Claude Code keeps "architectural decisions, unresolved bugs, and implementation details," drops redundant tool output, and carries over the five most recently accessed files.
Structured notesThe agent writes notes outside the context window (a to-do list, a NOTES.md) and reads them back later.
Sub-agentsFocused tasks run in clean context windows and return only a condensed summary to the lead agent.

The harness post (November 2025) turns this into a checkpoint protocol for work that spans many context windows. An initializer session writes an init.sh that starts the dev server, a claude-progress.txt log, and a JSON feature list in which every feature (over 200 in their example) starts out marked failing. Then it makes an initial git commit. Every later coding session starts the same way: read the progress file and the git log, run init.sh and a basic end-to-end test to catch damage from the last session, pick the highest-priority failing feature, and finish by committing and updating the progress file, leaving the environment clean.

Map that onto this handbook's model and each file has a job. The git commit is the checkpoint, the progress file is the resumable state, and the feature list with its passes field is the verifier that keeps "done" honest. Even the file format is a reliability decision: the authors chose JSON because the model was less likely to inappropriately rewrite it than a Markdown file.

06

Durable execution: replay without repeating side effects

Progress files are checkpoints the agent keeps for itself. A durable execution engine keeps them for the program running the agent, so a crashed process can resume instead of restarting. In Temporal, a workflow's steps are recorded in an Event History. After a crash, a worker replays that history to rebuild state and carries on from the last recorded event. In the docs' words, "completed Activities will not re-execute as part of a Workflow Replay." LangGraph's checkpointers do the analogous job for agent graphs: they "persist a thread's graph state as checkpoints," keyed by a thread_id, to support human-in-the-loop pauses, time travel and fault tolerance.

The gap that bites is between doing a side effect and recording it. Temporal notes that an Activity isn't written to history until it returns or errors, and that "Temporal recommends that Activities be idempotent" because retried Activities "may be executed more than once." For an agent that sends email, files tickets or moves money, a crash after the action but before the record means the retry does it twice, unless the action carries a key that is the same on every attempt:

def send_invoice(run_id, step, invoice):
  key = f"{run_id}:{step}"  # identical on every retry of this step
  if ledger.seen(key): return ledger.result(key)
  result = billing.charge(invoice, idempotency_key=key)
  ledger.record(key, result)
  return result

A sketch. The downstream API must honor the key too, because the crash can land between charge() and record(). Practice it in the Idempotency Key Handler challenge.

07

The time horizon — and how engineering extends it

The field now tracks an agent's time horizon, defined by METR in "Measuring AI Ability to Complete Long Tasks" (March 2025) as the time humans typically take to complete the tasks a model finishes with 50% success. At publication, frontier models such as Claude 3.7 Sonnet sat around 50 minutes, and the frontier horizon had doubled roughly every seven months since 2019. By METR's Frontier Risk Report of May 2026, the public frontier's 50% horizon was about 12 hours, with a wide interval of 5 to 61 hours. METR's Time Horizon 1.1 suite can't reliably measure past 16 hours, so the yardstick itself is running out.

The same report puts the 80% horizon at about 1.5 hours. That gap is this handbook's opening math in the wild: ask for more reliability and the task length a model can carry shrinks by roughly a factor of eight. A team that needs a long-running agent to succeed four times in five is working with a much shorter horizon than the headline number.

The lesson of this handbook is that the horizon isn't only a property of the model. Raw per-step reliability sets a baseline; checkpointing, retries and verification extend it. An agent that saves progress, verifies each step and retries locally has a longer usable horizon than its bare p would predict. So when METR's curve doubles, part of that is better models, and part is better harnesses doing exactly what's above.

08

Why it matters

The agents that will run for hours — refactoring a codebase, conducting deep research, driving a multi-stage workflow — don't win by having a magically reliable model. They win on reliability engineering: checkpoint often, make state resumable, verify between steps, retry the smallest failing unit. It's the same discipline distributed systems learned decades ago (idempotency, retries, checkpoints), now applied to an agent's step chain.

For a builder the takeaway is liberating: you don't have to wait for a perfect model to ship a long-running agent. You have to engineer around imperfect steps. Measure the decay with agent-evals, guard each step with the patterns in agent patterns, and structure the whole loop with a harness that checkpoints and resumes. The horizon you can reach is mostly up to you.

Read next

The measurement half: Agent Evals. The per-step guardrails: Agent Patterns. The loop that runs it: Harness Engineering. What survives a full window: Context Engineering.

RUN IT YOURSELF

Break the p^k collapse with checkpoints

Long-horizon reliability is one formula and its rescue. A single-shot run of k steps succeeds with probability pk — which collapses as the horizon grows. Checkpoint into segments of c steps and retry a failed segment up to r times, and each segment's success climbs to 1−(1−pc)r, with the whole task their product over k/c segments. Watch a 0.6% success become 51% at the same per-step reliability, and turn the segment-length and retry dials.

CPython · WebAssembly
Frequently asked

Quick answers

Why do long agent tasks fail?

Reliability compounds: a k-step task succeeds with probability p^k. At 95% per step, a 100-step task lands under 1%. The steps aren't hard — the length is, because one failure anywhere derails the whole run.

How does checkpointing help?

It saves progress so a failure doesn't restart from zero. Combined with resume, you break the p^k chain into segments and retry only the failed one — a c-step segment retried r times succeeds 1−(1−p^c)^r.

What is an agent's time horizon?

The task length it can complete at a given success rate (e.g. 50%). It's been doubling on a regular cadence. Reliability engineering — checkpoints, retries, verification — extends the usable horizon beyond raw per-step reliability.

How is this different from agent evals?

Agent-evals measures the decay (pass@k vs pass^k). This handbook engineers around it: checkpointing, resumable state, segment retries, and verification between steps. And self-improving agents asks the next question: can the agent shorten its own failures over time?

How do long-running agents keep state across context windows?

They keep it outside the context window. In Anthropic's harness for long-running coding agents, an initializer session writes an init.sh script, a progress file and a JSON feature list with every feature marked failing, then makes a git commit. Each later session reads the progress file and git log, runs a basic end-to-end test, works on one feature, commits, and updates the progress file. Compaction then summarizes a conversation near the context limit so work can continue in a fresh window.

The Long-Horizon Agents Handbook · Vibe Engines · 2026 · time-horizon figures from METR · more handbooks →
Finished this one? 0 / 208 Handbooks done
NextThe Multi-Agent Orchestration Handbook Next on the “Building agents” ladder · rung 7 of 10

Explore the topic

See this alongside everything else on the same subject — handbooks, system designs, challenges and tools, in one place.

More Handbooks