Multi-Agent Cost Optimization: Dividing Labor Between Large and Small Models
This article explores cost optimization strategies for multi-agent architectures by separating planning from execution. By assigning complex reasoning to high-tier models and repetitive tasks to cost-effective models, token consumption can be significantly reduced. It covers advisor and orchestration collaboration patterns, analyzes token distribution, and provides best practices for context caching, isolation, and identifying suitable use cases.
1. Problem Background
Agent systems typically handle multi-step tasks such as retrieving materials, reading documents, analyzing logs, and generating reports. Each step requires reading the context and generating output, causing token consumption to grow alongside both the number of steps and the context length. If all stages use the most capable and most expensive model, costs will quickly exceed budget. However, many subtasks do not require the strongest reasoning capabilities.
The key to cost optimization is determining the exact capability required for each stage and focusing computing power where it is needed.
2. Core Idea: Separating Planning and Execution
The work of an agent can be divided into two categories:
- Planning: Understanding goals, breaking down steps, judging direction, handling ambiguity, and synthesizing conclusions. This type of work relies on deep reasoning, has a high cost of failure, but usually involves fewer tokens.
- Execution: Completing operations such as search, reading, rewriting, extraction, and validation according to clear instructions. This type of work is highly repetitive, involves large token volumes, and has lower requirements for single-step reasoning depth.
Once separated, planning is assigned to a highly capable model, while execution is assigned to a cost-effective model. A prerequisite for this division of labor is that the planning results must be clear enough for the execution unit to complete its work independently. When instructions are vague, errors from the execution model can be amplified, and rework costs may offset the savings.
3. Two Common Collaboration Patterns
3.1 Advisor Collaboration
The execution model handles the majority of the work. When encountering an uncertain branch, it initiates a help request to the high-tier model. The high-tier model provides a judgment basis or corrective direction, and the execution model continues to complete the task.
Characteristics of this pattern:
- Few calls to the high-tier model, usually triggered only a few times per task.
- Most output is generated by the execution model, bringing the overall cost close to the execution model’s unit price.
- Requires well-designed escalation conditions. If conditions are too loose, the execution model will ask for help frequently; if too strict, it might proceed with incorrect conclusions.
Suitable scenarios: Tasks with a clear main thread but requiring judgment at a few nodes, such as boundary condition checks in code modifications or clause interpretation in document reviews.
3.2 Orchestration Collaboration
The high-tier model acts as the overall commander, breaking down the task into several subtasks, dispatching them to multiple execution models for parallel processing, and finally synthesizing the results. The high-tier model is only responsible for task decomposition and result synthesis, not directly processing large amounts of raw content.
Characteristics of this pattern:
- When subtasks are independent, they can be executed in parallel, significantly reducing end-to-end latency.
- Each execution unit only receives context relevant to its own subtask, reducing irrelevant tokens.
- The quality of decomposition determines the overall upper limit. If subtask boundaries are ambiguous, the synthesis stage will require significant effort to deduplicate and align results.
Suitable scenarios: Verifying information across multiple web pages, parallel review of multiple documents, and troubleshooting anomalies across multiple log sources.
4. Where Cost Comes From: Token Distribution Matters
Understanding cost structure requires looking at two variables: unit price and token distribution.
The following hypothetical values demonstrate the calculation method. Assume the high-tier model’s price per unit token is 5 times that of the execution model, and the execution model’s unit price is 1. A task consumes a total of 1 million input tokens. These values are for demonstration only; actual ratios depend on the pricing of the service used.
| Solution | Tokens Processed by High-tier Model | Tokens Processed by Execution Model | Relative Cost | Percentage of Full High-tier Solution |
|---|---|---|---|---|
| Full High-tier Model | 1M | 0 | 500 | 100% |
| Planning + Execution | 100K | 900K | 140 | 28% |
Calculation: The cost of the full high-tier solution is 100 5 = 500. The cost of the mixed solution is 10 5 + 90 * 1 = 140.
The actual savings ratio depends on two factors: the proportion of tokens processed by the high-tier model, and whether the execution model can complete tasks stably. If the high-tier model accounts for more than 30% of the tokens, the savings margin narrows rapidly. Since the unit price of output tokens is typically higher than that of input tokens, input and output should be accounted for separately.
5. Context Caching and Isolation
The billing method for repeated content directly affects costs. The following two practices are worth adopting:
- Stable Prefix: Place system instructions, tool definitions, and fixed reference materials at the beginning of the prompt, ensuring they match verbatim to hit the cache. If timestamps or random IDs are added to the prefix, the cache will frequently miss.
- Context Isolation: Each execution unit only retains the information needed to complete its own task. This both shortens the length of individual requests and prevents information interference between different subtasks.
6. Applicable Scenarios and Boundaries
Tasks suitable for decomposition usually have the following characteristics:
- High token consumption, including large amounts of repetitive reading or retrieval.
- Independent subtasks that can be executed in parallel.
- Verifiable results, such as clear test cases or acceptance criteria.
Tasks not suitable for decomposition include:
- Narrow problems that can be completed in a single call. Scheduling overhead exceeds benefits.
- Tasks heavily dependent on reasoning chains, where each step takes the full conclusion of the previous step as input. Parallelism offers no benefit.
- Open-ended tasks lacking acceptance criteria. The output of execution units is difficult to merge, resulting in high synthesis costs.
Most agent frameworks limit the delegation hierarchy and the number of concurrently active agents. Nested calls exceeding these limits may be ignored or throw errors directly. When designing, confirm the limits of the runtime environment before deciding on the decomposition depth.
7. Implementation Skeleton
The following pseudocode illustrates the basic control flow of advisor collaboration. Function names are for illustrative purposes only and should be replaced with the interfaces of the framework used in practice.
def run_task(task):plan = planner.plan(task) # Planning is done by the high-tier modelresults = []for step in plan.steps:ctx = build_context(step) # Each step uses an independent contextoutput = worker.execute(step, ctx)if output.needs_review: # Execution model flags uncertain resultsadvice = planner.advise(step, output)output = worker.execute(step, ctx, advice)results.append(output)return planner.synthesize(task, results) # Synthesize the final results
