Skip to content
All posts

· 11 min read · Aravind Baranitharan

long-horizon tasks.

Why AI agents that look brilliant for five minutes fall apart over five hours, and the architecture I would use to keep a long run on track.

  • AI agents
  • Architecture
  • Evals
  • Context engineering

Most agent demos are short. Ask a question, call two tools, return an answer. The work people actually want to hand off is long: migrate a codebase, research a market and write the report, reconcile a month of invoices, keep a data pipeline healthy for a week. Those are long-horizon tasks, and they break agents in ways a five-minute demo never shows.

This post is my working notes on the problem: what makes a task long-horizon, why errors pile up, a brainstorm of the ways long runs fail, and the architecture I would propose to keep one on track. Every section is open for feedback at the bottom of the page, so tell me where you think I'm wrong.

What makes a task long-horizon

Length on its own isn't the point. A task is long-horizon when it has most of these properties:

  • Many dependent steps. Step 40 depends on what happened at step 7, so an early mistake doesn't stay small.
  • More state than fits in one context window. Files, findings, decisions and half-finished work have to live somewhere other than the prompt.
  • Delayed feedback. You often can't tell whether a step was right until much later, when the tests run or the report reads wrong.
  • Wall-clock time. The run lasts minutes to days, so it will meet crashes, deploys, rate limits and expired tokens along the way.
  • Real side effects. It sends emails, merges code or moves money, so a mistake can't always be undone.

The length of task that frontier agents can finish is growing fast. METR's measurements found it roughly doubling every seven months. A better model raises the ceiling, but whether a given system reaches it depends on the scaffolding around the model, and that part is our job.

The maths of compounding error

Here is the uncomfortable arithmetic. If each step succeeds independently with probability p, a run of n steps succeeds with probability pⁿ.

36%chance a 20-step run finishes cleanly at 95% per-step accuracy
37%chance a 100-step run finishes cleanly at 99% per-step accuracy
0.6%chance a 100-step run finishes cleanly at 95% per-step accuracy

Real steps aren't independent, so treat these numbers as a picture rather than a forecast. The lesson still holds: you will not prompt your way to 99.99% per step. Long runs succeed because errors get noticed and repaired, not because they never happen. The design question shifts from "how do I make every step right?" to "how quickly do I catch a wrong step, and how cheaply can I recover from it?"

Brainstorm: how long runs fail

Before designing anything, I listed every way I've seen, or can imagine, a long agent run going wrong. Each one points at a part of the architecture.

  1. Context rot. The transcript grows until the instructions that matter are buried under tool output. The agent starts forgetting constraints it followed an hour ago.
  2. Goal drift. Each step is locally sensible, but the run slides away from what was asked. It ends up optimising for "tests pass" when the goal was "the feature works".
  3. Lost state. The process crashes, a deploy restarts the worker, a token expires. Without durable state, three hours of work start over from zero.
  4. Loops. The agent retries the same failing approach, or two sub-agents keep handing a task back and forth.
  5. Silent failure. A step returns something plausible but wrong, nothing checks it, and every later step builds on it.
  6. Budget blowout. Tokens, API calls or wall-clock time run far past what the task was worth, and nobody noticed until the bill came.
  7. Irreversible mistakes. A wrong action with real side effects, such as a deleted table or a sent email, can't be retried away.
  8. Planning too early, or never. A plan made at minute zero goes stale by hour two, but replanning every step throws away progress and burns budget.

The architecture I'd propose

The design separates thinking about the work from doing the work from checking the work, and keeps the run's state outside the model. The model is a component inside a loop, not the loop itself.

