Multi-Model Orchestration: How Layered Scheduling Fixes Coding Hallucinations

    This article explains why relying on a single large language model for end-to-end development often fails, and how a three-layer orchestration pattern separates planning, scheduling and acceptance, and execution to reduce coding hallucinations. It covers execution drift, rework costs, context isolation, machine-checkable task card contracts, scripted acceptance pipelines, and practical guidelines for controlling cost while improving output quality.

    1. The Problem: Why One Model Cannot Do Everything

    In real-world AI coding workflows, teams often combine large language models of different capability tiers to complete development tasks. One early pattern was to use the most capable model for intensive planning in a web interface, a mid-tier model to dispatch subtasks at low cost and perform acceptance checks, and the lightest model to execute continuously in an “infinite ammo” loop. This pipeline looks well organized, but in practice it repeatedly exposes two structural problems.

    The first is execution drift. Lightweight models tend to ramble during long sessions. The planning phase may reach the right conclusion, but during implementation the code goes wrong, with interface signatures, boundary conditions, and error handling deviating layer by layer. The second is rework cost. Once execution breaks, the strongest model has to be brought back to review, with the repository context and the entire conversation history loaded again. The tokens saved earlier are paid back all at once, making the total cost higher instead of lower.

    The deeper issue is misallocated resources: the most expensive model repeatedly reads extremely long tasks and extremely long histories, while the cheapest model produces a large volume of low-quality code. This is like asking a model that “thinks less but performs well” to do the thinking, and a model that “thinks more but performs poorly” to do the implementation. It is a textbook case of putting the cart before the horse.

    2. The Core Idea: Three-Layer Division of Labor, Borrowed from Modern Management

    A more reasonable structure splits a single chain into three layers, with clear inputs, outputs, and context boundaries for each.

    1. Planning layer: Use the model with the strongest reasoning capability at a high-intensity reasoning setting. It is responsible only for problem decomposition, solution selection, interface agreements, and definition of acceptance criteria. Its output is a structured task card, not code.
    2. Scheduling and acceptance layer: Use a mid-tier model at the highest execution budget. It breaks the task card into independently verifiable subtasks, dispatches them to the execution layer, compares outputs against acceptance criteria, and decides whether to send work back. It plays the role of middle management.
    3. Execution layer: Use a lightweight model at a low reasoning setting, strictly with no history. Each time it receives only one subtask card and the minimum necessary file snippets, returns the result as soon as it finishes writing, and keeps no long session.

    The benefits of this structure go both ways: token consumption is higher than the “infinite ammo” mode but significantly lower than having the strongest model repeatedly read the entire project; execution quality is higher than pure lightweight execution, with a more obvious advantage in scenarios that require graphical interface operations or image recognition. The middle layer occasionally makes a “dumb” judgment, but the overall execution direction is easier to correct.

    3. Key Design: Context Isolation and the Task Card Contract

    Whether the three-layer structure holds depends on whether context is truly isolated. Once the execution layer inherits the full history, it reintroduces the risk of drift. In practice, the convention should be: execution-layer sessions are single-use and destroyed as soon as the task is done; information shared across tasks is passed only through task cards.

    A task card should contain the following fields, forming a machine-checkable contract:

    1. {
    2. "task_id": "T-014",
    3. "goal": "Add idempotent writes to the order module",
    4. "files_in_scope": ["src/order/service.py"],
    5. "constraints": ["Do not change public interface signatures", "New logic must be rollbackable"],
    6. "acceptance": ["Duplicate requests produce no duplicate records", "Unit test coverage does not drop"],
    7. "context_refs": ["design#3.2"]
    8. }

    Acceptance at the scheduling layer should also be scripted: run static checks and tests first, then have the model perform semantic comparison, to avoid a false pass that merely “looks right”:

    1. # Scheduling-layer acceptance pipeline sketch
    2. lint && unit_test --changed-only
    3. model_verify --task T-014 --against acceptance

    4. Cost Structure Comparison and Selection Advice

    In terms of cost composition, the three-layer pattern concentrates overhead in the scheduling layer’s repeated comparisons, rather than in the execution layer’s repeated reading of long context; the strong model is involved only in planning and final review of difficult cases, with the fewest calls but the highest value per call. If a team can connect strong-model orchestration capabilities to a local development environment, a two-layer variant of “strong model commanding at high intensity, lightweight model implementing at low cost” is also viable, with similar results but higher engineering modification requirements.

    For implementation, follow three principles: keep task card granularity to one or two files; make acceptance criteria executable and quantifiable; never reuse sessions at the execution layer. As long as these three are held, layered scheduling can keep the probability of “correct planning but broken execution” within an acceptable range while keeping costs under control.