让大模型代码生成更可靠,通过双状态机制实现自动纠错。
The Dual-State Architecture for Reliable LLM Agents
- 用确定性验证约束随机生成,构建双状态执行架构。
- 实测可靠性提升最高达66个百分点,成本仅增1.2-2.1倍。
- 支持分层恢复,适合追求高可靠性的自动化编程场景。
将大语言模型部署为代码生成代理时,其随机行为难以满足软件工程所需的确定性要求。本文提出双状态动作对(DSAP),将随机生成与确定性后置条件验证耦合。守护函数作为感知动作,将模型的不可观测输出映射到可观察的工作流状态,实现有限确定性状态空间 S_workflow 与无限随机环境状态空间 S_env 的分离。证明对于 ε-能力生成器,失败概率 P(fail) ≤ (1−ε)^R_max → 0。为避免多步任务中重复尝试的指数爆炸,引入三级恢复机制:上下文精炼(单步内重试)、智能回溯(停滞检测、级联失效与上游上下文注入)和人工升级。在13个模型(1.3B–15B参数)上对三个诊断探针的实验表明,可靠性最高提升66个百分点,基准成本增加1.2–2.1倍。在99个SWE-Bench Pro实例-臂对(Qwen3-Coder-Next)上的评估显示,上下文注入在所有71次升级事件中均有效改变上游输出,但测试生成的恢复率为37.5%,补丁生成为0%,且端到端补丁生成率仍为0%。这确立了执行架构与计划合成之间的边界:执行恢复必要但不充分,无法实现自主软件工程。
原文摘要 · Abstract (English)
Large Language Models deployed as code generation agents exhibit stochastic behavior incompatible with the deterministic guarantees required by software engineering. We formalize the Dual-State Action Pair (DSAP), an execution primitive that couples stochastic generation with deterministic post-condition verification. Guard functions act as sensing actions that project opaque LLM outputs onto observable workflow state, enabling a dual-state decomposition: finite, deterministic S_workflow paired with infinite, stochastic S_env. We prove that for epsilon-capable generators, failure probability P(fail) <= (1-epsilon)^R_max -> 0. To prevent naive O(R^K) retry explosion across multi-step workflows, we introduce a three-level recovery hierarchy: context refinement (retry within step), informed backtracking (stagnation detection with cascade invalidation and context injection to upstream steps), and human escalation. Experimental validation across 13 LLMs (1.3B-15B parameters) on three diagnostic probes demonstrates reliability gains of up to 66 percentage points at 1.2-2.1x baseline cost. Recovery mechanism evaluation on 99 SWE-Bench Pro instance-arm pairs (Qwen3-Coder-Next) demonstrates 100% context injection effectiveness (upstream output changed in all 71 escalation events) with step-specific recovery asymmetry -- 37.5% for test generation vs. 0% for patch generation -- and 0% end-to-end patch production, establishing the boundary between execution architecture and plan synthesis: execution recovery is necessary but not sufficient for autonomous software engineering.
Thank you to arXiv for use of its open access interoperability. PaperDance 不是 arXiv 官方产品;中文卡片由大模型生成,请以原文为准。