An AI agent can work on a task for hours or days by splitting the job into a series of shorter working sessions. Between sessions, the software around the model saves progress, picks the work back up, retries what failed, and checks whether it is time to pause for a person, spend more or stop. The AI model does not gain stamina; the system around it is built to keep a long job on track after you stop watching.
A long-running agent is one whose task outlasts a single working session, so it has to stop, save its progress and pick up again, sometimes many times [1]. The model is the same one that answers quick questions; what changes is the scaffolding, meaning the software wrapped around it: checkpoints that record progress, a safe way to pause and resume, caps on turns and spending, a record of what happened, and rules for when the run ends [2, 3, 4]. Without that scaffolding, small mistakes have hours to compound. For the basics, start with what an AI agent is.
The previous guide, how AI agents remember what they are doing, explained the records an agent keeps during a task. This guide shows what happens when those records have to carry a job across hours, pauses and a world that keeps changing.
TL;DR
- Long tasks are broken into sessions. The text a model can take in at once fills up, so long jobs depend on progress saved outside the model [1, 5].
- Checkpoints save less than you might think. A saved conversation is not saved files, and file checkpoints miss some changes [6, 7].
- Resuming can repeat actions. Builders need safeguards so a payment or message isn’t sent twice [8].
- Errors build on errors. Agents become more error-prone when their own earlier mistakes sit in their context [9].
- Set limits first. Spending caps, monitoring and a definition of “done” come before the run [3, 10, 1].
What Makes a Task “Long-Running”?
It is a task too big for one sitting. In November 2025, Anthropic said developers increasingly give agents work spanning hours or even days, and that keeping progress consistent across many context windows remained an open problem [1]. A context window is the amount of text a model can take in at once: instructions, conversation and every tool result so far.
In usage data for one product, Claude Code, long runs were the exception: the median turn (how long the agent works before stopping) lasted about 45 seconds, and the longest turns, at the 99.9th percentile, grew from under 25 minutes to over 45 minutes between October 2025 and January 2026 [10]. That is one vendor’s data, not a measure of agents in general.
Why Can’t an Agent Just Keep Going?
The space in its context window runs out, and performance slips before that. Anthropic reports that models tend to lose coherence on lengthy tasks as the context window fills, and that some wrap up early as they near what they treat as their limit [11].
Compaction summarizes a conversation nearing the limit and restarts from the summary; structured note-taking has the agent write notes outside its context window and read them back later [5]. Neither was enough alone in Anthropic’s tests of building a production-quality web app [1]. Either the agent ran out of room mid-feature, leaving the next session to guess, or a later session saw partial progress and declared the job done [1].
What an agent carries between steps, and how context, memory and saved state differ, is covered in the guide on agent memory and state.
Checkpoints: Saving Work You Can Return To
A checkpoint is a saved snapshot of progress that lets a run continue from that point rather than from scratch. In the LangGraph framework, the run’s state is saved after each step, so a failed run can restart from the last successful step [2].
Anthropic’s long-running coding harness (the software wrapped around the model) used ordinary developer tools instead. A first session wrote a progress log, an initial commit to the version-control system git, and a list of more than 200 required features, all marked as failing [1]. Each later session built one feature, committed it and updated the log, so the agent could revert bad changes [1].
Checkpoints cover only what they track. In Anthropic’s Agent SDK, a saved session holds the conversation, not the files the agent changed [6]. Claude Code’s file checkpoints generally miss files changed only by shell commands or by people outside the session, and Anthropic advises keeping version control for anything lasting [7]. And no checkpoint can unsend an email.
Pausing and Resuming Without Doing Things Twice
Long runs often pause on purpose, usually to wait for a person. A LangGraph interrupt saves the run and waits indefinitely for someone to resume it [12]. OpenAI’s Agents SDK lets developers store a paused run in a database and recreate it later [8]. In May 2026, Microsoft said its durable-agent extension supports waits lasting hours, days or weeks without consuming compute [13].
The hard part is resuming without repeating. When a LangGraph run resumes, the paused step starts again from its beginning, so an update made before the pause can run twice and create duplicate records [12]. The fix is to make such actions idempotent, meaning a repeat has no further effect [12]. OpenAI’s documentation warns that approval does not guarantee an action runs exactly once; its own example is a payment that completes without the saved snapshot recording it [8]. It recommends a stable idempotency key for each consequential action, or checking with the destination system before any retry [8].
Stopping halfway has its own cost. A white paper by OpenAI researchers argues that people should always be able to shut an agent down gracefully, and notes the difficulty when a run is cut off after sending two of five meeting invitations [14]. It suggests agents prepare a fallback, such as notifying those two invitees [14].
The World Keeps Moving While the Agent Works
A paused agent’s picture of the world goes stale. In a March 2025 paper, the evaluation group METR noted that real tasks, unlike its benchmark tasks, often involve dynamic environments and resource limits and rarely come with automatic scoring, and agents did worse on these “messier” tasks [15].
In Vending-Bench, a 2025 simulation in which an agent runs a vending business, one agent wrongly believed its orders had arrived, and later errors flowed from that [16].
A hypothetical example: an agent drafting supplier orders pauses overnight for approval. By morning a price has changed, and resuming from the saved plan would act on yesterday’s facts.
Anthropic’s harness had each session read the git log and progress notes, then run a basic test before new work, so a broken app was caught early [1].
How Small Errors Pile Up
Over a long run, mistakes rarely stay isolated. One study found that per-step accuracy falls as tasks lengthen, partly through “self-conditioning”: a model becomes more likely to err when its context already contains its own earlier errors [9]. That preprint used a synthetic task.
Vending-Bench shows similar drift on simple, repeated jobs. Runs typically took 5 to 10 real-world hours, and every model tested had runs that derailed through misread delivery schedules, forgotten orders or loops they rarely escaped [16]. Failures showed no clear link to the context window filling up [16]. The models tested in that early-2025 study are now older [16], and a simulation is not a measure of real-world reliability.
Self-checking doesn’t reliably catch the drift. Anthropic found agents grading their own work tend to praise it even when it is mediocre, and that a separate, skeptical evaluator was easier to tune [11]. The wider range of breakdowns is in how AI agents can fail when they act.
Budgets: Capping Turns, Time and Money
Long runs cost more. In one Anthropic experiment reported in March 2026, a single agent built an app in 20 minutes for $9, while a fuller multi-agent setup took 6 hours and $200, but produced clearly better work [11]. A later, simplified run took about 4 hours and $124 in token costs [11].
Anthropic’s Agent SDK can stop a run after a set number of turns or at an estimated spend; neither is on by default, though the documentation recommends a budget for production [3]. Caps are approximate: spend is checked after each model response, so a run can overshoot by up to one response’s cost, plus whatever background helper agents spend before stopping [3].
Monitoring a Run You Aren’t Watching
Nobody approves every step of a six-hour job, so oversight shifts to watching and stepping in. OpenAI’s Agents SDK records a trace of each run by default, logging model outputs, tool calls, handoffs and guardrail checks [4]. Anthropic found experienced Claude Code users auto-approve more but also interrupt more, shifting from approving each action to monitoring and intervening [10]. Watching less closely does not hand off responsibility: the people and organizations that launch a long run, grant its access and set its limits remain answerable for what it does.
Agents can also pause themselves: in Anthropic’s data, Claude Code’s own requests for clarification outnumbered human interruptions by more than two to one on its hardest tasks, though it may not always stop at the right moments [10]. For the question of timing, see when an agent should stop and ask you.
Stop Conditions: Deciding in Advance When a Run Ends
Ending rules belong in place before a run starts. The basic ways a loop ends are covered in the agent loop; over hours, four matter most.
- A written definition of done. Anthropic’s feature list, each item failing until tested, guarded against declaring victory early [1].
- Hard limits. Turn and spend caps end a run that has stopped paying off [3].
- A working off switch. People should be able to halt a run gracefully at any time [14].
- A no-progress signal. Loops agents rarely escape, as in Vending-Bench, are a reason to stop [16].
What We Know, What We Don’t, and Where Experts Disagree
What We Know
- Long tasks are split across sessions, with progress saved outside the model [1, 5].
- Resuming can repeat actions unless builders guard against it [12, 8].
- Errors tend to build on earlier errors [16, 9].
What We Don’t Know
- How long agents run unattended across products; the best usage data come from one vendor [10].
- How often stale information or repeated actions cause harm in practice; the sources offer warnings and simulations, not incident counts.
What Experts Disagree About
Confidence: Expert Debate
Anthropic reads its usage data as showing people grant agents less independence than they could handle [10]. Vending-Bench and METR point to long runs that still derail and real tasks messier than benchmarks [16, 15]. Anthropic’s engineers add that harness designs can go stale as models improve [11]. Claims about how long agents can work are time-sensitive: every figure in this guide is dated to its source, and the figures come from vendor experiments, benchmarks and simulations rather than measures of reliable everyday performance.
Practical Takeaways
- Ask where progress is saved: files and outside actions, or only the conversation?
- Ask what happens on resume. Payments and messages must not run twice.
- Set a spending cap with headroom. Caps can be overshot slightly.
- Write down “done” first. A checklist the agent can only tick off beats its own verdict.
- Re-check the world after a pause. Prices and files change.
- Make sure someone can stop it, and plan for half-finished actions.
This guide closes the block on how agents plan and act. The next guide, What Can AI Agents Actually Do on Their Own—and Where Do They Still Need People?, opens the block on controlling and checking agents by asking what they can be trusted to do without a person.
Sources
- Effective harnesses for long-running agents. Anthropic, 2025-11-26, accessed 2026-11-09.
- Checkpointers (LangGraph documentation). LangChain, accessed 2026-11-09.
- How the agent loop works (Claude Agent SDK documentation). Anthropic, accessed 2026-11-09.
- Tracing (OpenAI Agents SDK documentation). OpenAI, accessed 2026-11-09.
- Effective context engineering for AI agents. Anthropic, 2025-09-29, accessed 2026-11-09.
- Work with sessions (Claude Agent SDK documentation). Anthropic, accessed 2026-11-09.
- Checkpointing (Claude Code documentation). Anthropic, accessed 2026-11-09.
- Human-in-the-loop (OpenAI Agents SDK documentation). OpenAI, accessed 2026-11-09.
- The Illusion of Diminishing Returns: Measuring Long Horizon Execution in LLMs. arXiv, 2025-09, accessed 2026-11-09.
- Measuring AI agent autonomy in practice. Anthropic, 2026-02-18, accessed 2026-11-09.
- Harness design for long-running application development. Anthropic, 2026-03-24, accessed 2026-11-09.
- Interrupts (LangGraph documentation). LangChain, accessed 2026-11-09.
- Durable Task Extension for Microsoft Agent Framework. Microsoft, 2026-05-04, accessed 2026-11-09.
- Practices for Governing Agentic AI Systems. OpenAI, accessed 2026-11-09.
- Measuring AI Ability to Complete Long Software Tasks. METR (arXiv), 2025-03, accessed 2026-11-09.
- Vending-Bench: A Benchmark for Long-Term Coherence of Autonomous Agents. Andon Labs (arXiv), 2025-02-20, accessed 2026-11-09.
