DEV Community

Cover image for Evaluating AI Agents Beyond "It Worked Once": A Practical Test Set Approach
Shaheryar Yousaf
Shaheryar Yousaf

Posted on

Evaluating AI Agents Beyond "It Worked Once": A Practical Test Set Approach

TL;DR for devs

  • Build test sets from realistic requests, edge cases and failures.
  • Evaluate the trace (tools, arguments, actions), not just the final text.
  • Define explicit pass criteria before running tests and measure quality, cost and latency together.
  • Rerun a fixed regression suite after changes to prompts, tools, models or retrieval.
  • Do not treat a model grader as ground truth, and avoid changing many things at once.

Realistic requests, trace-level checks, pass criteria and regression suites

A developer tests an AI agent with one request, sees the expected answer, and declares the feature ready. The demo looks good. But a customer asks the same question with different wording, the database returns no match, or the model selects the wrong tool—and the agent breaks.

This happens because agents do more than generate a single response. They may interpret user intent, select tools, make several calls, use returned data, and decide when to stop. Evaluating only the final sentence misses important parts of the system.

In this guide, we’ll explain how to evaluate AI agents beyond a one-time successful run. You’ll learn what to measure, how to create realistic test cases, and how to use Python to score a small set of expected outcomes.

What Does Agent Quality Mean?

Agent quality is the degree to which a system completes the user’s task correctly, safely, and consistently. The exact definition depends on the product. A support agent may need to find the right policy and escalate when uncertain. A research agent may need to cite sources and mark missing facts. A coding agent may need to make a correct change without touching unrelated files.

A useful evaluation looks at several layers:

  • Task outcome: Did the system solve the user’s problem?
  • Tool choice: Did it use the right tool, and only when needed?
  • Arguments: Were the tool inputs valid and grounded in the request?
  • Policy behavior: Did it respect permissions and approval requirements?
  • Evidence: Did the answer match the tool results and cite sources where required?
  • Efficiency: Did it use a reasonable number of steps and finish in acceptable time?
  • Recovery: Did it handle missing data or tool failures honestly?

OpenAI’s evaluation guidance provides a framework for testing model behavior with defined inputs and expected outcomes. For agents, the evaluation should include tool use and intermediate states, not just the final prose.

Build a Test Set From Realistic Requests

Start with examples that represent actual user needs. Include different phrasings of the same intent, common edge cases, and requests that the agent should refuse or escalate.

For an order-status assistant, a small evaluation set might include:

  1. A valid order belonging to the signed-in customer.
  2. A valid order number belonging to someone else.
  3. A typo in the order number.
  4. A request without an order number.
  5. A shipping API timeout.
  6. A user asking to change the delivery address when the tool only reads status.
  7. A prompt injection attempt embedded in a support message.
  8. A status result with a missing estimated-delivery date.

Write down what correct behavior means for each case. For example, when no order number is given, the agent should ask for it and make no API call. When an order belongs to someone else, the backend must deny access even if the model requested it.

Evaluate the Trace, Not Just the Final Answer

A final answer can look polished even when the system used the wrong data. Inspect the interaction trace where appropriate:

  • What did the user ask?
  • Which tools were available?
  • Which tool did the model request?
  • What arguments did it provide?
  • Did the application allow the call?
  • What did the tool return?
  • Did the model report that result accurately?
  • Did the system stop at the right time?

This gives you a way to distinguish model behavior from application behavior. If the tool returned the wrong account data, the issue may be in the backend. If the tool result was correct but the answer changed the status, the issue may be in synthesis or instructions.

Define Pass Criteria Before Running Tests

A test is useful only if you know what success means. Avoid criteria such as “the answer sounds good.” Specify observable conditions.

For example, a test for a failed order lookup might require:

  • The system calls get_order_status no more than once.
  • It does not call any update or refund function.
  • It tells the user that the status could not be retrieved.
  • It does not claim the order shipped or the task completed.

Some criteria can be checked with code: correct tool name, no prohibited calls, exact output fields, or whether a confirmation gate was respected. Other criteria—such as whether a summary is clear—may need human review or a model-assisted rubric. Treat model-based grading as a useful signal, not unquestionable truth.

A Small Python Evaluation Example

This example scores a simplified trace against expected tool behavior. In a production system, traces might come from your agent framework or application logs.

from dataclasses import dataclass

@dataclass
class Case:
    name: str
    expected_tools: list[str]
    forbidden_tools: list[str]
    expected_status: str


def evaluate_trace(case: Case, trace: dict) -> dict:
    calls = [item["tool"] for item in trace.get("tool_calls", [])]
    checks = {
        "expected_tools_used": all(tool in calls for tool in case.expected_tools),
        "forbidden_tools_avoided": all(tool not in calls for tool in case.forbidden_tools),
        "status_matches": trace.get("status") == case.expected_status,
    }
    return {
        "case": case.name,
        "passed": all(checks.values()),
        "checks": checks,
    }


