feat(graders): trajectory / multi-step path grader (#9)#17
Merged
Conversation
A `trajectory` grader that scores the agent's tool-call PATH against an expected ordered trajectory. Unlike `tool-check` (presence/subsequence of tool names), this scores PATH ADHERENCE — the ordered step sequence — via the LCS ratio, so a near-miss path gets graded partial credit (the "Agent GPA" style). The GradeResult flows into the run and, when federated (#85), is recorded in AgentLens's hash chain like any other verdict. - graders/trajectory.py: TrajectoryGrader(expected, allow_extra, max_steps). score = LCS(expected, actual) / (len(expected) if allow_extra else max(len,len)); extra steps penalize unless allow_extra; max_steps fails an over-long path. Falls back to case.expected['trajectory'] then ['tools_called']. - registered as "trajectory" in the grader registry. Tests: 10 cases (exact pass, reorder partial, extra-step penalty, allow_extra subsequence, max_steps, missing-step partial, empty-expected, case fallback, registry, LCS unit). pytest 10/10, mypy + ruff clean (venv). Closes #9. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_019tXZpN29akdmG8AEjgSZwk
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #9.
What: a
trajectorygrader scoring the agent's tool-call path against an expected ordered trajectory. Unliketool-check(presence/subsequence of names), this scores path adherence — the ordered step sequence — via the LCS ratio, so a near-miss path gets graded partial credit (the 'Agent GPA' style). The verdict flows into the run and, when federated (#85), is recorded in AgentLens's hash chain.How:
TrajectoryGrader(expected, allow_extra, max_steps)—score = LCS(expected, actual) / (len(expected) if allow_extra else max(len,len)); extra steps penalize unlessallow_extra;max_stepsfails an over-long path. Falls back tocase.expected['trajectory']then['tools_called']. Registered as"trajectory".Tests: 10 cases (exact pass, reorder→partial, extra-step penalty, allow_extra subsequence, max_steps, missing-step partial, empty-expected, case fallback, registry, LCS unit). pytest 10/10, mypy + ruff clean (venv).
Self-contained, additive (new grader + one registry entry); no behavior change to existing graders.