Reinforcement Learning for Machine Learning Engineering Agents

Sherry Yang, Joy He-Yueya, Percy Liang

TL;DR

This paper demonstrates a surprising finding in the realm of AI agents: training a small, 3-billion parameter language model using reinforcement learning (RL) can actually outperform massive frontier models (like Claude 3.5 Sonnet or GPT-4o) on Machine Learning Engineering (MLE) tasks. To make RL viable in this domain, the authors introduce "duration-aware gradient updates" to handle variable code execution times and "environment instrumentation" to provide partial credit for intermediate coding steps, effectively solving the sparse reward problem.

The Problem: Static Models and RL Roadblocks

Currently, the standard approach to building AI agents for Machine Learning Engineering—such as writing code to solve Kaggle competitions—is to take a massive, frozen language model and wrap it in an "agent scaffold" (like AutoGPT or AIDE). These scaffolds allow the model to write code, test it, and try again. However, because the model's underlying parameters never change, it doesn't fundamentally learn from its mistakes; it merely searches through its existing knowledge.

Adapting the model via Reinforcement Learning (RL) is a natural solution, but applying RL to coding agents introduces two major roadblocks:

  1. Variable-Time Actions: In standard distributed RL, multiple agents attempt tasks simultaneously. If an agent writes a simple logistic regression, it runs in seconds. If it writes a complex neural network, it takes hours. Standard RL frameworks process fast actions much more frequently, heavily biasing the agent to write fast, low-quality code just to get quick feedback.
  2. Sparse Rewards: In MLE tasks, the reward is usually the model's accuracy on a test set. If an agent writes a brilliant 100-line script but makes a typo on line 99 when saving the file, the script crashes. The agent gets a score of 0, which is indistinguishable from a script that failed to even load the data.

Proposed Methods: Making RL Work for Code

To solve these challenges, the authors propose two novel techniques for their RL training loop:

Overview of the proposed RL framework featuring duration-aware updates and environment instrumentation.
  • Duration-Aware Gradient Updates: To stop the agent from favoring fast, suboptimal solutions, the authors mathematically reweight the RL policy gradient updates based on how long an action takes to execute. If a script takes 100 times longer to run, its resulting gradient update is weighted more heavily. This cancels out the frequency bias of fast actions.
  • Environment Instrumentation (for Partial Credit): To solve sparse rewards, the authors use a separate, frozen copy of the language model to read the agent's generated code and inject print() statements after key steps (e.g., print("loaded data"), print("defined model")). When the code runs, regex matches on the terminal output provide dense, partial credit. Crucially, using a frozen model for this prevents the RL agent from "reward hacking" (e.g., just writing print("loaded data") without actually loading the data).
  • Self-Improvement Prompting: During training, the agent is explicitly prompted to improve upon its previous solutions 50% of the time, rather than always starting from scratch.

Evaluation and Key Results

The authors evaluated their approach on 12 Kaggle tasks from the MLEBench benchmark, spanning vision, language, and tabular data. They specifically filtered for tasks where a small 3B parameter model was capable of at least producing a valid submission format, ensuring the evaluation focused on ML engineering skills rather than basic Python syntax capabilities.

Performance comparison over time: RL on a small model vs. prompting a large model.
  • Outperforming Frontier Models: The RL-trained small model (Qwen2.5-3B) outperformed prompting Claude-3.5-Sonnet (using the state-of-the-art AIDE scaffold) on 8 out of 12 tasks, achieving an average performance improvement of 22%.
  • Beating Top Scaffolds: The 3B model also outperformed GPT-4o equipped with various popular agent scaffolds (AIDE, OpenHands, MLAgentBench) on 9 out of 12 tasks.
  • Ablation Success: Removing the duration-aware gradients caused the agent to rapidly converge on fast, suboptimal code (like linear regression). Keeping it allowed the agent to explore slower, high-reward models (like gradient boosting), improving top scores by ~3.8%. Environment instrumentation was even more critical, improving best solutions by ~22% by preventing the agent from getting stuck early in training.

Limitations and Future Work

The primary limitation of this study is compute. Because RL training requires running thousands of ML experiments, the authors were restricted to using a very small base model (3B parameters) and a limited subset of 12 tasks.

For future work, the authors suggest scaling this approach up to larger base models and a wider variety of tasks. More broadly, they argue that future AI agent research needs to shift focus: instead of just scaling up inference-time compute (thinking longer), we need to balance compute across inference, interaction, and gradient updates (actually learning).

Summary updated

BibTeX
@inproceedings{yang2026reinforcement,
  author = {Sherry Yang and Joy He-Yueya and Percy Liang},
  title = {{Reinforcement Learning for Machine Learning Engineering Agents}},
  booktitle = {International Conference on Learning Representations},
  year = {2026},
  url = {https://openreview.net/forum?id=mfIbSouoaZ},
}
Figure