Turning Interaction History into Execution State: A Runtime Layer for Long-Horizon Coding Agents

TL;DR

Ledger provides explicit execution state, boosting Pass@1 to 64.2% and reducing costs by 28.9% in long-horizon coding agents.

cs.SE 🔴 Advanced 2026-08-02 54 views
Zehao Wang Yisen Xu Chenglin Li Chao Peng Bram Adams Ahmed E. Hassan Tse-Hsun Chen
AI agents long-horizon reasoning execution state software engineering efficiency

Key Findings

Methodology

This paper introduces Ledger, a deterministic runtime layer that maintains an online execution ledger, transforming interaction history into an explicit, mechanically derivable execution state comprising observations, modifications, and attempted commands. Two paths—inform and govern—operate at each step: inform appends a compact state view to the prompt, ensuring the model has current context; govern evaluates proposed commands against the ledger, reusing valid results or flagging redundancies. The approach requires no additional language model calls and seamlessly integrates with unmodified agents. Extensive experiments on 500 SWE-bench instances demonstrate significant improvements: Pass@1 increases from 56.2% to 64.2% with GPT-5 mini, and from 75.8% to 81.0% with MiniMax M2.5, while total costs decrease by approximately 29-32%.

Key Results

  • Ledger consistently improves success rates across models, with the highest Pass@1 gain of 8.0 percentage points, and reduces total costs by up to 31.8%. Specifically, GPT-5 mini's cost drops by 28.9%, with an 11.7% reduction in model calls and a 24.2% decrease in redundant snippet re-reads. MiniMax M2.5 shows similar trends, with a 31.8% cost reduction and 35.1% fewer redundant reads.
  • Ablation studies reveal that governance primarily boosts resolution, while inform enhances efficiency. The combined use yields the best overall performance, confirming that explicit execution state management effectively addresses long-horizon challenges.
  • These results demonstrate that explicit, mechanically maintained execution states can significantly outperform traditional trajectory-based approaches, offering a scalable, model-agnostic solution to improve reliability and efficiency in AI coding agents.

Significance

This work addresses a fundamental bottleneck in long-horizon AI agents: the implicit, often inconsistent, understanding of current execution status. By explicitly tracking what has been observed, modified, and attempted, Ledger enables agents to avoid redundant work and act more reliably. This innovation has profound implications for automated software development, code repair, and AI-driven programming, where maintaining a clear, up-to-date execution context is critical. It bridges the gap between model reasoning and mechanical state management, paving the way for more robust, scalable AI systems capable of complex, multi-step tasks with minimal overhead. The approach's simplicity, requiring no additional model calls, makes it highly practical for deployment in real-world scenarios.

Technical Contribution

Ledger introduces a deterministic, mechanically maintained execution ledger that captures the agent’s interaction state through observation, modification, and command records. This contrasts with prior approaches relying on implicit history summaries or learned relevance models. The ledger enables two key paths—inform for context rendering and govern for command mediation—both derived directly from the ledger without model inference. This design ensures consistent, up-to-date state management, significantly reducing redundant actions and improving success rates. The method is model-agnostic, scalable, and compatible with various agent architectures, representing a substantial step forward in long-horizon reasoning and execution management.

Novelty

This paper pioneers the explicit, mechanically derivable execution state concept for long-horizon coding agents, diverging from traditional reliance on implicit history or learned relevance. The dual-path (inform and govern) framework operationalizes this state, allowing real-time, deterministic management of interaction facts. Unlike prior work that compresses or truncates history, Ledger maintains a precise, up-to-date record of observations, modifications, and attempted commands, directly addressing issues of stale information and redundant work. This approach introduces a new paradigm in AI agent design, emphasizing transparent, mechanical state tracking to enhance performance and reliability.

Limitations

  • Ledger’s reliance on command and observation records may face challenges in environments with highly dynamic or complex changes, where maintaining an accurate ledger becomes computationally expensive or error-prone.
  • In scenarios involving multiple agents or distributed systems, synchronization of execution states could introduce additional complexity.
  • The current implementation assumes relatively stable repositories; highly volatile environments might require further robustness enhancements.

Future Work

