A long-running agent is an AI agent that works toward a goal over an extended period, from hours to days or weeks, across many model calls, tool invocations and often several sessions, while persisting its state, memory and progress outside the model’s context window. Within AI agents, a field of artificial intelligence, the concept is also called a long-horizon agent, because the main difficulty is staying coherent over a long sequence of dependent steps.
Short agents answer a question in a few loop iterations. A long-running agent must instead survive interruptions, context limits and partial failures, and it must still deliver a result that matches the original intent. That shift turns agent design from prompt engineering into systems engineering.
How a long-running agent sustains work over time
A long-running agent sustains work by externalizing everything that must outlive a single context window. The model itself is stateless between calls, so the surrounding agent harness stores the plan, completed steps, intermediate artifacts and open questions in durable storage such as files, databases or a task queue.
Each working cycle follows the familiar agent loop: observe the current state, decide on an action, call a tool, record the result. What differs is the outer layer of checkpointing, context compaction and resumption, which lets the agent pause and continue later without repeating work or losing track of the goal.
The table below lists the main components and the role each one plays.
| Component | Role | Typical implementation |
|---|---|---|
| Durable state store | Keeps plan, progress and artifacts | Files, database rows, workflow engine |
| Checkpointing | Saves resumable snapshots | Periodic or per-step state writes |
| Context compaction | Shrinks history to fit the window | Summaries, pruning of tool outputs |
| Long-term memory | Recalls facts across sessions | Notes files, vector store, knowledge base |
| Scheduler or trigger | Starts and resumes work | Cron jobs, events, queue workers |
| Progress log | Shows humans what has happened | Structured trace, status reports |
Long-running agents compared with related agent types
A long-running agent is defined by duration and persistence, not by a specific architecture, so it overlaps with several neighboring concepts. A background agent describes where the work happens, out of the user’s sight, while a long-running agent describes how long the work lasts and how state is kept.
| Concept | Defining trait | Relation to long-running agents |
|---|---|---|
| Conversational assistant | Responds turn by turn | Usually short-lived, no durable plan |
| Background agent | Runs without the user watching | Often long-running, but not always |
| Agentic workflow | Predefined steps with model calls | Can be long-running with fixed structure |
| Multi-agent system | Several cooperating agents | May split long tasks among subagents |
| Plan-and-execute agent | Separates planning from execution | Common design for long horizons |
In practice, many long-running agents use an orchestrator-worker pattern: a coordinating agent holds the overall plan and delegates bounded subtasks to subagents with fresh context windows, which keeps each individual context small and focused.
Managing context and memory over long horizons
Context management is the central engineering problem for a long-running agent. Even with windows of hundreds of thousands of tokens, a task that spans thousands of tool calls quickly exceeds capacity, and model quality tends to degrade as the context fills with stale detail.
Common techniques include summarizing completed phases, dropping raw tool outputs once their conclusions are recorded, and keeping a concise progress file that a fresh session reads first. The agent effectively writes notes for its future self, much as an engineer leaves a handover document before a shift change.
| Strategy | Benefit | Risk |
|---|---|---|
| Rolling summarization | Keeps context compact | Loses details that later prove relevant |
| Structured notes file | Explicit, inspectable memory | Depends on disciplined updates |
| Retrieval from memory store | Scales to large histories | May recall the wrong fact |
| Subagent delegation | Fresh context per subtask | Coordination and handoff overhead |
| Session restart from checkpoint | Clears accumulated noise | Requires complete state capture |
Reliability, oversight and failure modes
Errors compound over long horizons: a step that succeeds 95 percent of the time gives a much lower chance of success across dozens of dependent steps unless the agent can detect and recover from mistakes. Reliability therefore depends on verification, retries and clear stopping conditions, not only on model capability.
- Goal drift: the agent gradually optimizes a proxy and loses the original intent.
- Looping: the agent repeats an action that keeps failing without changing strategy.
- Premature completion: the agent declares success before the acceptance criteria are met.
- State corruption: a crash between steps leaves inconsistent records, causing duplicated actions.
- Cost runaway: unbounded retries or exploration consume large token and compute budgets.
Oversight usually combines human-on-the-loop monitoring with human-in-the-loop approval gates for irreversible actions such as deployments, payments or data deletion. Tight agent permissions, an agent sandbox and budget limits keep the potential damage of a mistaken plan bounded.
Designing tasks for a long-running agent
Long-running agents succeed most often on tasks with clear, machine-checkable acceptance criteria, such as passing test suites, reconciled data or completed checklists. Vague goals give the agent nothing to verify against and make drift harder to detect.
| Situation | Recommended choice | Reason |
|---|---|---|
| Task has testable output | Let the agent self-verify | Tests catch errors early |
| Actions are irreversible | Require human approval | Limits costly mistakes |
| Work splits cleanly | Use parallel subagents | Shorter wall-clock time |
| Infrastructure may fail | Checkpoint after every step | Enables idempotent resumption |
| Budget is fixed | Set token and time caps | Prevents cost runaway |
Idempotent tool design is a decisive recommendation: if a resumed agent repeats a step, the repetition should have no harmful side effect. Agent observability, meaning structured traces of each decision, makes post-incident analysis possible.
Put simply
Most AI assistants handle a request in one sitting and then forget it. A long-running agent keeps working on a large job over many hours or days, like a contractor renovating a house over several weeks.
Because the AI cannot hold everything in its head at once, it keeps a written record of the plan and progress. When it stops and starts again, it reads its own notes, sees what is done and continues. People check in at key moments and approve the big decisions.
In practice
A software team asks a coding agent to migrate a codebase of about 300,000 lines from an old web framework to a newer one. The work spans roughly three days of agent time and thousands of file edits, far beyond any single context window.
The orchestrating agent first writes a migration plan with 140 module-level tasks into a tracking file. For each module, it starts a subagent that edits the code, runs the relevant tests and records the outcome. After each task, the state is checkpointed, so when a cloud worker restarts overnight, the agent resumes at task 87 instead of starting over.
Engineers review a daily progress summary and approve merges in batches. At the end, all 140 tasks pass their test suites, and the team spends its time reviewing difficult edge cases rather than performing repetitive edits by hand.