Long-horizon agent architectureLong-horizon agent architecture: a goal contract feeds a planner and a task ledger; an orchestrator dispatches small, scoped workers; a verifier gates every result; memory and a checkpointer keep state outside the model; a governor enforces budgets and human approval.next ready taskpassmark donepersistbudgets · gatesread / writefail + reason → retry or replan01goal contractobjective · constraintsdefinition of donebudget02plannerdecompose · replantask ledgergraph of tasks + acceptance checksdonerunningwaiting03orchestratorpick · assembledispatch04worker · codeworker · researchworker · tools05verifiertests · schemasllm judge08governortoken + time budgetsloop detectionhuman gate06memoryworkingthis step onlyfresh every callepisodic logappend-onlywhat happened + whysemantic storefacts + decisionsretrieved on demand07checkpointerstate saved after every stepcrash → resume, not restart
Fig. 1 · The proposed architecture. Numbers match the walkthrough below.
  1. 01

    Goal contract

    A short, structured statement of the objective, the constraints, the definition of done and the budget. It's written once, sent with every model call and never summarised away. This is the fix for goal drift.

  2. 02

    Planner and task ledger

    The planner breaks the goal into a small graph of tasks, each with its own acceptance check. The ledger is that graph stored in a database: status, inputs, outputs, attempts. Replanning edits the ledger instead of starting over.

  3. 03

    Orchestrator

    A plain loop, mostly ordinary code: pick the next ready task, build a fresh, minimal context for it, dispatch it, record the result. Keeping this deterministic makes the system debuggable.

  4. 04

    Workers

    Short-lived agents with a narrow job, a scoped tool set and a small context. A worker never sees the whole history, only the goal contract, its task and the memory relevant to it. This is the main defence against context rot.

  5. 05

    Verifier

    Every result is checked against its acceptance criteria before it counts. Cheap, deterministic checks come first (schemas, tests, linters, row counts), then an LLM judge for what code can't check. A failure goes back to the orchestrator with the reason attached, for a retry or a replan.

  6. 06

    Memory, in three tiers

    Working memory is what the current step needs. The episodic log is an append-only record of what happened and why. The semantic store holds durable facts and decisions ("we chose Postgres", "the API paginates by cursor") that are retrieved when relevant.

  7. 07

    Checkpointer

    State is persisted after every step, so a crash means resume, not restart. It also gives you time travel: rewind to step 31, change one thing and replay.

  8. 08

    Governor

    The adult in the room. It enforces token, cost and time budgets, detects loops (the same task failing the same way three times), and stops for human approval before anything irreversible.

Context is a budget, not a bucket

The easiest mistake is to treat the context window as a bucket and keep pouring the transcript in. Long runs need the opposite: assemble a fresh context for every step from durable sources, and keep it small.

  • Always include the goal contract and the current task with its acceptance check.
  • Pull only the memory this task needs, by retrieval or by explicit links in the ledger.
  • Replace raw tool output with a summary plus a pointer ("full log stored at …"), so the worker can fetch details on demand.
  • Write decisions down as they're made. If it only lives in the transcript, it will be forgotten.

If the agent needs to remember something for more than one step, it belongs in the ledger or the memory store, not in the prompt.

Verification is the real engine

If I could add only one component to an existing agent, it would be the verifier. Most long-run failures are really silent failures that compound. Turning "done" into something checkable changes the whole system:

  • Acceptance checks are written when the task is planned, before the work starts, so the worker can't redefine success after the fact.
  • Cheap checks first. A JSON schema, a unit test or a SQL count catches most errors for almost nothing. Save the LLM judge for questions that need judgment.
  • Failures carry information. "Test test_refund_rounding failed: expected 10.00, got 9.99" is a far better retry prompt than "try again".
  • Whole-run evals still matter. Per-step checks catch local errors; an end-of-run eval against the goal contract catches drift.

Humans at the checkpoints, not in the loop

Asking a person to approve every step defeats the point of a long run. Never asking them is how a deleted production table happens. The middle ground: the governor classifies actions by how reversible they are and only pauses at the gates that matter. Think merging to main, sending external messages, spending above a threshold, or deleting data.

Because state is checkpointed, a pause costs nothing. The run waits for an hour or a weekend, the person approves from their phone, and it resumes exactly where it stopped.

What I'd build first

You don't need all eight boxes on day one. If I were starting tomorrow, in this order:

  1. A task ledger in Postgres with status, attempts and acceptance checks. Even a single table changes how you debug.
  2. Durable checkpoints. LangGraph's checkpointer, Temporal, or any durable workflow engine, so a crash means resume.
  3. A verifier with deterministic checks before adding any LLM judging.
  4. Budgets and loop detection, because they're cheap and they prevent the expensive surprises.
  5. Memory tiers and human gates, once the basic loop is reliable.

Open questions

These are the parts I'm least sure about, and where I'd most like your view:

  • When should the planner replan? On every failure, on a schedule, or only when the verifier says the plan itself is wrong?
  • How do you evaluate a whole run when the ground truth only exists at the end, days later?
  • What should memory forget? An episodic log that only grows becomes its own kind of context rot.
  • How small should workers be? Smaller contexts are more reliable but cost more hand-offs, and each hand-off is a chance to lose information.

Leave a rating, start a thread on any concept below, or share this with someone building agents. I'll update the post as the discussion changes my mind.

Discussion

feedback.

Rate the post, then start a thread on any concept. Disagreements are especially welcome. No sign-up needed.

Reader rating

–No ratings yet. Be the first.

How useful was this?

Start a thread

Loading the discussion…