Tiered LLM Selection: Performance, Cost, and Agent Workflows

    This article treats LLM selection as an engineering decision across model tiers. It explains how to interpret tiered pricing, estimate cost per successful task, build an in-house evaluation set, apply AI-assisted coding with engineering validation, route tasks in agent workflows, and govern risks. It closes with implementation steps and a checklist for balancing quality, latency, and cost.

    1. Background: Model Selection Is an Engineering Decision

    LLM capabilities continue to improve, and a single provider often offers multiple model tiers. High-tier models are good at complex reasoning and long-horizon tasks. Mid- and low-tier models respond faster and cost less per unit, making them suitable for high-frequency calls. For development teams, the key question is not “Which model is strongest?” but “Which tier should handle each type of task, and what are the quality and cost trade-offs?”

    A reasonable selection can significantly reduce inference costs while keeping quality roughly comparable. A poor selection can make simple tasks too expensive, while critical tasks may produce unstable output. Model selection should therefore be treated like capacity planning and driven by quantifiable metrics rather than impressions or marketing claims.

    2. Understand the Structure of Tiered Pricing

    Model tiers usually differ along three dimensions:

    • Capability: performance on complex reasoning, code understanding, and multi-step planning;
    • Speed: time to first token and overall generation speed;
    • Price: input and output tokens are billed separately, and output unit prices are generally higher.

    Separate input and output pricing is an important detail. When analyzing a large codebase, most consumption is input tokens. When generating test cases or technical documentation, most consumption is output tokens. Estimating by total token volume alone can produce a large deviation.

    3. Compare Cost per Task Instead of Unit Price

    Unit price only describes the cost per million tokens. It does not directly reflect the real cost of completing a task. A more capable model may pass on the first attempt, while a weaker model may require multiple attempts and additional manual review time. The final cost depends on the total cost per successfully completed task.

    The cost-per-task calculation is as follows:

    Single-call cost = input tokens / 1,000,000 × input price + output tokens / 1,000,000 × output price

    Expected cost per success = single-call cost / first-pass success rate + manual review cost

    This formula assumes that attempts are independent, making it suitable as an initial estimate. In the example below, all prices are hypothetical demo values, not actual quotes for any product.

    1. from dataclasses import dataclass
    2. @dataclass
    3. class ModelTier:
    4. name: str
    5. input_per_m: float # Price per 1M input tokens (CNY, hypothetical demo value)
    6. output_per_m: float # Price per 1M output tokens (CNY, hypothetical demo value)
    7. pass_rate: float # First-pass success rate on the in-house evaluation set
    8. def cost_per_success(tier: ModelTier, in_tokens: int, out_tokens: int,
    9. review_cost: float = 0.0) -> float:
    10. single_call = (in_tokens / 1_000_000 * tier.input_per_m
    11. + out_tokens / 1_000_000 * tier.output_per_m)
    12. expected_attempts = 1 / tier.pass_rate # Assumes independent attempts
    13. return single_call * expected_attempts + review_cost
    14. top = ModelTier("Top tier", input_per_m=10.0, output_per_m=50.0, pass_rate=0.95)
    15. mid = ModelTier("Balanced tier", input_per_m=2.5, output_per_m=12.0, pass_rate=0.92)
    16. for tier in (top, mid):
    17. cost = cost_per_success(tier, in_tokens=20_000, out_tokens=3_000, review_cost=0.5)
    18. print(f"{tier.name}: expected cost per successful task ≈ {cost:.2f} CNY")

    The example shows that manual review cost can account for a large share of total cost. Improving first-pass success rates and reducing review steps can therefore be as important as lowering unit prices.

    4. Build an In-House Evaluation Set

    Public leaderboards reflect general model capability, but they do not necessarily fit a team’s business context. It is advisable to sample 50 to 200 cases from real tickets and historical requirements, covering three task categories:

    1. Code tasks: provide repository snippets, then ask the model to locate defects, implement features, and add tests;
    2. Multi-step tasks: require information retrieval, tool calls, and summarization;
    3. Lightweight tasks: summarization, rewriting, and classification, with a focus on latency and cost.

    Each sample should include an input, acceptance criteria, and recorded fields. Prefer automatable acceptance criteria, such as unit tests and structured field validation. Use a human rubric only when automated judgment is not possible. Recorded fields should include token usage, latency, and failure reasons. During evaluation, keep prompts, sampling parameters, and input order fixed so that comparisons across tiers are fair.

    5. Key Practices for AI-Assisted Coding

    The value of AI-assisted coding lies in shortening repetitive work, but generated results must be validated through engineering. The following are practices for four common scenarios.

    1. Understanding a large codebase: first build a code index, retrieve relevant files, interface definitions, and call relationships, and then provide this content to the model. Putting an entire repository into the context at once is expensive and can bury key information.
    2. Implementing complex features: ask the model to first output design points and a change list. After human confirmation, generate code. This reduces the risk of broad, incorrect changes.
    3. Writing tests: require coverage of boundary conditions and exception paths, and actually run the tests. Pass/fail should be based on execution results, not the model’s self-assessment.
    4. Frontend and interaction: render generated pages in a real browser and check accessibility and interaction behavior. For 3D modeling tasks, rendering results and performance metrics should also be used as acceptance criteria.

    Before merging code, automated gates can be set up as follows:

    1. # Illustrative CI gates for model-generated code
    2. stages:
    3. - name: Static checks
    4. required: true
    5. - name: Unit tests and coverage
    6. required: true
    7. - name: Dependency and security scanning
    8. required: true
    9. - name: Human review
    10. required: "true when core modules are involved"

    6. Tiered Routing in Agent Workflows

    An agent usually calls models multiple times to complete a task, so tiered routing is more important than single-call model selection. Common practices include:

    • Use high-tier models for planning, key decisions, and complex reasoning;
    • Use mid- and low-tier models for repetitive operations such as field extraction, format conversion, and classification;
    • When low-tier output fails validation, automatically escalate to a high-tier model for a retry.
    1. CHEAP_TASKS = {"extract", "classify", "format"}
    2. def route(task_type: str) -> str:
    3. return "mid_tier" if task_type in CHEAP_TASKS else "top_tier"
    4. def run_with_escalation(task, call_model, validate):
    5. result = call_model(route(task.type), task)
    6. if validate(result):
    7. return result
    8. # Low-tier result failed validation; escalate to top tier for one retry
    9. return call_model("top_tier", task)

    In addition to routing rules, set the following constraints:

    • Minimize tool permissions so the agent can only access interfaces required to complete the task;
    • Set maximum steps, timeout, and per-task budget to prevent infinite loops and runaway costs;
    • Log the model tier, token usage, latency, and result at each step for later audit.

    7. Risks and Governance

    • Data security: redact source code and user data in inputs, and confirm the service terms regarding data retention and training use;
    • Output reliability: model output is a draft that must be validated and cannot be used directly as a security or compliance conclusion;
    • Prompt injection: file contents, web page contents, and tool return values are all untrusted data and should not be allowed to override system instructions;
    • Version migration: after a model version update, rerun the evaluation set, compare quality and cost, and then switch production traffic through a canary release.

    8. Implementation Steps and Checklist

    Implementation can be divided into four steps:

    1. Inventory task types and mark quality requirements and per-task budget caps;
    2. Use the in-house evaluation set to measure first-pass success rates and cost per task for each tier;
    3. Design routing and escalation rules, and configure step, timeout, and budget limits;
    4. After launch, continuously monitor success rates, costs, and user feedback, and review monthly.

    Checklist:

    • Every task type has clear quality acceptance criteria;
    • Cost is calculated per task, not only by unit price;
    • The evaluation set is updated regularly and covers real business scenarios;
    • Agents have budget, step, and permission limits;
    • Regression testing and canary validation are completed before switching model versions.