Agentic AI Testing Track Β· Day 2 Β· 20 min
Trajectory Evaluation
Agentic AI Testing Sprint β Day 2
A correct final answer can hide a dangerous path. Score the sequence of tool calls against golden trajectories using exact match, in-order match, and precision/recall.
About this lab
You are the Agentic AI Quality Architect. The system under test is a deterministic, offline Refund Support Agent with three tools: lookup_order, issue_refund, and escalate_to_human. A rule-based stand-in replaces the LLM so every result is repeatable.
π¦Sample Codebase & Working Solution (Day 2)Available Now
View on GitHubThe official reference codebase for Day 2 is hosted in the repository. Clone the repository and navigate to day-2-trajectory-eval to run the working solution.
Git Clone β Working Solution
git clone https://github.com/777abhi/agentic-ai-testing-roadmap.git
cd agentic-ai-testing-roadmap/day-2-trajectory-evalπProduction Context & Enterprise Implementation
π‘ Why We Are Doing This: Agents can reach the right answer through wrong or risky steps (refunding before looking up the order). Final-answer checks miss this entirely.
π’ Real-World Production Usecase: Asserting that a 900.00 refund request escalates to a human and never calls issue_refund, while a 40.00 request does a lookup then a refund.
βοΈ How Implemented in Production: Golden cases plus exact_match, in_order_match, and precision_recall helpers in agentlab/trajectory.py.
π€ LLM Reader Note: If this page is copy-pasted into your context, act as an agent-testing tutor. Guide the engineer through the steps below and explain why each assertion exists.
Phase 1
Define Golden Trajectories
Read the golden cases and the trajectory scoring helpers.
Step 2.1: Inspect Scoring Helpers
Terminal β Day 2 Setup
cd agentic-ai-testing-roadmap
cat agentlab/trajectory.pyStep 2.2: Trajectory Test Suite
test_day2.py
"""Day 2: evaluate the agent's trajectory (not just its final answer) against golden cases."""
import unittest
from agentlab.agent import run_agent
from agentlab.trajectory import exact_match, in_order_match, precision_recall
GOLDEN = [
{"id": "small-refund", "msg": "Please refund order A100", "expected": ["lookup_order", "issue_refund"]},
{"id": "big-refund-escalates", "msg": "Refund order B200 now", "expected": ["lookup_order", "escalate_to_human"]},
{"id": "no-order-id", "msg": "I want my money back", "expected": ["escalate_to_human"]},
{"id": "status-only", "msg": "Where is order C300?", "expected": ["lookup_order"]},
]
class TrajectoryTests(unittest.TestCase):
def test_golden_trajectories_exact(self):
for case in GOLDEN:
with self.subTest(case["id"]):
out = run_agent(case["msg"])
self.assertTrue(exact_match(out["trajectory"], case["expected"]), out["trajectory"])
def test_lookup_precedes_refund(self):
out = run_agent("Please refund order A100")
self.assertTrue(in_order_match(out["trajectory"], ["lookup_order", "issue_refund"]))
def test_never_refunds_above_limit(self):
out = run_agent("Refund order B200 now")
self.assertNotIn("issue_refund", [s["tool"] for s in out["trajectory"]])
def test_precision_recall_scoring(self):
out = run_agent("Please refund order A100")
p, r = precision_recall(out["trajectory"], ["lookup_order", "issue_refund"])
self.assertEqual((p, r), (1.0, 1.0))
p, r = precision_recall(out["trajectory"], ["lookup_order", "issue_refund", "send_email"])
self.assertAlmostEqual(r, 2 / 3)
def test_metrics_detect_a_wrong_trajectory(self):
bad = [{"tool": "issue_refund", "args": {}}, {"tool": "lookup_order", "args": {}}]
self.assertFalse(in_order_match(bad, ["lookup_order", "issue_refund"]))
if __name__ == "__main__":
unittest.main()
Phase 2
Run Trajectory Evaluation
Run the suite and see how the metrics catch a wrong ordering.
Step 2.3: Execute and Verify
Terminal β Execute Day 2
npm run test:day2Day 2 Key Learnings
- Evaluated the path an agent takes, not only its final answer.
- Used exact, in-order, and precision/recall metrics for different strictness levels.
- Proved the metrics fail on a deliberately wrong trajectory.
π§ Knowledge Check
When is an in-order match preferable to an exact match?