LLM Selection and Engineering Practices for AI Agents: A Practical Guide
This guide explains why choosing a large language model for AI agents is an engineering problem rather than a benchmark contest. It covers how to design controlled experiments, which quantitative metrics to collect, common failure modes and their root causes, cost and capacity considerations, and observability with regression evaluation. The goal is to help teams build a reproducible, cost-controlled system for evaluating and replacing models behind a routing layer.
1. Why Agentic Systems Turn Model Selection into an Engineering Problem
Traditionally, a language model was evaluated by its scores on standardized benchmarks, the fluency of its writing, and whether its code ran on the first attempt. Once a model is placed inside an AI agent framework, the evaluation dimensions change fundamentally. The model no longer just generates a piece of text; it must repeatedly perform a loop of perceiving context, selecting tools, generating parameters, observing results, and revising its plan. What really determines the experience is the stability of long-horizon tasks, how strictly instructions are followed, the reliability of structured output, and the resources consumed per task.
A common situation many teams run into is that a model performs excellently in chat scenarios but, once connected to an agent, frequently fails to call tools, produces malformed parameters, forgets system constraints, or executes high-risk actions without confirmation. This does not mean the model has become “dumber.” Instead, the requirements that agent scenarios place on model capabilities differ structurally from those of ordinary conversation. Model selection therefore has to return to controlled experiments rather than relying on scattered impressions from usage.
2. Experiment Design: Controlling Variables Is the Prerequisite for Trustworthy Conclusions
To judge the differences between models, the first step is to lock down all irrelevant variables. A reproducible controlled experiment should at minimum fix the following elements:
- The agent framework and scheduling loop are completely identical, including the maximum number of iterations, timeout thresholds, and retry strategy;
- The memory mechanism is identical, including the short-term context window strategy and the write and recall rules for long-term memory;
- The way skills are registered is identical, with the same tool descriptions, parameter schemas, and permission boundaries;
- The system prompt and output constraints are identical, for example whether the model must think before acting and whether structured output is enforced;
- The only variable is the underlying reasoning model, with the highest available reasoning tier enabled when permitted.
Only under this setup can the observed differences be attributed to the model itself. It is worth emphasizing that different models have different context lengths, billing methods, and rate-limiting policies. These differences directly affect experiment cost and should be recorded as known biases rather than mixed into capability conclusions.
3. Evaluation Metrics: Replace “Feels Smarter” with Quantifiable Signals
Subjective impressions are extremely noisy. It is recommended to collect at least four categories of metrics:
- Task success rate: judged by whether the final state is achieved, not by whether the text looks good;
- Tool-call correctness: including whether a call should be made, whether the right tool is chosen, and whether the parameters pass schema validation;
- Safety confirmation rate: for high-risk actions such as deletion, transfers, or publishing, whether a second confirmation is performed according to policy;
- Resource consumption: the average number of rounds, input and output tokens, and end-to-end latency required to complete a task.
A sample evaluation record structure can be simplified as:
{"task_id": "T-017","model": "model-a","success": true,"tool_calls": 6,"schema_valid_rate": 0.83,"risk_confirm": "passed","tokens_in": 48200,"tokens_out": 3100,"latency_ms": 92000}
Repeating the same task multiple times and taking the mean and failure distribution is more convincing than a single demonstration. In particular, pay attention to “failure modes”: whether it is missing tool calls, parameter hallucination, or forgetting constraints in the later stages of a long task. Failure modes are more useful than success rates for guiding subsequent optimization.
4. Common Failure Modes and Root-Cause Analysis
In agent scenarios, high-frequency problems usually fall into four categories:
- Skill recognition failure: tool descriptions are too long or semantically overlapping, so the model cannot distinguish similar tools;
- Constraint decay: as rounds increase, hard rules in the system prompt are gradually ignored;
- Resource amplification: the model tends to repeatedly read files or repeat retrievals, causing token consumption to multiply;
- Safety policy spinning idle: high-risk actions are executed without confirmation, or, conversely, excessive confirmation stalls the workflow.
When performing root-cause analysis, first rule out framework-side issues, such as invalid tool schemas, incorrect permission configuration, or context trimming that cuts off critical instructions. Many phenomena blamed on “the model is not good enough” are actually caused by improper context management strategies.
5. An Engineering View of Cost and Capacity
Selection cannot be based on unit price alone. Real cost = unit token price × average tokens per task × retry factor. A model with a lower unit price but more rounds may end up with a higher total cost. Capacity is equally critical: the rate at which quota is consumed, rate-limiting thresholds, and whether long tasks get cut off midway determine whether a model can serve as the mainstay for long periods online.
In practice, a more robust approach is layering: assign high-frequency, short-chain, low-risk subtasks to cost-effective models; assign long-horizon planning, complex refactoring, and strongly constrained output to more capable but more expensive models; and for extremely long-context tasks, use summary compression and segmented retrieval to control input size. By unifying the interface through a routing layer, models can be replaced without affecting business code.
6. Observability and Regression Evaluation
Before going live, establish an offline evaluation set and online monitoring. The offline part fixes a batch of representative tasks and runs them every time the model or prompt changes, forming trend curves; the online part records the call chain, tool error codes, number of confirmation interceptions, and token consumption, with logging and alerting configured. When success rate or latency shows abnormal fluctuations, you can quickly locate whether the cause is a model change, a tool change, or a context strategy change.
7. Conclusion
Model selection for agent scenarios is essentially three things: reproducible experiments, quantitative metrics, and layered scheduling. Rather than chasing a single “strongest model,” it is better to build an engineering system that can continuously evaluate, smoothly replace, and control costs. Baidu AI Cloud provides complete support in general capabilities such as model services, container platforms, and logging, monitoring, and alerting, which can help teams quickly turn the above practices into stable agent infrastructure.
