LLM Upgrade Evaluation: Cost, Quality, and AI Agent Practices

    Evaluating large language model upgrades requires looking beyond benchmark scores. This article explores five core dimensions for upgrade decisions—pricing structures, context windows, knowledge cutoffs, hallucination rates, and agent task costs—and provides a practical guide to building a custom evaluation pipeline with Python.

    I. Why Leaderboard Scores Are Not Enough

    Comprehensive benchmark scores reflect a model’s general capabilities, but they cannot answer the questions teams care about most: how many business tasks can be completed within the same budget, what is the cost of erroneous outputs, and which workflows need modification after switching models. A new model typically alters pricing, context length, output limits, and knowledge recency simultaneously. Looking only at an overall score makes it easy to overlook the interactions between these variables.

    Therefore, technical selection should treat models as components with distinct cost structures, quality distributions, and behavioral characteristics. Measure each aspect individually before deciding whether to upgrade.

    II. Five Core Dimensions for Upgrade Decisions

    2.1 Pricing Structure: Separate Input and Output Billing

    Most LLM services bill by Token, and the unit prices for input and output are often different. Output is usually more expensive because the model must generate content token by token. Comparing a single “price per million tokens” is inaccurate; you should calculate based on the actual input-output ratio of your business.

    The following figures are hypothetical values used to illustrate the calculation method, not actual data from any product. Assume a task averages 200,000 input tokens and 20,000 output tokens:

    • Old model: Input price $2/million tokens, output price $8/million tokens. Single task cost: 0.2 × 2 + 0.02 × 8 = $0.56.
    • New model: Input price $4/million tokens, output price $16/million tokens. If the same task consumes only half the tokens of the old model, the single task cost is 0.2 × 0.5 × 4 + 0.02 × 0.5 × 16 = $0.56. If token usage remains the same, the cost rises to $1.12.

    The table below shows how the single-task cost changes as the new model’s token usage changes relative to the old model:

    New Model Token Usage (Relative to Old) Single-Task Cost ($) Cost Relative to Old Model
    100% 1.12 2.0x
    75% 0.84 1.5x
    50% 0.56 1.0x
    40% 0.45 0.8x

    Thus, doubling the unit price does not mean doubling the total cost. The key lies in the total number of tokens required to complete the task, a figure that must be measured using real tasks.

    2.2 Context Window and Maximum Output

    The context window determines how much input a single request can hold, including system prompts, conversation history, retrieved chunks, and tool return results. The maximum output limits the length of a single generation. Both must be evaluated separately.

    A large window does not mean the model can effectively utilize all the content. In some models, the recall of information located in the middle of a long text might be weaker than at the beginning or end, depending on the model. It is recommended to use a “needle-in-a-haystack” test to verify the actual usability of long contexts: embed specific facts at different positions in a long document and check if the model can accurately retrieve them. This test is more reliable than trusting the window size number directly.

    2.3 Knowledge Cutoff Date

    The knowledge cutoff date determines the model’s awareness of recent events, new dependency library versions, and latest regulations. For applications with high timeliness requirements, Retrieval-Augmented Generation (RAG) should be combined to inject the latest materials as context, and the model should be required to cite information sources. The cutoff date itself cannot replace retrieval.

    Before going live, verify the following items one by one:

    • Whether retrieved results include publication timestamps and whether outdated materials can be filtered.
    • Whether each factual conclusion in the model’s answer can be mapped to a specific source snippet.
    • Whether source links or document IDs are verified programmatically, rather than relying solely on the model’s self-reporting.

    2.4 Hallucination Rate: Beyond Accuracy

    The hallucination rate measures the proportion of fabricated answers when the model is uncertain. It is related to accuracy, but the two are not equivalent. A model might reduce its hallucination rate by abstaining more frequently, without improving accuracy. Therefore, evaluation should classify each answer into three categories: correct, wrong (hallucination), and abstain or uncertain, and tally them separately.

    The business cost of a wrong answer is typically higher than that of an abstention. Teams should set an acceptable upper limit for the error rate based on the scenario. For example, the error tolerance for legal Q&A should be much lower than for internal document retrieval.

    2.5 End-to-End Cost of Agent Tasks

    Agent tasks refer to tasks where the model continuously calls tools, reads and writes files, and plans and executes over multiple rounds, taking anywhere from a few minutes to several hours. The key metric for such tasks is not single-response quality, but the cost per successful task:

    1. cost_per_success = total_cost / number_of_successful_tasks

    If one model costs more per call but completes the task in one go, while another requires multiple retries, the former may have a lower unit cost. Statistics should include the cost of failed retries, the number of tool calls, and manual intervention time. If only token costs are calculated, the conclusion may deviate from reality.

    III. Building Your Own Evaluation Pipeline

    Before upgrading, comparative tests should be conducted on your own data, following these steps:

    1. Extract tasks from real business operations, covering common scenarios, edge cases, and historical failures. Retain a sufficient sample size for each category.
    2. Define automatically verifiable success criteria for each task, such as field matching, unit test pass, or correct source citation.
    3. Apply uniform prompts, sampling parameters, and tool configurations to candidate models. Record token usage, latency, raw output, and judgment labels for each call for post-hoc review.
    4. Aggregate into three categories of metrics—quality, cost, and latency—and compare comprehensively based on business weights.

    The following code implements the core logic of steps 3 and 4. The code is ready to run, where fake_call and fake_judge are stub functions for demonstration and need to be replaced when integrating real models. The interface conventions are as follows:

    • call_model(model, prompt) must return a dictionary containing four fields: text, input_tokens, output_tokens, and latency_s.
    • judge(task, text) must return one of "correct", "wrong", or "abstain". Other values will raise an error directly.
    • tasks cannot be empty, or the function will throw an exception to avoid division by zero errors.
    1. from dataclasses import dataclass
    2. from typing import Callable, Literal
    3. Verdict = Literal["correct", "wrong", "abstain"]
    4. PRICE = { # Unit: $/Million Tokens, example values, please replace with actual quotes
    5. "model-old": {"input": 2.0, "output": 8.0},
    6. "model-new": {"input": 4.0, "output": 16.0},
    7. }
    8. @dataclass
    9. class Result:
    10. task_id: str
    11. verdict: Verdict
    12. raw_output: str
    13. input_tokens: int
    14. output_tokens: int
    15. latency_s: float
    16. cost: float
    17. def token_cost(model: str, inp: int, out: int) -> float:
    18. p = PRICE[model]
    19. return inp / 1e6 * p["input"] + out / 1e6 * p["output"]
    20. def evaluate(
    21. model: str,
    22. tasks: list[dict],
    23. call_model: Callable[[str, str], dict],
    24. judge: Callable[[dict, str], Verdict],
    25. ) -> dict:
    26. """
    27. call_model(model, prompt) must return:
    28. text (str), input_tokens (int), output_tokens (int), latency_s (float)
    29. judge(task, text) must return: "correct", "wrong", or "abstain"
    30. """
    31. if not tasks:
    32. raise ValueError("tasks cannot be empty")
    33. results: list[Result] = []
    34. for task in tasks:
    35. out = call_model(model, task["prompt"])
    36. verdict = judge(task, out["text"])
    37. if verdict not in ("correct", "wrong", "abstain"):
    38. raise ValueError(f"Invalid verdict label: {verdict!r}")
    39. results.append(Result(
    40. task_id=task["id"],
    41. verdict=verdict,
    42. raw_output=out["text"],
    43. input_tokens=out["input_tokens"],
    44. output_tokens=out["output_tokens"],
    45. latency_s=out["latency_s"],
    46. cost=token_cost(model, out["input_tokens"], out["output_tokens"]),
    47. ))
    48. n = len(results)
    49. successes = sum(r.verdict == "correct" for r in results)
    50. hallucinated = sum(r.verdict == "wrong" for r in results)
    51. abstained = sum(r.verdict == "abstain" for r in results)
    52. total_cost = sum(r.cost for r in results)
    53. return {
    54. "n": n,
    55. "accuracy": successes / n,
    56. "hallucination_rate": hallucinated / n,
    57. "abstain_rate": abstained / n,
    58. "avg_latency_s": sum(r.latency_s for r in results) / n,
    59. "total_cost": total_cost,
    60. "cost_per_success": total_cost / successes if successes else float("inf"),
    61. "results": results, # Keep detailed records for auditing
    62. }
    63. # ---- The following are stub functions for demonstration, illustrating the interface only. Replace with real implementations. ----
    64. def fake_call(model: str, prompt: str) -> dict:
    65. return {"text": "42", "input_tokens": 1000, "output_tokens": 50, "latency_s": 0.8}
    66. def fake_judge(task: dict, text: str) -> Verdict:
    67. return "correct" if text == task["expected"] else "wrong"
    68. if __name__ == "__main__":
    69. demo_tasks = [
    70. {"id": "t1", "prompt": "Question 1", "expected": "42"},
    71. {"id": "t2", "prompt": "Question 2", "expected": "7"},
    72. ]
    73. report = evaluate("model-new", demo_tasks, fake_call, fake_judge)
    74. for key, value in report.items():
    75. if key != "results":
    76. print(key, value)

    Running the demo code will yield an accuracy of 0.5 and a hallucination rate of 0.5, indicating that the statistical logic is functioning. After integrating real models, the quality of the judgment function determines the credibility of the evaluation results. Therefore, it is recommended to first verify judge with a small batch of manually annotated samples to ensure its judgments align with human evaluation before conducting large-scale comparisons.

    For the aggregation in step 4, the results field retains the raw output and judgment labels for each task. When encountering anomalous metrics, the team can directly inspect specific samples rather than relying solely on aggregated numbers.

    IV. Pre-Upgrade Checklist

    • Have you completed comparisons using your own tasks rather than public benchmarks?
    • Have you calculated costs using separate input and output billing, converted with actual token usage?
    • Have you tracked hallucination and abstention rates, rather than just accuracy?
    • For agent tasks, have you accounted for the costs of retries, tool calls, and manual intervention?
    • Have long context windows been validated using a needle-in-a-haystack test?
    • Do time-sensitive scenarios include retrieval with programmatically verifiable sources?
    • Has the judgment function been manually spot-checked to ensure results generally align with human evaluation?

    V. Conclusion

    The benefits of a model upgrade must be proven by business metrics. Leaderboard scores can serve as a starting point for screening candidates, but the final decision should rely on cost, error rate, and latency data from your own tasks. Standardizing the evaluation process allows every upgrade to be measured with the same yardstick, enabling the team to quickly determine whether a new model is worth the switch.