Module 08 · Lesson 8.4
Measuring Accuracy, Task Completion and Tool Selection
On this page
- What you will learn
- What to measure: from one run to a score
- Four core metrics for an AI agent
- Compute the metrics with a short Python script
- Small samples: why one case moves the number
- Reading metrics honestly
- Conclusion and your next step
- Common errors and fixes
- Validation checklist
- Hands-on exercise
- Knowledge check
- Frequently asked questions
- 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
- Evaluation Datasets, Rubrics and Expected Behaviours, where the case format comes from.
- Most of this lesson needs no coding. You should be able to read a short Python script.
- Optional: Python 3.10 or later, if you want to run the example yourself.
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.
- Eval cases
What should happen
- Run the agent
One result line per case
- Score
Compare result with expectation
- Count
Passed out of total
- 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.
{"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?
| Metric | Counted over | Counts as a pass when | A low score often means |
|---|---|---|---|
| Status accuracy | All cases | Result status equals expect_status | Wrong outcome, such as a needless handover |
| Tool selection | All cases | Expected tool was called (or no tool, if none expected) | Weak tool descriptions or instructions |
| Must-include rate | Cases with must_include | Every required word is in the reply | Missing facts, or wording that dodges the point |
| Completion rate | Cases not expecting a person | Status is not needs_person | The agent gives up too easily |
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.
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
CASESandRESULTSare strings with one JSON object per line.splitlines()turns each into a list of lines, andjson.loadsturns a line into a dictionary.casesis a dictionary keyed by case id, so each result can find its expectation quickly.tallyholds a pair for each metric:[passed, total]. Python treatsTrueas 1 andFalseas 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
MISSline prints each case whose status was wrong, so you can read the failures next to the totals.
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 pointsNotice 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 set | Value of one case | What a jump of one case looks like |
|---|---|---|
| 8 | 12.5 points | 75% becomes about 87% |
| 25 | 4 points | 72% becomes 76% |
| 100 | 1 point | 72% becomes 73% |
- 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.
Step 1: Write the counts first
Record passed out of total for every metric. Add the dataset version and the agent version.
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.
Step 3: Sort failures by risk
A wrong refund promise matters more than a clumsy sentence. Mark the serious ones first.
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.
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.
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.
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.
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.
- Demystifying evals for AI agents(opens in a new tab)
Anthropic · Official documentation · Background on how evaluations for agents are designed and read.
- Create strong empirical evaluations(opens in a new tab)
Anthropic · Official documentation · Guidance on building test cases and choosing how to grade them.
- Building effective agents(opens in a new tab)
Anthropic · Official documentation
- json: JSON encoder and decoder(opens in a new tab)
Python Software Foundation · Official documentation · Reference for json.loads, used in the example.
- AI Risk Management Framework(opens in a new tab)
NIST · Official documentation · General background on measuring and managing AI system risk.
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.