Training Coding Models and Building Agent Capabilities: A Practical Guide
This article breaks down a three-stage training framework for coding agents, covering mid-training, supervised fine-tuning with rejection sampling, and agentic reinforcement learning scaling. It also includes a hands-on evaluation design using an interactive N-Back task, along with practical recommendations for turning demo-level output into verifiable engineering delivery. Readers will learn how verifiable signals, context cost control, and data flywheels shape reliable coding agents.
1. Why the Crowded AI Coding Assistant Space Still Deserves Investment
The number of intelligent coding tools has grown rapidly over the past two years, evolving from code completion to conversational generation, and further to agents that can autonomously read repositories, modify files, and run tests. At the product level, the market does look saturated. But if you shift the perspective from “number of products” down to “capability supply,” the truly scarce resource is not another entry point. It is the ability to reliably complete long-chain engineering tasks: locating an issue across dozens of files, following existing project conventions, self-correcting after failures, and delivering a change as a reviewable commit.
Given this, debating whether the space is crowded has limited value. A more useful question is: what training stages and data construction methods does a coding agent need to move from “writing code snippets” to “delivering engineering results”? This article uses the publicly described technical roadmap of a self-developed coding model series as an abstract reference, strips away product-specific attributes, and discusses a general, reusable methodology.
2. A Three-Stage Training Framework: From General Capability to Agent Behavior
2.1 Mid-Training: Building the Foundational Skills Agents Need
The goal of mid-training is not to teach the model a specific syntax, but to fill in the综合 capabilities required to execute tasks. Common industry practices cover the following areas:
- Instruction following: strictly constraining output format, paths, naming, and prohibited actions;
- Tool use: understanding tool descriptions and parameter schemas, and forming a “observe first, then act” habit;
- Multi-turn interaction: keeping the goal from drifting as context grows;
- Code knowledge injection: adding framework conventions, engineering practices, and common defect patterns;
- Version control semantics: understanding commits, branches, diffs, and review workflows;
- General and reasoning capabilities: ensuring cross-domain problems do not regress.
An illustrative capability constraint (defining the expected output style when constructing training samples):
Constraint: modify only necessary files; add no new dependencies; output must include a change summary and verification method.Action: read target file -> locate relevant symbols -> make minimal change -> run available checks -> report results.
2.2 Supervised Fine-Tuning and Rejection Sampling Fine-Tuning (SFT & RFT): Aligning the Task Distribution with Real Scenarios
The supervised stage typically covers high-frequency task types and common code scenarios, such as bug fixing, test supplementation, interface adjustments, script writing, log troubleshooting, configuration changes, documentation updates, and refactoring. The value of rejection sampling fine-tuning lies in the following: sample multiple candidate trajectories for the same prompt, use verifiable signals (compilation, unit tests, static checks, result comparison) to filter correct trajectories, and feed them back into training. This improves sampling efficiency and stability in the subsequent reinforcement learning stage.
A simplified filtering flow:
candidates = sample(model, prompt, n=8)valid = [c for c in candidates if run_checks(c)] # compilation/unit tests/static checksif valid:keep(prefer_shortest(valid)) # prefer shorter, more focused changes when equally correct
The key point is “verifiability first”: the more objective the reward signal, the less likely the model is to learn surface-level tricks.
2.3 Agentic RL Scaling: Efficiency Sets the Ceiling
The cost of agentic reinforcement learning lies mainly in trajectory sampling and cluster utilization. Two common optimization ideas in public roadmaps are:
- Prefix tree compression and entropy-guided pruning: merge massive trajectories by common prefixes, rank them by entropy and visit probability, and prioritize expanding high-information nodes within budget;
- Heterogeneous scheduling that decouples training from agent logic: pipeline inference sampling and training updates to reduce bubbles and improve cluster occupancy.
In engineering terms, this can be abstracted as optimizing for “the number of effective verified trajectories obtained per unit of compute,” rather than simply increasing sampling volume.
3. Evaluation Design: Testing the Agent Loop with an Interactive Experiment Page
To observe how a model performs on “requirement understanding + state machine implementation + interaction details,” you can design a typical task: implementing an N-Back cognitive experiment page. The rule is to present one stimulus image every second, and the user judges whether the current stimulus is the same as the one from N rounds earlier. The stimulus set consists of 10 common Chinese characters; before starting, the user can choose N to be 2, 3, or 4.
The value of this task is that it simultaneously tests timing precision, history queue maintenance, judgment logic, boundary handling, and interface feedback.
Reference implementation skeleton (frontend pseudocode):
const STIMULI = ["国","火","道","市","天","家","理","态","至","心"];let n = 2, history = [], current = null, timer = null;function start(selectedN) {n = selectedN; history = []; current = null;clearInterval(timer);timer = setInterval(step, 1000); // switch stimulus every second}function step() {current = STIMULI[Math.floor(Math.random() * STIMULI.length)];history.push(current);render(current);}function judge(same) {const target = history[history.length - 1 - n];const correct = target !== undefined && (target === current) === same;feedback(correct); // record accuracy and reaction time}
During evaluation, focus on three types of issues: whether the timer is properly cleared when restarting; whether the history queue resets after switching the N value; and whether a “no judgment available” hint is given instead of a wrong judgment when the history length is shorter than N.
4. Implementation Recommendations: Turning “Demo-able” into “Deliverable”
- Build a verifiable loop: integrate compilation, unit tests, static checks, and automated page inspection into the agent’s default actions;
- Control context cost: supply context in layers by retrieval and summarization, avoiding stuffing the entire repository in;
- Strengthen convention constraints: write directory conventions, dependency whitelists, and commit message formats as explicit prompts and validation rules;
- Focus on observability: use logging services, monitoring alerts, and container platforms to run batch evaluation tasks for easier regression comparison;
- Data flywheel: return online failure samples after desensitization and filtering, forming a loop of “failure pattern - training sample - validation case.”
5. Conclusion
The endgame of competition among intelligent coding tools is not the number of entry points, but “verifiable engineering delivery capability.” The three-stage training framework provides a clear path: mid-training builds agent foundational skills, supervised and rejection sampling fine-tuning align with the real task distribution, and agentic reinforcement learning scaling amplifies effective experience within a compute budget. For developers, mastering this methodology brings more long-term value than chasing a single tool. With the general capabilities provided by cloud platforms such as Baidu AI Cloud, building and evaluating agents will also become more efficient.
