Practical technical guides / AI engineering: evaluation

Grade Agent Runs by the End State They Leave, Not by One Reference Tool Sequence

Seven synthetic runs of one refund task: exact sequence matching fails valid runs, in-order matching passes a double refund, and an end-state check catches every bad run.

By Sandeep Belgavi · Published 2026-11-06

Seven synthetic runs of one refund task: exact sequence matching fails valid runs, in-order matching passes a double refund, and an end-state check catches every bad run.

Two graders, two different answers

The refund agent at Belgavi's Book Store has an evaluation case for a simple request: Jenya returned two paperbacks under order BK-2291 and wants the 24.49 refund. The reference solution calls four tools in order: lookup_order, check_return_received, issue_refund(amount=24.49) and send_email(template=refund_done). For months the team graded runs by comparing the agent's tool calls with that reference.

Then two things happened in the same week. A prompt change made the agent check the return before looking up the order, and the evaluation reported a regression, although the outcome was identical. And a production incident refunded one customer twice, while the matching evaluation case had passed. Both were grading problems, not agent problems.

This guide compares tool-sequence matching with grading by end state on seven synthetic runs, and shows where each one belongs.

What sequence matching checks

The ADK evaluation documentation describes tool_trajectory_avg_score as a criterion that "compares the sequence of tools called by the agent against a list of expected calls" using one of three match types:

  • EXACT: the same calls, with the same arguments, in the same order, and nothing else.
  • IN_ORDER: the expected calls appear in order, and other calls may sit between them.
  • ANY_ORDER: the expected calls all appear, in any order, with others allowed.

The docs recommend each for a purpose. EXACT is for enforcing a specific path, IN_ORDER for key calls that must happen in sequence while "leaving some scope for other tools calls to happen as well", and ANY_ORDER for key calls whose order does not matter. These are useful regression signals. They are not, on their own, a statement that the task was done correctly.

What end-state grading checks

τ-bench, the 2024 benchmark from Yao and colleagues, grades differently: it "compares the database state at the end of a conversation with the annotated goal state". The agent may take any path. What is checked is the world it leaves behind.

For the refund case the end-state grader is short and specific:

def end_state(store):
    problems = []
    if [r['amount'] for r in store.refunds] != ['24.49']:
        problems.append(f"refunds {[r['amount'] for r in store.refunds]} instead of ['24.49']")
    if store.orders['BK-2291']['status'] != 'refunded':
        problems.append('order not marked refunded')
    if store.emails != [{'case': 'CASE-4107', 'template': 'refund_done'}]:
        problems.append(f'{len(store.emails)} confirmation emails')
    # Ordering is a requirement here, so it is checked on the effect itself.
    if any(not r['return_seen'] for r in store.refunds):
        problems.append('refund issued before the return was confirmed')
    return problems

It checks the intended effects (one refund of 24.49, the order status, one email), the effects that must not happen (a second refund, a second email) and one ordering rule that is a genuine business requirement: a refund may only be issued after the return has been scanned. That last check reads a flag recorded on the refund at the moment it was issued, not the tool sequence.

Seven runs, four grades

The companion example replays seven synthetic runs against a fake store and grades each one four ways. The three match types are my own implementation of the semantics the ADK documentation describes, not ADK code.

RunEXACTIN_ORDERANY_ORDEREnd state
R1 same as referencepasspasspasspass
R2 checks the return firstfailfailpasspass
R3 refunds twicefailpasspassfail
R4 emails without refundingfailfailfailfail
R5 uses search_orders instead of lookup_orderfailfailfailpass
R6 refunds the wrong amountfailfailfailfail
R7 refunds before the return arrivesfailfailpassfail

Read it by the disagreements. EXACT never passed a bad run here, but it failed two good ones, R2 and R5, which is exactly the false regression the team saw after the prompt change. IN_ORDER passed R3, the double refund, because extra calls are allowed between expected ones. ANY_ORDER passed both R3 and R7, the refund issued before the return was confirmed. The end-state grader failed all four bad runs and passed all three good ones.

No grader is free. The end-state grader needed someone to write down the intended effects and the forbidden ones, and it is only as good as that list. Its advantage is that the list is about the business, which changes slowly, rather than about a tool path, which changes every time the prompt or the tool set changes.

Building end-state graders without a rewrite

The practical obstacle is that most agent tools talk to real services. You need a store you can inspect after the run.

  1. Put the agent's tools behind fakes that record state, the same fakes your contract tests use. The example's FakeStore holds orders, return scans, refunds and sent emails.
  2. For each evaluation case, write the goal state as data: expected records, forbidden records and invariants. Keep it next to the case, reviewed like code.
  3. Run the agent, then diff the store against the goal. Report each problem in words, as the example does, so a failing case explains itself.
  4. Keep trajectory checks only where order is itself the requirement, and prefer to express those as invariants on effects (refund after scan), which survive refactors of the tool set.
  5. Add one adversarial case per forbidden effect. The double refund should exist as a case before it exists as an incident.

When sequence matching is the right tool

Some requirements really are about the path. A compliance rule that an identity check must be called before any account data is read is a sequence requirement, and IN_ORDER on those two calls expresses it directly. Cost budgets are another: if a task must not call an expensive search tool more than once, count the calls. And EXACT is a fine smoke test for a deterministic workflow where the agent has no real choice, as long as everyone knows that a failure may mean the path changed, not that the outcome is wrong.

The mistake is using a sequence match as the pass criterion for tasks whose correctness is defined by outcomes. Combine them deliberately: an end-state grade decides pass or fail, and trajectory metrics are reported alongside as diagnostics and cost signals.

Tasks that change nothing

Not every case writes to the store. When Tanishka asks where the refund for order BK-2291 is, the right outcome is an accurate answer and no side effects. End-state grading still applies, in two parts. The forbidden-effects half is unchanged: the store must be identical before and after, which catches an agent that "helpfully" re-issues the refund. The answer half becomes a check against the same store: the amount, date and order number in the reply must match the records, extracted with a small parser or a constrained judge prompt that sees both the reply and the record.

What should not happen is grading the answer against a reference sentence. A correct reply phrased differently fails a string match, and a fluent reply with the wrong amount can pass a loose similarity score. The facts to check live in the store; grade against them.

Failure modes of end-state grading

  • Goal states that are too loose. "A refund exists" passes the double refund. Assert exact counts and amounts.
  • Forgetting side channels. Emails, notifications and audit entries are effects too. If the fake does not record them, the grader cannot see them.
  • Invariants checked on the sequence instead of the effect. Record the facts at the time of the effect (return_seen on the refund record) so the check does not depend on tool names.
  • Shared mutable fixtures. Reset the store for each run, or one case's refund leaks into the next case's grade.
  • Graders that are never tested. Feed each grader at least one known-bad run, as the table above does, and make sure it fails.

Verification

The companion example has six offline tests: the reference run passes all four graders; EXACT fails exactly R2 and R5; IN_ORDER false-passes exactly R3; ANY_ORDER false-passes R7 and the end-state grader reports why; and the three matchers behave as described on small hand-written cases. Nothing here calls a model. The runs are scripted to isolate grading behaviour; with a real agent you would add repeated trials per case, because the same prompt does not always produce the same path.

Primary references and authorship

Original explanation and synthetic examples by Sandeep Belgavi. Companion code: Sandeep-BA/agent-decision-lab/examples/python/end_state_grading. Views are my own and do not represent any employer, past or present.