esc
  • WorkflowsPages
  • Case studiesPages
  • Machine Learning FoundationsLearn
  • AI EngineeringLearn
  • AI Guardrails & Red TeamingLearn
  • UI/UXLearn
  • Design SystemsLearn
  • Production System DesignLearn
  • AI papersPages
  • Interview KitPages
  • Book a callContact
Let’s talk

I’ll build the agent for it.

What Are the Challenges of Long-Running Agents?

Why agents that work for hours or days lose track between sessions, drift off course and cost more, and how teams keep them on track, for your AI interview.

In short

A long-running agent works across many sessions, and each new session starts with no memory of the last one. The main challenges are lost state, small errors that add up, claiming a job is finished too early, and rising cost. Teams handle them with notes, checkpoints, tests and hard limits.

10 min readAdvancedCommon · estimateFacts checked 27 November 2026

Say it out loud

Read it once, then say it without looking. Start with the short one; use the long one when they ask you to go deeper.

A long-running agent works for hours or days, across many sessions. Each new session starts with no memory of the last one, so the agent can lose track, repeat work, or call the job done too early. Small mistakes also add up over many steps, and long runs cost more. I handle this with a notes file, git commits, checkpoints so a run can resume, a test after each feature, and limits on steps and spend.

What is a long-running agent, in plain words?

A long-running agent is an AI app that works on one big job for hours or days, across many separate sessions. A session is one stretch of work with the model.

Think of a ward nurse at shift change. The nurse going off duty hands over the chart and a list of what is still open. The nurse coming on reads that handover before touching a patient. An agent needs the same kind of handover, because the model does not carry one session into the next by itself.

A made-up but realistic case: a legal team's contract review agent reads 40,000 contracts overnight, flags risky clauses and writes a summary by morning. If it crashes at contract 18,204, the next run must know where it stopped.

Key words

Long-running agent
An AI app that works across many sessions over hours or days.
Session
One stretch of work with the model, with its own fresh context window.
Context window
The text the model can see at one time.
Checkpoint
A saved snapshot of the run's state, so it can restart from the last good step.
Harness
The code around the model that runs the loop, the tools and the saved notes.

Why does an agent lose track between sessions?

The model keeps no memory between sessions unless your code gives it one. Anthropic's engineering team puts the core problem in one line.

  • “The core challenge of long-running agents is that they must work in discrete sessions, and each new session begins with no memory of what came before.”

    Anthropic, engineering blog, 2025

  • “must be treated as a finite resource with diminishing marginal returns”

    Anthropic, context engineering, 2025

The window that holds the work is small, and it gets worse as it fills. Anthropic describes context rot: the model's ability to accurately recall information from that context decreases as the number of tokens (the small pieces of text the model reads) grows. Anthropic says context windows of all sizes face context pollution and information relevance concerns, so a bigger window does not remove them. A long run can't simply keep adding text.

Two ways the same overnight run can end

Path A: no handoff

Run hits its limit

One feature left half built

Path B: clean handoff

Write notes and commit

Progress log and git history

Guesses what changed

No record to read

Reads notes, tests app

Finds the next open feature

Bugs stay in the code

Hours go to repair

One clean feature done

Tested and committed

  1. 1The run hits its limit with one feature half built.
  2. 2With no record, the bugs stay in the code.
  3. 3The next run reads the notes and the git history.
  4. 4The next run tests the app and finishes one clean feature.
Two ways the same overnight run can end. Without notes, the next run guesses and the bugs stay in. With notes and a commit, it reads the record and finishes one clean feature.

Anthropic's fix in its 2025 harness work was plain engineering. Each session commits its progress to git with descriptive commit messages, so the next session has a record to read.

What goes wrong over many hours?

  • It does too much at once

    The run dies half-way through a feature, and the next run has to work out what happened.

  • It calls the job done too early

    A later run sees progress so far and declares victory, even with features still missing.

  • It marks work done without testing

    Code can look right and still fail when a real user tries it.

  • It wraps up early near its limit

    Anthropic's March 2026 harness work says some models 'begin wrapping up work prematurely' as they near their context limit.

  • Small errors compound

    One early mistake shapes every later step, and each step adds cost.

  • “Agents are stateful and errors compound.”

    Anthropic, multi-agent research system, 2025

