> ## Documentation Index
> Fetch the complete documentation index at: https://notes.kodekloud.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Evaluating Your Agents

> Guide to testing conversational agents by validating response meaning and tool call trajectories, using eval sets, scoring methods, and sandboxed execution for model-generated code.

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.](https://mintcdn.com/kodekloud-c4ac6d9a/heceQKBf52UJgxP-/images/Google-ADK-20/Advanced-Tools/Evaluating-Your-Agents/same-question-different-answers-1042-refund.jpg?fit=max\&auto=format\&n=heceQKBf52UJgxP-\&q=85\&s=9f9d150426c87c6bf143174bc8d04983)

Why exact-string tests fail
A typical unit test asserts equality against a single canonical string. For agents, that’s brittle:

```python theme={null}
def test_refund_reply():
    reply = ask_agent("Why was I charged twice?")
    assert reply == "Order #1042 was billed twice. Refund sent: $49.00."
```

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.](https://mintcdn.com/kodekloud-c4ac6d9a/heceQKBf52UJgxP-/images/Google-ADK-20/Advanced-Tools/Evaluating-Your-Agents/two-runs-one-answer-invoice1042-kodekloud.jpg?fit=max\&auto=format\&n=heceQKBf52UJgxP-\&q=85\&s=5055e63fc9078ff8cd24246a583b8c4f)

Trajectory matching modes
You can choose how strictly ADK compares expected vs actual tool usage.

| Mode | Description |
| - | - |
| EXACT | Tool calls must match the expected list exactly — no missing calls and no extras. |
| IN\_ORDER | Expected calls must appear in the correct order, but other calls may appear in between. |
| ANY\_ORDER | Expected calls can appear in any order; only presence matters. |

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.](https://mintcdn.com/kodekloud-c4ac6d9a/heceQKBf52UJgxP-/images/Google-ADK-20/Advanced-Tools/Evaluating-Your-Agents/reference-vs-generated-llm-judge-rouge1.jpg?fit=max\&auto=format\&n=heceQKBf52UJgxP-\&q=85\&s=ff700f3363f77de86230ecd21f232e55)

Where tests live
You can store checks in two main places:

| Location | Purpose |
| - | - |
| Test files | Simple, fast checks for development (regression tests). |
| Eval sets | Collections of many test cases and multi-turn conversations; each case can include user messages, expected tool usage, intermediate responses, and a reference final response. |

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.

```json theme={null}
{
  "eval_set_id": "billing",
  "eval_cases": [
    {
      "eval_id": "charged_twice",
      "conversation": [
        {
          "user_content": "Why was I charged twice?",
          "intermediate_data": {
            "tool_uses": [{ "name": "lookup_invoice" }],
            "intermediate_responses": []
          },
          "final_response": "Refund sent: $49.00."
        },
        {
          "user_content": "When will I see it?",
          "final_response": "In 5 to 7 days."
        }
      ]
    }
  ]
}
```

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:

```bash theme={null}
$ <eval-command> support_agent support_agent/billing.evalset.json
```

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:

```json theme={null}
{
  "criteria": {
    "tool_trajectory_avg_score": 1.0,
    "response_match_score": 0.8
  }
}
```

Example using LLM-based final response match v2:

```json theme={null}
{
  "criteria": {
    "tool_trajectory_avg_score": 1.0,
    "final_response_match_v2": 0.8
  }
}
```

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).](https://mintcdn.com/kodekloud-c4ac6d9a/heceQKBf52UJgxP-/images/Google-ADK-20/Advanced-Tools/Evaluating-Your-Agents/generated-code-sandboxed-python-executor.jpg?fit=max\&auto=format\&n=heceQKBf52UJgxP-\&q=85\&s=8bace6c528ae768a4bca8bd7c1153b0b)

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

* ROUGE metric: [https://en.wikipedia.org/wiki/ROUGE\_(metric)](https://en.wikipedia.org/wiki/ROUGE_\(metric\))
* Python: [https://www.python.org/](https://www.python.org/)

> [card] [Watch Video](https://learn.kodekloud.com/user/courses/google-adk-2-0/module/73e63dcd-2829-46d7-bbaa-5ac2336079d7/lesson/c6ae57c6-c517-4b29-b018-84ad8c9e106c)


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.