LLM Selection and Agent Implementation: A Practical Guide
This guide explains how to evaluate and select large language models for AI Agent systems rather than chat use cases. It covers the key differences in model requirements, how to build a reproducible evaluation set with metrics such as task success rate and schema validity, and a four-dimension comparison method. It also provides engineering practices for validation, state management, observability, fallback, and budget control, along with common pitfalls to avoid.
1. Why Agent Requirements Differ from Chat Requirements
In conversational Q&A, a model only needs to “sound good.” In an Agent framework, the model must handle planning, tool selection, parameter filling, result validation, and failure recovery in sequence. This introduces three constraints that are very different from chat:
- Long-horizon stability: A complex task may involve dozens of tool calls, and the model must still remember the original goal and constraints after many turns.
- Strict instruction and format compliance: If the structure of a tool call is invalid, the entire chain breaks. The cost of fault tolerance is much higher than a minor flaw in text output.
- Predictable cost: Token consumption in an Agent grows roughly non-linearly with task complexity. Without budget constraints, the quota can be exhausted by just a few long tasks.
For these reasons, asking “which model is the strongest” has limited value. A more professional question is: Under given budget and latency constraints, which model performs best in success rate and stability on the target task?
2. Evaluation Design: Turning Subjective Experience into Reproducible Metrics
Before selecting a model, build a small but reproducible evaluation set. It should cover four task types: single-step tool calls, multi-step chaining, failure recovery that requires mid-course correction, and long-context information extraction.
Recommended core metrics:
- Task success rate: Whether the final state achieves the goal, not whether the text “looks right.”
- Schema validity rate: The proportion of tool call parameters that conform to the agreed format.
- Average steps and token consumption: Measures efficiency and cost; both must be considered together.
- High-risk action confirmation rate: Whether the system proactively requests confirmation for operations such as deletion, write access, or transfers.
- Long-task dropout rate: The proportion of cases where the goal drifts or loops repeat after a set number of turns.
A sample evaluation skeleton (pseudocode that only expresses the flow and does not point to any specific product):
def run_case(model_client, case, max_steps=30):ctx = Context(goal=case.goal, budget=case.token_budget)for step in range(max_steps):if ctx.exceeded_budget():return Result(status="BUDGET_EXCEEDED", steps=step)action = model_client.plan(ctx.snapshot())if not schema_valid(action):return Result(status="SCHEMA_INVALID", steps=step)if action.risk_level == "HIGH" and not ctx.confirmed:ctx.ask_user_confirmation(action)obs = executor.run(action)ctx.append(action, obs)if ctx.goal_reached(obs):return Result(status="SUCCESS", steps=step + 1)return Result(status="LOOP_OR_DRIFT", steps=max_steps)
The key point is: Count “invalid format” and “budget exceeded” as explicit failure states. These two problems account for a high proportion in real Agent systems, yet they are often masked by “successful demo cases.”
3. A Four-Dimension Comparison Method
3.1 Reasoning Tier and Task Matching
A high reasoning tier is not always the best default. For tasks with a clear path and well-defined tools, the higher tier brings limited gains but significantly increases latency and consumption. For tasks that require long-chain planning and involve many implicit constraints, a low tier is prone to goal drift. In practice, a more reliable approach is tiered routing by task: first run a lightweight classification, then decide the tier.
3.2 Context and Token Economics
The same task can consume several times more tokens on different models. When evaluating, fix the task set and maximum steps, and record the “total tokens required to complete the task” rather than only the per-call price. Also account for differences caused by cache reuse, history trimming, and summary compression.
3.3 Tool Calling and Framework Fit
Some models exhibit unstable recognition of the local skill/tool list or fail to ask before high-risk actions under an Agent framework. The root cause is insufficient adherence to the system prompt and tool descriptions. Mitigations include: removing ambiguity from tool descriptions, strongly constraining parameters with structured schemas, and performing secondary validation and interception at the framework layer, rather than relying entirely on the model’s own judgment.
3.4 Quota and Commercial Terms
Subscription and pay-as-you-go billing carry different risk structures: the former fears “short bursts of high-intensity tasks exhausting the quota,” while the latter fears “long tasks accumulating without limit.” In either case, set per-task budget, daily budget, and circuit-breaker thresholds at the framework layer.
4. Engineering Practice Recommendations
- Two-layer validation: Model output first passes format validation, then business semantic validation. Failure at either layer triggers a retry or fallback.
- Externalized state: Write the goal, constraints, and completed steps to external storage to avoid losing the goal after context compression.
- Observability: Log steps, tokens, latency, and failure type for each call, connect to a logging service and monitoring alerts, and build a trend dashboard.
- Fallback chain: Switch to a backup model or a rule-based flow when the primary model fails, ensuring the chain stays available.
- Cost governance: Allocate quotas by business line, enforce budget caps for long tasks, and automatically pause and request human confirmation when exceeded.
5. Common Pitfalls
- Inferring Agent performance from chat experience;
- Counting only successful cases while ignoring format failures and loops;
- Leaving high-risk confirmation to the model’s own judgment instead of enforcing it at the framework level;
- Looking only at per-call price rather than the overall cost of completing a task;
- Lacking a budget circuit breaker, allowing the quota to be swallowed by a few long tasks.
6. Conclusion
The core of Agent selection is not finding a “single strongest model,” but building an engineering system of task tiering + multi-dimensional metrics + framework safeguards + budget circuit breakers. On cloud platforms such as Baidu AI Cloud, you can combine general capabilities like container platforms, object storage, logging services, and monitoring alerts to build an evaluation and runtime foundation, so that model capabilities are delivered reliably at a controllable cost.
