Low-Cost Multi-Agent Coding: A Practical Guide to Role-Based Model Selection and Token Control

    This article explains how to build a low-cost multi-agent coding workflow without giving up core capabilities. It covers why chained planning-execution-review pipelines increase token usage, how to assign models to agent roles, how to combine lightweight and chained modes, how to configure and validate a compatible model access layer, and how to control cost through category selection, review strategy, and model tiering. The goal is not to replace capable models with weak ones, but to match model cost and capability to task difficulty.

    1. Introduction: Capability, Cost, and the Chained Scheduling Dilemma

    Multi-agent collaboration has become an important direction in agentic programming tools. Its core idea is division of labor and checks and balances: one agent plans, one executes, and one reviews. Separating “writing code” from “finding defects” across different roles often helps reveal problems that a single model may miss when self-checking.

    Take terminal-oriented agentic coding assistants as an example. These tools can read and write code files in the terminal, execute commands, and be extended through open-source plugin ecosystems. A multi-agent plugin for such an assistant typically provides several clearly defined roles:

    • Main planner role: Understands requirements, decomposes tasks, and orchestrates execution steps.
    • Deep execution role: Handles engineering tasks that require substantial reasoning, such as cross-file refactoring and complex algorithm implementation.
    • Solution role: Produces design ideas and implementation plans.
    • Review role: Independently checks solutions and outputs, pointing out omissions and risks.
    • Lightweight role: Handles small subtasks such as classification, summarization, code retrieval, and local edits.
    • Vision role: Understands image inputs such as UI screenshots, design mockups, and screenshots of error logs.

    This introduces a problem. Chained scheduling is essentially a serial workflow of planning → execution → review. Each role needs to load the relevant context independently in order to understand the overall task. The same tool rules and the same project description may be sent to the model repeatedly along the chain. As a result:

    • Task complexity and token consumption are roughly positively correlated.
    • If any single role in the chain uses a higher-end model, the unit cost of the entire chain increases.
    • If the review role finds a defect and triggers rework, the chain becomes even longer.

    The “budget” configuration described in this article does not mean reducing functionality. Its goal is to use lower-cost models to support the foundation of multi-agent collaboration, while allowing lightweight mode and chained scheduling mode to coexist according to need.

    2. Problem Breakdown: Why Tokens Get Out of Control in Chained Scheduling

    2.1 Call Count Scales with the Number of Roles

    A single-turn conversation calls the model only once. A chain containing three core roles—planning, execution, and review—can result in more than three times as many model calls as single-turn mode, even if each role is called only once. If solution design and rework iterations are included, the number of calls can be even higher.

    2.2 Context Accumulates as Tasks Grow

    During execution, an agent often needs to read files repeatedly, inspect command outputs, and compare diffs. For a medium-sized engineering change, a complete execution chain may easily place tens of thousands or even hundreds of thousands of tokens into context. Many services bill by total input and output tokens, and input tokens often make up the majority.

    2.3 Cost Amplification from Higher-End Models

    It is not entirely accurate to view “a better model” as simply “a more expensive token price plus stronger capability.” Chained scheduling amplifies the number of calls and therefore amplifies the cost of every individual call. For example, if a role participates in 20 calls during a task and each call processes 3,000 tokens, that role alone accounts for 60,000 tokens. If its unit price is significantly higher than other models, this role may consume most of the budget.

    2.4 Hidden Cost of Failed Retries

    A failure by a smaller model on a complex task can lead to one rework cycle. Rework usually means reloading context and replanning. A poorly designed “cost-saving” approach may end up costing more.

    From this, we can derive a core principle: allocate cost according to each role’s need for capability, rather than using one high-price model across the entire chain.

    3. Overall Architecture: One Access Layer, Two Modes

    The proposed setup consists of four parts:

    1. ┌─────────────────────────────────────────────┐
    2. │ Agentic Coding Assistant │
    3. │ (Terminal-side) │
    4. │ ┌────────────────┐ ┌──────────────────┐ │
    5. │ │ Lightweight │ │ Chained │ │
    6. │ │ Mode │ │ Scheduling Mode │ │
    7. │ │ Default built- │ │ Plan → Execute → │ │
    8. │ │ in assistant │ │ Review │ │
    9. │ │ Few turns, │ │ Multiple roles, │ │
    10. │ │ short context │ │ rework-capable │ │
    11. │ └───────┬────────┘ └────────┬─────────┘ │
    12. │ └────────┬───────────┘ │
    13. │ Unified Model Access Configuration │
    14. └─────────────────────┬───────────────────────┘
    15. ▼
    16. ┌───────────────────┐
    17. │ Model Access │
    18. │ Platform │
    19. │ Unified auth and │
    20. │ unified billing │
    21. └─────────┬─────────┘
    22. ▼
    23. ┌────────────────────────────────────────┐
    24. │ Long-context planning / Balanced │
    25. │ reasoning-code / Lightweight code / │
    26. │ General lightweight / Multimodal vision│
    27. └────────────────────────────────────────┘

    Two key points define this architecture:

    1. Single access point: All roles share one set of authentication information and one model mapping table.
    2. Two modes: Lightweight mode is suitable for most daily tasks, while chained mode is enabled only when the task is genuinely complex.

    3.1 Lightweight Mode: The Daily Workhorse

    Lightweight mode is the assistant’s built-in default. It completes work in a single turn or a small number of turns. Examples include:

    • Reading files, modifying functions, adding comments, and fixing a clearly identified bug.
    • Running unit tests, checking logs, and executing format checks.

    Its characteristics are short context, few calls, and fast responses. In a unified model access configuration, it usually maps to a default model.

    3.2 Chained Scheduling Mode: Tackling Complex Tasks

    Chained mode is suitable for situations such as:

    • Refactoring across multiple modules.
    • Implementing a complete feature from scratch.
    • Requiring solution design.
    • Requiring review of high-risk changes.
    • Involving multimodal inputs, such as “implement the corresponding page based on this UI screenshot.”

    It schedules tasks in the order of planning → execution → review, and each role is assigned a model by the plugin according to its responsibility.

    3.3 The Essence of Compatibility

    Both modes share the same model configuration. Switching modes does not mean switching providers or reconfiguring API keys. Developers only need to understand two things:

    • Which models are assigned to each role in chained mode.
    • Which default model is used in lightweight mode.

    Both are read from the unified mapping table, making maintenance easier and cost governance more consistent.

    4. Model Tier Selection: Allocating Cost by Role Capability

    4.1 Three Selection Principles

    1. Capability matching: Choose models that are strong in the capabilities a role actually needs.
    2. Cost matching: Roles that do not require top-tier capability should not use top-tier models.
    3. Fault-tolerance matching: Roles with high error costs, such as the review role, may use stronger models because the issues they catch can prevent the entire chain from reworking.

    4.2 Agent Role and Model Correspondence

    The “model” column below describes general capability tiers. When integrating, you can choose specific models that match each tier on the selected access platform.

    Role Recommended Tier Reason
    Main planning Long-context strong planning type Requires global understanding of requirements and task decomposition; context is long, and planning quality directly determines execution direction.
    Deep execution Balanced reasoning-code type Requires strong code understanding and generation, while reasoning capability must also keep up.
    Solution design Long-context strong planning type Should stay consistent with the main planner role; solution design and task decomposition need coherent logic.
    Review/analysis Strong analysis and reasoning type Review requires accurate judgment and places high demands on analysis and reasoning capability.
    Light reasoning, such as classification and strategy selection Balanced reasoning-code type Light reasoning tasks can be covered by both code and reasoning capability.
    Code retrieval/exploration Lightweight code type Mainly involves searching, reading, and summarizing; capability should be “good enough” to reduce token consumption.
    Light subtasks Lightweight code type Suitable for small-scope changes and simple subtasks.
    Vision understanding Multimodal vision model Must support image input; this is a hard capability requirement and cannot be replaced by a text-only model.

    4.3 Interpretation of the Selection Logic

    Why should planning and solution design use the same model tier?
    Because these two roles are at the front of the chain, and their outputs become the basis for subsequent execution. Keeping solution design and task decomposition aligned in thinking style improves semantic consistency within the chain.

    Why should the execution role prioritize balance?
    Deep execution needs to balance code generation quality and reasoning capability. Choosing a model that is balanced in both aspects is often more economical than maximizing a single dimension.

    Why should retrieval roles be “good enough”?
    Tasks such as code retrieval and file summarization usually produce structured results and do not require the highest model capability. These roles can also generate a large number of calls, which consume a considerable number of tokens. Using lightweight models preserves sufficient capability while lowering unit cost.

    Why should the review role be “strong rather than weak”?
    Review is the last gate for preventing rework. If the review role is too weak, it may miss real defects, allow incorrect code to pass, and ultimately let humans discover the problem later, resulting in higher rework costs.

    5. Category-Based Selection: Difficulty-Driven Dynamic Matching

    In addition to agent roles, many plugins also support categories. Developers can specify a task category when asking a question, and the plugin will use the model associated with that category to handle the request. Common categories include:

    Category Recommended Tier Use Case
    ultrabrain Long-chain reasoning model Complex algorithm design, difficult bug localization, and architecture-level trade-offs.
    deep Strong analysis and reasoning type Deep code analysis, solution comparison, and performance bottleneck analysis.
    artistry / writing Long-context strong creation type Documentation, comments, design descriptions, and creative naming.
    quick / unspecified-low General lightweight type Simple Q&A, format conversion, term explanation, and simple modifications.

    5.1 Meaning of Dynamic Matching

    Categories allow developers to make fine-grained allocations by difficulty within the same model configuration. When asking a question, developers only need to switch categories instead of manually specifying models. This is flexible and helps control costs.

    5.2 Importance of the Default Fallback

    Many plugins use unspecified-low as the default category. If no category is specified, the request may be treated as a low-difficulty task. Therefore:

    • When asking questions, do not habitually omit the category. Requests that need deep analysis should explicitly use deep or ultrabrain; otherwise, they may be downgraded and receive shallow answers.
    • Conversely, simple tasks should keep the default to avoid unnecessary model upgrades.

    6. Cost Governance: Continuous Control from Selection to Runtime

    6.1 Set Cost Limits for High-Frequency Roles

    Lightweight code models have low unit prices and are well suited for high-frequency, low-value calls such as code retrieval and file summaries. Moving these roles to lightweight models can often reduce overall cost significantly.

    6.2 Evaluate Token Amplification

    A practical characteristic of chained scheduling is that token consumption grows nonlinearly as the number of roles increases and context becomes longer. Before adopting a new model, you can first run a small task through the complete chain, observe actual token usage and the selected model’s billing method, and then decide whether to move that role to another model.

    6.3 Let Lightweight Mode Handle Most Daily Requests

    In daily development, many requests are simple, such as “modify this function,” “add a comment,” or “check this log.” These tasks can be handled entirely by lightweight mode. Chained mode is only needed when:

    • The task involves multiple files.
    • The solution needs to be redesigned.
    • Strict review is required.

    6.4 Treat Review as an Investment

    The review role produces additional token usage, but in return it reduces rework. In practice, you can observe whether the review role actually finds problems. If the review role repeatedly allows incorrect output, it may be necessary to switch to a stronger model or adjust the review strategy, rather than remove review altogether.

    7. Implementation: From Access Configuration to Validation

    7.1 Prerequisites

    1. Choose an access platform: Select a model service that provides multiple models and is compatible with a common interface specification, typically a chat-completion-style interface. Register an account and obtain an API key.
    2. Install the coding assistant: Install the selected coding assistant in the local terminal and confirm that it starts properly.
    3. Review access documentation: Consult the assistant’s model access configuration documentation to understand how to configure a custom access platform.

    7.2 Configuration Steps

    The following example assumes a model access platform compatible with a chat-completion-style interface.

    1. # Example: set the gateway URL and key as environment variables
    2. export AI_GATEWAY_URL="https://<your-gateway-url>/v1"
    3. export AI_GATEWAY_KEY="<your-api-key>"
    1. # Example: coding assistant configuration snippet
    2. # Field names are illustrative only; follow the official documentation.
    3. provider:
    4. gateway:
    5. npm: "@ai-sdk/openai-compatible"
    6. options:
    7. baseURL: "{env:AI_GATEWAY_URL}"
    8. apiKey: "{env:AI_GATEWAY_KEY}"
    9. models:
    10. # Chained scheduling roles
    11. sisyphus: { provider: gateway, model: "<long-context strong planning model>" }
    12. hephaestus: { provider: gateway, model: "<balanced reasoning-code model>" }
    13. prometheus: { provider: gateway, model: "<long-context strong planning model>" }
    14. oracle: { provider: gateway, model: "<strong analysis and reasoning model>" }
    15. metis: { provider: gateway, model: "<balanced reasoning-code model>" }
    16. momus: { provider: gateway, model: "<balanced reasoning-code model>" }
    17. atlas: { provider: gateway, model: "<balanced reasoning-code model>" }
    18. librarian: { provider: gateway, model: "<lightweight code model>" }
    19. explore: { provider: gateway, model: "<lightweight code model>" }
    20. "sisyphus-junior": { provider: gateway, model: "<lightweight code model>" }
    21. "multimodal-looker": { provider: gateway, model: "<multimodal vision model>" }
    22. # Categories
    23. categories:
    24. ultrabrain: { model: "<long-chain reasoning model>" }
    25. deep: { model: "<strong analysis and reasoning model>" }
    26. artistry: { model: "<long-context strong creation model>" }
    27. writing: { model: "<long-context strong creation model>" }
    28. quick: { model: "<general lightweight model>" }

    7.3 Validation Checklist

    • Connectivity: Use a simple question to confirm that the API key is valid and the gateway URL is reachable.
    • Model availability: Confirm that every model name exists on the selected platform. Incorrect model names are one of the most common causes of configuration failures.
    • Capability matching: Use a small refactoring task and a review task to verify that the output quality of the execution role and the review role meet expectations.
    • Vision role: Upload a UI screenshot and confirm that the multimodal model can recognize it correctly.
    • Default lightweight mode: Confirm that requests without a specified category use the lightweight model, preventing unexpected consumption of higher-cost model quota.

    8. Advanced Tuning: Practical Tips

    8.1 Use Categories Instead of Manually Specifying Models

    When asking questions, prefer categories such as deep or quick instead of manually specifying a model every time. Categories are managed by the plugin, making switching easier and helping form stable usage habits.

    8.2 Pay Attention to Context Length

    Planning and solution roles need to process longer contexts. If the selected model has a relatively small context window, consider the following:

    • Use models with longer context capability for these roles.
    • When asking a question, provide key background first, such as a list of relevant files, interface contracts, and constraints, to reduce the model’s need to explore on its own.

    8.3 Give the Review Role an Independently Strong Model

    The quality of the review role directly affects whether rework is needed. Do not assign it a lightweight model just because it “only reads and does not write.” In practice, the capability ceiling of the review role often determines the final quality of the entire chain.

    8.4 The Vision Role Cannot Be Replaced

    Tasks involving screenshots, UI design mockups, or error screenshots must be handled by multimodal models that support image input. These tasks cannot be replaced by text-only models. When selecting a model, prioritize verifying real availability of multimodal capability.

    8.5 Understand Billing Methods and Rate Limits

    • Billing methods: Different models use different billing methods. Some bill separately for input and output tokens, while others offer monthly call packages or free quotas. In chained scheduling, input tokens are usually much larger than output tokens, so the input price has a greater impact on total cost.
    • Rate limits: Lightweight models usually have more relaxed rate limits, while higher-cost models may have stricter limits. Using lightweight models for high-frequency tasks can also reduce the chance of hitting rate limits.
    • Failed retries: Integration failures, such as incorrect model names, invalid API keys, or insufficient quota, do not automatically fall back to another model. They need to be corrected manually in the configuration.

    9. Quick Reference for Common Issues

    Symptom Possible Cause Recommendation
    API call fails with 401/403 Invalid API key or insufficient quota Check environment variables and platform quota.
    API call fails with 404 Model name is misspelled or does not exist Compare against the platform’s model list.
    Response is truncated or reasoning is incomplete Context window is insufficient Use a model with a larger context window for long-context roles.
    Lightweight mode gives overly shallow answers No category is specified, so the request falls into the default low-difficulty branch Explicitly use deep or ultrabrain.
    Review role fails to find problems Review model is too weak Switch to a stronger analysis and reasoning model.
    Cost is still too high High-frequency roles are using higher-cost models Move retrieval and light subtasks to lightweight code models.
    Multimodal task fails Vision role is configured with a text-only model Switch to a multimodal model that supports image input.

    10. Conclusion: Spend Tokens Where They Matter

    The core of this “budget” multi-agent configuration is not to replace expensive models with cheaper ones. It is to match model selection to task difficulty. The approach can be summarized in three principles:

    1. Role tiering: Use long-context strong planning models for planning and solution design; balanced reasoning-code models for execution; strong analysis and reasoning models for review; lightweight code models for retrieval and light subtasks; and multimodal vision models for vision tasks.
    2. Difficulty routing: Let simple questions use the lightweight default branch; explicitly use deep or ultrabrain categories for deep analysis.
    3. Mode coexistence: Use lightweight mode for daily development, and start chained scheduling only for genuinely complex tasks.

    With this strategy, most developers can keep multi-agent collaboration costs low while still retaining a complete planning, execution, and review chain for complex engineering tasks. Cost control is not a compromise on capability; it is about allocating compute where it is truly needed.