TL;DR
ProgAgent introduces a training framework that teaches Large Language Models (LLMs) to orchestrate tools using executable code—Programmatic Tool Calling (PTC)—rather than sequential, turn-based calls. By leveraging variables and control flow (like loops and try-except blocks), ProgAgent significantly reduces "context rot" and enables agents to solve complex, long-horizon tasks where traditional models typically fail.
What Problem Does This Paper Address?
Most current AI agents interact with tools via Direct Tool Calling (DTC). In this paradigm, the model generates a tool call (often in JSON), receives a raw response, appends that response to its conversation history, and then decides on the next step.
This approach has two major flaws:
- Context Rot: Raw tool outputs (like a list of 800 database IDs) quickly fill the model's context window with noise, leading to "orchestration breakdown" where the model loses track of the original goal.
- Logic Limitations: Expressing complex logic—such as iterating through a list, handling specific errors, or transforming data—is difficult and token-expensive when done turn-by-turn.
While some systems use PTC at inference time (giving the model a Python sandbox), there has been little research into using PTC as a training paradigm. The authors identify a lack of verifiable, programmatic training data as the primary bottleneck.
Methods
The authors developed ProgAgent, a full-stack solution for programmatic agent training:
- Task Synthesis Pipeline: They created a pipeline to generate 215 unique, verifiable long-horizon tasks across 23 domains (e.g., Finance, Healthcare). Crucially, they implemented Controlled Scaling, where the environment state (database size, file count) is expanded from $v_0$ to $v_3$ while keeping the core logic identical. This allows for testing how models handle increasing "noise."
- PTC Runtime: A lightweight, sandboxed environment using a persistent IPython kernel. This allows the model to store intermediate results in variables that persist across turns, rather than dumping everything into the text context.
- Two-Stage Training:
- Cold-start SFT: Supervised Fine-Tuning on high-quality teacher trajectories.
- Reinforcement Learning (RL): Using Group Sequence Policy Optimization (GSPO) with binary rewards provided by automated Python verifiers.
Datasets
The models were trained on the 215 synthesized tasks (instantiated at four scales, totaling 860 instances). Evaluation was conducted across four major benchmarks:
- MCPMark: Stress-tests realistic Model Context Protocol (MCP) use.
- Toolathlon-Verified: A benchmark for diverse, realistic tool execution.
- MCP-Atlas: A large-scale benchmark for tool-use competency.
- LOCA-bench: Specifically designed to evaluate agents under extreme context growth.
Key Insights and Ideas
- Coding Skills Transfer: The authors argue that PTC allows foundation models to transfer their pre-trained programming capabilities (loops, conditionals) directly to tool orchestration.
- Context Management as a Learned Behavior: Through RL, models learn to "selectively print." Instead of returning a whole database row, the model learns to write code that only prints the specific value needed for the next step, effectively managing its own context window.
- Uniform Action Space: The study found that "Hybrid" models (trained on both DTC and PTC) actually performed worse than pure PTC models. A uniform programmatic action space appears to lower the learning difficulty for the model.
- Robustness to Scale: As environment size grows, DTC performance plummets. PTC performance remains remarkably stable because the "noise" stays in the environment variables, not the model's reasoning context.
Key Results
ProgAgent-8B and 14B models (based on Qwen3) outperformed much larger baselines and even rivaled frontier proprietary models:
- LOCA-bench: In environments with 64k tokens of state, ProgAgent-14B achieved a 30.7% pass rate, while all comparable open-source baselines scored 0%.
- MCP-Atlas: ProgAgent-14B scored 45.6%, slightly outperforming Claude Sonnet-4.5 (43.8%) evaluated under the standard DTC harness.
- Efficiency: During RL training, PTC models used roughly half as many tool calls as DTC models and reduced tool-output tokens in the context by 20%.
Limitations and Future Work
- Unstructured Environments: In highly unpredictable environments (like web browsing via Playwright), models sometimes revert to "DTC-like" behavior—calling one tool at a time without using programmatic logic. This limits the benefits of PTC.
- Silent Failures: The current system relies on explicit error flags from servers. If a tool fails silently or returns an error message as a "success" string, the agent's exception-handling logic is bypassed.
- Future Directions: The authors suggest exploring how PTC training might improve "cross-interface" capabilities, as their experiments showed that PTC-trained models even improved at standard direct tool calling.
Summary updated