# 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.

AI and LLM interview question Q447, Multimodal and newer topics. Advanced, common (our estimate). From Venkat R. Murty's free Interview Kit: https://designervenkat.online/interview/ai/what-are-the-challenges-of-long-running-agents

## Say it in 30 seconds

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.

## Say it in 2 minutes

The hard part of a long-running agent is memory. It works in sessions, and each new session starts with no memory of the last one. Think of it as a team working in shifts, where each new person arrives with no memory of the last shift. A contract review agent that reads 40,000 contracts overnight hits this the first time it crashes.

The second problem is context. A model can only hold so much text, and its recall gets weaker as that text grows. Anthropic calls this context rot. Long runs also drift. The agent tries to do too much at once and leaves a feature half built, or a later run sees the progress so far and calls the job finished too early.

Then there are small errors. A mistake early in the run can shape every step after it, and each step adds cost. Anthropic's guidance says the autonomous nature of agents means higher costs and the potential for compounding errors. Updates can also land while a run is still going, which is why Anthropic uses rainbow deployments, keeping old and new versions running side by side.

So I design for restarts. The agent writes notes and commits to git after each step. It saves checkpoints so a run resumes where it stopped. A separate test checks each feature end to end, and hard limits stop a run that loops or overspends. The goal is a run that recovers from failure and stops when it should.

## 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.

- **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.

*Diagram, Two ways the same overnight run can end: 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.*
1. The run hits its limit with one feature half built.
2. With no record, the bugs stay in the code.
3. The next run reads the notes and the git history.
4. The next run tests the app 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. **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. **Restart with no checkpoints:** The next run reads all 40,000 contracts again, paying for the 18,203 it had already finished.
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. **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. **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. **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. **Test each feature end to end:** A separate check uses the app the way a person would, before the feature counts as done.
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. **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." Better: Bigger 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." Better: Add 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." Better: Not 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?

A. Save a checkpoint after each contract, keyed by a run ID, so the next run resumes at 18,204.
B. Write a progress file and commit to git after each contract, then read both first on restart.
C. Keep the whole run in one chat window and rely on the model to remember all 40,000 contracts.
D. Cap spend per night, and alert a person when the same contract fails three times in a row.

**Answer:** C. No window holds 40,000 contracts, and recall weakens as the window fills. The other three keep progress outside the model or limit the damage.

**Quick check:** Which change best stops a long run from repeating finished work after a crash?

A. A longer system prompt
B. Saving a checkpoint after each step, so the run restarts from the last good one
C. A higher temperature setting
D. A bigger model

**Answer:** B. A checkpoint stores progress outside the model, so a restart skips finished steps. A prompt, a sampling setting or a larger model does not store progress.

## Can you answer these from memory?

**Flash cards**

- **What is a long-running agent?** An agent that works across many sessions, with no memory between them unless code adds it.
- **What is context rot?** Recall gets weaker as the context window fills with more tokens.
- **Why do long runs drift?** Lost state, doing too much at once, calling the job done early, and small errors that compound.
- **What is a checkpoint?** A saved snapshot of the run's state, so it can restart from the last good step.
- **Why test each feature end to end?** Code can look right and still fail for a real user, and agents mark work done too easily.
- **Name one hard limit.** A cap on steps, time or spend, so a loop stops and a person is told.

## Likely follow-up questions

- Q182 How do long-running agents use checkpoints? https://designervenkat.online/interview/ai/how-do-long-running-agents-use-checkpoints
- Q184 How do you manage agent state? https://designervenkat.online/interview/ai/how-do-you-manage-agent-state
- Q163 Short-term vs long-term agent memory? https://designervenkat.online/interview/ai/short-term-vs-long-term-agent-memory
- Q173 How do you stop endless agent loops? https://designervenkat.online/interview/ai/how-do-you-stop-endless-agent-loops
- Q187 How do you control agent cost? https://designervenkat.online/interview/ai/how-do-you-control-agent-cost
- Q192 What are cascading failures in multi-agent systems? https://designervenkat.online/interview/ai/what-are-cascading-failures-in-multi-agent-systems

## Learn it in depth

- [Harness Engineering](https://designervenkat.online/learn/ai-engineering/harness-engineering)
- [State & Historical Context](https://designervenkat.online/learn/ai-engineering/state-and-historical-context)
- [Long-Context Processing](https://designervenkat.online/learn/ai-engineering/long-context-processing)
