← 返回 2026-05-18

Solvita:通过智能体进化增强大语言模型的竞赛编程能力 Solvita: Enhancing Large Language Models for Competitive Programming via Agentic Evolution

Han Li, Jinyu Tian, Rili Feng, Yuqiao Du, Chong Zheng, Chenyu Wang, Chenchen Liu, Shihao Li, Xinping Lei, Yifan Yao, Weihao Xie, Letian Zhu, Jiaheng Liu 📅 2026-05-14 👍 22 2026-07-13 08:36
REINFORCE 代码生成 多智能体系统 强化学习 智能体 竞赛编程

冻结LLM权重,用四智能体+可训练知识图谱的闭环系统让代码生成越用越强。

前置知识

上下文赌博机(Contextual Bandit)

一种序列决策框架:在每一轮,智能体根据当前上下文 $x$ 从候选动作集合中选择一个动作 $a$,获得奖励 $r$ 后更新策略。区别于完整 RL,它只关心当前收益、不考虑未来状态转移。Solvita 用它来为每个智能体挑选最佳的「策略家族」「攻击路线」或「解题范式」。

Solvita 把四个知识网络都形式化为 contextual bandit,正是这套机制让「不微调 LLM、只更新路由权重」成为可能。

REINFORCE 策略梯度

经典策略梯度算法 $\nabla_w J=\mathbb{E}[R\cdot\nabla_w\log\pi(a|x)]$。Solvita 用对比式 REINFORCE,同一 backbone 在有/无网络辅助下各跑一次,取差值 $\Delta R$ 作反事实奖励更新图边权重。

这是 Solver 知识图谱权重更新所用算法,决定了它如何从解题成败中学习。

testlib 验证框架

Codeforces 等平台用的 C++ 测试库,提供 `registerGen/Validation/TestlibCmd` 等接口,用来生成合法输入、校验输入、做独立判定。Oracle 用它三件套构建「经认证」的内部测试。

Oracle 是 Solvita 的「内审」,其可信度完全建立在 testlib 这种工业级合约上。

对抗样本与 Hack 思想

在竞赛圈,「hack」指对他人代码构造反例使其失败。Solvita 的 Hacker 智能体把这一人类行为自动化:先用 Code Analyst 检查代码、形成漏洞报告,再走「语义攻击 / 压力测试 / 反哈希碰撞」三路 cascade,目标是找出会让提交者拿 WA/TLE/RE 的对抗输入。

Hacker 是 Solvita 区别于 AlphaCodium/MapCoder 等流水线最关键的一环,直接决定了它在 Codeforces 上的真实对抗表现。

pass@1 与 Codeforces 评分

pass@1 是「单次生成即通过全部测试」的比例,是代码生成的金标准。Codeforces 评分基于 Elo 期望胜率 $p=1/(1+10^{(r_1-r_2)/400})$ 反推,≥2400 为 Grandmaster,≥3000 为 Legendary Grandmaster。

本文所有主要指标都用 pass@1 报告,并辅以 Codeforces 评分展示真实竞赛水平。

研究动机

当前 LLM 做竞赛编程的主流范式(单次生成或 AlphaCodium/MapCoder 这类多步骤流水线)本质上都是「无状态」的:每个新题目从零开始,过去积累的解题、调试经验全部丢弃。即使引入 RAG,把过往题解文本塞回 prompt 也不改变底层推理过程。实验中可观察到这一硬伤:以 GPT-5.4 为底座、165 道 CodeContests 题为基准,单次生成的 pass@1 只有 40.00%,即便用上 Codex CLI 这种商业代理也只有 81.82%,在 AetherCode 这种高难度集上更跌到 18.00%。人类选手之所以能稳定进步,是因为他们会沉淀「哪些策略适配哪类题」「哪类实现容易踩坑」「赛前要主动攻击自己的解法」这类元经验,而 LLM 智能体缺少这种持续积累的机制。

