The AI Agent Testing Crisis: Why a Perfect Answer Can Hide a Broken Process
AI agents are failing in ways that look like success. A support agent might generate an answer before retrieving the relevant policy, call the same tool twice, or use an unapproved fallback, yet still return text that sounds helpful and passes basic quality checks. The problem isn't just that the answer is wrong; it's that the process behind it violated the system's design, and nobody noticed.
Why Do AI Agents Fail Silently?
The phrase "it worked on my prompt" has become the AI equivalent of "it worked on my machine." A developer runs an agent locally, sees a convincing response, and assumes the system is behaving correctly. But the same agent may behave differently in a pull request, with a slightly different input, after a model update, or inside a longer workflow. The visible output can still look polished even when the internal trajectory is broken.
This creates a dangerous blind spot. Most agent testing focuses on answer correctness, which matters because users care about the final response. But once agents become production software, how they arrive at that answer matters just as much. A flat log might show that every tool ran, but it won't reveal whether generation happened before retrieval, whether a forbidden tool appeared on an invalid branch, or whether the run completed successfully or just looked like it did.
What Are the Three Layers of Agent Correctness?
Teams need to distinguish between three separate types of correctness when evaluating agent behavior:
- Answer Correctness: Was the response useful, accurate, and appropriate? This is typically evaluated through human review, dataset evaluation, or model grading.
- Trajectory Correctness: Did the agent use the required tools, follow an acceptable order, and complete the run as designed? This relies on execution facts and deterministic rules that can be verified without subjective judgment.
- Evidence Correctness: Can another engineer inspect what happened without relying on a screenshot or exposing raw data? This requires a portable, redacted, integrity-checked artifact that travels with the failure.
Most teams focus only on the first layer. But the other two are what separate a working system from one that happens to produce acceptable output by accident.
How to Build Reproducible Agent Artifacts?
The solution is to treat each agent run as a reviewable engineering artifact, similar to how teams use Playwright traces, JUnit reports, or CI logs. A trace becomes a usable artifact through a structured lifecycle:
- Capture: Collect the full hierarchical structure of the agent run, not just a flat list of events. An agent run is inherently hierarchical: a plan creates a tool call, the result informs a model step, and the model may trigger a retry, fallback, or handoff.
- Normalize and Inspect: Convert the raw trace into a standardized format that can be understood independently of the system that created it. This includes metadata like tool names, step types, statuses, durations, token counts, and parent-child relationships.
- Check and Redact: Apply deterministic rules to verify structural facts (Did retrieve_policy run? Did forbidden tool appear? Did generation happen before retrieval?), then redact sensitive information like user messages, credentials, or retrieved documents before sharing.
- Package and Verify: Attach hashes, provenance information, schema details, and assessment results to the artifact so it can be archived, reopened, discussed, and compared independently of the machine that created it.
This approach separates the source trace, which stays local and access-controlled, from the derived artifact, which is redacted and share-checked. Metadata-first capture can answer many trajectory questions without storing raw prompts or outputs, reducing privacy risk while preserving debugging value.
Should AI Agents Use Semantic or Deterministic Testing?
The testing strategy depends on the question being asked. Semantic evaluation, where another AI model judges the output, remains valuable for assessing helpfulness, tone, factuality, and other open-ended qualities. But many agent failures are structural trajectory failures that should be testable without asking another model to judge them.
Deterministic testing belongs in continuous integration (CI) because it is inexpensive, explainable, and repeatable. Objective questions should be evaluated deterministically: Did the required tool run? Did the run finish? Did a recorded outcome fail? Did the run exceed a token or duration budget? These are facts about a captured trajectory, and the same rules should produce the same result for the same trace. Semantic evaluation can use model grading or human review where ambiguity justifies the additional cost and variance, but a merge-blocking rule should be deliberately boring whenever the underlying question is objective.
The distinction matters because it changes how teams approach quality gates. A rule that blocks a merge should be explainable to another engineer without requiring them to run the agent again or trust a screenshot. If the rule is "Did the agent call retrieve_policy before generate_answer?" that is testable and repeatable. If the rule is "Is the answer good?" that requires human judgment or model evaluation, and it should not be the default CI gate.
What Privacy Risks Come With Sharing Agent Traces?
Agent traces combine user messages, retrieved documents, system instructions, tool arguments, outputs, identifiers, and credentials. The raw run is often the best debugging artifact and the worst thing to paste into a public issue. A safer approach separates the source trace from the shared artifact, with an explicit human decision before sharing.
Redaction is not magic. A scanner can miss context-specific secrets, and a value may become sensitive when combined with another field. Therefore, a redacted artifact should not be presented as "certified safe." The more accurate term is share-checked: a best-effort derived artifact that passed a stated local policy and still requires human review before being shared externally. Before choosing a tool or process, teams should define what a reviewable run artifact must guarantee and ensure instrumentation captures the necessary information to verify those guarantees.
As AI agents move from experimental projects into production systems, the ability to reproduce, review, and test agent behavior becomes as critical as the ability to test traditional software. The difference is that agent failures can hide inside plausible-looking answers, making structural correctness invisible without the right artifacts and tools.