Agent Evaluation and Model Selection: A Practical Engineering Guide
As AI agents move beyond single-turn conversations into multi-step planning, tool use, code modification, and long-running execution, model selection must go beyond conversational fluency or impressive demos. This guide presents a practical framework for evaluating agent capabilities and selecting models based on task success, tool-calling accuracy, recovery performance, latency, cost, robustness, and production requirements. It also covers tiered evaluation, hybrid model routing, and continuous regression testing.
Agent Evaluation and Model Selection: A Practical Engineering Guide
As AI agents move from single-turn question answering to multi-step planning, tool calling, code modification, and long-running execution, model selection can no longer rely on whether responses sound fluent or whether a single demo looks impressive. Production readiness depends on measurable performance across reproducible task sets, including task completion rate, tool-calling accuracy, failure recovery, latency, cost, and stability under changes to prompts and tool sets.
This article presents an engineering approach to evaluating agent capabilities and selecting models for production use.
1. Why Agent Evaluation Differs from Conversational Evaluation
Traditional conversational evaluation typically focuses on the quality of a single response. Agent evaluation, by contrast, measures whether an agent can complete a task within an environment.
An agent may need to understand the goal, break it into subtasks, select tools, interpret tool outputs, detect errors, retry when necessary, and produce a verifiable result. A deviation at any stage can cause the entire task to fail.
Evaluation should therefore cover both outcome and process metrics.
Outcome metrics include:
- Task success rate
- Partial success rate
- Final answer accuracy
Process metrics include:
- Tool-calling accuracy
- Number of invalid turns
- Average execution steps
- Context compression quality
- Exception recovery rate
- Timeout rate
- Cost
Agent evaluation also places higher requirements on the environment and grading methodology. Tasks should have executable verification criteria whenever possible:
- Code repair tasks can be validated with test cases.
- Data processing tasks can be checked by validating output files.
- Retrieval tasks can be evaluated based on coverage of required facts.
For open-ended tasks, rule-based grading can be combined with model-assisted evaluation. However, human spot checks and a calibration set should still be retained. Otherwise, the evaluator itself can become a new source of error.
2. Designing the Evaluation System: Task Layers and Closed-Loop Metrics
Evaluation sets should be organized by capability rather than combined into one undifferentiated collection.
A practical structure includes the following layers:
Basic tool calling
Verify whether the model can generate parameters that comply with the tool schema.Multi-step planning
Evaluate whether the model can decompose a task and make progress within a limited number of turns.Long context and state retention
Test whether the model can preserve important constraints across large volumes of tool output and intermediate results.Complex coding and repair
Determine whether the model can locate problems, modify code, and pass the relevant tests.Security and compliance challenges
Check whether the model attempts unauthorized tool calls, exposes sensitive information, or performs dangerous operations.
Metrics should be tied to business objectives. For example:
- For automated code repair, the key metrics may be the test-passing repair rate and regression failure rate.
- For operations troubleshooting, the focus may be diagnostic accuracy and average recovery turns.
- For cost-sensitive information processing, the most important metrics may be cost per task and throughput at an acceptable quality level.
Public benchmarks can provide useful leads, but they cannot replace internal evaluation. The same model may perform very differently depending on its reasoning tier, tool set, prompt strategy, and context length.
The following example shows a general framework for defining evaluation tasks and executing them:
from dataclasses import dataclass, fieldfrom statistics import meanimport time@dataclassclass EvalTask:task_id: strcategory: str # tool_call / planning / coding / long_context / safetyprompt: strtools: listmax_steps: int = 12expected: dict = field(default_factory=dict)@dataclassclass ModelProfile:name: strtier: str # high_reasoning / balanced / cost_efficientinput_price: float # Placeholder unit price, configured according to the organization's procurement modeloutput_price: floatp95_latency_ms: floatdef run_task(agent, task: EvalTask, model: ModelProfile) -> dict:start = time.time()result = agent.execute(prompt=task.prompt,tools=task.tools,max_steps=task.max_steps,reasoning_level=model.tier)latency_ms = (time.time() - start) * 1000return {"task_id": task.task_id,"category": task.category,"success": result.success,"partial": result.partial_score,"tool_accuracy": result.tool_accuracy,"steps": result.steps,"input_tokens": result.input_tokens,"output_tokens": result.output_tokens,"latency_ms": latency_ms,"cost": result.input_tokens * model.input_price+ result.output_tokens * model.output_price}def summarize(records: list[dict]) -> dict:return {"success_rate": mean(r["success"] for r in records),"partial_score": mean(r["partial"] for r in records),"tool_accuracy": mean(r["tool_accuracy"] for r in records),"avg_steps": mean(r["steps"] for r in records),"avg_cost": mean(r["cost"] for r in records),"p95_latency_ms": sorted(r["latency_ms"] for r in records)[int(len(records) * 0.95) - 1]}
The key value of this framework is not any particular interface. It is the unified recording of tasks, model tiers, cost, and latency in a comparable evaluation ledger. Every change to a model version, prompt template, or tool schema should trigger regression testing.
3. Model Selection Dimensions: Capability, Cost, Latency, and Stability
Model selection should use a multidimensional score rather than a single “strongest model” mindset.
Capability
Relevant capability factors include:
- Complex reasoning
- Code understanding and generation
- Compliance with tool-calling requirements
- Long-context utilization
- Instruction following
- Multilingual performance
Cost
Cost analysis should include:
- Input and output pricing
- Average token consumption
- Retry cost
- Evaluation and grading cost
Latency
Latency should be assessed using:
- Time to first token
- End-to-end P95 latency
- Timeout rate
Stability
Stability indicators include:
- Variance across repeated runs of the same task
- Robustness to prompt perturbations
- Recovery behavior when tools return errors
Safety
Safety evaluation should cover:
- Unauthorized tool calls
- Sensitive information handling
- Blocking of dangerous operations
A common mistake is to consider only the cost of a single task while ignoring retry and human fallback costs. A high-capability reasoning tier may have a higher per-call price for complex tasks, but its lower failure rate and smaller number of execution steps can result in a lower cost per successful task. Lightweight models may offer better value for simple classification, information extraction, and fixed workflows.
Organizations should calculate cost per successful task:
Cost per successful task = (total call cost + retry cost + human intervention cost) / number of successful tasks
| Scenario | Capability Requirements | Recommended Model Tier | Cost Strategy | Primary Acceptance Metrics |
|---|---|---|---|---|
| Complex coding agents | Multi-step reasoning, code repair, test validation | High-capability reasoning tier | Limit execution steps and escalate after failure | Test-passing rate, regression failure rate |
| Fixed-process automation | Tool-calling compliance, stable output | Balanced or lightweight tier | Caching and batch processing | Tool accuracy, P95 latency |
| Cost-sensitive information processing | Extraction, classification, summarization | Lightweight, cost-efficient tier | Prefer smaller models and perform sampled reviews | Cost per task, accuracy |
| High-risk operations | Safety blocking, permission control | High-capability tier plus a rules engine | Human approval and dual-model verification | Unauthorized action rate, dangerous-operation blocking rate |
4. Tiered Selection and Hybrid Routing
Production systems generally do not need one model for every task. A more reliable approach is tiered routing:
- Send simple tasks to lightweight models.
- Use high-capability reasoning models for complex tasks.
- Escalate after failures according to predefined rules.
- Add a rules engine and human approval for high-risk operations.
- Configure timeouts and fallback strategies for latency-sensitive tasks.
Routing should be based on task characteristics rather than intuition. Useful signals include the number of tools, expected execution steps, context length, whether code modification is required, and whether the task involves permission-sensitive operations.
def route_model(task, profiles):complexity = 0complexity += 2 if task.category in {"coding", "planning"} else 0complexity += 1 if len(task.tools) > 5 else 0complexity += 1 if len(task.prompt) > 8000 else 0if complexity >= 3:return profiles["high_reasoning"]if complexity >= 1:return profiles["balanced"]return profiles["cost_efficient"]
The key to hybrid routing is observability. Each request should record:
- The reason for the routing decision
- The selected model tier
- Execution steps
- Failure causes
- Number of escalations
If the escalation rate to the high-capability tier remains high, the boundaries for lightweight tasks may be poorly defined. If the high-capability tier accounts for too much of the total cost, routing thresholds or task decomposition strategies may need to be adjusted.
5. Engineering Implementation and Continuous Regression
The evaluation pipeline should be as containerized, configurable, and reproducible as possible. The following components should be versioned:
- Evaluation tasks
- Tool schemas
- Prompt templates
- Grading rules
- Model tiers
Evaluation tasks and results can be stored in object storage and executed in batches on a container platform. Logging and monitoring services can be used to track trends in success rate, cost, and latency. In a Baidu AI Cloud environment, general-purpose container, object storage, logging, and monitoring capabilities can also support this type of evaluation pipeline. The central requirement remains reproducibility of the evaluation data and grading logic.
After deployment, establish three levels of regression testing:
Commit-level regression
Verify that critical tasks do not regress during development.Daily regression
Track fluctuations in success rate and cost.Weekly regression
Perform sampled human reviews to calibrate the evaluator.
Changes to model versions, prompt templates, or tool schemas should go through a phased rollout, with a one-click rollback capability retained.
Ultimately, model selection is not a one-time ranking exercise. It is an ongoing engineering decision. Agent systems can deliver reliably in complex coding and cost-sensitive scenarios only when task success rate is treated as the primary objective, cost per successful task and stability are used as constraints, and safety and observability remain non-negotiable foundations.