本文的目标是Solvita 想要在不改动 LLM 权重的前提下,让代码生成系统具备「越用越强」的持续学习能力。具体可量化的目标:在 CodeContests/APPS/AetherCode 三个 benchmark、五个前沿 LLM 底座(GPT-5.4、Claude Opus 4.6、Qwen3.6、DeepSeek V4 Pro、Grok)的 15 组 backbone×benchmark 组合中拿下 SOTA;让 GPT-5.4 底座在 CodeContests 上的 pass@1 从 40.0% 提升到接近翻倍;在 12 场赛后真实 Codeforces 对抗中三个底座都达到 Legendary Grandmaster(≥3000)水平。

与已有工作不同的是,已有工作要么只改 LLM 权重(成本高、灾难性遗忘),要么只做静态检索(RAG,没改变推理过程),要么只在通信层面做多智能体(debate/self-consistency,不沉淀经验)。Solvita 切入了此前被忽视的中间地带——把记忆做成「图结构 + 边权重」,用强化学习把每一次 pass/fail 转化为图边权重的更新,使记忆本身变成可学习的路由机制;并且把「出题—写题—审题—攻题」组成闭环,让 Hacker 发现的 bug 能通过事件总线一次性写入四个知识网络,形成持续叠加的复利效应。

核心方法

Solvita 可以类比为一家永远在开「内部训练赛」的软件公司:四名员工(Planner/Solver/Oracle/Hacker)各管一摊,但所有人共用一套「可学习的记忆本」(图结构知识网络 + 上下文赌博机)。每来一道新题,Planner 先把它翻译成形式化描述并预测算法范式;Solver 据此写 C++ 代码、写错了就用 SEARCH/REPLACE 补丁最小化修复;Oracle 平行地构造一份带 testlib 的认证测试套件作为「内部裁判」;Hacker 则扮演恶意攻击者,从语义/压力/反哈希三路 cascade 出对抗输入。任何一次失败信号——bad case、certification ratio 不达标、Hacker 抓到的 bug——都通过一个 contextual bandit 策略转化为对应知识网络边权重的 REINFORCE 更新。整个 LLM 权重保持冻结,但推理能力随着使用单调提升。直觉上,这套设计把「人脑靠经验变强」的机制移植到 LLM 智能体上,只不过用图边权重代替了突触权重。

与已有方法最本质的区别在于「记忆是可学习的路由,而非静态的检索表」。AlphaCodium、MapCoder、AgentCoder 等流水线虽然引入了多步骤迭代,但都把每道题当作独立事件处理;RAG 类方法虽然引入了记忆,但只做相似度匹配,并未改变推理过程。Solvita 的关键创新有三层叠加:(1) 每个智能体单独拥有一张异构图(如 Solver 的 QMS 三层图:问题 Q-元认知 M-技能 S,边权重 $w_{qm}, w_{ms}$ 通过 REINFORCE 学习),把「该用哪种策略」转化为可学习选择;(2) 用反事实对比奖励 $\Delta R = R_{\text{with}} - R_{\text{without}}$(同一 backbone 在有/无网络下各跑一次)作为低方差强化信号,专门训练路由;(3) 四个网络通过事件总线互联——Hacker 抓到一个 bug,会同时在 Planner/Solver/Oracle 写入对比样本和规避策略,使经验沿闭环传播而不是孤立地被消化。

方法步骤详情

离线从多源爬 30,018 题,经完整性→标签均衡($C_{\max}=2300$)→embedding 去重($\delta=0.93$)→难度剪枝四道过滤得 8,017 题冷启动语料。在线四步:①Planner 改写 canonical_problem 并预测标签,命中真标签给 +1 否则 −1 的 bandit 奖励;②Solver 从 QMS 图检索 top-4 Q 节点两跳扩展到 S 技能,按 $\rho(s|q_{\text{new}})=\sum\text{Sim}\cdot w^q_m\cdot w^m_s$ 打分 softmax 采样 $1\sim5$ 个技能;初始全程序生成后最多 8 轮走 SEARCH/REPLACE 补丁(仅 patch_decision 判全局缺陷才退 full_regen),补丁须保留回归通过;③Oracle 并行产出 testlib 三件套,按 custom checker > 正确解 runner > exact match 验证,得 $\rho$,过门 $\rho\geq\tau=0.9$ 才被接受;④Hacker 从 $\mathcal{U}=\{\text{semantic, stress, anti\_hash}\}$ 选一路生成对抗输入,最多 3 轮 cascade,命中 bug 时通过事件总线写入其它三网络。

