ClawVM: Curing LLM Agent “Amnesia” by Adopting OS Virtual Memory
AI agents driven by Large Language Models (LLMs) face a core bottleneck when handling complex, long-running tasks: the limited context window. This “working memory” limitation leads to frequent “amnesia,” making it unreliable for agents to maintain task state. To solve this problem, independent researcher Mofasshara Rafique and Laurent Bindschaedler from the Max Planck Institute for Software Systems have co-authored a paper proposing a framework called ClawVM that manages a virtual memory system, applying the wisdom of classical computer science to the field of AI engineering.
The “Memory Dilemma” of AI Agents and the Limitations of Existing Solutions
When an AI agent executes a task, its context window must accommodate various types of information, such as system instructions, task plans, conversation history, and tool call results. As interactions increase, the context window fills up quickly. Current mainstream agent frameworks, like OpenClaw or various RAG (Retrieval-Augmented Generation) systems, typically use “best-effort” strategies to manage memory overflow, which mainly include:
- Direct Discard: Removing the earliest conversation records based on a first-in, first-out (FIFO) principle.
- Summarization: Using the LLM itself to summarize long texts, trading information fidelity for space.
- External Retrieval: Storing information in external storage like vector databases and recalling it via semantic search when needed.
The paper points out that these strategies lack deterministic guarantees, leading to three types of severe “policy-controllable faults”: critical instructions (e.g., “the user prohibits scheduling meetings on Tuesdays”) are lost during summarization; the agent fails to persist its intermediate state before a reset or memory cleanup; and the system does not provide a clear error after memory loss, causing the agent to repeatedly call tools or produce incorrect outputs.
Returning to the Classics: ClawVM Introduces OS Virtual Memory Design
Researchers argue that instead of patching the problem at the application layer with prompt engineering, it should be solved at the system level. The core idea is to treat the agent harness as an AI’s “Operating System” (OS) and borrow the “virtual memory” technique invented decades ago by operating systems to address the shortage of physical memory (RAM).
ClawVM (Claw Virtual Machine) was born, with its full title being ClawVM: Harness-Managed Virtual Memory for Stateful Tool-Using LLM Agents. It acts as a middleware layer between the agent and the large model, responsible for deterministic, contract-based management of the context window. ClawVM aims to establish a set of hard rules to ensure that critical information is not lost, state persistence is enforced by the harness, memory operation failures are traceable, and it is cost-aware.
The Three Core Technical Mechanisms of ClawVM
To achieve these goals, ClawVM is built on three interconnected technical pillars that form the foundation of its efficient operation.
1. Typed Pages & Invariants
ClawVM abandons the practice of treating all memory as undifferentiated text. Instead, it divides memory into six types of “pages,” including system instructions (Bootstrap), task plans (Plan), and tool call evidence (Evidence). Each type is assigned a “minimum-fidelity invariant” contract. For example, the contract for system instructions is that their complete structured rules must be preserved, whereas the contract for tool evidence allows it to be demoted to a simple pointer, as the original data can be re-fetched. This design provides a clear basis for prioritizing memory management.
2. Multi-resolution Residency and Dynamic Upgrades
This is ClawVM’s most innovative part. It defines four resolution states for each memory page, enabling a smooth degradation from “lossless” to “low-fidelity”:
- Full: The verbatim original text.
- Compressed: A condensed text with redundancies removed by algorithms like LLMLingua-2.
- Structured: A key-value summary retaining only critical fields.
- Pointer: Retaining only a reference identifier in the context, such as
<span leaf="">[Evidence_#123]</span>.
Before each generation request, ClawVM executes an optimization algorithm similar to the “knapsack problem.” First, it places all necessary pages into the context at their minimum fidelity. Then, using the remaining token budget, it selectively “upgrades” high-value pages from low to high resolution based on a “utility scoring system” (which considers factors like recency and re-fetch cost). The entire process is executed efficiently by the harness and does not consume LLM computation resources.
3. Validated Writeback Protocol
To prevent state loss, ClawVM implements a mandatory three-stage persistence protocol. This protocol is triggered at any lifecycle point that could lead to memory loss (e.g., before memory compression, at the end of a task):
- Intercept and Stage: The harness first intercepts the eviction operation and packages the data to be persisted.
- Validate: It performs a validity check on the staged data to prevent destructive overwrites and other errors.
- Commit: Only after successful validation is the data officially written to persistent storage (e.g., a database).
This mechanism ensures a “guaranteed save before eviction,” fundamentally solving the problem of “memory gaps” caused by unexpected system resets or memory management operations.
Experimental Results: A Leap from Probabilistic Errors to Zero Faults

The research team compared ClawVM against five other strategies, including pure retrieval and community best practices, through synthetic stress tests and real-world “programmer assistant” task replays. The results showed that in terms of “policy-controllable faults” caused by poor memory management:
- The pure retrieval strategy produced an average of 67.8 faults per task.
- A best-practice hybrid strategy optimized by human experts still faulted under tight token budgets, reaching up to 26 faults.
- ClawVM achieved 0 such faults in all test scenarios, matching the performance of a theoretical optimum (Oracle) with future information.
Moreover, ClawVM’s performance overhead is extremely low. The median additional computation latency it introduces is less than 50 microseconds, with memory usage below 83 KB, having a negligible impact on the overall response time of the LLM. This demonstrates that ClawVM provides strong reliability while maintaining extremely high operational efficiency.
Conclusion and Outlook
The ClawVM research marks a significant paradigm shift in AI agent development: moving from relying on the unpredictable art of prompt engineering to hope models don’t forget, to building deterministic memory guarantees through rigorous systems engineering. It proves that applying classic computer science principles to AI system design is an effective path to solving current engineering challenges.
This work provides a solid blueprint for the memory management module of future “Agent Operating Systems” (Agent OS). As this foundational infrastructure matures, future AI agents will be able to execute long-term, complex tasks more reliably, truly becoming intelligent partners capable of deep and sustained collaboration with humans.