# Useful but Little-Known Features of ADK 2.0
🌍 What if you could grade your agent on custom criteria that go beyond standard metrics — like compliance, tone, or domain-specific accuracy?
ADK 2.0's custom evaluation metrics let you define your own evaluation logic as Python functions, measuring agent quality against any criteria you choose.
📌 Title: Custom Evaluation Metrics
🔗 URL:
🧩 Overview
Custom evaluation metrics are Python functions that return an `EvaluationResult`. Each function receives four parameters: `eval_metric` (the metric definition), `actual_invocations` (the agent's actual responses), `expected_invocations` (the expected responses), and `conversation_scenario` (the conversation context). Async functions are fully supported, enabling integration with external services.
🛠 How to use it
Create a custom metric function and register it in the eval config JSON.
```python
from google.adk.evaluation.eval_metrics import EvalStatus
from google.adk.evaluation.evaluator import EvaluationResult
async def response_length_metric(
eval_metric,
actual_invocations,
expected_invocations,
conversation_scenario
) -> EvaluationResult:
# Evaluate whether the response length is appropriate
last_response = "".join(
part.text for part in actual_invocations[-1].final_response.parts
)
score = 1.0 if len(last_response) < 500 else 0.5
return EvaluationResult(
overall_score=score,
overall_eval_status=(
EvalStatus.PASSED
if score >= eval_metric.criterion.threshold
else EvalStatus.FAILED
),
)
```
Register the metric in eval config JSON with a `criteria` threshold and a `custom_metrics` entry whose `code_config.name` is the function's import path.
```json
{
"criteria": {
"response_length": {"threshold": 0.8}
},
"custom_metrics": {
"response_length": {
"code_config": {"name": "my_metrics.response_length_metric"}
}
}
}
```
🏗 Building it into production
・Implement domain-specific quality criteria (accuracy, tone, compliance) as metrics
・Run custom metrics automatically in CI/CD pipelines and block deployments when quality drops below thresholds
・Use async metrics to integrate with external evaluation APIs or LLM-as-a-Judge patterns
・Combine multiple metrics to compute a comprehensive quality score for your agent
💡 Use cases
📏 Evaluate response conciseness and information density against custom standards
🏢 Automatically check compliance with industry regulations and requirements
🎯 Verify that specific tool call patterns match expected behavior
🗣 Score response tone and politeness automatically using LLM-as-a-Judge
⚠️ Watch out
Heavy processing inside custom metric functions can slow down the entire evaluation run. Use async functions and set timeouts as needed. Also, the `code_config` module path must be importable from the evaluation execution environment.
✨ Custom evaluation metrics let you systematically enforce quality standards that go beyond what built-in metrics can cover. Build evaluations tailored to your specific use case.
#
ADK# #
AIAgent#