LLM Selection for AI Agents: Evaluating Capabilities and Cost

    Choosing an LLM for an AI agent requires more than comparing token prices. This article explains how input modalities, context windows, generation budgets, and tool-calling reliability affect task performance and total cost. It presents a three-step evaluation process, practical metrics, and illustrative code for comparing models by cost per successful task.

    1. Why the Same Agent Task Can Produce Very Different Bills

    Reading files, writing code, and calling tools are three typical AI agent activities. Running the same task on different models can cost several times more—or even an order of magnitude more. The difference often comes not from token prices alone, but from four cost multipliers:

    • Input volume: Long documents, code snippets, screenshots, and video frames can quickly increase input token counts.
    • Output volume: The generation limit determines how much a model can produce in one call. Reasoning tokens can also count toward generation usage.
    • Number of rounds: In multi-round tool workflows, conversation history is repeatedly included in subsequent requests.
    • Failures and rework: An unsuccessful attempt adds the cost of retries and manual corrections.

    Model selection therefore needs to answer two questions: Can a cheaper model complete the task correctly on its first attempt? Can a more expensive model reduce rework?

    This article organizes the selection process into three steps: define inputs and acceptance criteria, calculate total cost, and retest candidates on the same tasks. Always check specifications against each provider’s latest official documentation.

    2. Capability Requirements: Eliminate Models That Fail Hard Constraints

    Input Modalities Determine Workflow Complexity

    Mainstream LLMs commonly support text and image inputs, while some also support direct video understanding. If a workflow requires direct video processing, prioritize models with native video input support.

    Otherwise, you need to handle frame extraction, transcoding, or speech transcription yourself. That creates an additional preprocessing pipeline outside the model, increasing development and operational costs while potentially losing information.

    Context Windows: Advertised Capacity Is Not Usable Capacity

    Many flagship and lightweight models offer context windows ranging from hundreds of thousands to a million tokens. However, three factors need attention:

    • Shared limits: Some models share a total window between input and generation for the current request. A million-token window does not mean you can supply a million input tokens and then generate another million.
    • Effective context length: Retrieval of information from the middle of a long context may deteriorate. Validate this with needle-in-a-haystack tests.
    • Billing implications: Long contexts incur input charges, and repeatedly sending conversation history amplifies those charges.

    Generation Budgets and Reasoning: Avoid Truncated Answers

    The per-request output limit determines how much content a model can generate. When reasoning mode is enabled, internal reasoning and the final answer often share the same generation budget.

    For complex reasoning tasks, a small output limit can leave the model spending too much of its budget on reasoning and too little on the answer. Additional reasoning tokens can also increase generation charges and latency.

    Tool Calling and Structured Output: The Foundation of an Agent

    Reliable agents depend on models that can generate tool arguments in the required format, recover from errors, and consistently return structured results.

    Evaluate the following:

    • Adherence to tool definitions, including names, descriptions, and parameter schemas.
    • Parallel tool calling and the ability to continue after tool results are returned.
    • Validity rates for structured outputs, such as JSON-mode responses.
    • Stability when tool definitions and conversation history coexist in long conversations.

    These capabilities cannot be inferred from a model’s name or suffix. They require testing.

    3. Cost Accounting: From Token Prices to Cost per Successful Task

    The basic cost structure is:

    1. Total cost = Input tokens × Input price
    2. + Output tokens × Output price (including reasoning tokens)
    3. + Additional usage from retries

    A more useful comparison metric is cost per successful task:

    1. Estimated cost per successful task =
    2. Average cost per round × Average number of rounds
    3. / First-attempt pass rate

    This estimate combines capability—pass rate and number of rounds—with price. For measured evaluations, calculate cost per successful task by dividing total spending, including retries, by the number of successful tasks.

    Also account for:

    • Consistent units: Providers may use different conventions for K and M or different measurement units. Normalize them before comparing prices.
    • Discount eligibility: Check whether caching or batch-request discounts apply to your actual request patterns.
    • Hidden costs: Include preprocessing, retry handling, and manual review.

    4. A Three-Step Model Selection Process

    Step 1: Define Inputs and Acceptance Criteria

    Build a dataset from real business tasks, covering typical cases, edge cases, and adversarial cases. Define automatically verifiable acceptance criteria for every sample.

    Set these criteria before choosing a model. This prevents selecting a model first and then designing an evaluation to justify the choice.

    Step 2: Establish a Cost Baseline

    Use frequent, structured tasks with easily verifiable results—such as information extraction or format conversion—as a baseline dataset.

    Run each candidate through the complete workflow and record its cost per successful task. Use that result as the reference point for subsequent comparisons.

    Step 3: Retest on Identical Tasks and Route by Use Case

    • Frequent text-and-image or structured-output tasks: Prioritize the cost baseline while considering first-attempt pass rate.
    • Budget-sensitive tasks requiring substantial generation: Focus on output limits and truncation rates.
    • Tasks requiring direct video input: First filter for native video support.
    • Complex agents: Compare average rounds, tool-call validity, and rework rates using the same multi-round task set.

    5. Running Repeatable Evaluations: Metrics, Workflow, and Example Code

    Record at least the following metrics:

    Metric Definition Purpose
    First-attempt pass rate Share of tasks that meet acceptance criteria on the first attempt Assess first-attempt reliability
    Average rounds Average number of model calls per task Assess planning and tool-use efficiency
    Tool-call validity rate Share of tool calls with valid arguments Identify causes of agent failures
    Truncation rate Share of tasks left incomplete because the output budget was exhausted Check whether the generation budget is sufficient
    P95 latency Duration within which 95% of requests complete Assess interaction responsiveness
    Cost per successful task Total cost, including retries, divided by successful tasks Support the final selection decision

    The following pseudocode illustrates the evaluation approach:

    1. # Pseudocode: compare candidates using the same tasks and acceptance rules
    2. def evaluate(candidates, tasks, verify):
    3. report = {}
    4. for name, client in candidates.items():
    5. total_cost, success, rounds, truncated = 0.0, 0, 0, 0
    6. for task in tasks:
    7. history = [{"role": "user", "content": task.prompt}]
    8. for _ in range(task.max_rounds):
    9. resp = client.chat(history, tools=task.tools)
    10. total_cost += resp.input_tokens * client.price_in
    11. total_cost += resp.output_tokens * client.price_out
    12. rounds += 1
    13. if resp.finish_reason == "length":
    14. truncated += 1
    15. break
    16. if resp.tool_calls:
    17. history.append(resp.message)
    18. history.append(tool_executor.run(resp.tool_calls))
    19. continue
    20. success += verify(task, resp.text)
    21. break
    22. report[name] = {
    23. "pass_rate": success / len(tasks),
    24. "avg_rounds": rounds / len(tasks),
    25. "truncate_rate": truncated / len(tasks),
    26. "cost_per_success": total_cost / max(success, 1),
    27. }
    28. return report

    In practice, a model service platform can provide a common interface and consistent usage accounting across multiple models. Baidu AI Cloud is one such option where the relevant services are available; consult the official documentation for applicable availability.

    Archive evaluation samples in object storage, record request workflows through logging services, and connect key metrics to monitoring and alerts. This makes selection results easier to review continuously.

    6. Common Model Selection Mistakes

    1. Treating context length as agent capability: A larger window can hold more history, but that does not mean the model can use it effectively.
    2. Treating the output budget as answer length: Reasoning can consume part of the same budget.
    3. Comparing token prices alone: Ignoring rounds and rework can lower the unit price while increasing total cost.
    4. Replacing business evaluations with public leaderboards: Different task distributions mean benchmark conclusions may not transfer directly.
    5. Ignoring version changes: Models and billing rules evolve. Record evaluation versions and dates, and run regression tests regularly.

    7. Conclusion

    LLM selection is an ongoing engineering process, not a one-time ranking exercise.

    Start by defining input requirements and acceptance criteria. Establish a baseline centered on cost per successful task, then compare candidates using the same evaluation tasks.

    Specifications and prices are only the starting point. A reproducible evaluation process is the foundation for sustained cost reduction and better agent performance.