What Memory Continuity and Process Longevity Actually Cost Across Compute Models
Serverless saves on idle compute, but persistent VMs keep agents cheaper.

Persistent AI agent infrastructure and serverless functions place the cost of continuity in different parts of the bill. Serverless favors infrequent, bounded work by avoiding idle compute, but repeated context reloads and warm-instance charges can erode that advantage. Persistent VMs with snapshot-restore keep process state while freeing idle compute, so they are a better fit for agents whose memory, execution environment, and isolation must last between sessions.
Why persistence has a price tag that most cost estimates miss
An agent doing nothing can dominate its infrastructure bill. The task has finished, but its allocated vCPU and RAM remain billable because the environment stays alive for the next interaction. For agents that work in brief bursts, most of the bill can come from resources held between tasks. Keeping the agent ready is not free.
Shutting it down creates the opposing bill. The next session must recover prior context, spending inference tokens to reconstruct what the agent already knew. Persistence therefore creates a tension between the cost of remembering and the cost of forgetting. Treating infrastructure and inference as separate budgets obscures this trade because the compute model determines both.
The four actual cost drivers, and why only two of them appear on most invoices
Idle compute is the cost of allocated resources that perform no useful work. An agent can be alive without being active. General-purpose cloud workloads already have low average CPU utilization, and utilization can fall further when agent sandboxes work in short bursts and then go dormant. For a fleet with intermittent activity, this can become the dominant infrastructure expense.
Cold-start avoidance over-provisioning is the cost of keeping capacity warm so that a request does not wait for initialization. Readiness becomes a resource commitment of its own. Warm instances are billed even when they serve no requests, while minimum billing increments can charge for more time than a short task actually uses.
Context-reload overhead is the inference cost of re-establishing state. Tool calls and retries already use more tokens in agentic flows, and loading past decisions again and again adds to the bill. Infrastructure invoices do not expose this cost, although inference invoices record the resulting token usage.
Storage pays for semantic recall, exact facts, and, where used, saved VM state. A dormant agent still needs its retained memory, so storage grows with the number of distinct agents even when execution stays flat. Most cloud invoices expose compute and storage directly, while readiness costs blend into compute charges and context reloads appear elsewhere.
What the three-layer memory architecture actually costs to run
In-context memory is the working layer available during inference. Every loaded token is billed on each call. This layer is fast but ephemeral, so a later session must reload it if the session state has disappeared. For small fleets with limited context, loading the full history can compete economically with operating a managed memory service. Larger context windows make that choice possible, but frequent calls and many concurrent users multiply its token cost.
A vector store holds semantic long-term memory as embeddings of past sessions and decisions. Retrieval can select only the history needed for the task. Its costs include embedding API calls at ingestion, index storage, and retrieval latency, typically tens to a few hundred milliseconds. Managed storage can be modest for a small deployment but grows across many agent identities. Retrieval remains approximate, so its lower reload cost does not guarantee that the right context reaches the model.
Structured files or databases provide exact long-term memory for user IDs, configuration values, and decision logs. Semantic similarity is not a substitute for exact retrieval. Storage costs are low and grow slowly, but keeping the schema up to date and maintaining tenant isolation take work. The compute model determines how these layers are accessed between sessions. Stateless execution reconstructs working context from external stores, whereas a persistent VM can retain loaded state, although tokens supplied to subsequent inference calls remain billable.
What are the limitations of running AI agents on serverless functions?
Stateless execution exchanges idle compute for per-invocation reconstruction. At zero load, there is no idle execution bill. The operational model is simple because each invocation performs bounded work. In a pure function-per-call design, however, the runtime has no prior state to resume, so the agent must recover the memory it needs from external services before acting.
That reconstruction becomes expensive when one task requires repeated loops. Each iteration may reload context before making progress. Tool calls, retries, and retrieved history then add to both the inference tokens used and the time spent on execution. At scale, inference cost per task can exceed infrastructure cost by a wide margin. Preserving a running process requires more than externally stored memory.
Warm instances cut startup latency by keeping capacity ready to use. They also bring idle charges back into the model. Minimum billing increments can make sub-second tool calls disproportionately expensive when the billed duration exceeds useful execution. AWS Lambda SnapStart addressed initialization latency by resuming an encrypted Firecracker snapshot, cutting cold starts from several seconds to sub-second. Even with that improvement, invocation-based execution still lacks a way to keep agent state continuously.
Isolation is a separate consideration from startup speed. Agents on shared infrastructure can be exposed to other workloads running alongside them. For agents handling untrusted code or sensitive data, the execution boundary therefore belongs in the comparison. Serverless remains a strong option for bounded work, but long-running agents encounter a mismatch when their design assumes process continuity that their execution model does not provide.
What persistent VM-based agents cost — and why snapshot-restore changes the idle-compute equation
With snapshot-restore, the bill shifts from idle execution to storage for the saved state. The agent need not keep consuming allocated compute. When it becomes dormant, its filesystem, memory, and running processes are snapshotted, and its vCPU and RAM allocations are released. This is perpetual scale-to-zero, with state preserved, rather than ephemeral scale-to-zero, with state destroyed. Resume can take tens to low hundreds of milliseconds because the saved process state is already there.
That preservation changes host density as well as latency. Dormant agents no longer occupy active compute allocations. Snapshot-and-copy-on-write lets a host support many more agent identities than naive peak-sized allocation would allow, because only active sessions require execution resources. The host still needs capacity for concurrent work, but it does not need to reserve each agent’s requested resources throughout every idle interval.
Firecracker micro-VMs boot in roughly 125ms and use less than 5 MiB of memory overhead per VM. Each micro-VM has its own VMM process and kernel. This provides a stronger boundary for package installation, browsers, and untrusted code than a shared-kernel environment, without making isolation an absolute security guarantee. Google described Agent Compute Engine on October 22, 2026, with a microVM per agent session, copy-on-write cloning from warm snapshots, and checkpointing after a tool call finishes and the sandbox enters an idle state. AWS announced Lambda MicroVMs on June 22, 2026, with dedicated Firecracker-based environments, preserved in-session state, and direct lifecycle control.
For mostly dormant fleets, storage can consequently dominate per-agent cost. Active work still incurs compute and inference charges. The saving comes from removing continuous resource allocation between sessions.
Where the two models actually cross over: utilization thresholds and fleet size
No single utilization percentage establishes the crossover for every deployment. The threshold depends on the costs being compared. At low sustained utilization, serverless per-invocation pricing can be cheaper than reserving or leasing persistent VMs because there is too little work to amortize fixed capacity. As sustained slot utilization rises, avoided reloads and better use of host capacity can outweigh that fixed expense.
Snapshot-restore makes fleet utilization more important than any one agent’s activity. A dormant identity consumes storage and leaves its slot available. Daily peaks still need compute, but that capacity can serve different agents. The relevant comparison is therefore not an always-running VM against a single function invocation. It is the cost of supporting the fleet’s active work, retained state, and readiness requirements over time.
Fleet size also changes the value of operational simplicity. A solo developer may gain little from managing VMs. At tens of agents, developer time can outweigh modest infrastructure savings, while a per-user agent product needs dormant identities to remain inexpensive enough to fit within product pricing. Snapshot-restore addresses that requirement without repeatedly discarding process state. Externalized memory is still an option when processes have no need to stay alive between sessions.
Task duration and isolation can override the utilization calculation. Boot overhead is proportionally large for sub-second work. Serverless or containers can therefore be more efficient for short, bounded tasks, while coding, data analysis, and browser agents may require VM isolation because of what they execute. In those cases, the comparison must account for both security exposure and execution cost.
How MCP's transport change and Google's memory billing signal where infrastructure costs are heading
The July 28, 2026 MCP specification made Streamable HTTP stateless by removing protocol-level sessions and the Mcp-Session-Id header. MCP servers could therefore use a plain round-robin load balancer in place of sticky routing and session-aware balancing. This separates agent state, held in a VM or memory store, from the transport used to reach tools. A2A remains the orchestration layer between agents, while MCP supplies tool access.
Anthropic shipped “Dreaming” on May 6, 2026, as an asynchronous hippocampal-replay process that reorganizes memory between sessions. Consolidation becomes background work rather than synchronous waiting. Its cost moves from the immediate response path into background compute. That distinction reinforces the need to account for memory operations separately from the invocation that ultimately uses their results.
Google Vertex AI began charging for memory as a billable resource. Memory management now has an explicit purchasing boundary. Together with the dated microVM announcements, this shows memory and process isolation becoming infrastructure offerings. These events establish that durable state, execution isolation, and stateless tool transport can be priced and operated as separate parts of an agent system, while leaving future prices and the success of any one model uncertain.
A practical cost-reasoning framework for developers choosing a compute model
Price comparison comes after the required execution boundary. Under this framework, agents that run untrusted code, run browsers, install packages, or handle data from multiple users should use VM isolation. For trusted, bounded work on behalf of a single authenticated user, without code execution, containers or serverless may be sufficient and cheaper at low utilization.
Rare, short bursts favor serverless per-invocation pricing. In that case, cold starts and context reloads are costs to accept, with no need to pay for warm capacity to remove them. Snapshot-restore is a better fit for work that is substantial but comes at uneven times, while high sustained utilization makes VMs that run continuously a better fit because their fixed cost is spread across more tasks.
Fleet size then determines how much optimization is justified. Managed serverless or a small persistent VM cluster can both be reasonable when developer time outweighs the infrastructure difference. For a large fleet with one agent per user and a durable execution environment, snapshot-restore keeps dormant identities on the storage side of the ledger.
Finally, the dominant cost driver should determine the intervention. Idle compute calls for snapshot-restore that preserves state. When context must be rebuilt again and again, persistent memory and VM state preservation can help, while a vector store alone narrows the history retrieved but leaves the process unsaved. If storage dominates, retention policies and selective forgetting, supported by frameworks such as Mi-Memory, deserve review. If inference dominates, token usage per task and tiered model routing deserve attention before a compute migration, because changing the execution model will not remove tokens required for new reasoning.


