Multi-Model Orchestration: Routing Tasks by Capability and Cost
Hardcoding a single LLM into your application is simple but quickly leads to mismatched capabilities, opaque costs, and painful model switching. This article explains how to treat models as interchangeable resources managed by an orchestration layer. It covers task-level routing, unified cost metering with relative rate multipliers, and context handoff across models, with practical Python examples for rule-based routing, cost estimation, and budget enforcement. Readers will learn how to build a scheduling system that picks the right model for each step while keeping spending visible and task state intact.
1. From “Picking One Model” to “Orchestrating a Set of Models”
A common approach when building intelligent applications is to hardcode a single model name and send every request to it. This is easy to implement, but it causes three recurring problems.
First, capability and task are mismatched. A long literature review demands strong reasoning and a large context window, while bulk rewriting of tags only needs a lightweight, low-latency model. Using the same model for both either wastes money or delivers poor quality on complex tasks.
Second, costs are opaque. Most teams only see a total on the bill and cannot answer “how much did this type of task actually cost?” Without per-task metering, budget control and optimization are impossible.
Third, switching is painful. When you change models, conversation history, intermediate conclusions, and tool call results are often scattered across places. Starting over means repeated computation, and results may become inconsistent.
A more mature approach is to treat models as replaceable resources: the system selects a model based on task characteristics, records the cost of every step, and preserves task state when switching. This idea breaks down into three layers — task-level routing, cost metering, and context handoff — all managed by a unified orchestration layer.
2. Core Concepts and Responsibilities
2.1 Task-Level Routing
Routing means deciding, before or during execution, “which model handles which step.” Common decision factors include:
- Reasoning complexity: whether multi-step deduction or cross-document synthesis is required
- Context length: whether the input exceeds a given model’s context window
- Latency requirements: interactive scenarios and background batch jobs tolerate different response times
- Cost sensitivity: the acceptable tier for a task within its budget
- Output constraints: whether a strict structured format is required
2.2 Cost Metering
Model prices vary widely. To make tasks comparable for both users and the system, you need a unified metering unit. A common practice is to assign each model tier a relative multiplier, with one baseline tier set to 1 and others scaled by capability and price. The multiplier is only a conversion factor — actual billing rules should follow the provider’s official documentation. Internally, the system only needs to store the comparable result of “raw usage × multiplier.”
2.3 Context Handoff
Handoff means that under the same goal, multiple models take on different sub-steps in sequence, with each step’s output serving as the next step’s input. This requires decoupling task state from any specific model. State should live in the orchestration layer, not in a particular model’s session, so that switching models does not lose it.
2.4 The Orchestration Layer
The orchestration layer is the runtime framework that carries the above capabilities, sometimes called a harness. It typically handles:
- Breaking down tasks and generating execution plans
- Scheduling models and tools
- Maintaining context and intermediate artifacts
- Handling failures, timeouts, and fallbacks
- Recording observability data
Model capability determines the quality ceiling of a single step; the orchestration layer determines whether a multi-step task completes reliably. Both are indispensable. In practice, the orchestration layer is often the more likely bottleneck.
3. Implementing Task-Level Routing
Routing strategies fall into three broad categories:
- Rule-based routing: developers write explicit conditions. Predictable behavior and easy to audit.
- Classification-based routing: a lightweight classifier determines task type, which maps to an execution tier. Flexible, but classification accuracy must be evaluated.
- Automatic routing: the provider or framework selects based on historical data. Convenient, but less transparent.
In production, start with rule-based routing to establish a baseline, then introduce other strategies as needed. Here is an example:
from dataclasses import dataclass@dataclassclass TaskProfile:task_type: str # e.g. "analysis", "rewrite", "summary"input_tokens: int # estimated input lengthneed_structured: bool # whether structured output is requiredbudget_level: str # "low" | "normal" | "high"# Model names appear only here; business code only cares about tiersMODEL_TIERS = {"long_context": "long-context-model","reasoning": "reasoning-model","balanced": "balanced-model","economy": "economy-model",}def route(profile: TaskProfile) -> str:if profile.input_tokens > 100_000:return MODEL_TIERS["long_context"]if profile.task_type in {"analysis", "synthesis"}:return MODEL_TIERS["reasoning"]if profile.budget_level == "low" or profile.task_type == "rewrite":return MODEL_TIERS["economy"]return MODEL_TIERS["balanced"]
The key point is that model names appear only in the mapping table. Switching models requires only a config change; calling logic stays untouched. Check order also matters: oversized inputs should satisfy the context constraint first, before cost is considered, so that saving money never causes a request to fail outright.
Routing also needs a fallback chain. When a model is rate-limited, times out, or fails, the orchestration layer should switch along a predefined backup order and log the reason. The fallback chain should be task-type aware. For example, a backup model for structured extraction must also support stable output formats — otherwise the fallback merely moves errors from the request layer to the parsing layer.
4. Cost Visibility and Budget Control
Cost governance needs three stages: pre-execution estimation, post-execution settlement, and runtime alerting.
The following example uses fictional multipliers for illustration only; they do not represent the real prices of any service:
# Example multipliers, not the real prices of any serviceRATE = {"long_context": 1.0, "reasoning": 1.5, "balanced": 0.5, "economy": 0.1}def estimate_cost(tier: str, base_units: float) -> float:"""Pre-execution estimate: base usage multiplied by the tier multiplier."""return round(RATE[tier] * base_units, 4)def check_budget(spent: float, budget: float, warn_ratio: float = 0.8) -> str:"""Runtime check: returns ok, warn, or stop."""if budget <= 0:return "stop"ratio = spent / budgetif ratio >= 1:return "stop"if ratio >= warn_ratio:return "warn"return "ok"
Estimation decides whether to execute. For example, if a batch job exceeds the remaining budget, the system can prompt the user to narrow its scope up front rather than fail midway. Settlement corrects estimation drift: when estimates consistently diverge from actual usage, the base-usage estimation model needs adjustment.
For statistics, track at least task type, project, and user. Aggregating only totals makes it impossible to spot abnormal consumption in a specific task category. Price changes such as promotions and limited-time discounts should also be managed as configurable items rather than hardcoded in business logic, or every adjustment will require a code change and redeployment.
5. Data Structures for Context Handoff
Successful context handoff depends on task state having a clear structure. A workable state design keeps the task goal, the execution plan, completed steps and their outputs, and pending steps in the orchestration layer, independent of any model’s session format. As long as each step’s output is stored in a model-agnostic structure, any downstream model can pick up where the previous one left off — which is exactly what makes models replaceable resources rather than fixed dependencies.
