Multi-Model Orchestration for AI Coding: A Layered Scheduling Approach in Practice

    This article explains how to structure AI coding workflows with layered model scheduling instead of relying on a single top-tier model with full-repository context. It covers a three-layer design (planning, scheduling, execution), role and effort-level configuration, context isolation through self-contained task cards, mechanical-first acceptance loops, the resulting cost model, and common pitfalls with engineering constraints. Readers will learn how to assign high-capability models to irreversible decisions and lightweight models to verifiable output, making AI-assisted development more predictable and measurable.

    1. The Problem: Long Context Is Undermining Coding Efficiency

    Once coding assistants entered a stage where multiple models are selectable, a common pattern emerged: developers default to the strongest model, the highest effort level, and full-repository context, expecting a perfect result in one shot. Feedback from practice shows the opposite. As context keeps expanding, the model’s attention to critical constraints gets diluted and output quality visibly degrades. At the same time, repeatedly reading long histories and the entire codebase makes compute cost grow non-linearly.

    A more subtle problem is the mismatch between planning and execution. Planning needs a global view, the ability to weigh trade-offs, and architectural judgment. Execution needs output that is stable, cheap, and parallelizable. Using one expensive model end to end means the most costly compute is spent on the most repetitive reading and rewriting, while the steps that genuinely require deep thinking get squeezed by the budget.

    2. Core Idea: Projects Are Layered, Models Don’t Have to Be

    The essence of layered orchestration is mapping the “layered architecture” already familiar in software engineering onto model orchestration:

    • Planning layer: requirement clarification, task decomposition, interface contracts, risk identification, and acceptance criteria.
    • Scheduling layer: task dispatch, dependency ordering, context trimming, result validation, and rework decisions.
    • Execution layer: completing coding, test completion, formatting, and local fixes within clear boundaries.

    The key principle is “strong models make decisions, weaker models produce output.” Decisions are few but high-impact; output is frequent but clearly bounded. This frees high-capability models from repeatedly reading the whole project and reserves them for the highest-density judgment points.

    3. Role and Effort-Level Configuration

    One practical configuration is: planning uses a high-capability model at a high effort level; scheduling and acceptance use a mid-tier model at a high effort level; execution uses a lightweight model at the lowest effort level and carries no history.

    1. Planning (strong model/high) -> Task card (structured) -> Scheduling (mid model/high)
    2. ^ |
    3. | v
    4. Rework decision <---- Acceptance (mid model/high) <---- Execution (light model/low, no history)

    There are three reasons for this arrangement. First, execution tasks are compressed into atomic operations with short context and a single objective, which a lightweight model can handle. Second, acceptance is handled by a model with stronger judgment, able to catch output that “looks done but has drifted.” Third, the high-capability model is only woken when necessary, avoiding repeated payment for long histories.

    4. Context Isolation: The Value of “No History” During Execution

    “No-history execution” is not missing information; it is purified information. The scheduling layer should turn a task into a self-contained task card so the execution model can start without tracing back through the conversation:

    1. task_id: T-017
    2. goal: Add unit tests for the order module
    3. files: [src/order/service.ts, tests/order/service.spec.ts]
    4. constraints:
    5. - Do not change public interface signatures
    6. - Use the existing factory function for dependency injection
    7. - Statement coverage threshold must not fall below the existing baseline
    8. acceptance:
    9. - All tests pass
    10. - No new static analysis warnings
    11. rollback: Keep a backup of the original files and roll back on failure

    Once a task card is self-contained, execution becomes parallelizable, replayable, and model-swappable, and cost stays controllable.

    5. The Acceptance Loop: Making “Ask the Big Model to Review” Systematic

    The traditional approach passes the repository and the entire conversation history to a strong model for review, spending tokens on large amounts of irrelevant information. A more economical approach is to have the scheduling layer run mechanical checks first (compilation, static analysis, unit tests, change-scope comparison), and only let output that passes mechanical checks enter sampled review by a human or a strong model. The review input should be “task card + diff snippet + failure logs,” not the full history.

    1. if mechanical check fails: rework directly (attach failure logs)
    2. elif changes exceed the files scope: reject and re-dispatch the task card
    3. else: send a sample to the strong model for review (diff and acceptance criteria only)

    6. Cost Model: Why Total Volume May Rise but Unit Price Improves

    After layering, total tokens are not necessarily the lowest, but the share of “high-unit-price tokens” drops significantly. It can be roughly expressed as:

    1. Total cost ≈ planning cost + Σ(scheduling cost + execution cost) + rework cost

    Because execution-side context is trimmed and unit price is lowest, and rework is intercepted early by mechanical checks, the overall budget becomes more predictable. If a task is extremely simple, completing it end to end with a low-tier lightweight model is often more cost-effective. When the quality bar rises, you only need to raise the effort level of a single layer instead of upgrading the whole chain.

    7. Common Pitfalls and Engineering Constraints

    • Pitfall 1: Treating planning output directly as execution instructions. Planning should produce verifiable task cards, not prose descriptions.
    • Pitfall 2: The scheduling layer lacks permissions. Scheduling needs access to build and test results; otherwise the loop cannot close.
    • Pitfall 3: Ignoring rollback. Every atomic task should be independently rollback-able so one failure does not pollute the main branch.
    • Engineering constraint: Scenarios involving access to external systems, or image or UI understanding, should be encapsulated as controlled tool interfaces, with the scheduling layer handling unified authorization and auditing.

    8. Conclusion

    Multi-model orchestration is not about stacking more models; it is about rebuilding responsibility boundaries: let the most expensive compute handle only the most irreversible decisions, let the cheapest compute handle the most verifiable output, and let the middle layer translate, trim, and gatekeep. In engineering practice on platforms such as Baidu AI Cloud, this combination of “layered scheduling + context isolation + mechanical acceptance,” together with common capabilities like logging services, monitoring and alerting, and containerized builds, can shift AI coding from a “one-shot gamble” to a sustainable, measurable delivery process.