case = Case(
    name="missing_order_number",
    expected_tools=[],
    forbidden_tools=["get_order_status", "issue_refund"],
    expected_status="needs_clarification",
)

trace = {
    "tool_calls": [],
    "status": "needs_clarification",
}

print(evaluate_trace(case, trace))
Enter fullscreen mode Exit fullscreen mode

This kind of deterministic check is valuable for rules that should not be left to subjective review. It does not evaluate whether the assistant’s message is helpful or whether the API authorization is correct; those need their own checks. Build a small set of targeted evaluators rather than expecting one score to represent everything.

Measure Quality, Cost, and Latency Together

A system can be accurate but too slow or expensive for the product. Track measures that reflect the user experience and operating cost:

  • Task completion rate.
  • Correct tool-selection rate.
  • Argument-validation failure rate.
  • Unsupported claims or incorrect answers.
  • Escalation and clarification rate.
  • Number of model and tool calls per request.
  • Response time and external-service latency.
  • Cost per successful task.
  • Human edit, approval, and rejection rates.

Do not optimize for fewer steps at any cost. A confirmation step might increase latency while reducing harmful actions. A more capable model may cost more but reduce repeated tool calls. Measure the trade-offs against the product’s actual priorities.

Keep a Regression Suite

Whenever you change the prompt, tool schema, model, retrieval logic, or backend behavior, rerun a fixed set of evaluations. This helps catch regressions: a change that improves one type of request may make another worse.

Keep test cases versioned and record the model and configuration used. Compare results across changes rather than relying on memory of a previous demo. Add new cases when real users encounter a failure, while removing or updating cases that no longer represent current behavior.

Use a mix of:

  • Deterministic tests: Validate schemas, permissions, tool calls, and state transitions.
  • Scenario evaluations: Run realistic user requests through the whole workflow.
  • Human review: Assess quality, tone, and nuanced correctness where needed.
  • Production monitoring: Detect failures, latency, and unexpected patterns after launch.

No single method covers everything.

Avoid Common Evaluation Traps

Testing only easy examples

A few happy-path cases will not reveal how the system handles ambiguity, missing data, or adversarial inputs. Add failure cases deliberately.

Scoring only the final text

A fluent response may hide a wrong tool call or unauthorized action. Inspect the trace and state transitions.

Using vague rubrics

“Good answer” is difficult to reproduce. Define explicit criteria and examples of pass, partial pass, and fail.

Treating a model grader as ground truth

A model can help assess open-ended outputs, but it can also miss errors or favor polished language. Use deterministic checks where possible and sample human review for important outcomes.

Changing many things at once

If you modify prompts, tools, and retrieval together, it becomes hard to know what caused a result to improve or degrade. Change one area at a time when practical and keep the evaluation set consistent.

Ignoring real-world drift

User requests, data sources, policies, and model behavior can change. Continue monitoring after launch and update evaluation cases when the product evolves.

Frequently Asked Questions

How many test cases do I need?

There is no universal number. Start with a compact set that covers the main user intents, important edge cases, and prohibited actions. Expand it as you observe new failures.

Can I use an LLM to grade agent answers?

Yes, for qualities that are difficult to score with simple rules, such as clarity or whether a summary addresses the request. Use a clear rubric, compare the grader with human judgments, and avoid relying on it alone for safety-critical checks.

Should I evaluate every tool call?

For development, inspect tool traces across a representative set of requests. In production, log and monitor outcomes according to privacy rules. Prioritize tools that can change data or cause meaningful side effects.

What is the difference between testing and evaluation?

Traditional tests often verify specific code behavior. Agent evaluations assess outputs and decisions across varied scenarios, including behavior that may be probabilistic. A robust system needs both kinds of checks.

When should I rerun evaluations?

After meaningful changes to the model, prompts, tools, retrieval, policies, or backend code—and regularly as the product and data evolve.

Conclusion

An AI agent that works once has demonstrated possibility, not reliability. To understand quality, evaluate the full path from user request to tool calls, application checks, results, and final response. Include ordinary requests, edge cases, failures, and actions the agent should not take.

Define pass criteria before testing, use code for objective checks, and bring in human review for nuanced judgments. Track accuracy alongside cost, latency, and escalation behavior. Keep a regression suite and update it as real failures appear. This turns evaluation into an ongoing development practice and helps you improve an agent with evidence rather than intuition.

References


I write about building AI agents and full-stack AI apps. Follow me for the next one, and tell me in the comments: How do you test your agent today: a few manual tries, or a real eval set?

Top comments (1)

Collapse
 
userxnom profile image
Abdullah Naseer •

The order-status test set is the strongest part — a valid order, someone else's order, a typo, a timeout, a prompt injection in a support message: eight cases that would catch the failures a single happy-path demo never shows. The pass-criteria example is the discipline most teams skip: "calls get_order_status no more than once, never calls a refund, and does not claim the order shipped" is checkable in code, not a vibe. One question: when a test fails, how do you decide whether the prompt, the tool schema, or the model is the culprit — do you change one thing at a time and rerun the whole suite, or do you have a shortcut for narrowing it down?