BXUP Track progress & test yourself — free
Data Science & ML/AI · Playbook · Advanced · ~6 min read
DATA SCIENCE & ML/AI · PLAYBOOK · ADVANCED

Agent Trajectory Evaluation: Tool Choice, Efficiency, and Safety

Single-turn evals grade an answer; agents produce trajectories — sequences of reasoning, tool calls, observations, and retries — and two trajectories can reach the same final answer where one took 4 sensible steps and the other took 19 steps, called the payments API twice "to check", and got lucky.

Tier: Advanced · Workflow area: Evaluation Engineering

Final-answer grading alone systematically overrates lucky agents and underrates unlucky-but-sound ones. This playbook builds trajectory-level evaluation over traced runs: tool-choice correctness, step efficiency, task completion, and safety-violation detection — the eval layer that agentic QA roles are now hired to build.

When to use

  • You run any multi-step agent (LangGraph, Claude Agent SDK, function-calling loops) beyond a single tool call — data-analysis agents, support agents, pipeline-triage agents.
  • Task-completion rates look fine but cost/latency is erratic, or you suspect the agent succeeds despite its process.
  • Before granting an agent more tools or autonomy — trajectory evidence is the promotion criterion.

Prerequisite mindset: this extends pb-34→pb-37 to agents; if you have no single-turn eval discipline yet, build that first — trajectory evals inherit all of it and add structure.

Prerequisites

  • Full tracing on agent runs (OTel/OpenInference into self-hosted Phoenix, LangSmith, or MLflow tracing): every LLM call, tool call with arguments, tool result, and final state — a trajectory you cannot replay is a trajectory you cannot evaluate.
  • A task suite: 30–50 tasks with defined success criteria, including known-hard and should-refuse cases; sandboxed/mock tools so evaluation runs cannot touch production systems.
  • Your pb-36 calibrated judge for the subjective sub-scores, and pytest/CI plumbing from pb-37.

The workflow

  1. Do trajectory error analysis first (pb-34, agent edition). Read 30 full trajectories — not summaries, the actual step sequences. Open-code what you see; agent-specific failure modes cluster reliably: wrong tool for the step, correct tool with malformed arguments, ignoring a tool error and proceeding, retry loops, hallucinating a tool result that never came back, goal drift mid-task, unnecessary steps, and stopping early with a confident wrong answer. Build the taxonomy; it defines your graders.

  2. Define the four metric families per task.

    • Task completion: did the final state satisfy the task's success criterion? Prefer programmatic checks (the file exists and parses; the ticket contains the required fields); judge-graded only where outputs are free-form.
    • Tool-choice correctness: for each step, was the invoked tool an acceptable choice given the state? Encode per-task as an allowed-tools-per-phase map or reference trajectory; grade steps, not just the set of tools used.
    • Step efficiency: steps taken ÷ reference steps for that task (build references from the best observed trajectories); plus tokens and wall-clock. Report as a ratio so tasks of different sizes aggregate.
    • Safety violations: hard boolean per trajectory — called a tool outside its permission set, passed PII into a tool argument, exceeded the step/token budget, acted when it should have refused or escalated. Any violation fails the trajectory regardless of task success.
  3. Implement graders in the assertions-before-judges hierarchy. Programmatic: tool-call sequence checks against the allowed-phase map, argument schema validation, budget counters, PII regexes on arguments, terminal-state checks — all pure code over the trace JSON. Judge-graded (pb-36 discipline: rubric, dual-order where pairwise, calibrated on human-labeled trajectories): reasoning coherence, whether a deviation from the reference path was legitimate creativity or drift.

  4. Score trajectories, not just endpoints. Emit per-trajectory records: {task_id, completed, first_divergence_step, tool_choice_accuracy, efficiency_ratio, violations[], cost_tokens, wall_clock}. The first-divergence-step field is the debugging gold: aggregate it to find which state transitions break agents most (it is usually one or two specific tool results the model misreads).

  5. Run the suite with repetition. Agents are high-variance: run each task 3–5× and report completion as mean ± spread, plus a flakiness stat (tasks with mixed outcomes across identical runs). A 70%-completion agent that is deterministic beats an 80% agent that is a coin flip on a third of tasks — flakiness is a first-class result, not noise to average away.

  6. Gate autonomy on trajectory evidence. Wire the suite into pb-37's CI (agents have prompts, tool definitions, and model pins too — all gate-worthy paths). Set promotion thresholds per capability tier: e.g., read-only tools → write tools requires completion ≥ X, zero safety violations across N×reps, flakiness ≤ Y. Demotion is automatic on any production safety violation.

  7. Close the loop from production. Sample production trajectories (with the pb-36 5–10% human-review pattern applied to trajectory judges), feed new failure modes into the taxonomy, and convert incidents into new suite tasks — the pb-34 growth rule, at trajectory scale.

