# AgentEvals

> Ready-made evaluators for scoring agent trajectories and tool-call paths

- Category: Evaluation & Production Ops / Evaluation & Red-Teaming
- Language: Python / TypeScript
- Repository: https://github.com/langchain-ai/agentevals
- Canonical page: https://ai-tldr.dev/tools/agentevals/

## In short

AgentEvals is a LangChain package that helps you evaluate how an AI agent behaves while it runs, not just its final answer. Its focus is the agent's trajectory: the intermediate steps, messages, and tool calls the agent produces on its way to a result. It sits in the Evaluation & Red-Teaming category of the Evaluation & Production Ops tools and is open-source, written in Python / TypeScript.

## Overview

AgentEvals is a LangChain package that helps you evaluate how an AI agent behaves while it runs, not just its final answer. Its focus is the agent's trajectory: the intermediate steps, messages, and tool calls the agent produces on its way to a result. You give it the agent's run as a list of OpenAI-style messages or LangChain message objects, and it returns a score and reasoning.

It is built for developers who write agents (for example with LangGraph) and want a repeatable way to catch regressions when they change a prompt, model, or tool. You can check a trajectory against an expected path with exact-match modes, or hand it to an LLM-as-judge evaluator when there is no single correct path. There is also support for evaluating LangGraph graph trajectories.

In the evaluation and testing category, AgentEvals sits alongside its more general companion package openevals. It plugs into LangSmith and pytest or Vitest/Jest test runners, so agent evaluations can live next to your normal test suite.

## What it does

- Trajectory match evaluators that compare an agent's steps against an expected trajectory, with strict, unordered, and subset/superset modes
- LLM-as-judge trajectory evaluator using a built-in TRAJECTORY_ACCURACY_PROMPT to score paths that have no single correct answer
- Accepts trajectories as OpenAI-style message dicts or LangChain BaseMessage objects, handling message formatting under the hood
- Tool args match modes to control how strictly tool-call arguments are compared
- Graph trajectory evaluators for LangGraph, including LLM-as-judge and strict match
- Python async support and integration with LangSmith, pytest, and Vitest/Jest

## Getting started

Install the package, set your model API key, then run a trajectory evaluator over a list of agent messages.

1. Install AgentEvals

   Install with pip for Python, or npm for TypeScript (which also needs @langchain/core).

```bash
pip install agentevals
```

2. Set your OpenAI API key

   The LLM-as-judge evaluator in the quickstart uses OpenAI's o3-mini model, so export your key first.

```bash
export OPENAI_API_KEY="your_openai_api_key"
```

3. Run a trajectory LLM-as-judge

   Create an evaluator with the built-in accuracy prompt, then pass your agent's trajectory as a list of OpenAI-style messages. It returns a key, reasoning, and a true/false score.

```python
from agentevals.trajectory.llm import create_trajectory_llm_as_judge, TRAJECTORY_ACCURACY_PROMPT

trajectory_evaluator = create_trajectory_llm_as_judge(
    prompt=TRAJECTORY_ACCURACY_PROMPT,
    model="openai:o3-mini",
)

outputs = [
    {"role": "user", "content": "What is the weather in SF?"},
    {"role": "assistant", "content": "", "tool_calls": [
        {"function": {"name": "get_weather", "arguments": json.dumps({"city": "SF"})}}
    ]},
    {"role": "tool", "content": "It's 80 degrees and sunny in SF."},
    {"role": "assistant", "content": "The weather in SF is 80 degrees and sunny."},
]

eval_result = trajectory_evaluator(outputs=outputs)
print(eval_result)
```

## When to use it

- Catch regressions in an agent's reasoning or tool-call path when you change a prompt, model, or tool definition
- Score agent runs that have no single correct path using the LLM-as-judge trajectory evaluator
- Assert that an agent follows an expected sequence of tool calls with strict, unordered, or subset match modes
- Evaluate LangGraph agents and wire trajectory evals into a LangSmith, pytest, or Vitest/Jest test suite