Anthropic's 2026 article adds a second trap. When agents grade their own work, they tend to praise it. Shrinking the old text (compaction) alone does not give the agent a clean slate.

  1. 1

    A made-up overnight run hits a crash

    The run stops at contract 18,204 when the database connection drops. Only a summary file from an hour earlier survives.

  2. 2

    Restart with no checkpoints

    The next run reads all 40,000 contracts again, paying for the 18,203 it had already finished.

  3. 3

    Restart from the last checkpoint

    A checkpoint after each contract lets the run resume at 18,204. Only the lost contract is retried.

How do teams keep long runs on track?

The fixes are plain engineering habits. The model does not need to be smarter for them.

  1. 1

    Keep a progress log and a feature list

    Start every feature as not done. The next run reads the log and the list before it touches code.

  2. 2

    Commit after every step

    A git commit is a saved snapshot of the code. Commits with clear messages let a bad change be reverted and a working state recovered.

  3. 3

    Checkpoint and resume

    Save the run's state after each step, so a crash restarts at the last good step. LangGraph's docs say persistence matters when an agent needs to resume after an interruption or recover from a failure.

  4. 4

    Test each feature end to end

    A separate check uses the app the way a person would, before the feature counts as done.

  5. 5

    Set hard limits

    Cap steps, time and spend, so a loop stops and a person gets told. Stop an endless loop before it burns the budget.

  6. 6

    Update safely

    Roll out new versions gradually, and keep old ones alive until running jobs finish. Anthropic calls this a rainbow deployment, and says it avoids disrupting running agents.

Checkpoints cost something too. LangGraph warns that over long conversations, checkpoints pile up, which can add delay and storage cost. So set a rule for how long to keep them, and delete the old ones. Anthropic's 2025 research system also found agents typically use about 4× more tokens than chat, so a long run needs a budget from day one.

Tip

Asked how you would make a long run reliable? Don't promise it never fails. Say you design for restarts: the run saves its place, tests each step, and stops itself when it loops or overspends.

What does the interviewer want to hear?

A strong answer covers

  • A plain definition: a job that runs across many sessions with no memory between them.
  • The main challenges: lost state, drift, false done, compounding errors and cost.
  • Why context limits matter: recall gets weaker as the window fills.
  • Checkpoints, notes and commits as the memory the run keeps outside the model.
  • Tests per feature, and hard limits on steps, time and spend.
  • Honesty: say the aim is a run that recovers from failure and stops when it should.

Common traps

  • Trap"A bigger context window solves long tasks."

    BetterBigger windows still suffer context rot. Keep the working set small and store progress outside the window.

  • Trap"Just let the agent run until it finishes."

    BetterAdd checkpoints and limits, so a stuck or expensive run stops, and a restart picks up at the last good step.

  • Trap"The model remembers last week."

    BetterNot by default. Memory lives in files, a database, or a checkpoint store that your code manages.

Can you spot the weak plan?

Spot the weak plan

The overnight review agent crashed at item 18,204 of 40,000. Which fix is the weakest?

Quick check

Which change best stops a long run from repeating finished work after a crash?

Can you answer these from memory?

Flash cards · tap a card to flip it

1 / 6

What will they ask next?

  1. Q182How do long-running agents use checkpoints?12 min
  2. Q184How do you manage agent state?12 min
  3. Q163Short-term vs long-term agent memory?12 min
  4. Q173How do you stop endless agent loops?11 min
  5. Q187How do you control agent cost?13 min
  6. Q192What are cascading failures in multi-agent systems?13 min

Learn it in depth

Last updated on 27 November 2026

Building an agent that has to run for hours?

I design and build AI agents, the interface and the system behind it, including the memory, checkpoints and limits that keep long jobs on track. Book a short call and tell me what your job is and where it stops today.