Key Takeaway:

Grade the process, not just the outcome — an agent that reached the right answer through the wrong process is a failure you have not observed yet.

Tool variants

  • Phoenix (self-hosted) agent evals: OpenInference tracing plus trajectory-level eval hooks; keeps traces in your boundary.
  • LangSmith agent evals: managed; strongest turnkey trajectory tooling and dataset-over-traces flow, with the data-residency caveat for client work.
  • Custom graders over trace JSON: every framework exports traces as structured data; 200 lines of pytest over that JSON implements the programmatic layer with zero new dependencies — often the right call for one team's one agent.

Verification

  • 30-trajectory error analysis done; taxonomy with agent-specific modes and exemplar trace IDs exists.
  • All four metric families implemented; safety checks are programmatic and hard-fail.
  • Reference trajectories or allowed-phase maps defined per task; efficiency reported as ratios.
  • Each task run 3–5×; flakiness reported; thresholds set outside observed variance (pb-37 discipline).
  • Suite runs against sandboxed tools only — verified by pointing the sandbox at a canary that alerts on real-system access.
  • Trajectory judges calibrated against human-labeled trajectories (κ reported, pb-36 method).

Pitfalls

  • Final-answer-only grading. The lucky-agent problem: process failures accumulate invisibly until a tool result changes shape and completion collapses overnight.
  • One run per task. Agent variance swamps single-run deltas; every reported number needs repetition behind it.
  • Penalizing all deviation from the reference path. Multiple valid strategies exist; the allowed-phase map should encode constraints, not a single blessed script — use the judge for legitimate-alternative calls.
  • Evaluating against live tools. An eval suite that files real tickets or sends real emails is an incident generator; mock or sandbox everything, and canary-verify it.
  • Ignoring cost as a metric. Step-efficiency regressions are budget regressions; an agent that got 5% more accurate and 3× more expensive did not necessarily improve.
  • Trusting the agent's self-report. "Task complete" from the agent is a claim, not a result — grade terminal state, never the parting message.

Restricted-environment variant

  • Trace storage is the sensitive core: trajectories contain tool arguments carrying client data. Self-hosted Phoenix or MLflow tracing inside the boundary; managed observability SaaS only with contractual clearance.
  • Trajectory judges run on the self-hosted pb-36 judge; prefer programmatic graders even more heavily — they are boundary-safe by construction.
  • Sandbox fixtures built from anonymized data snapshots (pb-28 placeholder discipline), so the suite itself can live in the delivery repo.
Warning

An agent trace is a recording of everything the agent saw and did — including secrets a tool accidentally returned; scrub tool-result payloads in traces before anyone outside the boundary views them.

Success criteria

  • Per-trajectory scorecards with completion, tool-choice accuracy, efficiency ratio, and violations — aggregated with variance, per task and per slice.
  • First-divergence analysis has identified at least one concrete state transition to fix, with a before/after suite delta proving the fix.
  • Autonomy tiers exist and the agent's current tool permissions are justified by suite evidence, not optimism.
  • Zero safety violations across the full suite at promotion reps — and a demonstrated demotion path when production violates one.
This is the free reading view. Open BXUP to track your progress, run the hands-on labs, and prove it with original, exam-pattern assessments.
© Anvi Innovate · BXUP — Be Exponentially Upskilled · BXUP is an independent learning platform, not affiliated with or endorsed by AWS, Microsoft, Google, NVIDIA, IBM, Salesforce, Databricks, Oracle or Anthropic. All trademarks belong to their respective owners. · bxup.in