Skip to content
If Agent tests only assert the final answer, they will let half the errors slip through

Agent tests that only assert the final answer will let half the errors slip through

Doing pre-launch acceptance for an after-sales Agent: 200 test cases run, pass rate 86%, and the meeting’s conclusion is “we can ship.” Two weeks after launch, complaints cluster around the same type of scenario: it tells users “I’ve already submitted your refund request for you,” but no refund order was actually created.

Digging through the trace makes it clear. At step 3 the model did indeed decide to issue a refund, but the tool call was missing one required field, and the API returned 400. The Agent swallowed this error into its context and added to its reply, “Submitted, expected to arrive in 1 to 3 business days.” The acceptance case’s assertion was that the reply text contains “refund.” It does.

This case is green in the report. Green with good reason, because that is exactly what the assertion says.

End-to-end pass rate compresses three different kinds of error into one number

The case above belongs to the first category, which I call “wrong but right”: the process was wrong, but the result happened to be right, or was judged right.

A typical form is two orders under the same username, the tool call did fuzzy matching, grabbed the wrong order, and the amount happened to be the same. The final answer’s amount, wording, and format are all correct, and every assertion passes. End-to-end testing cannot tell how much of the pass rate such samples account for, because end-to-end only sees one projection.

The second category is “right, but at high cost.” The Agent misunderstood the user’s constraint in round 2 and only corrected it by asking again in round 4. The answer is correct, the user waited two extra rounds, and nearly twice as many tokens were spent. The success-rate curve looks beautiful; the p95 latency and cost curves are in another report.

The third category is the most hidden: “answered correctly, but something happened.” To confirm order status, the Agent first called cancel and then called restore, and the final state is correct. But two notification SMS messages have already gone out, one to the user and one to the warehouse. The black-box assertion checks the final state; the side effects are outside the assertion.

Looking at these three categories together, the end-to-end pass rate is really a projection function: it compresses a complete trajectory into a boolean, discarding every branch, retry, tool call, and external write in between. The harder the compression, the better the report looks, and the worse the explainability.

There is another layer of problem in where the cases come from. Acceptance cases are mostly sampled from tickets that ran successfully in production, so they are naturally biased toward paths that already worked. Of the 200, fewer than 20 may actually trigger fuzzy matching, retries, or side effects; the most expensive failure modes were filtered out at sampling time.

In a single Agent run, the final answer is not the only place where an observable result can be left behind.

flowchart LR
    R[用户请求] --> S1[取数与检索]
    S1 --> S2[判断与规划]
    S2 --> S3[工具调用]
    S3 --> A[最终答案]
    S3 --> X[外部副作用]
    S3 --> C[耗时与成本]

Black-box assertions cover only the rightmost A. X and C are not in the assertions, and neither are S1 through S3. They are not unimportant; they just were not written into the acceptance criteria.

Errors do not disappear; they just get booked under a different account

On error accumulation in multi-step Agents, there is an arithmetic that gets cited far too many times: single-step accuracy 0.97, ten steps chained together gives 0.74.

The arithmetic itself is not wrong, but it is often used in the wrong direction. In real systems, the end-to-end pass rate is often higher than 0.74, because there are retries, reflection, and fallback wording. So some people conclude “my Agent is stronger than the theoretical value.”

The gap has not disappeared; it has been booked under a different account. The deviation’s destinations in the trajectory are roughly three.

flowchart TD
    E[某一步出现偏差] --> Q{下游能发现吗}
    Q -->|能且愿意修| F[修复 成本上涨]
    Q -->|不能| G[偏差进入上下文]
    G --> H{后续怎么处理}
    H -->|围绕它自洽| I[答案通顺但错]
    H -->|与别处抵消| J[答案对 方差大]

For the repair branch, the cost is booked in rounds, tokens, and latency. For the offset branch, the cost is booked in variance: the average pass rate shows no fluctuation, and the same case run three times may be right, wrong, right. The most dangerous is the self-consistency branch.

Errors in the context are not deleted, only explained. When a tool returns 400, the model does not treat it as “I was wrong”; it treats it as “the API has a problem,” and then continues on that premise: retry with different parameters, switch tools, or simply describe an ideal result in the reply. Every subsequent step serves a false premise, and the final text reads especially smoothly, because all of the model’s attention has gone into making the story coherent.

I have seen a type of team treat such output as “the model’s capability improved,” because failure cases decreased and the remaining cases all look professional. In reality, the failure has migrated from “answering wrong” to “answering as if right,” and the latter is harder for users and operations to notice.

An operational criterion: if a batch of failure samples reads almost indistinguishable from success samples, the problem is not the model, it is observability.

Assertions should be made where things are irreversible