Future research will explore extending Ledger to multi-agent systems, integrating learning-based updates to the ledger, and applying the approach to broader domains such as robotics or multi-modal AI. Additionally, optimizing ledger update mechanisms for highly dynamic environments and investigating hybrid models combining mechanical state tracking with learned relevance metrics are promising directions. The goal is to develop more adaptive, scalable, and intelligent systems capable of managing complex, real-world tasks with minimal human intervention.

AI Executive Summary

Long-horizon coding agents have revolutionized automated software development, yet their effectiveness is hampered by the difficulty of managing extensive interaction histories. Traditional approaches often truncate or summarize past interactions, risking the loss of critical, current information. As a result, agents may act on stale data or unnecessarily repeat work, reducing success rates and increasing costs. Recognizing this challenge, the authors introduce Ledger, a deterministic runtime layer that explicitly maintains an execution state derived from the agent’s interactions.

Ledger operates through two complementary paths: inform, which renders a compact, current view of the execution state into the prompt before each action, and govern, which evaluates proposed commands against this state to prevent redundant or unnecessary execution. This design ensures that the agent always has access to an up-to-date, mechanically derived understanding of what has been observed, modified, and attempted, without requiring additional language model calls. The approach is model-agnostic and seamlessly integrates with existing agents.

Extensive experiments on 500 SWE-bench instances demonstrate Ledger’s substantial benefits. With GPT-5 mini, Pass@1 improves from 56.2% to 64.2%, while MiniMax M2.5 sees an increase from 75.8% to 81.0%. Costs are reduced by nearly 30%, with model calls and redundant reads decreasing significantly. Ablation studies confirm that governance primarily boosts resolution, while inform enhances efficiency, with their combination yielding the best overall results.

This work marks a significant step toward more reliable, efficient, and interpretable long-horizon AI agents. By explicitly tracking execution states mechanically, Ledger addresses a core limitation of current systems, enabling scalable deployment in complex, real-world tasks. Its simplicity and effectiveness suggest broad applicability across AI-driven software engineering, automation, and beyond, setting a new standard for state management in intelligent agents.

Deep Analysis

Background

近年来,随着大型语言模型(如GPT系列、Claude、PaLM等)在代码理解与生成中的应用逐步深入,长时程交互管理成为关键难题。传统方法多采用截断、摘要或学习 relevance 模型,试图缩减上下文长度以应对模型输入限制,但难以保证信息的完整性与实时性。Wang等提出的交互摘要技术改善了部分性能,但仍未解决状态一致性和信息滞后的问题。随着模型规模和任务复杂度的提升,如何机械、实时、透明地维护交互状态,成为研究热点。此前的研究多关注模型推理能力,缺乏对交互事实的机械管理机制,导致重复劳动和信息滞后成为瓶颈。

Core Problem

长时程编码代理在多轮交互中难以准确追踪当前的执行状态,导致重复工作和信息过时。现有方案依赖历史摘要或模型推理,存在信息丢失、状态不一致和效率低下的问题。尤其在软件修复、代码生成等场景中,代理需要持续更新和利用交互事实,但缺乏一种机械、实时、透明的状态管理机制,限制了其性能和可靠性。如何在不增加模型调用的情况下,机械化维护和利用交互状态,成为核心难题。这关系到系统的成功率、效率和可解释性,亟待创新解决方案。

Innovation

Ledger的创新点在于引入机械可推导的执行状态账本,区别于传统的隐式历史或学习模型 relevance 的方法。它通过观察、修改和命令三类记录,机械反映代理的实际交互状态,确保状态的实时性和准确性。两个路径——inform(状态渲染)和govern(命令评估)——协同工作:前者在每次行动前,将当前状态渲染到prompt中,确保模型理解最新信息;后者在命令执行前,评估其是否已在账本中存在有效结果,避免重复执行。这种设计无需额外模型调用,兼容多种代理架构,显著提升效率和成功率,突破了传统依赖历史摘要的局限。

Methodology

  • �� 交互历史:存储代理的所有操作和观察,形成完整轨迹。
  • �� 账本维护:实时更新观察、修改和命令记录,确保状态一致。
  • �� inform路径:在每次行动前,将当前状态渲染成紧凑视图(Render),加入prompt。
  • �� govern路径:在命令执行前,利用账本(Govern)评估命令是否已在有效状态中,避免重复。
  • �� 结果应用:根据评估,决定执行、复用或提示,更新交互历史。
  • �� 无需模型调用:所有状态机械维护,兼容多模型架构。
  • �� 实验验证:在500实例中测试,比较不同模型和方法的性能提升。

