The Cost and Capability Trade-offs of Multi-Agent Coding
This article examines the trade-offs between cost and capability in multi-agent AI coding, using a real refactoring task that consumed roughly 48 million tokens. It explains why token usage grows non-linearly when a task shifts from writing code to making correct changes in an existing codebase, where that cost goes, and how to apply tiered model scheduling. You will also find a technical breakdown of viewport-driven dynamic resampling and practical engineering tips for keeping AI-assisted development affordable and reliable.
1. Background: What a High-Consumption Coding Run Revealed
In a recent refactoring task on a self-developed plotting library, a developer used a multi-agent collaborative coding framework. Every stage was handled by a mix of high-capability and lightweight models. The run consumed about 48 million tokens, at a cost of roughly 60 RMB. The task itself was to modify a downsampling algorithm so that resampling is triggered whenever the visible plotting window changes, avoiding the distortion that occurs when a local area is magnified after a one-time downsample. The resulting code passed compilation and tests, and the version commit was completed automatically.
The value of this case is not in judging a specific tool. It exposes a common problem: when a task grows from “write a piece of code” into “make the correct change inside an existing project,” token consumption and capability requirements rise non-linearly. This article sets aside product-specific details and focuses on the general technical issue.
2. Capability: Coding Is Now in the “Usable” Range
Judging by the engineering outcome, mainstream high-capability models are now reliably usable for code comprehension, cross-file modification, and test-driven verification, performing on par with first-tier solutions. Three boundaries still matter:
- Long-chain tasks still depend on constraints. In multi-step refactoring, a model may probe repeatedly, producing many ineffective reads and redundant reasoning passes.
- Longer context yields diminishing returns. Once the repository exceeds the effective context window, the overhead of retrieval and summarization rises sharply.
- “It runs” is not the same as “it is well designed.” Algorithm changes in particular require human judgment at the design level.
3. Cost: Where the 48 Million Tokens Went
High consumption usually comes from four factors stacking together:
- Repeated context loading: every turn carries prior history and file fragments;
- The multi-agent amplification effect: planning, retrieval, review, and execution roles run in parallel, so the same information is read multiple times;
- The extra cost of high reasoning tiers: complex reasoning modes consume more tokens by design;
- The back-and-forth of the verification loop: compile, test, and fix cycles often account for the largest share.
A schematic layered configuration looks like this (a generic illustration only):
{"planning_agent": { "tier": "high_reasoning" },"review_agent": { "tier": "high_reasoning" },"search_agent": { "tier": "lightweight" },"quick_task": { "tier": "lightweight" }}
The core principle: reserve high-cost capability for the nodes that genuinely need deep reasoning, and hand retrieval, summarization, and formatting to lightweight models.
4. Technical Focus: Viewport-Driven Dynamic Resampling
The algorithm behind the original task is worth expanding on. The weakness of one-time downsampling is that sampling density is fixed when data is loaded. When the user magnifies a local region, the available original detail has already been discarded, producing steps and jagged edges. The improvement approach includes:
- Retain multiple data levels (a raw level plus several pre-sampled levels);
- Take the current visible interval and pixel width as input to decide the sampling step dynamically;
- Recompute incrementally when the window changes beyond a threshold, instead of rebuilding everything;
- Handle extreme-value retention specially, so peaks are not averaged away.
// Pseudocode: choose a sampling level based on the visible windowint pick_level(double x_range, int pixel_width) {double samples_per_pixel = x_range / pixel_width;return level_for(samples_per_pixel); // the closer samples per pixel is to 1, the deeper the level}
5. Engineering Practices
- Clarify before letting go: define task boundaries, acceptance criteria, and off-limits areas up front;
- Commit in small steps: split a large refactor into verifiable small changes to lower rollback cost;
- Make cost observable: record tokens and time per stage to locate waste;
- Divide labor between human and machine: leave algorithm selection and architecture decisions to people, and delegate mechanical edits to automation;
- Use hybrid scheduling: dynamically choosing the reasoning tier by task difficulty is the most effective way to control cost.
6. Conclusion
This run shows that the bottleneck in AI coding has shifted from “can it write code” to “how to write it correctly at a reasonable cost.” For developers, the capabilities worth building are task decomposition, constraint design, and cost observability. For platforms, providing tiered model scheduling and usage transparency is what makes AI coding viable in everyday engineering workflows.
