Function-Aware Fill-in-the-Middle as Mid-Training for Coding Agent Foundation Models

📄 arXiv: 2607.12463v1 📥 PDF

作者: Yubo Wang, Jiarong Liang, Yuxuan Zhang, Xuye Liu, Cong Wei, Yuyu Zhang, Ping Nie, Wenhu Chen

分类: cs.AI, cs.CL

发布日期: 2026-07-14


💡 一句话要点

提出函数感知中间填充方法以提升编码代理模型能力

🎯 匹配领域: 支柱九:具身大模型 (Embodied Foundation Models)

关键词: 编码代理 函数感知 中间填充 自监督学习 程序依赖图 模型训练 性能提升

📋 核心要点

  1. 现有的编码代理模型在整合外部工具返回结果时存在能力不足,尤其是在推理过程中。
  2. 本文提出的函数感知中间填充方法通过掩蔽函数来增强模型的推理能力,利用程序依赖图分析进行自监督训练。
  3. 实验结果显示,经过中间训练的模型在多个基准测试上均有显著提升,尤其是在SWE-Bench-Verified和SWE-Bench-Lite上。

📝 摘要(中文)

编码代理需要将外部工具返回的结果整合到持续推理中,而标准的从左到右的预训练方法仅在前向方向上暴露这一能力。本文观察到编码代理的动作-观察-继续循环与函数调用结构相似,提出了一种函数感知的中间填充(FIM)自监督目标,通过程序依赖图分析和复杂性推断双重标准来掩蔽函数。我们在2.6B标记的去污染语料库上对Qwen2.5-Coder-Instruct和Qwen3-8B进行了中间训练,结果表明中间训练显著提升了模型在多个基准测试上的表现。

🔬 方法详解

问题定义:本文旨在解决编码代理在推理过程中整合外部工具返回结果的能力不足,现有的从左到右的预训练方法未能有效捕捉这一能力。

核心思路:提出函数感知的中间填充(FIM)方法,通过掩蔽函数并利用程序依赖图分析,增强模型在推理过程中的上下文理解能力。

技术框架:整体流程包括数据准备、函数掩蔽、模型中间训练和后续的代理后训练。数据准备阶段从968个GitHub仓库中提取去污染的语料库,随后进行函数掩蔽和模型训练。

关键创新:最重要的创新在于通过函数感知的中间填充方法,利用程序依赖图分析来选择掩蔽的函数,从而提升模型的推理能力,这与传统的预训练方法有本质区别。

关键设计:在训练过程中,采用复杂性推断双重标准来选择掩蔽函数,损失函数设计为自监督目标,确保模型在掩蔽和恢复过程中学习到有效的上下文信息。

🖼️ 关键图片

fig_0
fig_1
fig_2

📊 实验亮点

实验结果显示,经过中间训练的Qwen2.5-Coder-Instruct在SWE-Bench-Verified上提升了+2.8/+3.0,Qwen3-8B提升了+3.2。在SWE-Bench-Lite上,模型分别提升了+3.7/+4.0/+5.4,表明中间训练显著改善了模型性能。

🎯 应用场景

该研究的潜在应用领域包括智能编程助手、自动代码生成和代码审查等。通过提升编码代理的推理能力,能够更好地支持开发者在编程过程中的决策,未来可能对软件开发效率产生积极影响。

📄 摘要(原文)

Coding agents must integrate external tool returns into ongoing reasoning - a capability that standard left-to-right pretraining on code exposes only in its forward direction. We observe that the action-observation-continuation loop of a coding agent is structurally isomorphic to a function call site, where a caller binds arguments, a callee returns a value computed elsewhere, and downstream code consumes that value. This conditioning structure exists at internet scale in ordinary code. We exploit it through function-aware fill-in-the-middle (FIM) mid-training: a self-supervised objective that masks functions selected via program dependency graph analysis and a complexity-inferability double criterion. We mid-train Qwen2.5-Coder-Instruct (7B/14B) and Qwen3-8B on a 2.6B-token decontaminated corpus drawn from 968 GitHub repositories, then apply existing agentic post-training pipelines. Mid-training improves SWE-Bench-Verified by +2.8/+3.0 at 7B/14B and by +3.2 on Qwen3-8B; SWE-Bench-Lite gains are +3.7/+4.0/+5.4 on the same models. The improvement holds across two post-training pipelines (R2E-Gym, SWE-Smith) and on a non-Qwen2.5 base (Qwen3-8B with SWE-Lego). Beyond in-domain gains, mid-training also mitigates the capability erosion that agentic post-training otherwise inflicts on non-agent coding (e.g., LiveCodeBench) and non-coding tool-use benchmarks (tau-bench, BFCL): although the mid-training corpus contains Python code only, the function-call inductive bias survives post-training and yields consistent gains.