Evaluating AI Agents: Metrics and Methods
Briefly
Evaluating AI agents requires a combination of quality, reliability, and cost metrics; this article covers approaches from unit tests to LLM-as-a-judge.
Why Evaluate Agents
Agents perform multi-step actions, so an error at one step can lead to a cascading failure. Evaluation allows:
- identifying regressions when prompts or models change;
- comparing agent configurations;
- controlling cost and delays.
Metrics
Result Quality
- Accuracy — the proportion of successfully completed tasks.
- Completeness — the proportion of subtasks completed without omissions.
- Alignment — how well the result meets the requirements.
Reliability
- Robustness — the ability to handle non-standard inputs.
- Reproducibility — stability of results under the same conditions.
- Execution Time — average duration of a cycle.
Cost
- Number of Tokens per task.
- Number of API Calls.
- Latency.
Evaluation Methods
Unit Tests
Testing individual agent functions: response parsing, tool invocation, error handling.
def test_parse_tool_call():
response = agent.parse("Call tool: get_weather")
assert response.tool == "get_weather"
Scenario Testing
Running the agent on a set of typical scenarios with key step verification.
LLM-as-a-Judge
Using LLM to evaluate agent responses based on criteria. Example prompt:
Evaluate the agent's response on a scale of 1-5 based on criteria: completeness, correctness, absence of hallucinations.
Tracing and Logs
Tools Langfuse and LangSmith allow trajectory analysis and bottleneck identification.
Metrics Table
| Metric | Description | Tool |
|---|---|---|
| Success Rate | Proportion of successful tasks | Custom script |
| Tool Call Accuracy | Accuracy of tool calls | Unit tests |
| Cost per Task | Cost of one task | API logs |
| Latency | Response time | Monitoring |
Recommendations
- Create a set of golden scenarios.
- Use eval harness for automation.
- Combine quantitative metrics with qualitative analysis.
Agent evaluation is an iterative process that needs to be integrated into CI/CD to prevent quality degradation.