上下文记忆虚拟化:基于DAG的状态管理和结构无损修剪用于LLM代理
Contextual Memory Virtualisation: DAG-Based State Management and Structurally Lossless Trimming for LLM Agents
AI总结:
上下文记忆虚拟化通过DAG结构管理和无损修剪技术,提升LLM代理在长期推理任务中的上下文重用效率和经济性。
摘要:
当大型语言模型参与长期推理任务时,它们会在上下文窗口内积累显著的状态——建筑映射、权衡决策、代码库惯例。当会话达到上下文限制并经历有损压缩时,这种理解会丢失。我们提出了上下文记忆虚拟化(CMV),一个将积累的LLM理解视为受版本控制的状态的系统。借鉴操作系统虚拟内存,CMV将会话历史建模为有向无环图(DAG),并定义了正式的快照、分支和修剪原语,以在独立并行会话中实现上下文重用。我们引入了一种三步的结构无损修剪算法,该算法在保留每条用户消息和助手响应原文的同时,通过剥离机械冗余如原始工具输出、base64图像和元数据,将令牌数量减少平均20%,对于具有显著冗余的会话,最多减少86%。在76个真实世界编码会话的单用户案例研究评估中,修剪在提示缓存下仍具有经济可行性,混合工具使用会话的收益最强,平均减少39%,在10次回合内达到盈亏平衡。参考实现可在https://github.com/CosmoNaught/claude-code-cmv上获得。
英文摘要:
As large language models engage in extended reasoning tasks, they accumulate significant state -- architectural mappings, trade-off decisions, codebase conventions -- within the context window. This understanding is lost when sessions reach context limits and undergo lossy compaction. We propose Contextual Memory Virtualisation (CMV), a system that treats accumulated LLM understanding as version-controlled state. Borrowing from operating system virtual memory, CMV models session history as a Directed Acyclic Graph (DAG) with formally defined snapshot, branch, and trim primitives that enable context reuse across independent parallel sessions. We introduce a three-pass structurally lossless trimming algorithm that preserves every user message and assistant response verbatim while reducing token counts by a mean of 20% and up to 86% for sessions with significant overhead by stripping mechanical bloat such as raw tool outputs, base64 images, and metadata. A single-user case-study evaluation across 76 real-world coding sessions demonstrates that trimming remains economically viable under prompt caching, with the strongest gains in mixed tool-use sessions, which average 39% reduction and reach break-even within 10 turns. A reference implementation is available at https://github.com/IngressionLabs/contextual-memory-virtualisation.
机构、总结、中文摘要均由AI分析而来,可能存在错误,请以论文正文为准。