Knowing that white-box testing is needed, the next question is how much to record. Recording all intermediate states in full will collapse under storage and labeling costs first, and it is noisy, so nobody looks at it.

I tend to select assertion points by three criteria; if any one holds, assert:

  • After this call, has the external world changed (database write, message sent, charge made, order created)
  • If this judgment is wrong, can it still be corrected later
  • If this field is wrong, is the final answer necessarily wrong

The first corresponds to side effects, the second to irreversible decision forks, and the third to key fields on the data-passing chain. For steps where none of the three holds, such as an intermediate rewrite or a summary, no matter how high the error probability, it is not worth a separate assertion; let end-to-end cover it.

Applied to test cases, a test usually looks like this:

YAML16 lines
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
case: 退款超过免审额度,必须转人工
input: "帮我把这单退了"
assert:
final:
refund_amount: 0
reply_contains: ["人工", "复核"]
steps:
- tool: query_order
args.order_id: "O-1024"
- tool: check_policy
expect.need_manual_review: true
side_effects:
forbidden: [issue_refund, send_sms]
budget:
max_turns: 4
max_tokens: 6000

What is asserted here is the tool name plus key parameters, not the full parameter list, and not the call order. Order assertions easily hard-code an implementation detail; if the model switches to a reasonable different call order, the test goes red, and the maintenance cost outweighs the benefit.

There is more to save on cost: structured events (tool name, parameter hash, return code, latency, round) are recorded in full by default, since they are small and aggregatable; raw tool returns and model reasoning are sampled proportionally, and forcibly retained only on failed cases. Disputes are usually about the raw text, but attribution mostly needs only the events.

Beyond the pass rate, you also need to see which end of the distribution

The same 86% can mean very different things.

One approach is to change “pass once” to “pass all k times.” With the same 86% single-run pass rate, the all-three-pass rate may be 78%, or it may be 51%. The latter means the model wavers between “can” and “cannot,” gambling every time. After such an Agent ships, what users feel is occasional inexplicable failure, not 86% usefulness.

I currently look at these together:

  • Step-by-step accuracy at key decision points, and its gap from end-to-end
  • Invalid call rate and rollback rate, i.e., the proportion of calls made and then withdrawn
  • p50 and p95 of rounds and tokens, not just the mean
  • Clustering of failure modes, not just the number of failures

The last one is especially important. If the number of failures drops from 40 to 25 and it is the same type of problem being fixed, that is real progress; if it is just making hard cases easier, or splitting multi-turn tasks into single-turn Q&A, the pass rate rises and the capability boundary shrinks. This kind of “optimization” is completely invisible in the report.

Another situation is more common: the pass-rate improvement comes from fallback wording. When the Agent judges it is uncertain, it switches to “I’ll transfer you to a human,” the human catches it, and end-to-end counts as a pass. This behavior itself is not wrong, but if the human-transfer rate rises from single digits to 30%, the meaning of the pass rate has already changed. The human-transfer rate must be tracked as a separate metric and not mixed into the success rate.

The evaluation set itself also rots. The cases were sampled from production tickets at the time; the model changed, the tools changed, user behavior changed, and the cases are still where they were. Half a year later the pass rate on the same set may have risen, but that is because what it tests no longer represents production. My approach is that whenever the model or toolchain has a major change, first run step-by-step accuracy, see which layer’s distribution has shifted, and then decide which new cases to add.

When black-box testing is actually sufficient

Writing this far can easily lead to extremes, as if every Agent must have a full white-box setup. No.

The conditions under which black-box testing suffices are fairly clear: single-step, idempotent, no side effects, and the answer can be judged cheaply by a machine. Classification, extraction, rewriting, and single-turn Q&A basically all fit. In these scenarios the intermediate process is invisible to users and does not affect subsequent state, so putting assertions on the output gives the best value for effort.

The scenarios that require white-box testing are also clear: multi-turn state, write operations, answers that need human judgment (contract clauses, diagnostic recommendations, trade-off decisions), and hard cost constraints. In these cases, even if the final answer is correct, it may still be an incident.

Most products fall in between. My default approach is to use black-box testing as a gate and white-box testing for attribution: regression tests run end to end and catch obvious regressions; once they go red or a metric is abnormal, drill down to the step level to see which segment went wrong. Doing it the other way around—building a fine-grained set of step assertions first—often leads to collective failure when the model changes versions, and the maintainers quickly get tired.

The next time you write acceptance test cases for an Agent, you can first add a note to each case: if this case passes, can I explain clearly how it passed? If you can’t explain it clearly, it shouldn’t be tested only as a black box.

About this Post

This post is written by Lu's Blog, licensed under CC BY-NC 4.0.

#Agent Testing #Evaluation #Observability

Comments