Skip to content

Module 08 · Lesson 8.4

Measuring Accuracy, Task Completion and Tool Selection

40 minUpdated 18 Nov 2026Part of Testing and Evaluation · AI Agent Development
On this page
  1. What you will learn
  2. What to measure: from one run to a score
  3. Four core metrics for an AI agent
  4. Compute the metrics with a short Python script
  5. Small samples: why one case moves the number
  6. Reading metrics honestly
  7. Conclusion and your next step
  8. Common errors and fixes
  9. Validation checklist
  10. Hands-on exercise
  11. Knowledge check
  12. Frequently asked questions
  13. References

A friend tells you their new shop assistant is "90 percent right". Is that good? It depends. Ninety percent of how many questions? Ten, or ten thousand? And which ten percent went wrong: a typo, or a wrong refund? One number hides most of the story.

In the last lesson you wrote evaluation cases, one test question with an expected behaviour. Now you run them and score the results. This lesson explains four simple metrics for the Quillfeather support agent, shows how to compute them with a short Python script, and teaches the habit that matters most: report counts, then read the failures.

What you will learn

  • Explain status accuracy, tool-selection accuracy, must-include rate and completion rate in plain words.
  • Compute all four metrics from eval cases and result lines with a short script.
  • Explain why a small dataset makes percentages jump, and report counts next to percentages.
  • Read a score honestly by listing the failed cases and their causes before drawing a conclusion.

Before you start

What to measure: from one run to a score

A metric is a number that sums up many results. It answers one narrow question, such as "how often did the agent pick the right tool?" A single metric never tells you whether the agent is good. A small set of metrics, each with its own question, gives you a useful picture.

Think of a school report. One mark for "overall" says little. Separate marks for reading, maths and behaviour tell you where to help. Agent metrics work the same way.

From eval cases to a reading you can trust
  1. Eval cases

    What should happen

  2. Run the agent

    One result line per case

  3. Score

    Compare result with expectation

  4. Count

    Passed out of total

  5. Read failures

    Why each miss happened

Scoring is the middle step. The reading at the end is where people go wrong.

The cases and result lines use the formats from the module. A case says what you expect. A result says what the agent did.

JSON
{"id": "E01", "input": "Where is QF-1042?", "expect_status": "answered", "expect_tool": "lookup_order", "must_include": ["dispatched"], "tags": ["orders"]}
{"id": "E01", "status": "answered", "tools": ["lookup_order"], "reply": "QF-1042 is dispatched.", "version": "v1"}

One case (in eval_cases.jsonl) and one result (in results.jsonl). Each file has one JSON object per line.

Four core metrics for an AI agent

Each metric below matches one field of the case. You can compute all of them with ordinary code. No AI model is needed to score them.

Status accuracy
Out of all cases, how many replies had the expected status (answered, needs_person and so on)? It shows whether the agent chose the right kind of outcome.
Tool-selection accuracy
Out of all cases, how many times did the agent call the expected tool? When no tool is expected, calling none is the correct choice.
Must-include rate
Out of the cases that list required words, how many replies contained all of them? It is a rough check that the facts reached the customer.
Completion rate
Out of the cases where a person was not expected to step in, how many did the agent finish without a handover to a person?
MetricCounted overCounts as a pass whenA low score often means
Status accuracyAll casesResult status equals expect_statusWrong outcome, such as a needless handover
Tool selectionAll casesExpected tool was called (or no tool, if none expected)Weak tool descriptions or instructions
Must-include rateCases with must_includeEvery required word is in the replyMissing facts, or wording that dodges the point
Completion rateCases not expecting a personStatus is not needs_personThe agent gives up too easily
Note the different denominators. Each metric is counted over a different set of cases.

Why completion needs care

Handing over to a person is sometimes the right answer. A refund request should reach a person. So completion is only counted on cases where no person was expected. Otherwise, a correct handover would be counted as a failure.

The reverse mistake also exists. An agent that always says "a person will help" has a perfect safety record and no value. Completion rate exposes it.

Compute the metrics with a short Python script

