Small Execution Sub-Agents: Cutting Token Costs for Coding Agents
This article explains how a small language model can serve as an execution sub-agent in a coding agent system. A flagship model keeps planning and decision-making, while a 4-billion-parameter model trained for terminal tasks runs commands, reads outputs, and returns concise summaries. The article covers why execution tasks can be delegated, how domain-specific training narrows the capability gap, and practical engineering measures for fallback handling, evaluation, and deployment.
1. The Problem: Expensive Execution Work
If you have worked extensively with coding agents, you have probably noticed a pattern. In a typical bug-fixing workflow, the agent spends little time actually reasoning. Most tokens go to mechanical work: running terminal commands, executing test suites, reading error stacks, parsing build logs, and summarizing results. These tasks fill a large share of the agent’s context window but require little complex reasoning.
Consider the cost. A bug fix of moderate complexity may take a dozen or more command-observation-analysis cycles. In each cycle, the command output often contains thousands of tokens of log text, and that text is pasted directly into the main model’s context. If the main model is a flagship large language model, its input token price is typically several times to dozens of times higher than that of a lightweight model. In other words, the system pays PhD-level hourly rates for a lab assistant to organize experiment notes. From an engineering economics standpoint, this is a clear resource mismatch.
This raises a central question: does terminal execution really need a flagship reasoning model? A recent research work answers no. A 4-billion-parameter model trained specifically for terminal execution, used as an execution sub-agent, can reduce the main agent’s token consumption by about 30% without reducing its task success rate. On some metrics, it approaches or even exceeds the performance of a flagship model that handles execution itself.
2. Task Layering: Why Execution Can Be Delegated
2.1 The Capability Spectrum of Coding Agent Tasks
To understand why a small model can handle execution, first divide the agent’s work by capability requirements. A typical agent workflow falls roughly into three categories:
Planning tasks include understanding requirements, breaking down problems, designing a fix strategy, and adjusting direction after several execution steps. These tasks require long-horizon reasoning, world knowledge, and abstract generalization. They form the “brain” of the system and must be handled by a strong model.
Execution tasks include generating terminal commands from a plan, reading output after execution, judging whether a command succeeded, locating key error lines in logs, and condensing results into brief conclusions for the planner. These tasks share three traits: they are highly patterned, their reasoning chains are short, and their results are verifiable.
Retrieval tasks include locating relevant files in a codebase, searching symbol references, and reading surrounding code. They fall between the two categories, and engineering methods such as retrieval augmentation can support them.
With this layering, the difficulty ceiling of execution tasks is clearly much lower than that of planning tasks. Deciding whether a command succeeded is essentially a matter of parsing exit codes and output patterns. Extracting failed test cases from a test log is essentially structured information extraction. With targeted training, a small model can handle these tasks well.
2.2 Collaboration Architecture: Main Agent and Execution Sub-Agent
The architecture works as follows:
User request → Main agent (flagship model)│├─ Planning and decision-making (retained)│└─ Calls execution sub-agent (small model)├─ Generates and runs terminal commands├─ Reads and parses output└─ Returns a condensed summary of conclusions
The key design principle is information condensation. The main agent no longer consumes every token of raw logs. Instead, it receives structured conclusions distilled by the sub-agent, for example: “3 tests failed; all failures are assertion mismatches involving line 42 of file X.” Redundant information in the context window is greatly reduced, and this is where the token savings come from.
3. Why a Small Model Can Approach Flagship Execution Performance
A reader might ask: a small model has a lower capability ceiling, so how can it match a flagship model on execution? The answer is that domain-specific training compensates for the gap in general capability.
A flagship model spreads its capacity across all tasks, from writing poetry and solving math problems to discussing philosophy. Terminal execution, by contrast, is a relatively concentrated domain. Common command syntax patterns, common error message structures, and log formats are highly regular. Through the following methods, a small model can reach a high level of performance in this narrow domain.
High-quality trajectory distillation: The flagship model runs many tasks in real repository environments. Complete trajectories of “instruction → command → output → judgment” are collected, and the successful and efficient ones are selected as training data.
Reinforcement learning with verifiable rewards: Terminal tasks naturally provide verification signals. Whether a command succeeded, whether tests passed, and whether an error was located correctly can all be checked programmatically. This lets reinforcement learning optimize behavior efficiently without relying on expensive human annotation.
Format-constrained output: The sub-agent returns conclusions in a fixed structure (command, exit status, key errors, suggested action). This lowers generation difficulty and makes the output easier for the main agent to parse.
This confirms an engineering lesson worth remembering: on vertical tasks with a concentrated distribution, a well-specialized small model can approach or even exceed an unspecialized large model, potentially at a small fraction of the cost.
4. Engineering Practice: Key Points for Building an Execution Sub-Agent
4.1 Boundary Principles
Delegating more tasks to the sub-agent is not always better. A practical rule is this: steps that require judgment from global context stay with the main agent. Steps with clear inputs and outputs and objective success criteria go to the sub-agent. For example, “inferring the root cause from observed test failures” belongs to the first category, while “finding the failing tests in a log and extracting their error messages” belongs to the second.
4.2 Fallback Mechanisms
A sub-agent will sometimes make wrong judgments, so engineering practice calls for three layers of fallback:
- Confidence reporting: The sub-agent attaches a confidence estimate to each conclusion. When confidence is low, the main agent can request the raw log excerpt and review it independently.
- Replayable context: The original output is stored with a reference, such as an object storage entry or a local file, so the main agent can retrieve it on demand.
- Round-based circuit breaker: When the execute-observe loop exceeds a set number of rounds without converging, the full context is handed back to the main agent for takeover.
4.3 Evaluation Framework
Before deployment, establish evaluation along two dimensions. The first is effectiveness: compare task success rates before and after introducing the sub-agent, and confirm there is no statistically significant drop. The second is cost: track total input and output tokens for the main model, end-to-end latency, and combined cost per task. Benchmark suites that measure agent performance on real repository repair tasks can support this evaluation, and this dimension is recommended as the core acceptance metric.
4.4 Deployment Recommendations
Small models are flexible to deploy. They can run on a container platform as an independent service accessed through internal RPC calls. After inference optimization, a 4-billion-parameter model can support substantial concurrent throughput on a single mid-range inference GPU. For workloads that need elastic scaling, automatic scaling based on call volume, paired with a monitoring and alerting system, can further reduce unit cost. For example, the container platform and inference service offerings from Baidu AI Cloud could help set up a production environment for such sub-agents. Check the official documentation for service availability in your region.
5. Outlook: The Shift Toward Specialized Sub-Agents
The trend this research reveals may matter more than any single model. Future coding agent systems will likely move away from “one flagship model for everything
