Long-Running Background Agents in Production SaaS
Persistent infrastructure, not better prompts, fixes long-running agents in production.

Long-running background agents in production SaaS need persistent infrastructure as well as better models. Compared with a stateless serverless-function design, persistent agent infrastructure preserves task state, execution environments, and recovery points across waits and failures. An agent’s ability to resume safely after an invocation ends matters more than its ability to finish a demonstration within one.
Why long-running background agents fail in production — and why the model is rarely the culprit
When a well-prompted agent fails silently in production, developers go back to check its reasoning, even when the fault is elsewhere. Memory conflicts, orchestration bottlenecks, cascading failures, retry loops, and unstable tool execution are architectural symptoms. Prompt debugging targets the wrong layer in these cases. The system was designed as a bounded SaaS feature, but its job requires autonomous work across changing conditions.
Fudan University's Pera paper (August 2026) makes a structural argument for a perception-centered architecture that distinguishes bounded task-solvers from long-lived service systems. A bounded execution ends with its task. A persistent service must also preserve the conditions needed for future work, making state, coordination, governance, and recovery part of its design.
Why do stateless, monolithic agents fail on serverless infrastructure?
A monolithic agent is easy to prototype because reasoning, routing, and execution collapse into one LLM call. In an in-context-only design, that call's context window also becomes its only memory, serving as working memory. When the session ends and the context window is flushed, the next invocation has no retained working state unless the system saved it externally.
Timeouts cause the same problem when progress is saved only inside the execution that was cut short. The next invocation either needs a costly re-briefing or goes on without the information it needs to stay consistent. A code-generation agent illustrates the consequence clearly. If a correction to an architectural mistake never reaches durable storage, the agent can repeat that mistake next sprint.
Longer context windows allow more workflows to fit within one call, but they do not change this persistence boundary. Loading entire conversation histories at scale is also cost-prohibitive. Capacity does not make volatile memory durable. For buyers comparing persistent infrastructure with serverless functions such as Lambda or Cloud Run, the relevant criteria are retained state, resumable execution, and continuity across invocations.
The Tencent/Tsinghua “Chatbot to Digital Colleague” paper (July 2026) distinguishes episodic tool use from persistent work requiring state persistence, reusable procedures, task closure, and experience reuse. That distinction locates the limitation in the design. A stateless function can participate in a larger system, but an invocation alone does not supply those capabilities.
The memory architecture that persistent agents actually need across four tiers