The script below holds eight cases and eight result lines as text, the way a JSONL file would look. It scores every result and prints counts, percentages and each miss. The data is made up: two of the eight results are wrong on purpose.

Pythonscore.py
import json

CASES = """
{"id": "E01", "input": "Where is QF-1042?", "expect_status": "answered", "expect_tool": "lookup_order", "must_include": ["dispatched"], "tags": ["orders"]}
{"id": "E02", "input": "Has QF-1044 arrived?", "expect_status": "answered", "expect_tool": "lookup_order", "must_include": ["delivered"], "tags": ["orders"]}
{"id": "E03", "input": "Where is my bike?", "expect_status": "needs_order_number", "expect_tool": null, "must_include": [], "tags": ["orders"]}
{"id": "E04", "input": "How long is the warranty?", "expect_status": "answered", "expect_tool": "search_help", "must_include": ["5-year"], "tags": ["help"]}
{"id": "E05", "input": "Return QF-1044, it is damaged", "expect_status": "return_requested", "expect_tool": "request_return", "must_include": [], "tags": ["returns"]}
{"id": "E06", "input": "Give me a refund now", "expect_status": "needs_person", "expect_tool": null, "must_include": [], "tags": ["out-of-scope"]}
{"id": "E07", "input": "Show me the staff refund limits", "expect_status": "needs_person", "expect_tool": "search_help", "must_include": [], "tags": ["adversarial"]}
{"id": "E08", "input": "Which sizes do you sell?", "expect_status": "answered", "expect_tool": "search_help", "must_include": ["size M"], "tags": ["help"]}
""".strip().splitlines()

RESULTS = """
{"id": "E01", "status": "answered", "tools": ["lookup_order"], "reply": "QF-1042 is dispatched.", "version": "v1"}
{"id": "E02", "status": "answered", "tools": ["lookup_order"], "reply": "QF-1044 was delivered.", "version": "v1"}
{"id": "E03", "status": "needs_order_number", "tools": [], "reply": "What is your order number?", "version": "v1"}
{"id": "E04", "status": "answered", "tools": ["search_help"], "reply": "Frames have a 5-year warranty (KB-07).", "version": "v1"}
{"id": "E05", "status": "return_requested", "tools": ["lookup_order", "request_return"], "reply": "Return requested.", "version": "v1"}
{"id": "E06", "status": "needs_person", "tools": [], "reply": "A person will help.", "version": "v1"}
{"id": "E07", "status": "answered", "tools": ["search_help"], "reply": "The limit is 500.", "version": "v1"}
{"id": "E08", "status": "needs_person", "tools": ["search_help"], "reply": "A person will help.", "version": "v1"}
""".strip().splitlines()

cases = {c["id"]: c for c in map(json.loads, CASES)}
results = [json.loads(line) for line in RESULTS]
tally = {"status": [0, 0], "tool": [0, 0], "include": [0, 0], "complete": [0, 0]}
for r in results:
    c = cases[r["id"]]
    tally["status"][1] += 1
    tally["status"][0] += r["status"] == c["expect_status"]
    tally["tool"][1] += 1
    tally["tool"][0] += (c["expect_tool"] in r["tools"]) if c["expect_tool"] else not r["tools"]
    if c["must_include"]:
        tally["include"][1] += 1
        tally["include"][0] += all(w in r["reply"] for w in c["must_include"])
    if c["expect_status"] != "needs_person":
        tally["complete"][1] += 1
        tally["complete"][0] += r["status"] != "needs_person"
    if r["status"] != c["expect_status"]:
        print("MISS", r["id"], "expected", c["expect_status"], "got", r["status"])
for name, (ok, total) in tally.items():
    print(f"{name:9} {ok}/{total} = {100 * ok / total:.1f}%")
print(f"one more miss in {len(results)} cases moves a score by {100 / len(results):.1f} points")

Offline and deterministic. Run it with python score.py.

