Model Roles, Orchestration, and Cost Control for Multi-Agent Coding
Teams rarely rely on a single model in AI-assisted coding. This article treats role split, parallel scheduling, in-session model switching, context windows, and cache as engineering problems, with rules that keep spend tied to verifiable output.
In AI-assisted coding and automated R&D, teams rarely depend on one model. Lightweight models handle fast retrieval and first drafts; coding-oriented models land changes; more divergent models handle design and interaction. The issue is not how many models you have, but how they are orchestrated: parallel workers silently inherit expensive models, the same session switches back and forth, long context is compressed too early, and caches are flushed. Token spend then far exceeds useful output: status reports look complete, but the repo has no verifiable diffs.
This article treats that experience as operational engineering: role split, parallel scheduling, in-session switching, context and cache, and constraints you can write into global rules. The discussion stays on general mechanisms and practice, not a specific vendor or coding product.
Layer by capability, not by stacking names
Treat candidate models as three roles, not three all-purpose stand-ins.
Speed-first lightweight models fit parallel repo scans, evidence extraction, drafts, and formatting. Their value is throughput and cost, not final judgment. Coding-first models fit patches, refactors, test fixes, and interface alignment; output should be checkable by compile, test, or static analysis. Divergent models fit option comparison, information architecture, and interaction drafts, but if they own large implementation, discussion easily becomes unshippable speculation.
Overlapping positioning needs an explicit tradeoff. If two generations are close in capability, designate one default executor and enable the other only in named cases such as design review or coding repair. Default dual-open makes cache policy, billing, and failure fallback unpredictable.
Ask only three questions when choosing: must this role read the full repo; must it produce a verifiable artifact; is failure wasted quota or a bad merge. Speed models can be many; the model that merges conclusions should be few and fixed.
Four pitfalls of parallel subtasks
Parallel scheduling is meant to collect facts concurrently, then let the main model judge. Poor implementation creates four problems.
First, workers inherit the current session’s heavy model. If the main session is on a costly coding model, new workers often share that config. Parallelism multiplies spend while most workers only read files and quote sentences.
Second, progress can be faked. Models report in the past tense that they “modified and verified” without paths, line numbers, or command output. In parallel, the main model more easily trusts summaries and writes hallucination into conclusions.
Third, silent downgrade at dispatch. The scheduler may land workers on an older version or weaker config, visible only in logs. The main model still accepts against newer capability, so plans look new and execution looks old.
Fourth, no handoff on drop. After timeout, error, or idle spin, half-finished work in a worker’s directory is abandoned; the main model rescans everything at higher cost.
Five constraints help.
- In the parallel phase use only lightweight models, and submit raw findings: paths, line numbers or checkable excerpts, and “not found.”
- Judgment, tradeoffs, and final patches belong only to the main model; workers do not write concluding paragraphs.
- Dispatch a limited number of workers by workload, plus one fixed checker, to avoid unbounded forks.
- Immediately verify model id and version in run logs; discard the batch on downgrade.
- Give each worker an isolated directory, for example by task name and role; on timeout or error, hand progress files to another worker; do not start a conflicting set of notes.
Evidence format should be mechanical and script-checkable: every finding needs a file location or accessible source plus a quoted excerpt; if nothing is found, say so; never fill with “probably in config.” The main model then concludes from a fact list, not another unauditable essay.
Illustrative global rules (pseudo-config; implement at your own rules entry):
Parallel scheduling rules:1. Parallel workers may use only lightweight models; do not inherit the main session’s high-cost model.2. Workers write only raw findings under work/<task>/<role>/ and must not change product code.3. Each finding includes location and excerpt; if unlocatable, write “not found.”4. After dispatch, check model and version in logs; discard the batch on downgrade.5. On timeout or error, hand the worker’s progress files to another worker to continue.6. Conclusions, patches, and merge decisions come only from the main model after evidence is complete.
In-session model switching: split planning and execution
Another common pattern rotates a “planner” and an “executor” in one session: a stronger divergent or coding model writes the plan, a lightweight model edits files, then switch back on failure. That can approach all-heavy-model success rates at lower average cost, but caches are often isolated by model or config. A switch invalidates prefix cache, so later turns repay the same system prompt and tool list.
In practice, a single model with a stable prefix caches best; planning/execution ping-pong drops hit rate and spend rises out of proportion. Dynamic switching should be a controlled policy, not the default habit.
Split a session into two stages and default to one model throughout.
Do planning once at the start: goal, constraints, file scope, acceptance commands, and rollback, written fully and human-approved before execution. The execution stage does not chase questions or interject. Many products treat a new clarification as “re-plan,” forcing a switch back to a costly model and flushing cache. Allow return to planning only after consecutive test failures hit an agreed count (for example two); set a hard cap on model switches per session. Keep system prompt, tool list, coding standards, and long source material at the front and unchanged; append new logs only. Prefix stability is the condition for cache hits; changing the system prompt mid-session is an intentional cache kill.
If switching is required, store a cacheable prefix separately from per-turn increments: tool definitions and standards are not rewritten on model change; only append plan ids and failure logs. Prefer two sessions over repeated config changes in one.
Nominal context vs. the usable window
Vendors advertise large nominal context, but in coding environments auto-compression, tool returns, and multi-turn summaries make the effective window much smaller. Commonly, early agreements are already replaced by summaries well before the nominal cap; after more logs, the model repeats, drops constraints, or ignores confirmed interfaces. Compression thresholds, summary quality, and “when it forgets” must be measured; do not treat nominal length as usable length.
Practical steps:
- Probe memory with a fixed token: write an unguessable constraint early (a required error code or directory name), ask at 1/4, 1/2, and near the compression point, and record first loss. That is environment capability, not a marketing parameter.
- Put must-follow rules in the system prompt or a short prefix replayed each turn; do not assume chat from 100k tokens ago still holds.
- Externalize long material: specs, interface lists, and large logs live in the repo or object storage; the conversation keeps paths, versions, and excerpts, reading on demand instead of pasting full text.
- After compression, immediately replay constraints in a dozen lines: scope, bans, and acceptance commands, then continue coding.
- Monitor tokens, cache hits, and compression events together. A token curve without hit rate cannot explain why little writing still costs a lot.
If early context is forgotten far below the nominal cap, split the task rather than buy a larger window. A large window with aggressive compression feels like a small window plus uncontrolled summaries.
Quota governance: bind spend to verifiable output
Cost spikes are usually invalid calls, not unit price: heavy models used for excerpts, model inheritance in parallel, cache reset on switch, and evidence-free “done” that forces rework. Track four observables.
- Effective output ratio: merged patch lines or passing tests versus tokens for that run.
- Cache hit rate: a sudden drop in-session, first check whether the system prompt changed or the model switched.
- Parallel amplification: worker count times model unit price, estimated as a cap before dispatch.
- Rework count: batches voided by fake completion or downgraded models, counted separately from “model instability.”
Global rules should be short, checkable, and enforceable. Overlong rules occupy context and are first to vanish after compression. The parallel rules plus “default single model, plan once, switch cap, prefix unchanged” work as two fixed prefixes, not fragments in every turn.
Human gates remain: plan approval, directory isolation, log checks, evidence sampling. Models draft and retrieve; people do not treat “reported complete” as complete.
Rollout order
Do not enable every orchestration feature at once. Suggested order: first fix a default single model and a stable prefix, and measure the real usable window and cache hits; then limited parallelism with lightweight models and evidence format only; last, in-session switching with a count cap and failure threshold. Regression each step with the same small tasks: one happy path, one missing evidence, one worker timeout, one mid-run follow-up question. Expand to daily work only after those pass.
Model capability will keep converging; experience gaps come mainly from orchestration: who judges, who may only submit evidence, when a model may change, whether the prefix is stable, and whether constraints are replayed after compression. Write those as executable rules so quota, speed, and correctness stay controllable together.
