Long-running agent

Also known as: long-horizon agent

On this page 7

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.

ComponentRoleTypical implementation
Durable state storeKeeps plan, progress and artifactsFiles, database rows, workflow engine
CheckpointingSaves resumable snapshotsPeriodic or per-step state writes
Context compactionShrinks history to fit the windowSummaries, pruning of tool outputs
Long-term memoryRecalls facts across sessionsNotes files, vector store, knowledge base
Scheduler or triggerStarts and resumes workCron jobs, events, queue workers
Progress logShows humans what has happenedStructured trace, status reports
Components of a long-running agent

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.

ConceptDefining traitRelation to long-running agents
Conversational assistantResponds turn by turnUsually short-lived, no durable plan
Background agentRuns without the user watchingOften long-running, but not always
Agentic workflowPredefined steps with model callsCan be long-running with fixed structure
Multi-agent systemSeveral cooperating agentsMay split long tasks among subagents
Plan-and-execute agentSeparates planning from executionCommon design for long horizons
Comparison with related concepts

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.

StrategyBenefitRisk
Rolling summarizationKeeps context compactLoses details that later prove relevant
Structured notes fileExplicit, inspectable memoryDepends on disciplined updates
Retrieval from memory storeScales to large historiesMay recall the wrong fact
Subagent delegationFresh context per subtaskCoordination and handoff overhead
Session restart from checkpointClears accumulated noiseRequires complete state capture
Context strategies and their trade-offs

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.

SituationRecommended choiceReason
Task has testable outputLet the agent self-verifyTests catch errors early
Actions are irreversibleRequire human approvalLimits costly mistakes
Work splits cleanlyUse parallel subagentsShorter wall-clock time
Infrastructure may failCheckpoint after every stepEnables idempotent resumption
Budget is fixedSet token and time capsPrevents cost runaway
Design decisions for long tasks

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.