技术新颖性

技术新颖性体现在三个不易复制的组合:(1) 角色专属 + 可训练知识网络。每个智能体有独立的 contextual bandit 学习率 $\alpha=0.01$、独立的标签-键控特征空间 $\Phi(x)$(FSM 位置 + 失败类型 + 题目标签),运行平均奖励低于 −0.3 且使用 ≥20 次的条目会自动退役,这避免了静态 RAG 的「召回不准」问题。(2) 对比式 REINFORCE。Solver 同一 backbone 跑两次取 $\Delta R$,大幅降低方差;且当两次输出有差异时把正确答案和错误答案配成新的 contrastive M 节点挂进图,让图在「智能体最挣扎」的地方自动膨胀。(3) Hacker-Oracle 互补策略空间。Figure 4 显示 Oracle 集中在「DP/Search/Enumeration」等可靠监督路径,Hacker 集中在「Complexity/Structural/Boundary」等暴露 bug 路径,二者共享分类轴但分解方式相反,这使二者联合时能比单独任何一方多检出 5–10 个百分点的错误解。

Data pipeline overview. Raw artifacts are collected from multiple competitive programming platforms, normalized into a unified JSON schema, and passed through four filtering stages: completeness, tag load balancing, embedding deduplication, and per tag difficulty pruning.
Figure 1: Data pipeline overview. Raw artifacts are collected from multiple competitive programming platforms, normalized into a unified JSON schema, and passed through four filtering stages: completeness, tag load balancing, embedding deduplication, and per tag difficulty pruning.
The Solvita architecture and its comparison with existing agent frameworks. Solvita couples an Oracle for certified internal-test construction, a Planner–Solver loop with patch-based refinement, and a Hacker that launches cascading adversarial attacks; failure signals propagate across all four agents' knowledge networks (dashed arrows).
Figure 2: The Solvita architecture and its comparison with existing agent frameworks. Solvita couples an Oracle for certified internal-test construction, a Planner–Solver loop with patch-based refinement, and a Hacker that launches cascading adversarial attacks; failure signals propagate across all four agents' knowledge networks (dashed arrows).
The three-layer Solver knowledge network. Q nodes (top) store problem descriptions and metadata; M nodes (middle) hold contrastive or analysis solution decompositions as function-block DAGs; S nodes (bottom) store annotated skills with code templates.
Figure 3: The three-layer Solver knowledge network. Q nodes (top) store problem descriptions and metadata; M nodes (middle) hold contrastive or analysis solution decompositions as function-block DAGs; S nodes (bottom) store annotated skills with code templates.
Seed-level strategy taxonomy of Oracle and Hacker memory, showing how each agent factorizes the shared algorithm space into its own reusable strategy units.
Figure 4: Seed-level strategy taxonomy of Oracle and Hacker memory, showing how each agent factorizes the shared algorithm space into its own reusable strategy units.

实验结果

Table 1:Solvita 在 5 底座 × 3 benchmark 共 15 组中拿下 14 组第一,仅 Claude Opus 4.6 × AetherCode 输 0.5pp。最亮眼 GPT-5.4 × CodeContests:pass@1 从 40.00% 提到 82.42%(+42.42pp);DeepSeek V4 Pro × CC 推到 89.09%(绝对最高);AetherCode 上 GPT-5.4 从 18.00% 提到 49.25%(+31.25pp)。Figure 5b 失败分解全谱下降:GPT-5.4 上 Alg.WA 24.8%→6.7%、Edge/Spec 11.5%→4.2%、TLE 9.1%→3.0%、MLE 4.8%→1.2%、RE 9.7%→2.4%。Figure 6b:K=12 场真实 Codeforces 后三条 Solvita 曲线都跨过 3000 进入 Legendary Grandmaster,裸底座停留在 2700–2850 high GM。Table 2 消融:闭环本身 40.00%→67.70%,+Solver@4.5k 再涨 7.90pp,Full 叠加到 82.42%,三网络互补非替代。Table 3:patch 修复同时更准更省(GPT-5.4 × CC:82.42/3.74 轮/省 91.2% token vs regen 75.76/5.18 轮/67.4%)。Figure 6a:Oracle+Hacker 联合在 Claude 上 92.8/96.0/19.6,强测试发现率提升 8.2pp。

