Skip to main content
Back

ByteDance and CMU's CodeGym Trains AI Agents to Use Tools 8.7 Points Better

ByteDance Seed and CMU turn static coding problems into 13,000+ interactive gyms, boosting tool-use generalization by 8.7 points on tau-Bench.

Pro

  • CodeGym converts coding problems into 13,116 interactive multi-turn tool-use gyms for agent RL, larger than any prior benchmark. Paper
  • Qwen2.5-32B-Instruct trained with GRPO on CodeGym gains 8.7 points on tau-Bench and 7.3 average on OOD tasks.
  • Pipeline extracts atomic functions from solutions as tools, then verifies environments using pass at 10 unit test filtering.
  • Quality filters require 10-256 tool calls, at least 4 distinct tools, and under 25 percent base pass rate.
  • Ablations show RL clearly beats SFT and distillation for out-of-distribution generalization on unseen agent workflows.
  • Full generation pipeline is open-source under CC BY-NC 4.0 at github.com/StigLidu/CodeGym.

Training language model agents to use tools reliably has become one of the harder problems in applied ML. Supervised fine-tuning on hand-crafted trajectories tends to memorize patterns rather than learn them, and reinforcement learning setups usually target one narrow domain like coding or web search. A team from ByteDance Seed and Carnegie Mellon is proposing a different substrate for the problem: turn the massive supply of competitive programming problems into interactive multi-turn environments, and let agents learn tool use by solving them.

Their framework, CodeGym, does exactly that. It converts static coding problems into interactive environments by extracting atomic functions or logic into callable tools, yielding verifiable tasks that span various tool-execution workflows. The payoff shows up on benchmarks the model never saw during training. Qwen2.5-32B-Instruct picks up an 8.7-point absolute accuracy gain on the out-of-distribution tau-Bench after RL in CodeGym.

Why coding problems make good tool-use gyms

The core insight is that program execution already looks a lot like an agentic workflow: branches, loops, and sequential state updates map cleanly onto tool-call sequences. Instead of asking the model to write code end-to-end, CodeGym takes the reference solution to a problem, chops it into reusable pieces, and exposes those pieces as tools the agent must call to arrive at the answer.

Take a simple example: finding the number closest to K in a sorted array of length N. From the solution, three atomic actions are distilled: observe, which returns the array length together with the target; look_up_pos, which returns the element at index i; and done, which submits the final answer. The agent no longer writes binary search; it discovers it by probing the environment.

CodeGym architecture diagram showing how coding problems become interactive environments with tools, actions, observations and rewards

How the pipeline builds an environment

CodeGym follows a two-stage generation pipeline that starts from the KodCode dataset's Coding Assessment Questions and ends with a verified Gym environment. Every environment is formalized as a POMDP with a state, an action space of tool calls, deterministic transitions, and a sparse binary reward on submission.