Skip to content

Commit fdebd9d

Browse files
haranrkcopybara-github
authored andcommitted
feat: Add basic_criteria ADK eval sample
Add contributing/samples/evaluation/basic_criteria/, demonstrating the deterministic built-in metrics tool_trajectory_avg_score and response_match_score against the shared home-automation agent, run via `adk eval`. Co-authored-by: Haran Rajkumar <haranrk@google.com> PiperOrigin-RevId: 952586163
1 parent 6ba41ef commit fdebd9d

4 files changed

Lines changed: 152 additions & 2 deletions

File tree

contributing/samples/evaluation/README.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,9 @@ answer.
3737

3838
## Samples
3939

40-
| Sample | Concept | Criteria |
41-
| ------ | ------- | -------- |
40+
| Sample | Concept | Criteria |
41+
| ------------------------------------- | -------------------------------------- | --------------------------------------------------- |
42+
| [`basic_criteria`](./basic_criteria/) | Deterministic, reference-based scoring | `tool_trajectory_avg_score`, `response_match_score` |
4243

4344
## Graph
4445

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
# Basic evaluation criteria
2+
3+
## Overview
4+
5+
Evaluates the shared home-automation agent with the two deterministic,
6+
reference-based criteria:
7+
8+
- `tool_trajectory_avg_score`: does the agent call the right tools with the
9+
right args? Each expected tool call (name + args) is compared against what the
10+
agent actually did.
11+
- `response_match_score`: ROUGE-1 word overlap between the agent's final
12+
response and a reference answer.
13+
14+
Both criteria are computed locally with no judge model, so this sample needs only
15+
a model credential for the agent's own inference (a Gemini API key or Vertex).
16+
17+
## Sample Inputs
18+
19+
The eval set (`home_automation.evalset.json`) contains two single-turn cases:
20+
21+
- `Turn off device_2.`
22+
- `What is the temperature in the Living Room?`
23+
24+
## How To
25+
26+
Run the sample from the workspace root:
27+
28+
```bash
29+
adk eval contributing/samples/evaluation/home_automation_agent \
30+
contributing/samples/evaluation/basic_criteria/home_automation.evalset.json \
31+
--config_file_path contributing/samples/evaluation/basic_criteria/eval_config.json \
32+
--print_detailed_results
33+
```
34+
35+
`adk eval` takes the agent folder and the eval-set file as two separate
36+
arguments, so this folder holds only eval data (`home_automation.evalset.json`),
37+
the criteria config (`eval_config.json`), and this README, with no agent code.
38+
39+
### `match_type` for tool trajectory
40+
41+
`tool_trajectory_avg_score` has a `match_type` (set to `EXACT` here in
42+
`eval_config.json`) that controls how the expected and actual tool calls are
43+
compared:
44+
45+
- `EXACT`: the actual tool calls must match the expected calls one-for-one, in
46+
the same order, with identical args. Use this when the trajectory is fully
47+
deterministic (as in this sample).
48+
- `IN_ORDER`: the expected calls must appear in the given order, but extra
49+
actual calls in between are tolerated. Useful when the agent may take
50+
additional, harmless steps.
51+
- `ANY_ORDER`: the expected calls must all appear, but order does not matter.
52+
Useful when the agent may reorder independent tool calls.
53+
54+
The `threshold` is `1.0`, so every expected call must match for the case to pass.
55+
56+
### Why `response_match_score` uses a `0.6` threshold
57+
58+
`adk eval` runs live inference, so the exact wording of the agent's final
59+
response varies from run to run (for example, "I have turned off device_2." vs
60+
"device_2 has been switched off."). `response_match_score` is a ROUGE-1 score,
61+
which measures word overlap rather than exact-string equality, so it tolerates
62+
this phrasing variation. The `0.6` threshold requires the response to share most
63+
of its wording with the reference while still allowing some rewording. Raise it
64+
toward `1.0` for stricter wording, lower it to tolerate more paraphrasing.
65+
66+
### Expectations captured from a real run
67+
68+
The expected `tool_uses` (tool names and args) in `home_automation.evalset.json`
69+
were captured from an actual `adk eval` run of the agent: run with
70+
`--print_detailed_results`, read the printed Actual-vs-Expected, then set the
71+
expected values to match what the agent really produced. The reference
72+
`final_response` for each case is an independently written natural answer (not a
73+
copy of the model output), which is exactly what ROUGE-1 is designed to tolerate.
74+
75+
## Related Guides
76+
77+
- Evaluation overview: https://adk.dev/evaluate/
78+
- Evaluation criteria reference: https://adk.dev/evaluate/criteria/
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"criteria": {
3+
"tool_trajectory_avg_score": {
4+
"threshold": 1.0,
5+
"match_type": "EXACT"
6+
},
7+
"response_match_score": 0.6
8+
}
9+
}
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
{
2+
"eval_set_id": "basic_criteria",
3+
"name": "Basic deterministic criteria",
4+
"description": "Single-turn cases scored by tool trajectory and ROUGE-1.",
5+
"eval_cases": [
6+
{
7+
"eval_id": "turn_off_bedroom_device",
8+
"conversation": [
9+
{
10+
"invocation_id": "basic-1",
11+
"user_content": {
12+
"parts": [{"text": "Turn off device_2."}],
13+
"role": "user"
14+
},
15+
"final_response": {
16+
"parts": [{"text": "device_2 is now turned off."}],
17+
"role": "model"
18+
},
19+
"intermediate_data": {
20+
"tool_uses": [
21+
{"name": "set_device_info",
22+
"args": {"device_id": "device_2", "status": "OFF"}}
23+
],
24+
"intermediate_responses": []
25+
}
26+
}
27+
],
28+
"session_input": {
29+
"app_name": "home_automation_agent",
30+
"user_id": "user",
31+
"state": {}
32+
}
33+
},
34+
{
35+
"eval_id": "get_living_room_temperature",
36+
"conversation": [
37+
{
38+
"invocation_id": "basic-2",
39+
"user_content": {
40+
"parts": [{"text": "What is the temperature in the Living Room?"}],
41+
"role": "user"
42+
},
43+
"final_response": {
44+
"parts": [{"text": "The Living Room is 22 degrees Celsius."}],
45+
"role": "model"
46+
},
47+
"intermediate_data": {
48+
"tool_uses": [
49+
{"name": "get_temperature", "args": {"location": "Living Room"}}
50+
],
51+
"intermediate_responses": []
52+
}
53+
}
54+
],
55+
"session_input": {
56+
"app_name": "home_automation_agent",
57+
"user_id": "user",
58+
"state": {}
59+
}
60+
}
61+
]
62+
}

0 commit comments

Comments
 (0)