Main results (pass@1, %) on CodeContests (CC), APPS, and AetherCode (AC). Each backbone is a column group; bold marks the best per column.
Table 1: Main results (pass@1, %) on CodeContests (CC), APPS, and AetherCode (AC). Each backbone is a column group; bold marks the best per column.
Additive ablation of pipeline components on CC, APPS, and AetherCode (pass@1, %). Each trainable network is reported at three checkpoints along the 5,318-problem training trajectory (@1.5k, @3k, @4.5k processed problems).
Table 2: Additive ablation of pipeline components on CC, APPS, and AetherCode (pass@1, %). Each trainable network is reported at three checkpoints along the 5,318-problem training trajectory (@1.5k, @3k, @4.5k processed problems).
Patch-based repair vs. full regeneration in the Solver inner loop, under matched iteration budgets (Nmax = 8). Solve is pass@1 (%); Iters is mean Solver iterations per problem; TokSv is the relative completion-token saving against a fixed reference cost.
Table 3: Patch-based repair vs. full regeneration in the Solver inner loop, under matched iteration budgets (Nmax = 8). Solve is pass@1 (%); Iters is mean Solver iterations per problem; TokSv is the relative completion-token saving against a fixed reference cost.
Cost and failure-profile analysis. (a) Average prompt and completion token consumption per problem, grouped by backbone and agent framework. (b) Error-rate decomposition by benchmark and failure type under the representative GPT-5.4 backbone.
Figure 5: Cost and failure-profile analysis. (a) Average prompt and completion token consumption per problem, grouped by backbone and agent framework. (b) Error-rate decomposition by benchmark and failure type under the representative GPT-5.4 backbone.
Oracle/Hacker diagnostics across three backbones (Claude Opus 4.6, GPT-5.4, DeepSeek V4 Pro). Det'd: wrong solutions detected; Pres'd: correct solutions preserved; Str.: Solvita-rejects/official-accepts disagreement problems confirmed as stronger-test cases.
Figure 6a: Oracle/Hacker diagnostics across three backbones (Claude Opus 4.6, GPT-5.4, DeepSeek V4 Pro). Det'd: wrong solutions detected; Pres'd: correct solutions preserved; Str.: Solvita-rejects/official-accepts disagreement problems confirmed as stronger-test cases.
查看结构化数据
任务指标本文基线提升
CodeContests pass@1 (GPT-5.4) pass@1 (%) 82.42 40.00 (单次生成) / 81.82 (Codex CLI) / 60.61 (AlphaCodium) / 57.58 (MapCoder) +42.42 vs 单次生成 / +0.6 vs 最佳商业代理
APPS pass@1 (GPT-5.4) pass@1 (%) 67.70 37.90 (单次生成) / 67.10 (Codex CLI) +29.80 vs 单次生成 / +0.60 vs Codex CLI
AetherCode pass@1 (GPT-5.4) pass@1 (%) 49.25 18.00 (单次生成) / 48.50 (Codex CLI) / 33.00 (AlphaCodium) +31.25 vs 单次生成 / +0.75 vs Codex CLI
CodeContests pass@1 (DeepSeek V4 Pro) pass@1 (%) 89.09 47.27 (单次生成) / 79.39 (Codex CLI) / 70.91 (AlphaCodium) / 66.67 (MapCoder) +41.82 vs 单次生成(绝对最高)
AetherCode pass@1 (DeepSeek V4 Pro) pass@1 (%) 51.50 24.00 (单次生成) / 45.00 (Codex CLI) +27.50 vs 单次生成
Solver patch repair vs full regen (GPT-5.4 / CC) pass@1 (%) & 平均迭代数 & token节省率 82.42 / 3.74 轮 / 91.2% 75.76 / 5.18 轮 / 67.4% +6.66 pp / -1.44 轮 / +23.8 pp 节省
Oracle+Hacker 联合诊断 (Claude Opus 4.6) Det'd / Pres'd / Str (%) 92.8 / 96.0 / 19.6 Oracle 单 82.4/96.8/8.5;Hacker 单 87.6/92.9/11.4 检测+5.2pp、保留稳定、强测试发现+8.2pp
Codeforces 实战 rating (K=12 rounds) Codeforces 反演评分 ≥3000(LGM 区间,三底座均达到) 2700–2850(high GM,裸底座) 约 +200–250 rating
全量训练 vs 无训练 (GPT-5.4 / CC) pass@1 (%) 82.42 without training 67.70 / single-pass 40.00 训练闭环 +14.72 pp;闭环本身 +27.70 pp

