Skip to content

About

CI-integrated eval harness for LLM agents — intent accuracy, retrieval precision/recall/MRR, and hallucination detection

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Repository files navigation

Agent Eval Harness

A lightweight, dependency-light evaluation harness for LLM agents — built to plug into Autostream Agent and measure the three things that actually break agentic sales/support workflows in production:

  1. Intent classification accuracy — is the router sending messages to the right node (greeting / product inquiry / lead capture / ...)?
  2. Retrieval relevance — is the RAG layer pulling the correct knowledge base chunk for a query (precision@k, recall@k, MRR)?
  3. Faithfulness / hallucination rate — is the generated response actually grounded in what was retrieved, or is it inventing prices, policies, or facts?

Ships with offline fallback implementations (rule-based classifier, keyword-overlap retriever) so the whole harness runs with zero API keys and zero network access — useful as a CI gate, and as a sanity check before you ever plug in a real model.

It also has the pieces needed to debug an agent day to day:

  1. Hybrid scoring: deterministic checks + LLM-as-judge — free regex/overlap checks gate first; a schema-constrained LLM judge handles the semantic cases, and the judge itself is calibrated against human labels (agreement + Cohen's kappa).
  2. Step-level tracing — every step, tool call and LLM call becomes a span with latency, token usage and estimated cost (sync and asyncio), and first_failure() points at the exact step that broke.
  3. Versioned datasets with schemas — every test set is validated by a Pydantic schema and pinned by hash in data/manifest.json; editing one without bumping its version fails the run, so a dataset change can never silently move a score.
  4. Tool-calling eval — tools are defined once as Pydantic models that produce the OpenAI function-calling schema and validate the model's arguments. The eval scores tool selection, schema-valid calls, argument accuracy and tools called when none were needed; works offline or against any OpenAI-compatible model.
  5. Regression suite from observed failures + baseline gate — each bug found becomes a case in data/regression_cases.jsonl, and CI fails if any headline metric drops below baselines/baseline.json.
  6. Multi-model validation — the same judge runs on two or more models. The harness reports pairwise agreement and Cohen's kappa between judges, Fleiss' kappa across all of them, each judge's agreement with human labels, and each judge's tokens, cost and p50 latency. A consensus policy (unanimous or majority) decides the verdict, and rows where judges split go to a human review queue.

Quickstart

pip install -r requirements.txt
python run_eval.py                    # evals + regression gate (exit 1 on regression)
python run_eval.py --judge stub       # + judge pipeline, offline
JUDGE_API_KEY=... python run_eval.py --judge api   # + real LLM judge (any OpenAI-compatible API)
python run_eval.py --multi-judge stub # + multi-model validation, offline
JUDGE_MODELS=model-a,model-b JUDGE_API_KEY=... python run_eval.py --multi-judge api  # real judges
pytest -v                             # 53 tests

This writes reports/latest_report.{md,json} and appends spans to reports/traces.jsonl.

Sample output

## Intent Classification
- Accuracy: 100.0%
- Mistakes: 0

## Retrieval Relevance
- Precision@3: 33.3%
- Recall@3: 100.0%
- MRR: 1.000

## Faithfulness / Hallucination Check
- Flagged rate: 50.0% (4 responses checked)
- Flagged examples:
  - `how much is the pro plan` -> unsupported numeric claim(s): ['19']
  - `what's your refund policy` -> unsupported numeric claim(s): ['90'], low grounding overlap (0.18 < 0.25)

The two flagged examples above are deliberately-injected bad responses in data/generations_sample.jsonl (a fabricated discount price and a made-up refund policy) — included to prove the faithfulness check actually catches hallucinations rather than always passing.

Wiring into a real agent

Every eval function accepts your real implementation as a callable, so you never have to fork this repo — just pass your own function in:

from eval_harness.intent_eval import run_intent_eval

# your Autostream Agent's real LangGraph intent node
from autostream_agent.graph import classify_intent

result = run_intent_eval("data/intent_test_set.jsonl", classifier=classify_intent)
print(result.to_dict())

Same pattern for run_retrieval_eval(..., retriever=my_faiss_retriever).

Project layout

eval_harness/
  intent_eval.py         # accuracy, per-class precision/recall, confusion matrix
  retrieval_eval.py       # precision@k, recall@k, MRR
  hallucination_eval.py   # numeric-claim + grounding-overlap faithfulness check
  tools.py                # Pydantic tool schemas, validation, traced execution, planners
  tool_call_eval.py       # tool selection / argument accuracy / schema-valid rate
  triage.py               # SOP steps 1-3: find the broken step, draft a regression case
  llm_judge.py            # hybrid scorer, async LLM judge, retries, calibration
  multi_judge.py          # multi-model validation: consensus, kappa, review queue
  tracing.py              # spans: latency, tokens, cost, errors; first_failure()
  datasets.py             # Pydantic schemas + hash-pinned versions (manifest)
  regression.py           # baseline comparison gate
  report.py               # runs everything inside a trace, renders the report
data/                      # versioned test sets, calibration set, regression cases
baselines/baseline.json    # committed headline metrics
run_eval.py               # CLI entry point (exit 1 on regression)
tests/                    # unit tests + one test per regression case
docs/SOP-bad-output-triage.md  # the debugging procedure
.github/workflows/eval.yml # runs the harness on every push

Why the scoring works the way it does

  • Numbers are a hard deterministic fail. A price, date or dose that is not in the retrieved context is the most damaging hallucination, and a regex is never wrong about whether "19" appears in the context. These rows never reach the judge, so they cost nothing and can't be talked around by a lenient model.
  • The judge handles meaning, not string matching. cal-08 in data/judge_calibration_set.jsonl reuses the context's words but swaps "SOC 2" for "HIPAA": high lexical overlap, wrong claim. Only a semantic judge catches it.
  • The judge is constrained. Fixed rubric (faithfulness-v1), temperature 0, JSON validated by a Pydantic schema, one retry with the validation error fed back. A judge that still fails, or an API error, counts as a fail — an eval must never pass because the grader broke.
  • "Partially supported" is a fail. One invented claim in an otherwise correct answer is still a wrong answer for the user.
  • The judge is evaluated before it is trusted. calibrate() scores the hybrid scorer against 12 human-labelled responses. The offline stub (lexical only) gets 75% agreement / kappa 0.50 and misses exactly the three same-words-different-meaning cases — the test suite asserts this, which is the reason the real judge exists. Re-run calibration whenever the judge prompt or model changes.

Multi-model validation

One judge is one model's opinion, and changing its prompt or model can move every score at once. eval_harness/multi_judge.py asks several models the same rubric question on the human-labelled calibration set:

JUDGE_BASE_URL=https://openrouter.ai/api/v1 JUDGE_API_KEY=... \
JUDGE_MODELS=openai/gpt-4o-mini,meta-llama/llama-3.3-70b-instruct,google/gemini-2.0-flash-001 \
python run_eval.py --multi-judge api --policy unanimous
  • Verdict policy. unanimous (default) passes a row only if every judge says "supported", so a hallucination has to fool every model. majority passes on more than half. A judge error is always a fail vote.
  • Agreement. Pairwise agreement and Cohen's kappa for each pair of judges, and Fleiss' kappa across all of them, measured only on rows that reached the judges (the deterministic gate still fails unsupported numbers first, at no cost).
  • Review queue. Rows where judges split are returned as needs_review, and calibrate_multi() reports how many consensus errors that queue would catch.
  • Cost. Tokens, cost and p50 latency per judge, so the price of adding a model is visible next to what it buys.

The offline run (--multi-judge stub) uses two lexical judges with different thresholds. It is a deliberate negative example: they agree with each other on 90% of judged rows (Cohen's kappa 0.62) while the stricter one agrees with humans on only 66.7%, and the unanimous consensus still lets 3 unsupported answers through. Two judges built on the same signal share blind spots, so high inter-judge agreement is not accuracy. Use judges from different model families, and always check them against human labels. The test suite asserts these numbers.

Debugging workflow

The full procedure is written as an SOP: docs/SOP-bad-output-triage.md. Its first three steps are automated:

python -m eval_harness.triage reports/traces.jsonl --trace-id <id>
# -> step that broke, its input, error and traceback, plus a draft regression case

In short: an output looks wrong → open reports/traces.jsonl (or call first_failure(load_trace(path))) to find the deepest span that errored or produced the bad output → write a case in data/regression_cases.jsonl that reproduces it → fix → python -m eval_harness.datasets bump regression_cases → commit the case, the fix and (if scores moved on purpose) the new baseline.

The three intent-00x cases came from exactly this loop: the offline router used substring matching, so "does this work…" and "which plan…" matched the greeting keyword "hi". Fixed with whole-word matching; the cases keep it fixed.

Design notes

  • The deterministic checks have no LLM cost, so they run on every commit; the real judge (--judge api) is for PRs that touch prompts or models and for periodic audits.
  • Thresholds in test_eval_harness.py are conservative starting points; tighten them as the underlying agent improves and treat any drop across commits as a regression signal (prompt change, model swap, KB edit, etc).

About

CI-integrated eval harness for LLM agents — intent accuracy, retrieval precision/recall/MRR, and hallucination detection

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages