Building an Agent Evaluation System from Scratch: Fix the Data Pipeline First

    Most teams start building an AI Agent evaluation system by designing a scorecard, but that approach fails for two reasons: safety cannot be averaged into a total score, and an aggregate score only ranks systems without explaining why a run failed. This article walks through the correct build order—observability, data reliability, layered traces, judgment rules, and aggregated reports—and shows how to fix duplicate and missing telemetry with idempotency keys and explicit deduplication, how to structure traces into operation, reasoning, and context layers, and how to enforce hard safety rules as a veto gate while scoring soft quality dimensions separately. It also includes a pre-launch checklist for verifying that evaluation results are actionable.

    1. Two Common Misconceptions to Correct First

    When many teams start evaluating Agents, their first instinct is to design a scorecard: points for accuracy, points for formatting, points for tone, then a weighted sum. That starting point is wrong, for two reasons.

    First, safety cannot be part of an average. A single unauthorized write, or one instance of sending internal data to an external endpoint, does not carry the same cost as an answer that is “not concise enough.” Once safety items are folded into a weighted average, one high-severity failure can be diluted by a large number of high scores. The system that looks “good” on the leaderboard may be capable of causing real damage at any moment. The correct approach is to make safety an independent veto gate: if any hard red line is triggered, that sample is marked as failed outright, excluded from the average, and reported in its own separate column.

    Second, a total score can only rank; traces tell you what to fix. A total score answers “which one is better.” It is a scalar, and information is compressed away during aggregation. What engineering actually needs to answer is “why did this run fail, and should the next change be to the prompt or to tool permissions?” That answer exists only in the execution trace: which tool was called, what arguments were passed, what the model’s reasoning was at the time, and what came back.

    This leads to the build order for an evaluation system: observability → data reliability → layered traces → judgment rules → aggregated reports. Most rework comes from doing this in reverse.

    2. Without Reliable Observability, Evaluation Is Built on Sand

    The raw data that evaluation consumes is: every action the Agent takes, every tool call with its arguments and return values, and the reasoning and confidence in each round of model output. This data must pass through four stages—collection → reporting → persistence → aggregation—before it is usable. Skipping the first three and going straight to score design most often produces two kinds of silent failure: some executions are never collected at all, and the same execution is counted multiple times. Neither throws an error or crashes; they simply make scores quietly inaccurate.

    A real example at production scale: during one investigation, the server-side trace files for a single day totaled roughly 90MB, but the valid data after deduplication by session and step was only about 11MB—an amplification of roughly 8x. The root cause was two things stacking:

    1. On reporting, the full conversation history was stored once in each of two different fields, because different downstream stages each needed it;
    2. The reporting side repackaged and re-sent all completed steps of the current session every time it finished a step, while the server only appended writes without deduplicating by session and step, so early steps were written to disk repeatedly.

    Problems like this must be caught by a verifiable standard, not by “it looks fine.” The recommendation is to attach an idempotency key at persistence time and run an explicit deduplication pass before aggregation:

    1. # Reporting side: generate a stable idempotency key per (session, step) and report only increments
    2. def emit_span(span):
    3. span["dedup_key"] = f"{span.session_id}:{span.step_index}"
    4. queue.put(span) # local persistence queue, recoverable after process restart
    5. # Server side: deduplicate by idempotency key before aggregating
    6. def ingest(records):
    7. seen, clean = set(), []
    8. for r in records:
    9. k = r["dedup_key"]
    10. if k in seen:
    11. continue
    12. seen.add(k)
    13. clean.append(r)
    14. return clean

    The accompanying monitoring needs at least three metrics: the ratio of reported records to post-deduplication records (a sudden spike in the amplification factor is an anomaly), session coverage (sessions with traces ÷ actual sessions), and the step missing rate (the proportion of samples with broken traces). Without these three metrics, you cannot tell whether today’s score is comparable to last week’s.

    3. Traces Must Be Layered, or They Are Unreadable When Opened

    A flat block of logs cannot localize problems. The fairly consistent industry practice is to split traces into three layers, with the reasoning layer nested inside the operation layer:

    • Operation layer: who called whom, start and end times, latency, status codes, retry counts;
    • Reasoning layer: the reasoning chain at the time, its basis, confidence, and flags for truncation or degradation;
    • Context layer: input and output summaries of external dependencies such as outbound HTTP requests, database queries, and vector retrieval.

    The direct benefit of the nested structure is a very short debugging path: an alert at 2 a.m. says the Agent performed a write it should not have. Expanding from the operation span down to the reasoning span shows the basis for the decision at the time, something like “the user said ‘tidy things up,’ and I judged it should be archived to the main database”—and problem localization turns from guessing at logs into reading a causal chain.

    Example structure:

    1. {
    2. "session_id": "s-1024", "step_index": 7,
    3. "operation": {"tool": "db.write", "latency_ms": 132, "status": "ok"},
    4. "reasoning": {"chain_summary": "user said tidy up -> archive to main DB", "confidence": 0.61},
    5. "context": {"http": [], "sql": {"rows": 1}, "vector": {"topk": 5}}
    6. }

    Three things to watch when implementing this: inputs and outputs of external dependencies must be redacted and truncated, keeping only the fields needed for localization; the reasoning layer records the model’s self-reported basis, which is an observability signal rather than fact, and must not be used directly as a basis for judgment; and all three layers must be linked by the same trace_id so a complete chain can be reassembled across services.

    4. The Judgment Layer: Veto Gate Plus Multi-Dimensional Scoring

    Judgment falls into two categories. Hard constraints go through the veto gate, for example unauthorized tool calls, outbound transmission of sensitive data, exceeding budget and timeouts, and unauthorized high-risk write operations. Soft quality goes through multi-dimensional scoring, for example task completion, argument correctness, redundant steps, and language and format compliance.

    1. def evaluate(sample):
    2. if violates_any(sample.hard_rules): # security/compliance red lines
    3. return {"verdict": "fail", "reason": sample.violations}
    4. dims = {k: scorer[k](sample) for k in SOFT_SCORERS}
    5. return {"verdict": "pass", "scores": dims}

    Stick to two rules when aggregating: the veto rate gets its own column and is never merged into the mean; and each dimension keeps its distribution (P50/P90) rather than only a mean, because Agent failures tend to concentrate in the long tail. The evaluation set itself must also be layered—high-frequency real scenarios, boundary and adversarial samples, and regression cases—counted separately, so that a total does not mask a collapse in one category.

    5. Common Pitfalls and a Checklist

    • Reporting only full snapshots, with no increments and no idempotency → distortion in both storage and statistics;
    • Redundant storage of conversation history across multiple fields → higher amplification factor, and a tendency toward inconsistency between fields;
    • Traces missing a trace_id or not linked across services → the complete chain cannot be reassembled;
    • Safety items included in weighting → high-severity failures masked by the average score;
    • Looking only at the total score and not the distribution → long-tail failures go unnoticed for a long time;
    • Evaluation set disconnected from the production distribution → scores rise while experience declines.

    Self-check before launch: is the data amplification factor stable, does session coverage meet the target, do veto items stand in their own column, and can any failed sample be reconstructed into a causal chain across the three trace layers? Only when all four pass consistently are evaluation conclusions actionable; only then does refining the scoring system avoid rework. If the data pipeline is not yet stable, you can first rely on general-purpose cloud capabilities such as object storage, message queues, and log monitoring to cover persistence and alerting, and focus your effort on getting the measurement standard right.