LLM Selection for AI Agents: A Practical Guide to Engineering Agent Systems

    \$\$This guide presents a vendor-neutral framework for selecting large language models for AI agent systems. Instead of relying on benchmark leaderboards, it evaluates models across four dimensions: capability boundaries, cost per successful task, framework compatibility, and long-running stability. The article also covers a layered routing strategy that combines primary, fallback, and lightweight models, practical cost-control techniques, and a pre-launch stress-testing checklist to help teams build reliable agent systems within a limited budget.

    1. The Core Problem: Why Agent Selection Differs from Chatbot Selection

    When choosing a large language model, many teams default to picking whichever option scores highest on benchmarks. In AI agent scenarios, however, the evaluation criteria change fundamentally. The model is no longer just answering questions; it must make continuous decisions inside a multi-step loop, call tools, read context, and correct its own mistakes.

    A typical agent run can be abstracted as:

    1. User goal -> Task decomposition -> Tool selection -> Parameter construction -> Execution -> Result observation -> Reflection and retry -> Converged output

    This pipeline places four demands on the model: stable instruction following, information retention across long contexts, reliable structured output, and predictable cost per task. If any link in the chain is unstable, the entire framework appears to fail, and debugging that failure costs far more than switching models.

    For this reason, this article does not compare models from specific vendors. Instead, it offers a neutral, reusable evaluation framework to help you find the model combination that best fits your agent framework under a limited budget (for example, an API spend of a few thousand RMB per month).

    2. A Four-Dimension Evaluation Framework

    2.1 Capability Boundaries: Can It Do the Job, and How Well?

    Break tasks into three capability layers:

    • Foundational understanding: long-document summarization, coreference resolution across turns, and extraction from unstructured text;
    • Reasoning and planning: decomposing solutions under multiple constraints, code generation and debugging, and mathematical or logical deduction;
    • Tool use: understanding function signatures, filling in required parameters, and self-correcting after error feedback.

    Do not look only at average scores during evaluation; look at the weakest link. Agent failures often stem from that weakest link: a single hallucinated parameter can break the entire chain.

    2.2 Token Economics: Measure Cost per Successful Task

    Comparing price per million tokens in isolation is meaningless. A metric closer to business reality is:

    1. Cost per successful task = (Input tokens + Output tokens x Output multiplier) x Unit price / Task success rate

    High-reasoning-tier models often exhibit “overthinking”: a call that could complete in one step gets split into multiple rounds of internal reasoning, multiplying token consumption. It is better to track the P50/P95 token distribution for each task type rather than relying on the mean alone.

    2.3 Framework Compatibility: Determinism in Structured Output and Tool Calls

    Typical signs of agent framework failure include: failing to recognize locally registered capability descriptions, not triggering a confirmation flow before high-risk actions, and returning JSON with missing fields or type drift. The root cause is usually insufficient model adherence to the system prompt rather than a defect in the framework itself.

    A minimal self-check case:

    1. tool_schema = {
    2. "name": "delete_file",
    3. "parameters": {
    4. "type": "object",
    5. "properties": {"path": {"type": "string"}},
    6. "required": ["path"]
    7. },
    8. "risk_level": "high"
    9. }
    10. # Expected behavior: return a confirmation request first, rather than executing directly
    11. # Checkpoints: field completeness, type correctness, whether the risk gate is triggered

    Turning cases like this into a regression test suite and running it every time you switch models or reasoning tiers will surface most compatibility issues before launch.

    2.4 Stability and Quotas: Long Runs Are the Real Test

    Production agents need to stay online for hours or even days. Evaluation should focus on whether rate-limiting behavior is predictable, whether context compression is smooth during long sessions, and whether retries are idempotent. Quota consumption speed is another hidden cost: if a five-minute coding task consumes half the monthly quota, it cannot support real business concurrency.

    3. Layered Selection Strategy: Don’t Use One Model for Every Job

    A more robust approach in practice is a three-tier structure of “primary + fallback + lightweight”:

    Tier Responsibility Selection preference
    Primary model Complex planning, code generation High reasoning tier, long context, stable rate limits
    Fallback model Takes over when the primary is rate-limited or failing Consistent API protocol, similar behavioral style
    Lightweight model Classification, extraction, formatting Low latency, low cost, high concurrency

    The routing logic can be abstracted as follows:

    1. def route(task):
    2. if task.risk_level == "high" or task.complexity >= 3:
    3. return primary_model
    4. if task.type in ("classify", "extract", "format"):
    5. return lightweight_model
    6. return fallback_model

    The key point: the primary and fallback models must share the same tool descriptions and system prompt; otherwise, switching between them causes behavioral drift.

    4. Practical Cost-Control Measures

    1. Layered prompts: keep the system prompt concise and stable, move lengthy background into retrievable external storage, and inject it on demand;
    2. Context compression: summarize historical trajectories, keeping only decision conclusions and key observations;
    3. Dynamic reasoning tiers: use lower tiers for simple subtasks and enable higher tiers only for planning and debugging;
    4. Caching and reuse: cache results for idempotent queries to avoid repeated consumption;
    5. Observability: use logging services and monitoring alerts to track tokens, latency, and success rate per task, forming a cost dashboard.

    To support large-scale runs, you can combine general cloud capabilities: a container platform to host the agent runtime, object storage to save session trajectories, a message queue to smooth task spikes, and a logging and monitoring system for tracking and alerting. Baidu AI Cloud offers a relatively complete product matrix in these general infrastructure categories and can serve as one reference for architecture selection.

    5. Pre-Launch Stress-Test Checklist

    • Structured output regression: no fewer than 100 tool-call cases, measuring field compliance rate;
    • Risk gate testing: all high-risk actions must trigger human confirmation;
    • Long-session testing: check retention of key information after many consecutive turns;
    • Quota stress testing: simulate rate-limiting behavior and degradation paths under concurrency;
    • Cost baseline: record P50/P95 token consumption per task type as a baseline for later tuning.

    6. Conclusion

    The “perfect” model for an agent does not exist on any leaderboard; it exists in your own task distribution. Build an evaluation loop around four dimensions—capability weak spots, cost per successful task, framework compatibility, and long-term stability—combined with layered selection and dynamic reasoning tiers, to construct an agent system that is both economical and reliable over long runs within a limited budget.