Skip to content
LangChain
0:11:53
171
18
0
Last update : 01/04/2025

Evaluating Agent Trajectories with AgentEvals

Table of Contents

Understanding how an agent arrives at its results is crucial for effective AI system performance. Evaluating just the final response doesn’t capture potential inefficiencies or mistakes throughout the process. This is where AgentEvals comes in, an open-source package that provides tools for assessing agent trajectory evaluations.

🚀 Why Trajectory Evaluation Matters

Evaluating agents solely based on their final output can be misleading. An agent might provide a correct answer but could take unnecessary or incorrect paths to reach that conclusion.

Example:

Imagine asking an AI scheduler to set up a meeting on Friday. The agent responds with a confirmation, but upon reviewing the steps it took, you realize it only retrieved the calendar and never scheduled the meeting—resulting in a hallucinated response. This illustrates the need to analyze the entire trajectory, especially for complex tasks that involve multiple steps or tool interactions.

Surprising Fact:

Research shows that up to 30% of agent responses may be accurate but based on flawed trajectories. Recognizing this fact is critical for system developers who rely heavily on AI outcomes.

Practical Tip:

When assessing AI outputs, always question the steps that led to the conclusion. Conduct a retrospective analysis of the trajectory to ensure accuracy and efficiency.

🛠️ Overview of AgentEvals

AgentEvals offers a comprehensive set of tools for evaluating agent trajectories. Its flexibility makes it framework agnostic and compatible with the OpenAI format, enabling broader applicability in various AI contexts.

Evaluation Methods

AgentEvals allows you to evaluate agent trajectories in two primary ways:

  1. Trajectory Match: Directly compare agent output with a reference trajectory consisting of messages and tool calls.
  2. LM as a Judge: Use a language model (LM) to evaluate the trajectory based on content and logical reasoning.

Example of Usage:

By employing trajectory matching, developers can validate whether agents called the correct tools in the appropriate order. Conversely, using LM as a judge allows for a holistic review, considering the content and overall efficiency.

Quick Fact:

Agents utilizing multiple-step logic tend to perform better when their trajectories are scrutinized throughout all steps. Implementing AgentEvals can significantly reduce the margin of error.

📊 Key Features and Modes of Trajectory Matching

AgentEvals provides various modes to customize trajectory evaluations, vital for different scenarios.

Four Main Matching Modes:

  1. Strict Mode: Requires exact tool calls in exact order. This is ideal for situations like customer support where order matters.
  2. Unordered Mode: Ensures all tools are called, but in any order. Useful for tasks where the sequence holds no relevance.
  3. Superset Mode: Allows for additional tool calls, checking that a minimum set corresponds to the reference.
  4. Subset Mode: Ensures the agent output does not include unnecessary calls, focusing on efficiency.

Tool Arguments Flexibility:

By default, AgentEvals compares tool arguments strictly. However, developers can modify matching parameters to ignore argument match criteria if needed.

Example Scenario:

Using strict mode in customer support ensures that the agent utilizes a policy lookup before any actions. If the evaluation fails, developers can refine the process to achieve better performance.

Practical Tip:

Test agents using different matching modes to find the best fit for your specific use cases, ensuring the evaluation aligns with desired performance metrics.

🧑‍💻 Leveraging LM as a Judge

The LM as Judge evaluator takes trajectory evaluation a step further by incorporating reasoning and contextual understanding.

Initiating an LM Judge:

  1. Create an evaluator using the create trajectory LM as a judge method.
  2. Incorporate a detailed prompt that instructs the LM on evaluating the trajectory based on logical progression and efficiency.

Prompt Example:

A sample prompt might include asking the LM to rate the clarity and logical flow of the agent’s steps. This nuanced assessment reveals gaps in reasoning that might be missed in a strict trajectory match.

Understanding Performance:

By utilizing LM as a judge, developers can spot patterns of inefficiency or illogical processing that require attention or re-architecting of the agent.

Practical Tip:

Whenever possible, use LM evaluations to obtain richer feedback on trajectory quality. This can drive better training and refinement cycles for your agents.

🧪 Running Experiments with LangSmith and AgentEvals

Integrating AgentEvals into your development cycle involves systematic testing through platforms like LangSmith. This process not only helps in assigning results but also establishes a baseline for future enhancements.

Experiment Steps:

  1. Create a Dataset: Collect input and reference outputs for the agent to evaluate.
  2. Define Application Logic: Establish how the agent should operate and the expected trajectory.
  3. Set Up Evaluators: Implement trajectory matching rules (e.g., strict mode for tool matching).
  4. Run the Experiment: Execute tests across multiple iterations for reliability.

Monitoring Results:

After running tests, LangSmith offers insights into evaluation performance through a detailed results table, highlighting discrepancies between expected and actual outputs.

Focus for Improvement:

Analyzing experiment results allows developers to identify weak points in the agent’s reasoning process, enabling targeted refinements to the underlying models or algorithms.

Practical Tip:

Regularly utilize LangSmith to run comprehensive evaluations. Iterating through datasets not only helps in perfecting agent behavior but also improves overall understanding of performance dynamics.

💡 Resource Toolbox

Here are key resources that can support your journey in agent evaluation:

  • AgentEvals GitHub Repository: AgentEvals – Access the open-source code package for trajectory evaluation and documentation.

  • LangSmith SDK: LangSmith – Utilize this platform for running agent evaluations systematically.

  • OpenAI Documentation: OpenAI – Familiarize yourself with the OpenAI API and integration specifics for broader applications.

  • AI Development Patterns: AI Patterns – Explore effective development patterns that enhance AI agent functionalities.

  • Data Labeling Resources: Labeling Guide – Find tools and best practices for data labeling in AI systems.

By applying the insights gained from AgentEvals, developers can significantly refine agent behavior and elevate overall AI performance. The journey of evaluating trajectories is not only about fixing issues but fostering intelligence that evolves over time. 🌟

Other videos of

Play Video
LangChain
0:14:19
360
29
3
Last update : 01/04/2025
Play Video
LangChain
0:06:12
374
45
2
Last update : 29/03/2025
Play Video
LangChain
0:09:22
144
15
2
Last update : 29/03/2025
Play Video
LangChain
0:10:01
100
10
1
Last update : 29/03/2025
Play Video
LangChain
0:32:41
129
8
0
Last update : 30/03/2025
Play Video
LangChain
0:07:05
131
6
1
Last update : 27/03/2025
Play Video
LangChain
0:10:14
1 004
95
6
Last update : 27/03/2025
Play Video
LangChain
0:05:20
516
54
6
Last update : 26/03/2025
Play Video
LangChain
0:04:29
305
17
1
Last update : 26/03/2025