How to Choose Models for a Multi-Agent Development System by Role and Task

    Balancing cost and capability is a common challenge when integrating large language models into software development. Using only top-tier models drives up token costs, while using only small models struggles with complex architecture design and cross-module code generation. This article presents a two-layer approach of "lightweight execution with heavyweight orchestration" and explains how to select models based on Agent roles and task types.

    When integrating large language models into software development, a common challenge is balancing cost against capability. Running everything on top-tier models causes token expenses to rise quickly, while relying solely on small models makes it hard to handle complex architecture design and cross-module code generation. This article introduces a two-layer approach of “lightweight execution with heavyweight orchestration” and explains how to select models by Agent role and task type.

    1. An Architecture Combining Two Execution Modes

    The system operates in two modes. The first is a lightweight single-Agent mode for simple tasks such as code completion, basic refactoring, and unit test generation. It directly invokes the Agent built into the coding tool, so it requires few calls and responds quickly. The second is a multi-agent collaboration mode for complex tasks such as requirement decomposition, system-level refactoring, and cross-module feature development. In this mode, an orchestration framework schedules multiple specialized Agents to complete planning, coding, and review in sequence.

    Both modes share the same model API configuration and gateway routing. Developers can switch modes manually or apply rules at the task entry point to decide automatically. Cross-review between Agents reduces delivery risk, but final quality still depends on human acceptance.

    2. Environment Setup and Gateway Integration

    1. Obtain a model API key. Create an application on a cloud provider’s model platform (such as Baidu AI Cloud’s Qianfan) to get an API key. Choosing a platform with a rich model matrix and a unified calling protocol minimizes changes when switching models later.
    2. Inject the key via environment variables. Never hard-code the key or commit it to a repository. On Linux or macOS, run export MODEL_API_KEY="your-key" and confirm the variable is in effect before starting the orchestration framework.
    3. Unify the provider configuration. The example below maps three model categories to a single gateway so that Agents only reference aliases. When a model ID changes, only one place needs updating.
    1. {
    2. "provider": "unified_gateway",
    3. "api_key": "${MODEL_API_KEY}",
    4. "base_url": "https://your-gateway-endpoint/v1",
    5. "models": {
    6. "flagship": "flagship-model-id",
    7. "reasoning": "deep-reasoning-model-id",
    8. "coder": "code-specific-model-id"
    9. }
    10. }

    The base_url should be replaced with the actual address of your gateway. Configuration formats and dependency versions vary significantly across frameworks, so refer to the official documentation of the framework you use before deployment, and verify in a test environment that the Agent chain can call the gateway correctly.

    Keys should be granted minimum permissions and rotated regularly. Full keys must not appear in logs; only call status and model aliases should be recorded during debugging.

    3. Selecting Models by Agent Role

    Different Agents have different responsibilities and capability requirements. Assigning models by role concentrates flagship-model spending on critical nodes.

    1. Lead planning Agent: Responsible for requirement decomposition and task dispatch. It needs long-context understanding and global planning ability, so a flagship model is appropriate.
    2. Deep execution Agent: Writes the core code. It needs strong coding ability from code-corpus training as well as strong chain-of-thought reasoning.
    3. Solution design Agent: Evaluates architecture before coding. Its cognitive breadth requirements are close to those of the lead planning Agent, so a model of the same tier can be used.
    4. Review and analysis Agent: Handles code review and security analysis. It needs an analytical model that is sensitive to detail with low judgment bias.
    5. Auxiliary Agent: Handles peripheral tasks such as format conversion and status logging. A mid-sized reasoning model usually suffices, though actual results should be validated against your team’s own task set.
    6. Retrieval Agent: Searches codebases and documentation for context. A base model with good code comprehension is enough; creative generation is unnecessary.
    7. Vision Agent: Handles UI design mockup reproduction or chart analysis. A multimodal model is mandatory whenever images are involved.

    4. Dynamic Scheduling by Task Type

    Beyond static role configuration, the entry point can also route tasks dynamically based on type.

    • Ultra-hard reasoning: Tasks such as algorithm optimization and low-level architecture refactoring are routed to deep reasoning models. These models suit problems requiring multi-step deduction and typically have longer response times.
    • Deep analysis: System bottleneck analysis and complex log troubleshooting are routed to analytical flagship models.
    • Creative writing: Technical documentation, comments, and naming suggestions are routed to models with strong long-text generation.
    • Fast response: High-frequency, low-complexity tasks such as code completion, syntax correction, and bracket closing are sent directly to smaller lightweight models. Since these requests are numerous, switching to small models can noticeably reduce token consumption; the actual reduction depends on task distribution, model pricing, and cache hit rates.

    Automatic classification can start with simple rules—for example, judging by keywords, the number of files involved, and whether images are included—and thresholds can be refined gradually using production logs.

    5. Notes on Cost Estimation

    Cost estimation should be based on actual token usage and platform pricing. Multi-agent collaboration passes the same task through multiple nodes, so total token consumption may be higher than in single-Agent mode. Retries, repeated context passing, and human review time should also be counted toward total cost. It is recommended to review call volume and spending by role and task type weekly and adjust model assignments accordingly.

    6. Conclusion

    “Lightweight execution with heavyweight orchestration” is a practical path worth considering. It assigns simple tasks to small models, critical steps to strong models, and manages all configuration through a unified gateway. Teams should validate results against their own task distribution and evaluation data before settling on a specific model combination.