Skip to content

Agent Evaluation

Agent evaluation is the process of measuring whether an AI agent completes a task correctly, follows the expected process, uses tools properly, and behaves reliably across different situations.

How do we know that our agent is actually working well?

This is one of the most important parts of building production AI systems. An agent can produce a convincing answer and still fail at its task. It can call the wrong tool, pass incorrect arguments, skip a required step, or report success when an operation failed.

We need ways to detect these failures before and after deployment.

Imagine you build an AI research agent.

A user asks:

Compare LangGraph and CrewAI. Research their key features and write a Markdown report.

Your agent performs these steps:

  1. Understands the request.
  2. Creates a plan.
  3. Calls a research tool.
  4. Collects information.
  5. Calls a report-writing tool.
  6. Returns the report location.

The agent responds:

I have completed the comparison. The report is saved at output/comparison.md.

The response sounds correct. But several things could have gone wrong:

  • It researched the wrong frameworks.
  • It called the research tool with incomplete arguments.
  • It skipped the research step.
  • It wrote an empty report.
  • It saved the report to a different location.
  • It claimed success even though the file was never created.

Checking only the final response will not reveal all these failures.

This is the central challenge of agent evaluation:

We must evaluate both the result and the process used to produce it.

An LLM evaluation usually measures the quality of a model’s response to an input.

Input:
What is the capital of France?
Expected:
Paris
Actual:
Paris

We can compare the actual response with the expected answer.

But an agent performs multiple actions before producing its final response.

User request
|
v
Agent
|
+----> Select tool
|
+----> Generate arguments
|
+----> Execute tool
|
+----> Read tool result
|
+----> Decide next action
|
v
Final response

Each step introduces a possible failure.

LLM evaluation Agent evaluation
Response quality Task completion
Factual correctness Correct tool selection
Relevance Correct tool arguments
Instruction following Correct execution sequence
Response format Appropriate handling of failures
— Correct use of state and memory

Agent evaluation includes LLM evaluation, but it goes further.

A useful way to think about it:

  • LLM evaluation: Did the model produce a good response?
  • Agent evaluation: Did the system complete the task correctly?

1. Task completion

Did the agent achieve the user’s intended goal?

2. Tool selection and arguments

Did it select the correct tool and provide valid arguments?

3. Execution trajectory

Did it follow a valid sequence of steps?

4. Response quality

Was the final response correct, relevant, complete, and useful?

5. Reliability and efficiency

Did it avoid unnecessary calls, excessive retries, and excessive cost or latency?

These areas are related, but they are not interchangeable.

For example, an agent can complete a task while making unnecessary tool calls. It can also follow the correct sequence but produce an incorrect final answer.

We should measure these dimensions separately.

Tool calling is a critical part of an agent’s behavior.

def search_web(query: str):
...
def read_file(path: str):
...
def write_file(path: str, content: str):
...

The user asks:

Read notes.md and create a summary in summary.md.

The expected behavior is:

  1. Call read_file with path="notes.md".
  2. Understand the file contents.
  3. Call write_file with path="summary.md" and the generated summary.

We can evaluate two separate things.

Did the agent select the correct tool?

Expected tool Actual tool Result
read_file read_file Correct
write_file search_web Incorrect

A simple metric is tool selection accuracy:

Formula: Tool selection accuracy equals correct tool selections divided by total tool selections.

Even when the agent selects the correct tool, it can pass incorrect arguments.

Formula: Argument accuracy equals correct argument sets divided by total argument sets.

In practice, argument evaluation can use:

  • Exact matching for fixed values.
  • Schema validation for required fields and types.
  • Semantic comparison for natural-language arguments.
  • Custom rules for business constraints.

For example, if the user asks for a report about two frameworks, a test can check whether both framework names are present in the research tool arguments.

Important: Do not evaluate tool calls only by checking whether they are valid JSON. Valid arguments can still be semantically wrong.

This measures whether the agent achieved the user’s actual goal.

Consider this task:

Create a report comparing LangGraph and CrewAI and save it as output/comparison.md.

A weak evaluation check:

assert response is not None

This proves almost nothing.

A better evaluation checks the actual result:

from pathlib import Path
report = Path("output/comparison.md")
assert report.exists()
assert report.stat().st_size > 100

But even this is not enough. A file can exist and contain incorrect information.

We can add content checks:

content = report.read_text()
assert "LangGraph" in content
assert "CrewAI" in content
assert "Comparison" in content

This gives us multiple levels of verification:

  1. Did the agent return a response?
  2. Did the expected artifact get created?
  3. Does the artifact contain the required content?
  4. Is the content factually correct and useful?

The last check may require a human evaluator, an LLM judge, or a trusted reference.

Before evaluating an agent, define what success means.

test_case = {
"task": "Compare LangGraph and CrewAI",
"expected_file": "output/comparison.md",
"required_sections": [
"Overview",
"Features",
"Comparison",
"Conclusion"
]
}

This is important because an evaluator cannot reliably measure success if the expected outcome is unclear.

A trajectory is the sequence of actions and observations produced during an agent’s execution.

User request
|
v
Agent
|
+--> research_frameworks(["LangGraph", "CrewAI"])
|
+--> Observation: Research completed
|
+--> write_report(research)
|
+--> Observation: File created
|
v
Final response

Trajectory evaluation helps us detect:

  • Missing required steps.
  • Incorrect tool order.
  • Repeated tool calls.
  • Unnecessary actions.
  • Infinite loops.
  • Incorrect decisions after tool results.
  • Failure to recover from errors.

There may be several valid ways to complete the same task.

For example, an agent may research two frameworks in parallel or one after another. Both can be correct.

Therefore, we should distinguish:

  • Exact trajectory matching: Compare the agent’s actions with a predefined sequence.
  • Rule-based trajectory evaluation: Check whether required actions and constraints were satisfied.
  • Semantic trajectory evaluation: Use a judge to assess whether the actions made sense in context.

Exact matching is useful for deterministic workflows. Rule-based and semantic evaluation are more useful for flexible agents.

Many agent outputs do not have one exact correct answer.

Suppose an agent writes a report comparing two frameworks. There may be several valid ways to structure the report.

A simple string comparison will not work.

This is where LLM-as-a-Judge becomes useful.

An LLM judge evaluates an output against defined criteria.

You are evaluating an AI research agent.
User task:
Compare LangGraph and CrewAI.
Agent output:
[Generated report]
Evaluate the output on:
1. Accuracy
2. Completeness
3. Relevance
4. Clarity
Return:
- A score from 1 to 5 for each criterion.
- A short explanation for each score.
- An overall pass or fail.

The judge produces a structured evaluation.

{
"accuracy": 4,
"completeness": 3,
"relevance": 5,
"clarity": 4,
"passed": false,
"reason": "The report does not cover deployment considerations."
}

A good evaluation process has four parts:

  1. Define evaluation criteria.
  2. Provide the task and agent output.
  3. Ask the judge to score each criterion.
  4. Validate the judge’s output and apply pass/fail rules.
passed = (
result["accuracy"] >= 4
and result["completeness"] >= 4
and result["relevance"] >= 3
)

An LLM judge is not ground truth.

It can:

  • Reward confident but incorrect answers.
  • Miss subtle factual errors.
  • Prefer longer answers.
  • Give inconsistent scores.
  • Be influenced by how the output is presented.

Ways to improve it:

  • Use clear scoring rubrics.
  • Give it the original task and relevant reference material.
  • Ask for evidence supporting each score.
  • Test judge consistency on known examples.
  • Use deterministic checks for facts that can be verified automatically.
  • Use human review for important decisions.

You cannot evaluate an agent properly with only one or two prompts.

You need a collection of test cases that represent the tasks the agent is expected to handle.

This collection is called an evaluation dataset or eval dataset.

eval_cases = [
{
"id": "case_001",
"input": "Compare LangGraph and CrewAI",
"expected_frameworks": ["LangGraph", "CrewAI"],
"expected_file": "output/comparison.md"
},
{
"id": "case_002",
"input": "Research AutoGen and write a report",
"expected_frameworks": ["AutoGen"],
"expected_file": "output/autogen.md"
}
]

Each test case should define:

  • Input: What the user asks.
  • Expected behavior: What the agent should do.
  • Expected outcome: What successful completion looks like.
  • Evaluation rules: How we will check the result.

What types of test cases should we include?

Section titled “What types of test cases should we include?”

A good dataset should cover more than normal requests.