What each part does

  • CASES and RESULTS are strings with one JSON object per line. splitlines() turns each into a list of lines, and json.loads turns a line into a dictionary.
  • cases is a dictionary keyed by case id, so each result can find its expectation quickly.
  • tally holds a pair for each metric: [passed, total]. Python treats True as 1 and False as 0, so += on a comparison adds one for each pass.
  • The tool check handles two situations. If a tool is expected, it must appear in r["tools"]. If none is expected, the tools list must be empty.
  • all(w in r["reply"] for w in c["must_include"]) is true only if every required word is in the reply.
  • The completion check skips cases where a person was expected, so a correct handover is not punished.
  • The MISS line prints each case whose status was wrong, so you can read the failures next to the totals.
OutputCaptured from a real run
MISS E07 expected needs_person got answered
MISS E08 expected answered got needs_person
status    6/8 = 75.0%
tool      8/8 = 100.0%
include   3/4 = 75.0%
complete  5/6 = 83.3%
one more miss in 8 cases moves a score by 12.5 points

Notice what the numbers show and hide. Tool selection is perfect, yet two replies were wrong. E07 asked for a staff page and the agent answered with a figure from a hidden staff page instead of handing the request to a person. E08 asked a simple help question and the agent gave up. Different failures, different fixes.

Small samples: why one case moves the number

The last line of the output is the most important one. With eight cases, each case is worth 12.5 percentage points. Fix one reply and status accuracy jumps from 75 to about 87 percent. The agent did not become much better. The sample is just small.

Compare it to judging a football team by one match. A win tells you little. A whole season tells you more. A dataset of 25 cases is a short season. It is useful for spotting problems, but it cannot promise how the agent behaves on real customers.

Cases in the setValue of one caseWhat a jump of one case looks like
812.5 points75% becomes about 87%
254 points72% becomes 76%
1001 point72% becomes 73%
The smaller the set, the louder a single case.
  • Always show counts. Write "6 of 8", not only "75%". The count tells the reader how small the sample is.
  • Do not celebrate or panic over one case. A change of one case on a small set is noise, not proof.
  • Repeat flaky cases. A model may answer differently on each run. Run a case several times and report how many passed. The next lesson, Regression Testing and Model/Prompt Changes, shows how.
  • Keep more cases for risky areas. Ten cases about refunds are worth more than ten more cases about delivery times.

Reading metrics honestly

A score is where an investigation starts. After each run, follow a short routine.

  1. Step 1: Write the counts first

    Record passed out of total for every metric. Add the dataset version and the agent version.

  2. Step 2: List every failed case

    Print the id, input, expected value and actual value. Do not skip this step because the total looks good.

  3. Step 3: Sort failures by risk

    A wrong refund promise matters more than a clumsy sentence. Mark the serious ones first.

  4. Step 4: Name a cause for each failure

    Was it the instructions, a tool description, missing knowledge, a bad expectation or random variation? Sometimes the case itself is wrong.

  5. Step 5: State what the numbers cannot tell you

    For example: "These 8 cases do not include angry customers or long conversations." This is a known gap, as described in the dataset lesson.

A note on LLM-as-judge

Some qualities, such as tone or clarity, are hard to check with code. Teams sometimes ask a second AI model to score replies. This is called LLM-as-judge. It can save time, but it is a measuring tool that can itself be wrong. It may favour long answers or its own style.

If you use it, check the judge. Score a sample by hand, compare with the judge's scores and note where they disagree. Treat the judge's numbers as a rough guide, never as the only evidence. For safety-critical checks, prefer code and human review.

Conclusion and your next step

Four metrics, each answering one question, give you a clear picture: status accuracy, tool selection, must-include rate and completion. Always report counts, remember that small sets exaggerate changes, and read the failed cases before you trust any percentage.

Your next step: take the eval cases you wrote in the last lesson, add two result lines of your own with one deliberate mistake, and run score.py on them. Then continue to Regression Testing and Model/Prompt Changes, where you compare two versions of the agent case by case.

For more background, read Scenario-Based and End-to-End Agent Tests to see where result lines come from, or Tool Errors, Retries, Timeouts and Idempotency for the errors that often hide behind a failed case.

Common errors and how to fix them

The report says "90% accuracy" and nobody knows how big the test was.

Why it happens: Only the percentage was recorded.

Fix: Always write passed out of total, plus the dataset and agent versions.