The first memory tier answers what the agent needs for the immediate reasoning step. In-context working memory holds that active material, but it does not keep it across sessions. The second tier answers where the task stopped. Session or episodic state belongs in a structured external store, such as Redis, keyed to the agent's session or user ID, written after each turn, and read at the next turn's start.
The third tier holds what the agent already knows from past interactions. Summarized memory artifacts in a vector database allow semantic retrieval without reloading every conversation. A customer-facing agent can remember forty prior conversations this way. The fourth tier holds how the agent did this kind of task well before, in a structured procedural store that links task types to successful execution templates.
These tiers retain different kinds of knowledge. Outcome feedback can refine procedural memory, while session state preserves unfinished work and semantic memory preserves relevant history. A dedicated Memory Manager agent uses unified retrieval to get information from all four tiers.
Retention also needs explicit infrastructure support. Session data must be encrypted at rest and purged on configurable TTL to support GDPR data minimization. GDPR Article 17 creates an erasure requirement for long-term memory. Each vector entry needs a user_id and timestamp so deletion can be completed within the legally required window following a valid request.
Why multi-agent orchestration with specialized roles is the right structural response to long-horizon work
Persistent memory fixes continuity, but it does not untangle a monolith's responsibilities. Decomposition assigns planning, research, execution, review, and memory management to specialized sub-agents under a supervisor that retains the full task picture. Each role has a bounded responsibility. A retrieval failure need not bring down the planner, and one sub-agent can be upgraded without changing the others.
In production, this pattern creates temporary sub-agents for each job, each with its own prompt, context, and tool set. On completion, the sub-agent returns a summary, and the orchestrator advances the plan. This structure also supports asynchronous background execution. Queue events, including a CRM change, a GitHub action, or a timer, can trigger work without a synchronous user prompt.
Pera extends the orchestrator's responsibility beyond task routing to lifecycle control, with the agent perceiving changes in itself and its environment and adapting service procedures. The supervisor is itself a failure surface, however. Its plan state must persist, and its authority needs constraints. MCP (Model Context Protocol) for tool communication and A2A (Agent-to-Agent protocol) for inter-agent communication provide open protocol choices whose early adoption avoids costly retrofitting of custom communication layers.
Runtime governance as a structural layer, not an afterthought
An orchestrator that can delegate work over hours also needs enforceable limits on what its delegates can do. The critical risk boundary is plugin and skill execution, where a proposed action becomes an external effect. Prompt-level guardrails do not enforce that boundary. Policy must work beneath the model, before an action reaches a tool or service.
The Microsoft Agent Governance Toolkit takes the position that governance decisions are enforced deterministically before actions reach the wire. Privilege rings apply that principle to individual roles. An executor that only needs to read data should not receive credentials that also allow deletion.
Even constrained autonomous systems can fail unpredictably, so production governance requires kill switches and rollback systems. Human checkpoints provide another boundary at defined confidence or risk thresholds. Autonomy does not require eliminating human supervision. When a decision exceeds the allowed threshold, the system can suspend execution for approval, making governance a direct requirement for the runtime's pause-and-resume design.
Isolation infrastructure — why micro-VMs are the right compute primitive for multi-tenant agent fleets
Policy limits what actions are allowed, while isolation limits the damage an execution environment can cause. Agents that run arbitrary code and external tools alongside other tenants need a kernel boundary, hardware-level separation, and room to change their own environments. Container-level isolation is insufficient for this workload class. Maritime, a cloud infrastructure platform that hosts each AI agent inside its own dedicated Firecracker micro-VM, is built around precisely this requirement, which is why agents that outgrow serverless functions tend to need that kind of persistent, per-agent compute boundary. Firecracker provides KVM-based isolation, fast boot, and minimal memory overhead, making VM-per-session execution viable for production SaaS.
The one-session-one-micro-VM model gives each session its own execution environment. Compromising one VMM process does not affect the others through a shared VM-management daemon, because Firecracker has no such daemon. Amazon Bedrock AgentCore Runtime uses this model for isolated AI agent tools. The boundary lets an agent install packages, run browser sessions, and break and rebuild its environment without sharing a kernel with other tenants.
The distinction is not simply serverless versus virtual machines. AWS Lambda MicroVMs, announced June 22, 2026, combines VM-level isolation, near-instant launch and resume, and state persistence across interactions using Firecracker. The relevant comparison is the runtime contract. A service that provides persistent, isolated execution differs architecturally from a stateless function, even when both sit within a serverless offering.
That isolation comes with operational constraints. Firecracker requires Linux hosts with KVM enabled, affecting local development on macOS and Windows. Multi-tenant deployments must launch it through the jailer, which applies seccomp filters, drops privileges, and chroots the micro-VM. Lighter sandboxes may suit very high-density fleets where startup time dominates cost, but their isolation guarantee is weaker. For customer-facing agents executing code from untrusted inputs, the Firecracker model is the indicated tradeoff.
Snapshot-restore scheduling as the answer to the idle compute problem
VM-per-agent deployment becomes expensive when every waiting agent keeps compute allocated. Background agents spend most of their time idle, while warm pools bill continuously and retain resident RAM and a vCPU regardless of use. The runtime writes full memory state to durable storage and terminates the process, replacing idle compute cost with storage cost.
On the next wake event, the runtime restores the snapshot and continues execution from where it stopped. Copy-on-write memory mapping improves the economics of restoring agents from a common base template. Shared template pages use one physical copy. Private pages are allocated only when a guest writes to them, rather than allocating an entirely separate copy upfront.
Durable execution works the same way when an agent waits for tool responses, human approvals, or timers. Google's Agent Substrate, announced May 2026, assigns an active actor to an available worker pod and transfers its state. When the actor goes idle, the system snapshots state and frees the worker for another actor. Its activate/deactivate cycle is designed to complete in under a second.
Wake latency is part of the economic design. A restore that takes several seconds can disrupt interactive workflows and create cascading timeout risks in multi-agent pipelines. Sub-second wake lets the system free up compute without those delays. For per-user SaaS agents, this connects fleet affordability directly to the scheduler's ability to stop and resume work promptly.

Checkpoint and recovery design for agents that must complete, not just run
Snapshot-restore also helps work survive failures, but an unexpected failure needs more care than planned sleep. Network timeouts, upstream API failures, host preemption, and memory pressure can stop work before its next planned pause. Recovery therefore requires checkpoints throughout the task. Without them, work that runs for hours can finish only if nothing goes wrong along the way.
Saving only at task boundaries leaves too much progress exposed, while saving after every tool call is expensive. Natural orchestration handoffs provide useful recovery points. After a sub-agent completes and returns its summary, the supervisor can preserve that progress before advancing to the next stage.
If a payment or notification completed before an interruption, replaying the corresponding tool call can repeat the effect. Non-idempotent operations need deduplication keys in durable state. Any sub-agent or tool call eligible for retry must either be safe to repeat or use that durable record to prevent duplicate writes, payments, and notifications.
Approval checkpoints fit the same recovery structure. The runtime preserves execution state, the human acts asynchronously, and the agent resumes without repeating the preceding steps. Operators also need visibility into partial progress. Logs, traces, and replay systems reveal where execution stopped and whether partial actions require rollback before work resumes.
What a production-ready background agent stack looks like end to end
These decisions compose into layers whose boundaries must agree. The execution environment provides VM-isolated compute, persistent disk, and snapshot-restore scheduling with sub-second wake. Memory then preserves meaning across that execution lifecycle. Its session and long-term tiers must survive sleep, redeployment, and host migration, while working and procedural memory support immediate reasoning and reusable methods.
Above memory, specialized sub-agents do jobs with set limits under a supervisor that has a durable task plan. Sub-agents can stay stateless within their jobs because the supervisor keeps track of the work across them. Governance constrains what those jobs may execute. Deterministic policy enforcement, role-specific privileges, kill switches, rollback, and human checkpoints bound the authority that orchestration distributes.
Observability spans the entire orchestration graph, including individual model calls. Structured logs, traces, replay, and workflow evaluation probes support recovery and real-time auditability. The infrastructure layer can be a deployable primitive. A platform with persistent VM-isolated environments, persistent disk, snapshot-restore scheduling, and sub-second wake lets developers write agent logic without having to rebuild the system that runs it.
A runtime must preserve the environment and task plan, release compute during waits, and resume without duplicating external effects. A successful model call establishes none of those properties. Production readiness begins when the system can complete the work despite the boundaries between its calls.