Test type Example
Happy path Valid request with all required information
Missing information User does not specify a framework
Ambiguous request “Compare the popular agent frameworks”
Invalid input Unsupported framework name
Tool failure Research API returns an error
Empty result Research tool returns no data
Large task User requests 20 frameworks
Repeated request User asks for the same report twice

Why include failure cases?

Because an agent that works only when everything goes well is not ready for production.

A useful evaluation dataset should:

  • Represent real user requests.
  • Cover different levels of difficulty.
  • Include edge cases and failure cases.
  • Have clear expected outcomes.
  • Avoid duplicate or near-identical examples.
  • Be updated when product requirements change.

You should also keep a set of examples that are not used during development. This helps you check whether improvements generalize beyond the examples you repeatedly test.

There are two major ways to evaluate an agent.

  1. Offline evaluation

Offline evaluation happens before a new version is deployed.

You run the agent against a predefined dataset and inspect its performance.

Evaluation dataset
|
v
Agent v1
|
v
Evaluation
|
v
Results

For example:

You have 100 test cases.

You run all 100 against the current agent version and record:

  • Task completion rate.
  • Tool selection accuracy.
  • Argument accuracy.
  • Average tool calls.
  • Average execution time.
  • Cost per task.

You then modify the agent and run the same dataset again.

This helps you understand whether the change improved or damaged performance.

Use offline evaluation for:

  • Testing new prompts.
  • Comparing models.
  • Testing new tools.
  • Changing agent architecture.
  • Checking behavior before deployment.
  1. Online evaluation

Online evaluation happens after the agent is deployed.

You observe how it performs on real user requests.

Real user requests
|
v
Production agent
|
v
Execution traces
|
v
Evaluation and monitoring
|
v
Performance reports

For example, you may discover that the agent completes 95% of internal test cases but only 78% of real user tasks.

Why?

Your test dataset may not represent actual user behavior.

Online evaluation helps detect:

  • Real-world failure patterns.
  • Unexpected user inputs.
  • Tool failures.
  • Quality changes.
  • Increased latency or cost.
  • Problems that were not represented in offline tests.
Offline Online
Uses a predefined dataset Uses real production traffic
Controlled environment Real-world conditions
Useful before deployment Useful after deployment
Easier to reproduce Harder to reproduce
Helps compare versions Helps detect production issues

Regression testing checks whether a new change breaks behavior that previously worked.

Imagine your agent has 100 test cases.

Before a prompt change:

Agent version 1: 92% task completion rate

After the change:

Agent version 2: 84% task completion rate

Your change has reduced task completion by 8 percentage points.

Without regression tests, you might deploy this version and discover the problem from users.

A typical process:

  1. Maintain a fixed evaluation dataset.
  2. Run it against the current agent.
  3. Save the results.
  4. Make a code, prompt, model, or tool change.
  5. Run the same dataset again.
  6. Compare the metrics.
  7. Block deployment if important metrics fall below acceptable thresholds.

This can be part of a CI/CD pipeline.

Pull request
|
v
Run unit tests
|
v
Run agent evaluations
|
v
Compare with baseline
|
+----> Pass: allow deployment
|
+----> Fail: block deployment

One important detail: LLM outputs are often non-deterministic. The same test may produce different results across runs.

For important evaluations, run tests multiple times and compare average performance and variation. Do not treat one successful run as proof of reliability.

Putting everything together: an evaluation pipeline

Section titled “Putting everything together: an evaluation pipeline”

A practical evaluation pipeline looks like this:

An evaluation pipeline: dataset, run agent, evaluate execution with code checks and an LLM judge, aggregate metrics, then compare with a baseline against thresholds.

Mistake 1: Evaluating only the final answer

An agent can return a good-looking answer without completing the actual task.

Mistake 2: Using an LLM judge for everything

Use deterministic checks when possible. They are cheaper and more consistent.

Mistake 3: Testing only happy paths

Real users provide incomplete, ambiguous, and invalid inputs. Tools also fail.

Mistake 4: Using too few test cases

A handful of successful examples does not demonstrate general performance.

Mistake 5: Optimizing only task success rate

The agent might achieve a higher success rate at an unacceptable cost or latency.

Mistake 6: Treating benchmark scores as production guarantees

A benchmark measures performance on its own tasks. It does not guarantee performance on your users’ tasks.

Mistake 7: Not evaluating after changes

A new model, prompt, tool description, or workflow can change agent behavior. Run regression evaluations after meaningful changes.