局限与改进

作者承认三个 trade-off:①冷启动成本高——多智能体循环本身比直接生成贵,知识网络需 ~5,000 训练题才能摊薄成本(Table 2 显示 @1.5k 几乎无增益);②Hacker 覆盖范围有限——anti-hash 和 lattice 攻击受底座推理能力制约,number-theoretic/几何类数学题 break-ratio 接近 0,呈 bimodal 失效;③Patch repair drift——全局缺陷被误判为局部问题时,Solver 会打出一连串累积不一致的小补丁直到预算耗尽,目前只能靠 Section 4.3 的回归率事后识别。我自己的观察:评测集中在 5 个封闭商用底座,缺少 7B/13B 开源小模型数据,外推未知;Solver QMS 图随训练增长但论文未报告检索延迟;AetherCode 400 题偏少,跨域稳定性待更大公开集验证。

独立分析的弱点

独立可改进点:①冷启动前 1500 题几乎无收益(Table 2 中 +Solver@1.5k 在 CC 上仅 67.70→70.86),新部署需大量在线算力;应设计难度阶梯预热或先用人类 editorial 做离线 warm-start。②Hacker 在数学题上 bimodal 失效——Code Analyst 推理能力不足,建议为数学题单独加一个符号化反例构造子模块(接 SymPy/SMT solver)补盲。③Patch repair drift 仅事后识别,应把 Section 4.3 回归率信号前置为 `FAIL:REGRESSION` 特征键,让路由器自动倾向 full_regen。④Hacker 失败事件是单向广播,误判好解为坏解时会污染 Solver 图;可加事后验证环节,对「Hacker 攻击但官方 AC」做负权重回写。⑤token 绝对值不低(GPT-5.4 上 ~150K tokens/题),可通过子任务路由(仅 Hacker 启用深度推理)降低平均开销。

未来方向

作者列出了三个方向:(a) 用开源经验语料(editorial、accepted 提交、调试轨迹)做 warm-start 缩小冷启动窗口;(b) 把四智能体闭环迁移到形式化定理证明(Oracle 变 proof checker,Hacker 找反模型)、数学奥赛(用符号验证代替测试案例)、科学推理(接可执行模拟器)等其他可验证奖励域;(c) 探讨把 Hacker 的逐步对抗信号从 prompt-level 升级为模型权重的 fine-tuning 信号,同时不丢失角色化信用分配。我个人补充的方向:(d) 把 Solvita 接到 Multi-Modal LLM 上扩展到几何/可视化题目;(e) 研究知识网络的「蒸馏/合并」协议,使不同底座训练出的图能彼此迁移,避免每个团队重复训练;(f) 把训练轨迹作为数据集发布,供后续 offline RL 研究复现。

复现评估

复现透明度较高:数据管线、prompt 模板、bandit 超参、token 预算全部附录化(附录 A-H)。冷启动语料可自行从 Codeforces/AtCoder/Aizu 公开抓取,8,017 题过滤管线参数($C_{\max}=2300$, $\delta=0.93$, 107 标签)完整。算力门槛:每题 ~150K tokens,5 底座 × 3 benchmark × 5,318 训练题 ≈ 数十亿 tokens,按 GPT-5.4 公开价估算需 5–10 万美元等价 API 额度;用 Qwen3.6 等本地底座可显著降本。作者声明随论文发布 prompt YAML(`config/prompt_template.yaml`)与沙箱(`src/sandbox/`),但未明确承诺开源全部知识网络权重,第三方必须从 5,318 题冷启动重训,耗时几天到一周。最可能失败的复现环节是 Hacker 反哈希攻击(依赖底座能否写出 Thue-Morse 类碰撞)和 patch_decision 的 LLM skill 选择(提示词略改一行即偏移行为)。