← Latest papers
💬 NLP

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

This paper introduces function-aware fill-in-the-middle (FIM) mid-training, a self-supervised approach that leverages the structural similarity between coding agent loops and function calls to significantly boost coding agent performance on benchmarks like SWE-Bench while simultaneously preserving general coding and tool-use capabilities often degraded by standard post-training.

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

Published 2026-07-15
📖 5 min read🧠 Deep dive

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

Original paper licensed under CC BY 4.0 (http://creativecommons.org/licenses/by/4.0/). This is an AI-generated explanation of the paper below. It is not written or endorsed by the authors. For technical accuracy, refer to the original paper. Read full disclaimer

Imagine you're teaching a robot to fix bugs in a giant, messy library of code. Usually, we teach these robots by letting them read books from start to finish, left to right. But there's a problem: when a robot actually goes to fix a bug, it doesn't just read forward. It takes a step, looks at what happened (maybe a tool gave an error), and then decides what to do next. It's a loop: Action → Observation → Next Step.

The authors of this paper noticed something cool: this robot loop looks exactly like a function call in normal computer code.

  • The Robot's Action is like a function calling another function.
  • The Robot's Observation is like that function returning a value.
  • The Robot's Next Step is like the rest of the code using that value.

The big idea? Instead of just reading code forward, the authors taught their robot models to play a "fill-in-the-blank" game with these function calls. They call this Function-Aware Fill-in-the-Middle (FIM) Mid-Training.

The Game: "Guess the Missing Piece"

Imagine you have a story where a character (the "caller") asks a friend (the "callee") to do a task, but the friend's actual work is hidden. The robot has to guess what the friend did and explain why they did it, based only on the context before and after.

To make this game effective, the authors didn't just pick random words to hide. They used a special map of the code (a "Program Dependency Graph") to find the perfect puzzles. They looked for functions that were:

  1. Complex enough to be a good challenge (not too easy, not impossible).
  2. Predictable enough that the robot could actually figure them out from the surrounding clues.

They also made the robot write a "reasoning note" (a Chain-of-Thought) before writing the missing code, forcing it to think before it acts, just like a human programmer would.

The Results: Does It Work?

The authors tested this on three different robot brains (models): two from the Qwen2.5-Coder family (7 billion and 14 billion parameters) and one from the newer Qwen3 family (8 billion parameters). They trained these robots on a massive dataset of 2.6 billion tokens (words and symbols) taken from 968 real-world Python code repositories.

Here is what they found:

  • Better at Fixing Bugs: When tested on a famous benchmark called SWE-Bench-Verified (which simulates real-world software issues), the robots improved significantly.
    • The 7B model improved by +2.8%.
    • The 14B model improved by +3.0%.
    • The 8B model improved by +3.2%.
  • Even Better on Easier Tasks: On a lighter version of the test (SWE-Bench-Lite), the gains were even higher, with the 8B model jumping +5.4%.
  • It Works Everywhere: These improvements happened even when the robots were trained using different methods afterward. This suggests the "fill-in-the-middle" training gave them a solid foundation that stuck, no matter how they were polished later.

The Surprise: It Didn't Break Other Skills

Usually, when you train a robot to be a super-specialist (like a bug-fixing agent), it forgets how to do other things, like writing simple code or using tools. The authors were worried this would happen.

But, the "mid-training" actually saved the robots' other skills!

  • Without this extra training, the robots got worse at writing code on their own (dropping on benchmarks like LiveCodeBench).
  • With the FIM training, they didn't just stay the same; they got better (+11.1% on LiveCodeBench).
  • Even though the training data was only Python code, the robots got better at using tools in completely different contexts (like τ-bench and BFCL), suggesting they learned a general "how to think about cause-and-effect" skill that transferred across tasks.

What They Explicitly Ruled Out

The authors were careful to say what this method is not:

  • It's not just about copying a smart teacher: They tested if the robot was just memorizing the answers from a powerful AI (Gemini-3-Flash) that helped generate the training data. They found that even when the robot generated its own reasoning notes, it still improved. So, the magic isn't just "copying the teacher"; it's the structure of the game itself.
  • It's not a magic bullet for everything: The method works best when the code is modular (broken into neat functions). If the code is a giant, messy script where everything is mixed together, the method doesn't work as well because it can't find clear "function call" puzzles to solve.
  • It's not proven for all languages yet: The training data was only Python. While the robots got better at other tasks, the authors admit they haven't proven this works for Java, C++, or Rust yet.

How Sure Are They?

The authors are quite confident in their numbers because they ran the tests three times with different random seeds to make sure the results weren't just luck. They measured the improvements precisely (e.g., +2.8%, +3.0%) and showed that the robots consistently solved more problems and made fewer mistakes when they got stuck.

They suggest that this "mid-training" stage is a crucial missing link. It's like giving the robot a specific type of gym workout before sending it into the real world, ensuring it has the right muscles to handle the complex loop of "act, observe, and continue" without losing its other abilities.

Drowning in papers in your field?

Get daily digests of the most novel papers matching your research keywords — with technical summaries, in your language.

Try Digest →