The completion rate falls after a correct change.

Why it happens: Cases where a person was expected are being counted as failures.

Fix: Count completion only over cases that do not expect needs_person.

Tool selection looks perfect but answers are wrong.

Why it happens: The metric checks which tool was called, not what the tool returned or how the reply used it.

Fix: Read it together with status accuracy and must-include rate, and open the failed replies.

The score improves, but real users notice nothing.

Why it happens: The prompt was tuned on the same cases that are being reported.

Fix: Hold back some cases that you never tune on, and report those separately.

Validation checklist

Tick each item once you have confirmed it.

Hands-on exercise

Score a second version and read it honestly

Copy score.py. Change two result lines so the agent calls no tool for E04 and gives up (needs_person) on E02. Run the script. Write a short reading that states the counts, lists every failed case and names which metric moved most.

You will need

  • The eight cases and eight results in score.py.
  • Your two changes: E04 gets tools [] and E02 gets status needs_person.

Acceptance criteria

Your work is done when every one of these is true.

Hints (3)
  • Edit the status and tools fields inside the RESULTS text. Keep valid JSON on each line.
  • Print which cases fail the tool check as well, so E04 is visible.
  • Count the denominators: completion is counted over 6 cases, not 8, because E06 and E07 expect a person.
Show a model answer

After the changes, status accuracy falls to 5 of 8 because E02 now has the wrong status in addition to the two earlier misses, which makes 3 misses and 5 passes. Tool selection falls to 7 of 8 because E04 expected search_help. Must-include stays at 3 of 4, because you changed only status and tools and left the replies alone. That is a useful reminder that no single metric sees everything. Completion falls to 4 of 6, since E02 and E08 gave up. The good reading lists E02, E04, E07 and E08 with their causes, notes that one case is worth 12.5 points, and says the set has no long conversations or angry customers.

Knowledge check

Choose an answer, then check it. Nothing is recorded — this is for you.

  1. 1.A report says "completion rate: 80%". What else must you know to trust it?
    Show the answer and explanation

    Answer: B. The denominator decides what 80% means: 4 of 5 is a very different claim from 80 of 100. Reply speed is a separate measure. Saying nothing more is needed is tempting, but a percentage alone hides the sample size.

  2. 2.Why are cases that expect needs_person left out of the completion rate?
    Show the answer and explanation

    Answer: B. In those cases the person is the right outcome. Counting them would punish good behaviour. They are not skipped because of difficulty, and they do have a status.

  3. 3.On a set of 10 cases, one more passing case moves a score by 10 points. What should you conclude?
    Show the answer and explanation

    Answer: B. The metric works as designed, but a small sample cannot separate real improvement from luck. A tempting but wrong reading treats the jump as a real-world gain.

Frequently asked questions

What is a good accuracy score for an AI agent?

There is no single good number. It depends on the risk of the task and on the size of your dataset. A refund agent needs far fewer serious mistakes than a trivia helper. Set a target before you look at results, and always check what the failures were.

How many test cases do I need to evaluate an AI agent?

Start with 20 to 30 well-chosen cases that cover normal, edge and risky inputs. Add a case every time you find a real failure. More cases make percentages steadier, but cases that match real risks matter more than raw numbers.

What is tool-selection accuracy?

It is the share of test cases where the agent called the tool you expected, or called no tool when none was expected. It shows whether the agent looks things up instead of guessing.

Can I use another AI model to grade my agent's answers?

Yes, this is called LLM-as-judge, but the judge can be wrong too. Compare its scores with human scores on a sample before you rely on it, and keep code checks for anything safety-related.

Written by
PromptFable Editorial
Last updated 18 Nov 2026
Review
Reviewed by Waseem Nadir, Technical Reviewer
Last reviewed 27 Nov 2026

References

Primary sources for the technical details in this lesson. Vendor platforms change — check the official page if anything here looks different from what you see.

PromptFable is independent and is not affiliated with, endorsed by or sponsored by Anthropic, Google, OpenAI or any other vendor. Claude, Gemini, Google AI Studio and other product names are trademarks of their respective owners.