LLM Selection and Agent Deployment: A Practical Guide to Cost and Performance

    This article explains how to select large language models and deploy AI agents in production by focusing on engineering practices rather than model scores. It covers the real requirements of agent scenarios, a reproducible four-layer evaluation framework, tiered reasoning routing, context and token governance, troubleshooting tool-calling failures, and comparing subscription versus usage-based pricing by effective cost per task. A recommended rollout process and a sample evaluation skeleton are included to help teams build stable, budget-aware agents.

    1. Background: What Agent Scenarios Actually Require from a Model

    In AI agent applications, the model is no longer just a reasoning engine that answers a single question. It has to operate inside a continuous loop, repeatedly performing perceive, plan, call tools, validate results, and re-plan. This makes the evaluation criteria fundamentally different from single-turn chat: single-turn scenarios reward writing quality and breadth of knowledge, while agent scenarios reward stability on long tasks, instruction following, accuracy of tool calls, and cost per unit of work.

    Many teams see good results during trials but run into frequent problems in production. The root cause is usually not that the model is not smart enough, but three engineering gaps:

    1. The reasoning tier does not match task complexity, so simple tasks are over-reasoned and complex tasks are under-reasoned.
    2. Context management is coarse, allowing message history and tool outputs to accumulate without limits.
    3. Permission and confirmation mechanisms are missing, so the model executes irreversible actions without constraints.

    The rest of this article addresses these three points.

    2. Evaluation Design: Making Benchmark Results Reproducible

    An unstructured “which one feels better” assessment has no engineering value. Break evaluation into four layers of metrics:

    • Task completion rate: whether the goal was genuinely achieved, not whether it merely looked complete.
    • Tool-call accuracy: whether function names, parameter structures, and required fields are correct, and whether multiple rounds of correction are needed.
    • Stability: whether the framework breaks down during long tasks, for example failing to recognize the locally registered capability list or skipping confirmation and executing directly.
    • Cost: measured per completed standard task in terms of token consumption and elapsed time, rather than comparing unit prices.

    A sample evaluation skeleton is shown below (pseudocode, expressing structure only):

    1. def run_case(model, case, max_steps=20):
    2. ctx = Context(case.init_messages, tools=case.tool_schema)
    3. for step in range(max_steps):
    4. out = model.generate(ctx.render(), tools=ctx.tools, reasoning=case.need_high_reasoning)
    5. if out.tool_calls:
    6. for call in out.tool_calls:
    7. if risk_level(call) == "high" and not ctx.user_confirmed(call):
    8. return Result(status="blocked", reason="need_confirm", step=step)
    9. ctx.append(execute(call))
    10. elif out.is_final:
    11. return Result(status="success" if verify(case, ctx) else "failed", step=step)
    12. return Result(status="timeout", step=max_steps)

    The key point is to count “a high-risk action was intercepted” as correct behavior rather than a failure; otherwise the evaluation incentivizes the model to skip confirmations.

    3. Reasoning Tier Strategy: High Reasoning Is Not Always the Default Best

    “Turn on high reasoning whenever possible” is a common intuition, but it needs correction in cost-sensitive production environments. A more robust approach is tiered routing:

    1. First use lightweight rules or a small model to classify the task (information extraction, format conversion, and simple retrieval go to the low tier).
    2. Upgrade tasks involving multi-step planning, cross-tool orchestration, or code-level changes to the high reasoning tier.
    3. Set a reasoning budget cap and timeout for the same task to avoid runaway single-step latency.

    The routing logic can be minimal:

    1. def pick_tier(task):
    2. if task.steps_est <= 2 and task.no_code_edit:
    3. return "low"
    4. if task.cross_tool or task.code_edit:
    5. return "high"
    6. return "medium"

    The benefits are twofold: it holds down average cost and ensures the high reasoning tier is genuinely used where it is worth it, which also makes later attribution analysis easier.

    4. Context and Token Governance: The Main Cause of Cost Blowups

    The phenomenon of “the same task consuming several times more tokens” is usually not a model characteristic but a lack of context engineering. Practical governance measures include:

    • Layered context: store system constraints, long-term memory, the current task, and tool results in separate partitions, each with its own limit.
    • Tool result trimming: return only necessary fields and summaries; pass large objects by reference via external storage.
    • History compression: produce structured summaries for completed subtasks, keeping conclusions and key parameters while discarding process noise.
    • Idempotency and retries: reuse existing intermediate results when retrying a failure instead of rerunning the whole segment.

    A quantifiable acceptance criterion is the “average tokens per completed standard task” and “peak context length.” Putting both into regression tests is the only way to catch degradation promptly after a version upgrade.

    5. Troubleshooting Tool Calls and Framework Breakdowns

    When the model “cannot see locally registered capabilities” or “does not ask when it should,” investigate the engineering side before the model side:

    • Whether the capability list is truncated as context length grows;
    • Whether tool descriptions overlap semantically, causing selection ambiguity;
    • Whether parameter schemas lack required constraints and enum ranges;
    • Whether two equivalent tools exist, causing the model to pick one at random and behave inconsistently.

    It is advisable to add brief positive and negative examples for each tool, and to establish an explicit allowlist and a two-step confirmation flow for high-risk actions. The confirmation information should include the target, scope, and a statement of reversibility.

    6. Cost and Quotas: Putting Subscription and Usage-Based Billing in the Same Frame

    Subscription plans and usage-based billing should not be judged by list price alone; convert both into “cost per effective task”:

    Dimension Subscription / Plan Usage-Based Billing
    Cost predictability High, suitable for stable workloads Low, fluctuates with tasks
    Peak elasticity Limited by quota Relatively good
    Quota exhaustion risk Exists, requires a fallback strategy Mainly a budget risk
    Suitable stage Long-running always-on agents Experiments and burst traffic

    Engineering teams must prepare a fallback path: when quota approaches a threshold, automatically switch to a lower tier, shorten context, and disable non-essential tools to preserve the core availability goal of “staying online for long periods without dropping.”

    1. Build a standard set of 20 to 50 real tasks covering three categories: simple, cross-tool, and high-risk.
    2. Run each task three times and take the average, recording completion rate, tool accuracy, tokens, and elapsed time.
    3. Add fault injection: network disconnection, tool timeouts, and permission denials, and observe recovery capability.
    4. Rank by “cost per effective task” rather than by unit price.
    5. Keep sampling continuously after launch, and run regression whenever the version changes.

    8. Conclusion

    An agent’s competitiveness comes from systems engineering rather than a single model score. Doing five things solidly, reasoning tiering, context governance, tool contracts, permission confirmation, and cost metrics, is what yields a stable, usable agent under budget constraints. If you need elastic compute along with general-purpose capabilities such as object storage, message queues, logging services, and monitoring and alerting, Baidu AI Cloud can provide the corresponding infrastructure support, allowing teams to focus their energy on evaluation and business logic itself.