Cutting Costs and Boosting Efficiency in Coding Agents with Small Model Execution Subagents

    Modern coding agents often rely on expensive large language models (LLMs) for every task, including executing terminal commands and reading logs. This article explores the "Execution Subagent" architecture, which leverages a specialized ~4B parameter small model for terminal execution. By separating the planning and execution roles, this approach reduces main agent token usage by up to 30% without compromising success rates, offering valuable insights into building cost-effective, multi-model coding agent systems.

    1. The Problem: Is Using Large Models for Terminal Execution Overkill?

    In current coding agent practices, an intriguing phenomenon exists: whether planning architecture, modifying code, executing terminal commands, reading test errors, or summarizing logs, all steps are often handled by the same expensive, frontier LLM. The former indeed requires strong reasoning capabilities, but the latter—especially tasks like “running a command, glancing at the output, and extracting key information”—does not demand high model intelligence.

    A recent industry study provides a clear answer: large models are not strictly necessary. Researchers proposed an “Execution Subagent” architecture and trained a dedicated terminal execution small model based on an open-source base model of around 4 billion parameters. Experimental results show that while maintaining the coding agent’s problem-solving success rate, the main agent’s token usage can be reduced by up to 30%, and the small model’s performance on some execution metrics approaches or even exceeds that of flagship LLMs acting as subagents. This finding suggests that coding agents may enter a new phase of “specialized small model subagentization.”

    2. Three Flaws of the Direct Execution Mode

    When programming agents handle real-world workflows, terminal execution is inevitable: running diagnostic tests to reproduce issues, validating fixes, reading compilation errors, etc. The current conventional approach is the “direct execution mode,” where the main agent runs commands directly within its context window and absorbs all output. This architecture has three structural flaws:

    1. Massive Token Consumption. A single test run outputting detailed logs can easily generate tens of thousands of tokens. If a top-tier model billed by token is used throughout, costs increase linearly or even super-linearly with interaction rounds.

    2. Squeezed Core Information. The context window is a finite resource. Verbose raw logs squeeze out content that the agent genuinely needs for subsequent decisions—code context, edit history, task planning, etc. Once critical context is flushed, the agent’s reasoning quality degrades noticeably.

    3. The Snowball Effect. As interaction rounds increase, the output of each new command further compresses the remaining window, causing the agent to execute significantly fewer effective problem-solving steps before hitting the token limit, making tasks more likely to fail midway.

    Essentially, what the main agent truly needs from terminal execution is often just a concise summary: the line of code corresponding to the error, or the test result statistics at the end of the log, rather than the entire raw output from the shell. Information “acquisition” and “comprehension” can be completely separated.

    3. Execution Subagent Architecture: Let Specialized Small Models Do Specialized Work

    The core idea of the execution subagent is role separation:

    • Main Agent (Planner): Served by a highly capable large model, responsible for understanding requirements, planning steps, editing code, and making critical decisions.
    • Execution Subagent (Executor): Served by a specially trained small model, possessing an independent context window, responsible for running terminal commands, reading raw output, and compressing the results into structured summaries returned to the main agent.

    The workflow can be abstracted as:

    1. Main Agent ──issues execution command──> Execution Subagent
    2. │ Runs command, reads full output
    3. │ Extracts error causes/test stats/key log lines
    4. Main Agent <──returns refined summary──────┘

    This design brings threefold benefits. First, the main agent’s context window is no longer polluted by raw logs, preserving valuable capacity for code and planning. Second, massive execution tokens are digested by the low-cost small model, significantly reducing overall reasoning costs. Third, the subagent can be specifically optimized for execution scenarios, yielding summary quality that can even surpass the on-the-spot performance of a general-purpose large model.

    4. How Small Models Learn to “Execute and Summarize”

    Enabling a ~4B parameter small model to handle this role relies on targeted training strategies, primarily including:

    • Task-Specific Data Construction: Collecting terminal interaction trajectories from real code repositories and constructing supervised samples mapping “full command output → ideal summary,” allowing the model to learn to identify error stacks, locate failed assertions, and extract test pass rates and other key patterns.
    • Reinforcement Learning Optimization: Using “whether the summary helped the main agent make the correct decision,” “whether critical information was retained,” and “whether it is sufficiently concise” as reward signals for policy optimization, enabling the model to balance information fidelity and compression rate.
    • Format Constraints: Agreeing on a unified summary structure (command, exit code, error location, key output snippets, suggested next step), reducing the parsing cost for the main agent.

    It is worth emphasizing that the training here is not for general conversational ability, but for a highly vertical “terminal output understanding and compression” capability. This is precisely a scenario where small models excel: clear task boundaries, relatively fixed patterns, and explicit evaluation criteria.

    5. Implications for Engineering Implementation

    This architecture offers direct reference value for building enterprise-grade intelligent programming assistants:

    1. Layered Model Scheduling: Grading subtasks like planning, editing, execution, and retrieval by intelligence requirements and matching them with different model specifications is a core method for controlling reasoning costs.
    2. Context Engineering Priority: Beyond expanding the window, one should proactively manage context quality through methods like subagent isolation and summary compression.
    3. Value Re-evaluation of Small Models: In vertical scenarios with clear task boundaries, domain-trained small models can fully replace general-purpose large models, offering advantages in private deployment, low latency, and low cost.

    Enterprises can combine their existing infrastructure (e.g., container platforms hosting execution sandboxes, log services aggregating run records, monitoring and alerting tracking token consumption) to build a similar layered agent system, enabling the scalable deployment of coding agent capabilities under controllable costs.

    6. Conclusion

    “Think with large models, work with small models” is becoming an important paradigm in agent system design. The practice of execution subagents proves that saving about 30% of tokens does not come at the expense of success rates; instead, it brings more robust performance due to cleaner context. The future competition of coding agents may no longer be about whose single model is stronger, but whose multi-model collaboration architecture is more refined.