LLM Selection in Practice: Capabilities, Cost, and Agent Security

    This article explains how to select large language models for real engineering work by evaluating capability, cost, latency, routing, and agent safety. It shows why public rankings are not enough, how to build task-based evaluation sets, how to measure unit success cost, and how to enforce execution boundaries for AI agents. The goal is a reliable selection process based on business constraints, verifiable evidence, and controlled risk.

    1. Model selection is optimization under business constraints, not a ranking comparison

    When several high-capability models are updated at the same time, development teams often make decisions based on aggregate scores, per-call pricing, or demo quality. These metrics describe only partial model behavior. They do not directly answer which option is more suitable for the current business.

    For coding assistance, knowledge question answering, and automated tasks, models play different roles, so selection goals differ. Knowledge question answering may focus on citation accuracy and first-response latency. Code modification requires patch correctness, test pass rate, and maintenance cost. Agents that can call tools must also satisfy task completion rate, permission boundaries, and execution reliability.

    Therefore, selection should start from the business problem, not from a model list. A practical approach is to define requirements in three layers:

    • Baseline constraints: whether data is allowed to enter an external inference environment, whether access permissions are sufficient, and whether response time falls within the business tolerance range.
    • Quality goals: whether answers are correct, whether code runs, and whether multi-step tasks are actually completed.
    • Economic goals: how much it costs to complete one acceptable task, whether it consumes too much manual review effort, and whether cost can grow stably with business scale.

    If baseline constraints are not met, even a strong model should not enter the candidate set. Only after constraints are satisfied should quality and cost be compared. This avoids the result of “strong capability, but cannot be deployed.”

    2. Break capability into task-specific evidence

    2.1 Coding capability is more than generating code

    Generating syntactically correct code is only the starting point of a coding task. Real development usually involves understanding existing code, analyzing dependencies, locating errors, modifying multiple files, and running regression verification.

    For code generation tasks, evaluation can check functional implementation, boundary conditions, exception handling, and readability. For code repair tasks, additional dimensions should be included:

    • Whether the real root cause is identified, rather than merely hiding the error;
    • Whether the change preserves interface and behavior compatibility;
    • Whether unnecessary dependencies are introduced or the modification scope is expanded;
    • Whether existing tests and new tests targeting the issue pass;
    • Whether there is opportunistic behavior such as bypassing checks or deleting tests.

    Evaluation must run in an isolated environment. A model’s claim that “tests have passed” cannot replace actual test results. Only evidence from real builds, execution, and verification is suitable for engineering decisions.

    2.2 Agent capability is system capability, not only model capability

    An agent usually includes task planning, tool invocation, state management, and result verification. Good performance in standalone question answering does not mean the model can reliably execute long-chain tasks.

    For example, an automated modification may require reading requirements, searching relevant files, editing code, running tests, and finally submitting results. A parameter error, misinterpretation of tool output, or lost state at any step can cause final failure.

    Therefore, agent evaluation should at least distinguish:

    • Planning quality: whether steps are reasonable and key constraints are recognized;
    • Tool-use quality: whether tool selection, parameters, and execution order are correct;
    • Recovery ability: whether execution can be corrected based on feedback after failure;
    • Termination judgment: whether completion is declared prematurely when evidence is insufficient;
    • Operational compliance: whether the authorized scope is always respected.

    If candidate solutions use different tool sets, retrieval strategies, or execution budgets, evaluation results cannot be simply attributed to the model itself. Fair comparison requires unifying these conditions and separately recording the effects of model performance and system configuration.

    2.3 Long context capacity is not long context reliability

    A larger context window can hold more documents or code, but it does not automatically guarantee good information utilization. As input grows, relevant information may be diluted by irrelevant content, and multiple versions of instructions may conflict.

    When validating long-context capability, focus on:

    • Whether accuracy remains stable when key facts appear at the beginning, middle, or end;
    • Whether the model can locate the correct evidence when similar but incorrect content is present;
    • Whether the model can use the valid version when documents contain version conflicts;
    • Whether the model can integrate information across files instead of repeating local fragments;
    • Whether latency and cost remain acceptable as input length increases.

    In engineering, structured, relevant, and filtered context should be provided first. Retrieval, summarization, and on-demand reading have not lost value because context windows have expanded. They remain important for controlling cost, reducing interference, and improving explainability.

    3. Build a real-task evaluation set instead of relying on aggregate scores

    Public benchmarks are useful for an initial understanding of capability directions, but they should not directly replace business acceptance. Aggregate scores often cover many task types, and their weights may not match actual business proportions.

    It is better to build an evaluation set from historical requirements, defect records, and manual processing workflows, layered by the following dimensions:

    Task type Main focus Common failure modes
    Simple Q&A and summarization Correctness, completeness, response speed Missing conditions, unsupported additions
    Single-file code modification Functional correctness, modification scope Fixing surface symptoms, breaking boundary behavior
    Cross-file issue handling Dependency understanding, regression risk Locally correct, globally incompatible
    Multi-step automation Completion rate, tool-call reliability Lost state, incorrect retries, premature termination
    High-risk operations Authorization boundaries, audit and confirmation Unauthorized execution, sensitive information leakage

    Evaluation samples should cover both high-frequency tasks and low-frequency but high-loss scenarios. Security requirements should not be ignored just because a certain operation occurs rarely.

    Each sample should have clear input, allowed tools, execution budget, and acceptance criteria. Open-ended outputs can use manual review. Code and automation tasks should use repeatable programmatic verification whenever possible.

    It is also necessary to keep test samples that did not participate in solution tuning. Otherwise, repeatedly adjusting prompts and workflows around the same questions can overestimate real generalization ability.

    For tasks with randomness, repeated tests should be arranged, and result variance should be reported rather than showing only the best run. Small leads should be interpreted together with sample size and failure distribution, avoiding treating accidental differences as stable advantages.

    4. Understand price through unit success cost

    4.1 Unit price is not total cost

    The inference cost of a single call can be estimated with the following simplified formula:

    Inference cost = input usage × input price + output usage × output price

    When calculating, units must be consistent, and the actual billing basis should be used. If a service includes other charges, they should be included separately according to the contract or billing rules. It should not be assumed that all options use the same billing method.

    In agent applications, one task often includes multiple calls. Reading tool results, revising plans, and retrying failures all increase consumption. A more complete cost should also include tool execution, runtime environment, manual review, and failure handling.

    A low-unit-price option may not be cheaper if it often requires retries. A high-capability option may not have a cost advantage if it produces verbose output and is called frequently.

    4.2 Use accepted tasks as the denominator

    A more suitable metric for selection is:

    Unit success cost = total task cost during evaluation ÷ number of tasks passing acceptance

    The “total task cost” must include the cost of failed tasks. Otherwise, real spending will be underestimated.

    For example, the following hypothetical data is only for explaining the method and does not correspond to any specific product: Option A spends 120 cost units on a batch of tasks and passes 80. Option B spends 180 cost units and passes 150. The unit success cost of A is 1.5, and that of B is 1.2. B has higher total spending, but a lower cost per accepted result.

    However, unit success cost alone should not determine selection. If task failure may trigger a production incident, an additional risk threshold must be set. High-loss events cannot be offset only by average cost.

    4.3 Recalculate after price changes instead of reusing old conclusions

    Promotional pricing can reduce evaluation cost, but it should not be the sole basis for long-term architecture design. A reasonable approach is to separately estimate current price, formal price, and cost after business growth.

    If the price of a candidate option changes, recalculate:

    • Unit success cost for each task type;
    • The upgrade-call ratio of high-capability models;
    • Whether manual-review savings are enough to cover the cost difference;
    • Cost amplification caused by long context and retries;
    • Whether the monthly budget remains controllable under peak load.

    Price changes do not necessarily require switching models, but they may change routing boundaries and task allocation.

    5. Latency and reasoning depth: more thinking is not always more cost-effective

    User experience depends not only on how quickly a model starts output, but also on when the complete task finishes. For agents, first-response time, single-call time, and end-to-end completion time should be distinguished.

    A model with fast responses may take longer overall if it repeatedly selects the wrong tool or makes repeated modifications. It may be slower than a less fast but more accurate option. Therefore, latency evaluation should cover the complete workflow and record high-percentile latency, avoiding averages that hide a few severe delays.

    Some inference services allow adjusting reasoning budget or depth, but the specific mechanism and billing method must be confirmed according to the service description. It should not be assumed that all candidate options have the same control capability.

    The general principle is to allocate compute by task difficulty. Tasks such as format conversion and field extraction do not always need a high reasoning budget. Cross-file localization and complex constraint analysis may justify more compute. Whether this is effective should be verified through quality gain, cost increase, and latency change together.

    6. Layered routing is more flexible than fixed use of one model

    In systems with diverse task types, regular requests can first be handled by a lower-cost path, and difficult tasks can be escalated to a high-capability path. However, the escalation mechanism must have verifiable trigger conditions.

    Common trigger signals include:

    • The task involves multiple files or interdependent constraints;
    • Output fails structured validation;
    • Build, test, or business validation fails;
    • Retrieval evidence is insufficient or sources conflict;
    • The task requires high-risk operations.

    It should not rely only on the model’s self-reported “confidence.” Self-evaluation may be inaccurate. External tests and rule validation are usually more suitable as escalation signals.

    A neutral workflow can be expressed as:

    Task input → classification and risk check → regular processing → external validation
    Validation passed → deliver result
    Validation failed → escalate or send to manual review

    A total call budget, maximum retry count, and stop conditions should also be set to prevent repeated loops across multiple processing paths. Escalation does not mean continuing to append all historical content. Key facts, failure evidence, and current state should be retained to reduce ineffective context.

    7. Agent security must be guaranteed by execution boundaries

    Security evaluation results can be used as reference, but they cannot replace system permission control. Agents may encounter untrusted inputs such as documents, web content, and tool results. These inputs may contain instructions that try to change the agent’s goal or trigger unauthorized operations.

    Such content should be treated as data to be processed, not as a new source of authorization. Engineering should establish the following boundaries:

    1. Least privilege: grant only the read and write permissions necessary to complete the task.
    2. Environment isolation: execute code, modify files, and access external resources in a controlled environment.
    3. Operation validation: independently check target paths, parameter ranges, and resource ownership.
    4. Human confirmation: high-risk actions such as deleting resources or modifying production configuration require confirmation.
    5. Sensitive information protection: credentials should not enter unnecessary context, and logs should be masked.
    6. Audit and rollback: record key decisions and operation results, and prepare recovery mechanisms for mutable resources.

    In particular, “the model thinks it can execute” should not be treated as authorization. Permissions must be enforced by external systems. Even if the model is misled, it should not be able to cross the boundary.

    8. Continue evaluation after launch and build a reversible selection mechanism

    Model selection is not a one-time procurement decision. Model versions, task distributions, prompt templates, and tool environments all change, so previous conclusions need periodic validation.

    At launch, shadow evaluation can be used first: the new solution processes real requests but does not directly execute high-risk actions. It is then compared with the existing solution. After meeting quality, security, and cost thresholds, traffic can be gradually expanded while keeping a rollback path.

    Runtime monitoring should cover at least task success rate, unit success cost, end-to-end latency, escalation ratio, manual takeover rate, and security interception events. If cost suddenly rises, determine whether it is caused by price changes, input growth, increased retries, or task-structure changes, rather than directly attributing it to model capability.

    In the end, a reliable selection conclusion should not be “which model ranks highest.” It should be “under the given tasks, budget, and risk boundaries, which processing path can stably deliver accepted results.” Build evidence with real tasks, define success with external validation, measure economics with unit success cost, and constrain execution risk with permission isolation. This turns short-term model comparison into a long-term maintainable engineering solution.