This article explains how to build long-running agents for production.
AI agents have entered the world of customer support and business reporting. These agents often work independently for long periods of time, without context drift.
If you are an AI engineer, you will find this article useful:
What Are Long-Running Agents
When To Use Long-Running Agents
Challenges With Long-Running Agents
Design Patterns for Long-Running Agents
It is based on research from Anthropic and AWS. All references are mentioned at the bottom of the article.
1. What are Long-Running Agents
A long-running agent is expected to complete tasks that span of hours, days or even weeks. The task definition may change along the way with new information added to the original task.
The long-running agent is expected to respond to new commands while managing context.
For example, a website builder agent has the workflow:
Accept initial website requirements.
create an initial draft of the website.
ask the user for feedback.
accept user changes and create a new version.
continue till the user is satisfied.

The agent creates new versions of the website based on user feedback and previous context.
They are suitable for complex tasks that can be solved with iterative improvement.
2. When To Use Long-Running Agents
For simple tasks, a basic agent with a RAG pipeline is sufficient. Use long-running agents when a task requires domain expertise, multiple iterations, and long-term memory.
Complex Multi-Version Task (Every version is an improvement on the previous)
User Feedback Is Actionable (Agent knows what to do with feedback)
Storing Previous States Is Simple (Context Management is straightforward)
Examples include content generation and editing, multi-week coding projects, and website design.
3. Challenges with Long-Running Agents
There are three major challenges with Long-Running Agents.
Massive Context WindowSince a long-running project can have hundreds of versions, our agent has two types of memory. Working memory:-- Long Term Memory: Compacted summary of all previous versions.-- Short Term Memory: Recent N versions of the project (Latest version with Previous Diff files)Persistent memory:-- Vector Database: Finds the most relevant data for a user query.-- Persistent Object Store: Stores project versions permanently.When working on the project, the agent can pull relevant versions from the object store and vector database. It manages its context window by summarising previous work and using the latest project version as the baseline.
Poor PlanningLong-Running Agents shouldn't attempt to complete complex tasks in one shot. To avoid this problem, we use two types of Agents.1. Planner-- decomposes the original task into sub-tasks-- assigns the tasks to executors-- evaluates results from executors-- decides when to stop2. Executor-- decides how to do a task* *-- call relevant tools to execute a task-- returns results to the planner

The Planner-Executor design pattern forces the agent to think in stages, improving the final result.
Getting Mired in Poor ResultsThis happens when a long-running agent locks onto an early, mediocre solution and never escapes it. Instead of fixing the core problem, the agent keeps making improvements on a bad foundation.To avoid this, define clear success criteria, use structured tests, and define constraints written in JSON.
The following table summarises the above points.
PROBLEM TYPE
SOLUTION
Massive Context Window(cannot store context in memory)
Split Context in Working Memory and Persistent Memory.
Poor Planning(misses features)
Planner + Executor Design Pattern: Plans tasks at a high level and executes them step by step.
Miring in Poor Results
(Description here)
Define clear Success Criteria + Tests + JSON constraints
Note: A multi-step agent isn't necessarily* a Long-Running Agent*. Solving a math problem has multiple steps, but it doesn't require an agent to work for weeks with user feedback.
The Planner-Executor Design Pattern helps agents scale reliably and cost-effectively.
Conclusion
As AI agents increasingly power long-running tasks, **reliability and cost-effectiveness **are essential.
Splitting information into long-term and short-term memory, along with two types of Agents (Planner + Executor),** **provides a practical foundation for building long-running agents in production.
To learn more about AI Agents and Context Engineering, start with the AI Engineering Course on our website.