How to Choose LLMs for AI Agents
Agent workloads chain reading, extraction, generation, and tool checks in one loop, so sticker price is a poor proxy for success. This article covers a task-first selection process: define inputs and acceptance tests, read context, output, tools, and modalities correctly, compare total cost including retries, and retest on a frozen set.
When you put an AI agent into production, the model often has to read source material, extract structure, write code or documents, then call external tools to verify results. On the surface it looks like one conversation plus a few tool calls. The bill can still differ by an order of magnitude. The price gap is worth noticing, but two questions come first: can a cheaper option pass acceptance in one shot, and does a more expensive option clearly cut rework? Context-window size and labels such as “long context” or “multimodal” do not by themselves prove task success.
Define inputs and acceptance before cost
Keep selection to three steps. Do not start by collecting model cards.
First, write down the input shape. Plain text, mixed image-and-text, and native video understanding are different capability boundaries. Many APIs accept images; that does not mean they stably read table screenshots, flowcharts, or frames with a timeline. If the work is mainly documents, receipts, or UI captures, treat structured vision extraction as the primary scenario. If the source is recordings, operation replays, or monitoring clips, require in the spec whether video is a native input and whether the caller must extract frames, so you do not discover a preprocessing pipeline only after launch.
Second, write acceptance criteria, not impressions. Examples: completeness of required fields in extraction, test pass rate after code edits, rate of valid tool arguments on the first try, whether a long-document summary keeps specified numbers and exception clauses. Without a reproducible pass standard, price comparison is only comparing list prices.
Third, estimate cost on the same sample set. Split cost into at least four parts: input tokens, output tokens, whether thinking or intermediate reasoning is billed separately or shares the output budget, and extra rounds caused by tool round-trips. For batch image-and-text work, run a cheaper, acceptable-latency option first as a baseline. For long generation that needs a reasoning draft, list the per-call generation cap and whether thinking consumes the same budget. Put video-capable options in the first round only when video is a hard requirement. Which model a complex agent uses must be decided on the same task set, not a spec sheet.
Four items that actually matter on the spec sheet
Public specs usually list input types, context length, max output per call, and tool calling. Watch how numbers are defined. Do not treat K, M, or “about one million” from different documents as exact, additive values.
Context length is the cap for what fits in the window this turn. It does not mean you can fill the input and then generate arbitrarily long output. In many implementations, current input, history, tool results, and upcoming generation share one window. In agents, “million-token context” is often eaten by tool returns and multi-turn history, leaving far less room for the final answer than marketing numbers suggest. Design prompts with truncation: which history can be summarized, which tool results keep only key fields, how to slice oversized logs.
The output budget is not the length of the answer the user sees. If the model uses thinking, drafts, or self-checks, those intermediate tokens often count on the generation side and share the cap with the final reply. A high stated limit can still run out during thinking, showing up as a truncated answer or half-written tool arguments. In acceptance, record full answer length, whether truncation occurred, and how unit price and latency change when thinking is on. For long code or long reports, cap thinking length explicitly, or split “plan then generate in steps” into multiple calls so one call does not exhaust the budget.
Tool calling is required for agents, but “function calling” only means the protocol can return structured arguments. It does not guarantee stable parameter names, fewer hallucinations in multi-tool orchestration, or recovery from errors using the tool’s error message. Evaluation should cover missing parameters, invalid enums, multiple tools in one response, tool results that conflict with the user goal, and whether retries after timeout repeat side effects. A tier suffix in the model name does not replace this suite.
Check input modalities against real business data. A text-plus-image product cannot be assumed to accept a video container. If docs mention video, confirm duration, resolution, whether audio is used, and whether billing is per frame, per duration, or per transcribed text. Frame extraction on the business side treated as images is often cheaper but loses temporal order. It fits static checks, not questions such as “what happened at second N.”
Why one round can cost so much more
Unit-price gaps usually come from three places, not from “more expensive therefore stronger.”
On the input side, long system prompts, a whole code repo, and several high-resolution images raise the floor of every round. If the agent replays full history at every step, even a cheap model becomes expensive. Separate stable prefixes from changing content. Do not rewrite long, cacheable system instructions every round.
On the generation side, thinking, multiple self-rewrites, and oversized tool-argument examples inflate output tokens. A cheap model that misses fields and forces a full rerun can cost more than a pricier model that passes once. Compare total cost to complete an accepted task, including failed retries and human rework, not only the price per thousand tokens.
On rounds, each extra tool hop bills another input and output. Fields that local rules can validate need not go back to the model. Put deterministic steps (format checks, ID dedup, permission checks) on the caller and let the model handle ambiguity. That often saves more than switching model tiers.
Trial order and how to retest
For high-volume image-and-text structured extraction, first establish a cost baseline with acceptable latency and unit price. Frozen samples should at least cover clear images, blurry images, multi-column tables, and cross-page references. When budget is tight but generation is long, add options with a higher output cap to the same samples and watch truncation and first-pass rate, not only the advertised cap. When the task truly requires native video understanding, filter for matching input support and record preprocessing cost separately so it is not mixed with image-and-text bills.
Do not rank models by spec sheets. Prepare a small frozen task set: each item has input, allowed tools, success criteria, and acceptable latency. Run each task multiple times. Record success rate, P95 latency, tokens per task, and failure types (truncation, illegal tool arguments, factual error, refusal). Use the same prompt, the same temperature or greedy decoding, and the same tool sandbox for fair comparison. You may tweak prompt format per model; success criteria must stay the same. With too few samples, do not claim a winner for all agents.
After launch, keep watching three signals: whether first-pass rate drops as prompts grow, whether tool failures cluster on certain parameters, and whether long context degrades suddenly as history accumulates. These often expose architecture issues before a model swap. Object storage for raw assets and eval sets, a message queue for peak smoothing, and logs and monitoring to replay tokens and tool traces by task ID are general engineering; the model API does not replace them.
If the team already unifies accounts, quotas, and audit on Baidu AI Cloud or another compliant model service, selection should still be task-set driven: plug candidates into the same evaluation job and align input, output, and call counts with bill fields. Do not treat console recommendations or marketing tiers as quality conclusions, and do not assume a cloud vendor will ship unpublished, custom capabilities for one business.
Practical constraints at launch
Keep prompts and tool definitions short and testable. Each tool should do one thing, with clear enums and length limits, and return error codes rather than long prose so the model can correct on the next turn. For tools with side effects (writes, notifications, permission changes), default to dry-run or human confirmation; use fake data in evaluation.
Long context needs a trim policy. Prefer keeping the user goal, unmet acceptance items, the latest tool error, and key entity IDs. Replace large source dumps with citation IDs and fetch on demand. Then even a large window is not filled with irrelevant history.
Thinking and the answer should be observable separately. If the platform returns thinking to the caller, redact logs. If thinking and the answer share a budget, set a generation cap on the business side and auto-continue on truncation instead of restarting the whole job. Continuation prompts should carry only the unfinished fragment and the acceptance list, not the full document again.
Finally, write the selection decision as a revocable record: primary scenario, sample version, pass rate, cost per task, known failure types, and inputs not covered (for example very long video or live streams). Specs change; a task set can be rerun. Only then are price, capability, and agent scenario numbers on the same table, not three incomparable marketing stories.
