重试失败的AI任务会因上下文污染导致成功率下降,本文提出模型解释并优化重试策略。
Why Retrying Fails: Context Contamination in LLM Agent Pipelines
- 构建上下文污染重试模型,揭示失败尝试残留影响后续表现
- 发现污染使每步错误率升至原始7.1倍,重试次数需增加近2倍
- 证明清除上下文可显著提升效率,适合调试复杂AI任务系统者
当大语言模型代理在多步骤工具调用任务中失败后重试时,失败过程通常仍保留在上下文窗口内,导致后续尝试被污染,每步错误率高于基础水平。这一现象普遍存在于实践中,却缺乏理论分析。本文提出上下文污染重试模型(CCRM):T步工具调用链中,每步基础失败率为ε₀;任一步失败后,后续尝试在污染上下文中进行,错误率升至ε₁ > ε₀。在此模型下,我们推导出五项核心结果:(R1) 成功所需最多尝试次数K的精确闭式公式;(R2) 污染带来的额外尝试数ΔK的级联开销定理;(R3) 在总预算B=KT固定下,最优管道深度T*的分配定理,其闭式为T* = √(B·log(1/(1−ε₁))/log(1/(1−ε₀))),对应K*=B/T*;(R4) 通过Le Cam方法的信息论下界,证明K_CCRM在O(1)意义下紧致;(R5) 清除上下文优于重试的主导性定理,量化了清理的收益。在真实SWE-bench Verified数据上验证,独立同分布模型高估pass@3达17.4个百分点(98.6% vs. 81.2%),而CCRM拟合误差小于0.001,表明污染比率ε₁/ε₀ = 7.1。蒙特卡洛实验验证所有理论预测。
原文摘要 · Abstract (English)
When an LLM agent fails a multi-step tool-augmented task and retries, the failed attempt typically remains in its context window -- contaminating the next attempt and elevating the per-step error rate beyond the base level. This context-contaminated restart phenomenon is widely observed in practice yet entirely lacks formal treatment. We introduce the Context-Contaminated Restart Model (CCRM): a chain of T tool-call steps, each failing with base rate epsilon_0; after any failed attempt, the subsequent attempt operates in contaminated context with elevated error rate epsilon_1 > epsilon_0. Under this model we derive five main results. (R1) An exact closed-form formula for P(succeed in at most K attempts). (R2) A cascade-overhead theorem giving the additional attempts Delta K incurred by contamination versus the clean-restart baseline. (R3) An optimal budget-allocation theorem identifying the pipeline depth T* that maximises success probability for a fixed total budget B=KT; we prove the closed form T* = sqrt(B * log(1/(1-epsilon_1)) / log(1/(1-epsilon_0))), with K*=B/T*. (R4) An information-theoretic lower bound via Le Cam's method showing K_CCRM is tight up to O(1). (R5) A clean-restart dominance theorem quantifying the exact benefit of context-clearing before retry. We validate CCRM on real SWE-bench Verified data: the IID model overestimates pass@3 by 17.4 percentage points (98.6% vs. 81.2%), while CCRM fits with error less than 0.001, implying a cascade ratio of epsilon_1/epsilon_0 = 7.1. Monte Carlo experiments confirm all theoretical predictions.
Thank you to arXiv for use of its open access interoperability. PaperDance 不是 arXiv 官方产品;中文卡片由大模型生成,请以原文为准。