LLM Selection and Cost Evaluation for AI Agents
A practical guide to evaluating large language models for AI agents. Instead of benchmark accuracy, this article frames model selection as an engineering constraint and covers evaluation design with controlled variables, scoring dimensions such as instruction following, tool-call correctness, risk awareness and cost, a unit-cost-per-successful-task model, tiered routing, observability, common pitfalls, and a deployment checklist.
1. Background: Agents Turn Model Selection into an Engineering Constraint
Model evaluation used to mean measuring accuracy on standardized benchmarks. In AI agent scenarios, however, a model does more than answer questions: it makes decisions continuously inside a multi-step loop. It reads context, selects a skill, issues a tool call, parses the returned result, and decides whether to continue or stop. These requirements differ substantially from single-turn question answering.
This shift brings three changes. First, failures are amplified. A wrong answer in a single turn can be fixed by asking again, but an agent that picks the wrong tool at step ten may already have caused irreversible side effects. Second, costs are amplified. An agent’s token consumption scales roughly with the number of steps, so a model with verbose planning and repeated retries can cost more per task even at a lower unit price. Third, stability matters more. Long-running agents need consistent availability and reliable rate-limit behavior; an occasional quota exhaustion is more damaging than slightly weaker output quality.
The core selection question should therefore be reframed: under a given budget and latency constraint, which model lets an agent complete the task loop most reliably?
2. Evaluation Design: Controlled Variables Are a Prerequisite for Trustworthy Conclusions
Reusable conclusions require that differences come only from the model itself. A practical constraint checklist:
- Identical agent implementation: the same main loop, the same system prompt, and the same set of skill definitions.
- Identical memory: the same short-term context window strategy and long-term memory retrieval strategy, with the same write and forgetting rules.
- Identical tools: the same tool list, the same parameter schemas and permission boundaries, with high-risk actions going through the same confirmation flow.
- Identical reasoning tier: enable enhanced reasoning consistently where configurable, so tier differences are not misread as model differences.
- Identical task set: cover categories such as information retrieval, code modification, batch file processing, structured output, and multi-step planning, averaging multiple tasks per category.
The evaluation loop below is illustrative; the key point is that all branches share one configuration:
CONFIG = dict(max_steps=25, temperature=0.2, reasoning="high",memory="shared", skills="shared", tools="shared")def run_once(agent, task):trace = []for step in range(CONFIG["max_steps"]):decision = agent.step(task, trace, CONFIG) # only the model differsif decision.type == "tool":result = executor.call(decision.tool, decision.args) # unified permission checktrace.append(result)elif decision.type == "final":return summarize(trace, decision)return summarize(trace, timeout=True)
3. Evaluation Dimensions and Scoring Criteria
Break subjective impressions into quantifiable metrics, and record raw data for each dimension rather than scores alone.
- Instruction following and format compliance. Measure whether output satisfies the agreed structure (for example, JSON parse rate and missing-required-field rate). Agent downstream components typically parse results programmatically, so a single format deviation can invalidate an entire step.
- Tool-call correctness. Include tool selection accuracy, parameter completeness, the proportion of invalid calls, and whether the model asks for clarification when information is insufficient instead of guessing.
- Skill recognition and loading. Assess whether the model can locate the correct entry in a long skill list and make reasonable trade-offs when multiple skills conflict.
- Long-context and memory consistency. Check whether the model still honors the initial constraints after dozens of steps, and whether it contradicts itself or repeats work.
- Risk awareness. Check whether the model requests confirmation before high-risk actions such as deletion, overwriting, or external sending. This is a hard gate for production use.
- Cost. Measure cost per successful task rather than unit price: total consumption divided by the number of successful tasks, while also recording retry counts and average steps.
- Engineering usability. Rate limiting policy, concurrency limits, the ability to resume after long-task interruption, and whether error codes distinguish retryable from non-retryable failures.
4. Cost Model: A Low Unit Price Does Not Mean a Low Bill
Let S be the expected number of steps for a model to complete a task, T the average tokens consumed per step, p_in and p_out the input and output unit prices, and r the task success rate. The cost per successful task can be approximated as:
Cost_success ≈ (S × T × p_avg) / r
This formula shows two things. The success rate r sits in the denominator, so a 20% drop in effectiveness usually raises cost more than a 20% lower unit price saves. The step count S is determined by the model’s planning style, and running the same task on different models commonly produces several-fold differences in steps. An evaluation report must therefore report the raw values of S, T, and r; otherwise cost comparisons are meaningless.
For engineering practice, add three layers of budget guardrails: hard caps on steps and tokens per task, daily and monthly quota alerts, and sub-budgets allocated by task type. When a guardrail triggers, prefer degrading to a cheaper tier rather than failing outright.
5. Tiered Routing: Use Strong Models Where They Matter Most
The final output of a comparison is usually not a single winner but a routing table. A practical tiered strategy:
- Use a strong reasoning tier for planning, responsible for decomposing tasks and defining acceptance criteria. It is called infrequently but affects the whole workflow.
- Use a cost-effective tier for execution, handling large volumes of repetitive tool calls and format conversion.
- Use an independent model for verification to review results and avoid the bias of judging its own output.
- Keep a stable, available small tier as a fallback for retries after rate limiting or timeouts.
Routing keys can combine task type, estimated complexity, historical success rate, and remaining budget. The routing rules themselves should also be evaluated, using offline replay to verify whether adjustments genuinely reduce cost and improve effectiveness.
6. Observability: No Trace, No Trustworthy Conclusion
Every run should produce a structured record: model identifier (internal code name), tier, step count, a summary of tools and parameters per step, token usage, latency, error codes, the final decision, and human ratings. With this data, teams can answer whether a drop in effectiveness was caused by the model or by a prompt change. Connect logging services and monitoring alerts as well, set thresholds on three curves — success rate, average steps, and unit cost — and automatically pause traffic ramp-up when anomalies appear.
Model capabilities keep iterating, so any comparison conclusion has a limited shelf life. Making evaluation a repeatable pipeline is more valuable than a one-off conclusion.
7. Common Pitfalls
- Measuring only average scores and not variance. Agents are most vulnerable to occasional runaway behavior, so focus on worst-case performance and the distribution of failure modes.
- Tuning prompts and models together. Changing the prompt while switching models makes conclusions impossible to attribute.
- Ignoring permissions and confirmation mechanisms. A design without confirmation for high-risk actions should not go to production regardless of effectiveness.
- Using the total bill instead of unit cost. Changes in task structure make the total bill lose comparability.
- Overlooking rate limiting and resumption. Stability for long-running tasks should be a first-class metric.
8. Deployment Checklist
- Fix the agent framework and skill library to form a versionable evaluation baseline.
- Build a task set of at least three categories with automated scoring scripts, backed by manual spot checks.
- Produce a four-column table containing S, T, r, and cost per successful task rather than a single ranking.
- Roll out tiered calls based on the routing table, with budget guardrails and degradation policies configured.
- Connect logging, metrics, and alerts, and incorporate the evaluation pipeline into daily iteration.
Following this approach, teams can make evidence-based trade-offs among effectiveness, latency, and bills instead of relying on scattered usage impressions. For a faster start, this evaluation and routing pipeline can be built on general capabilities such as the model services, container platform, logging service, and monitoring alerts offered by Baidu AI Cloud, turning model selection into a continuously measurable engineering process.