Experiments

采用SWE-bench验证集,使用mini-swe-agent和OpenAI Codex两种代理架构,评估指标包括Pass@1、总成本、模型调用次数和重复读取数。对比基线模型和Ledger增强模型,进行ablation分析以区分治理(govern)和信息(inform)路径的贡献。超参数包括模型类型(GPT-5 mini、MiniMax M2.5)和任务复杂度。实验还分析了重复读取和调用次数的变化,验证效率提升的机制。统计学检验确保结果显著,验证Ledger在不同场景中的普适性。

Results

Ledger在所有实例中均显著提升成功率,Pass@1最高提升8.0个百分点,成本降低最高达31.8%。GPT-5 mini模型成本由23.60美元降至16.78美元,减少28.9%,调用次数减少11.7%,重复读取减少24.2%;MiniMax M2.5模型成本由34.31美元降至23.39美元,减少31.8%,调用减少31.9%,重复读取减少35.1%。ablation显示治理路径主要提升解决率,信息路径优化效率,两者结合效果最佳。这些数据验证了Ledger在长时程推理中的优越性。

Applications

该机制适用于自动化软件修复、代码生成、持续集成等场景,特别是在多轮交互和状态持续更新的复杂任务中。通过机械化维护执行状态,减少重复劳动,提高成功率,降低成本。未来可结合多模态数据和学习机制,扩展到机器人、自动驾驶等领域,推动AI在工业中的智能化应用。其透明、机械的状态管理方式,为复杂系统的可靠性和可解释性提供新思路。

Limitations & Outlook

Ledger依赖于命令和观察的机械记录,在高频变更或复杂操作中可能出现状态滞后或误判,影响效果。极端动态环境下,账本同步和维护的复杂性增加,可能带来性能瓶颈。多代理场景中,状态同步和一致性问题尚未解决。未来需优化账本的鲁棒性和扩展性,增强系统适应性。

Plain Language Accessible to non-experts

想象你在厨房里做饭,每次用完锅碗瓢盆都会记在一本账本上:哪个锅用过、洗干净了没有、还剩什么食材。每次你准备下一步时,可以翻开账本,看看哪些东西还能用,哪些需要重新准备。这样,你就不用反复洗锅或买新食材,也不会忘记自己做过什么。Ledger就像这个账本,帮AI记住它做过的事:它看过的文件、改过的代码、试过的方案。每次行动前,它会先看看账本,确认哪些工作已经完成,哪些还需要做。这样,AI就不会重复之前的工作,也能更快完成任务。这个机制让AI变得像个聪明的厨师,知道自己做过什么,还剩什么可以用,效率大大提高,出错也少了。

Abstract

Long-horizon coding agents accumulate hundreds of actions and observations in their trajectories, yet nothing in this record indicates which observations still describe the repository as it currently stands. Before every decision, the model must implicitly infer the execution status from raw history, and when this inference falls short, the agent acts on outdated file contents or re-executes work whose results are still valid. We propose Ledger, a deterministic runtime layer that distills an agent's completed interactions into an explicit execution state: what has been observed, what has been modified, and what has been attempted. Ledger keeps this state in an online execution ledger and applies it at two boundaries of every step. Before the model acts, an inform path appends a compact runtime state view to the prompt; before a proposed command runs, a govern path checks it against the ledger, returning still-valid earlier results in place of re-execution and flagging likely-redundant repetition. The layer adds no language-model calls and wraps an otherwise unmodified agent. Across all 500 SWE-bench Verified instances, Ledger raises Pass@1 from 56.2% to 64.2% with GPT-5 mini and from 75.8% to 81.0% with MiniMax M2.5, while cutting total cost by 28.9% and 31.8%. Attached to OpenAI Codex, it adds 3.4 percentage points of Pass@1 at 24.4% lower cost. Ablations attribute most of the resolution gain to govern and most of the efficiency gain to inform, with their combination performing best. What long-horizon agents lack, we conclude, is not a shorter view of their history but an explicit account of their own execution state.

cs.SE