Skip to main content
Okay — your support agent is finished. It routes customer questions to billing or shipping, calls tools, and even remembers previous turns. You open it, type a question, and the answer looks good. Feels done, right? Ah, feels done. And that’s the trap. Because the language model is probabilistic, asking the same question twice can produce two different but valid phrasings. That variability breaks normal software tests.
A diagram titled "Same Question, Different Answers" showing an email asking "Why was I charged twice?" routed through a language‑model icon and branching into two reply boxes that both explain a $49 refund for order #1042. The image illustrates different phrasings of the same answer.
Why exact-string tests fail A typical unit test asserts equality against a single canonical string. For agents, that’s brittle:
The agent might produce a perfectly correct reply that uses different wording. Relying on exact equality can make valid runs fail. What to check instead When testing agents you need two things:
  • The final answer (what was said).
  • The trajectory (how the agent arrived there — the sequence of tool calls and intermediate steps).
Example: a billing question. One run might route to billing, call lookup_invoice, retrieve the actual amount, and answer correctly. Another run might fabricate a number without calling any internal tools. If the fabricated number happens to be correct, the final answers will match but only the first run is trustworthy. Visibility into intermediate steps reveals whether the agent used trusted tools or guessed.
Always validate both the final response and the agent’s tool trajectory. The final string alone is not sufficient for reliable testing.
ADK separates trajectory evaluation from final-response evaluation. You declare the expected trajectory and ADK compares it to the actual run, with configurable strictness.
A dark-themed flowchart titled "Two Runs, One Answer" shows a billing question (envelope) branching into two workflow runs — the top run looks up invoice #1042 and returns an answer of $49.00 while the bottom run skips the lookup and fails. The KodeKloud logo is visible in the bottom-left corner.
Trajectory matching modes You can choose how strictly ADK compares expected vs actual tool usage. This lets you demand an exact trajectory when required, or allow more flexibility when the order or extra helper calls don’t matter. Scoring the final answer There are multiple ways to score the final response:
  • ROUGE-style overlap metrics measure word-level similarity. Useful when precise phrasing matters.
  • Final response match v2 uses an LLM as a judge to decide whether the generated response has the same meaning as the reference, even when wording differs (e.g., “your order shipped yesterday” vs “your package was dispatched yesterday”).
A dark-themed infographic diagram showing a test file that compares a reference sentence ("Your order shipped yesterday") and a generated sentence ("Your package was dispatched yesterday") fed into an LLM judge. Below are two metric boxes showing a ROUGE-1 score of 0.44 and an LLM-as-judge final match score of 1.0.
Where tests live You can store checks in two main places: Eval sets are the recommended format for running larger suites and for preserving multi-turn scenarios and intermediate expectations. Example eval set (JSON) Each eval case can include intermediate expectations and multi-turn conversation entries.
You don’t have to hand-author everything. Run the agent, capture a conversation that demonstrates correct behavior, edit it if needed, and save it to an eval set. That becomes your development loop: build → run → capture a good case → change agent → re-run evals. Running evals from the command line Run eval sets in CI/CD by invoking the evaluation command with your agent and the eval set:
This ensures the suite runs automatically whenever the agent changes instead of relying on manual click-through testing. Default configuration and thresholds Defaults provide sensible checks: a perfect trajectory match and a response-match threshold of 0.8. Change the thresholds or criteria as your project requires. Example using ROUGE-style response match:
Example using LLM-based final response match v2:
Executing model-generated code Sometimes an evaluation case contains model-generated code (for example, Python that computes a refund). That code must run somewhere — but never execute it inside your production application server. A malicious or buggy prompt could trigger dangerous behavior, unexpected side effects, or data exfiltration.
Run generated code in isolated environments only. Do not execute model-generated code inside your application server or other trusted infrastructure.
ADK provides a sandboxed code executor that runs Python (and other generated code) inside a separate, isolated environment. Even if generated code misbehaves, it cannot reach your application servers.
A diagram titled "Where Generated Code Runs" showing a language model fed a test file (billing.evalset.json) and a malicious prompt, which outputs code run inside a sandboxed Python executor. The sandbox prevents the generated code from reaching the application server (blocked).
Prove, don’t guess The core shift is from “Does it seem to work?” to “Prove that it works.” Use trajectory checks to verify how answers were produced and use robust final-response scoring (ROUGE or LLM-as-judge) to verify meaning. Store those checks in eval sets, run them in CI, and execute any model-generated code only in isolated sandboxes. Links and references

Watch Video