Skip to content

feat(graders): trajectory / multi-step path grader (#9)#17

Merged
amitpaz1 merged 1 commit into
mainfrom
feat/issue-9-trajectory-grader
Jun 26, 2026
Merged

feat(graders): trajectory / multi-step path grader (#9)#17
amitpaz1 merged 1 commit into
mainfrom
feat/issue-9-trajectory-grader

Conversation

@amitpaz1

Copy link
Copy Markdown
Member

Closes #9.

What: a trajectory grader scoring the agent's tool-call path against an expected ordered trajectory. Unlike tool-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 unless allow_extra; max_steps fails an over-long path. Falls back to case.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.

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
@amitpaz1
amitpaz1 merged commit b1e1e19 into main Jun 26, 2026
4 checks passed
@amitpaz1
amitpaz1 deleted the feat/issue-9-trajectory-grader branch June 26, 2026 07:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Trajectory / multi-step path grader (record verdict into chain)

1 participant