The green build that proves nothing about the agent
Your CI pipeline is green. The service compiles, the container starts, the health endpoint returns 200. Somewhere inside that process an LLM agent decided which tool to call, read the result, and wrote an answer. None of that was checked.
Infrastructure security does not establish whether an LLM agent selected an allowed tool, grounded its answer in tool output, or followed a required workflow. That sentence is the premise of a recent paper describing AgentTrustCI, a Java/JUnit 5 framework that turns those three questions into build-time checks over recorded traces (arXiv cs.SE).
The idea is worth understanding even if you never touch Java, because the mechanism is portable: record what the agent did, then assert against the record instead of against the model.
What a trace is, and why it is the right unit to test
A trace is an ordered log of one agent run. For each step it holds the model's output, the tool it chose, the arguments it passed, the tool's return value, and the final answer. It is the only artifact that contains all three things you actually care about: which tool ran, what the tool said, and what the agent claimed afterwards.
Testing the live model in CI is a bad fit. It costs money per run, it is slow, and it is nondeterministic — the same prompt can produce a different tool call on Tuesday. Testing the trace is a better fit. The trace is a fixed input. Replay it through your validators and you get a fixed verdict.
AgentTrustCI splits the work into three check families, and the split matters because each one catches a different class of bug:
- Policy checks — was every tool call on the allowlist for this agent?
- Grounding checks — does the final answer actually cite or derive from tool output, rather than from the model's memory?
- Trajectory checks — did the steps occur in the required order?
The paper's own example is the clearest argument for the third family: an answer that is correctly grounded can still have been obtained through a disallowed sequence. Grounding alone passes it. Only the trajectory check fails it.
A worked example: three assertions over one trace
The framework is Java/JUnit 5, and the paper describes a deterministic replay implementation plus an optional judge interface. The exact API is not something I can reproduce faithfully from the abstract, so the example below is a small, self-contained Node.js harness that implements the same three checks over a JSON trace. The shape is what transfers; swap the assertions into JUnit 5 @Test methods if you are on the JVM.
// agent-trace.test.js — run with: node agent-trace.test.js
import assert from "node:assert/strict";
import { readFileSync } from "node:fs";
const ALLOWED_TOOLS = new Set(["lookup_order", "issue_refund", "escalate"]);
const REQUIRED_ORDER = ["lookup_order", "issue_refund"];
function loadTrace(path) {
try {
return JSON.parse(readFileSync(path, "utf8"));
} catch (err) {
throw new Error(`could not load trace at ${path}: ${err.message}`);
}
}
function toolCalls(trace) {
return trace.steps.filter((s) => s.type === "tool_call");
}
function checkPolicy(trace) {
for (const call of toolCalls(trace)) {
assert.ok(
ALLOWED_TOOLS.has(call.tool),
`disallowed tool "${call.tool}" at step ${call.index}`
);
}
}
function checkGrounding(trace) {
const cited = new Set(trace.answer.citations ?? []);
assert.ok(cited.size > 0, "answer cites no tool output");
for (const ref of cited) {
assert.ok(
trace.steps.some((s) => s.type === "tool_call" && s.id === ref),
`answer cites ${ref}, which is not a tool call in this trace`
);
}
}
function checkTrajectory(trace) {
const seen = toolCalls(trace).map((c) => c.tool);
let cursor = 0;
for (const tool of seen) {
if (tool === REQUIRED_ORDER[cursor]) cursor += 1;
}
assert.equal(
cursor,
REQUIRED_ORDER.length,
`required order ${REQUIRED_ORDER.join(" -> ")} not satisfied; saw ${seen.join(" -> ")}`
);
}
const trace = loadTrace("./traces/refund-happy-path.json");
checkPolicy(trace);
checkGrounding(trace);
checkTrajectory(trace);
console.log("trace checks passed");The trace file it expects looks roughly like this — one tool call, one answer that points back at it:
{
"steps": [
{ "index": 0, "type": "tool_call", "id": "c1", "tool": "lookup_order", "result": { "status": "shipped" } },
{ "index": 1, "type": "tool_call", "id": "c2", "tool": "issue_refund", "result": { "refund_id": "r_88" } }
],
"answer": { "text": "Refund r_88 issued.", "citations": ["c2"] }
}Three assertions, three failure modes. The policy check fails when someone adds a tool to the agent's toolbox and forgets to update the allowlist. The grounding check fails when the model answers from prior knowledge and cites nothing. The trajectory check fails when the agent issues a refund before it looks at the order.
How this fits into a real build
The pattern is: capture traces in staging or from a replay corpus, commit the interesting ones as fixtures, and run the checks as ordinary unit tests. The paper describes a deterministic replay implementation for exactly this reason — the validator run should be repeatable and fast, not a second network call.
A senior engineer would treat the fixture set as a regression suite with intent. Each trace should exist because it represents a scenario you care about: the happy path, the escalation path, the path where the model tries a tool it should not have. When a production trace reveals a new failure, you add it as a fixture. The suite grows from incidents, not from imagination.
The paper reports results on 55 synthetic cases across seven enterprise domains, where the full pipeline correctly classified all 30 injected faults and 25 passing controls, and each single-layer configuration classified 35 cases because the corpus deliberately isolates ten faults per layer. Read that carefully: the corpus was built so that each layer has its own dedicated faults. It demonstrates that the checks fire on the faults they were designed for. It does not demonstrate that they fire on faults nobody anticipated.
Determinism versus model nondeterminism
This is the tradeoff that decides whether the approach is useful to you.
Property — Deterministic replay — Live model testing · Cost per run — Near zero — Per-token API cost · Repeatability — Same verdict every time — Varies run to run · Catches orchestration regressions — Yes — Yes, noisily · Catches model behavior change — No — Yes · Debuggable failure — Exact trace — Prompt and luck
Replay tests the contract between your code and the trace. If you change the allowlist, the required workflow, or the grounding rule, replay catches it. If the model provider silently updates the model and it starts choosing a different tool, replay does not notice — your recorded traces still contain the old choices.
That is not a flaw in the framework; it is the boundary of what a recorded artifact can prove. You need both: replay for the contract, and a smaller, slower live-evaluation pass for model behavior. The small-team AI eval stack is a reasonable starting point for the second half.
What a judge interface can and cannot verify
AgentTrustCI includes a judge interface as an extension point for optional semantic evaluation. The paper is explicit that it is optional and an extension point, not the core mechanism.
A judge is an LLM asked to grade an output. It is useful for things structural checks cannot express: whether the answer is phrased helpfully, whether a summary is faithful in tone, whether an escalation message contains the right context. It is not useful as a substitute for the policy check, because a judge asked "was this tool allowed?" is doing string matching with extra cost and extra variance.
The limits are worth stating plainly. Judge verdicts are not deterministic, so a judge-backed test can flake. Judge verdicts depend on the judge model, so a model change can flip a test without any change to your code. And a judge can be talked into agreement by a persuasive answer, which is the same failure mode as any other LLM-as-grader setup. Use the judge for the semantic residue, keep the structural assertions structural, and do not let a judge failure block a merge unless you have measured its stability.
Where trace-based tests give false confidence
Four failure modes are worth watching for.
Fixtures that only encode success. If every committed trace is a happy path, your suite proves the agent can succeed when nothing goes wrong. The paper's corpus deliberately includes injected faults and non-trivial controls for this reason. Your fixtures should too.
Checks written to match the current behavior. If you generate the expected trajectory by recording the agent and pasting it into the test, you are asserting that the agent does what it currently does. That is a snapshot, not a contract. Write the expected order by hand from the requirement.
Grounding checks that only look for a citation field. An agent that cites a tool call it did not use, or cites a call whose result it ignored, passes a naive check. Compare cited IDs against actual tool calls, as the example does, and consider whether the cited result supports the claim.
Silent drift in the trace format. If the recorder changes its schema, the validator may pass on empty data. Assert that the trace has the steps you expect before asserting anything about them.
There is also a coverage question the paper is honest about: the results establish coverage of the authored regression suite, not production accuracy. A passing suite means your agent honors the contracts you wrote down. It does not mean the agent is correct in the world. For the broader architectural view of why agents misbehave, prompt injection is an architecture problem is a useful companion read — policy checks catch the symptom, not the cause.
Maintaining expectations as workflows evolve
The paper names maintenance of expectations as an open concern, and it is the practical cost of this approach. Workflows change. A refund flow gains an approval step; the required trajectory changes; every fixture that encodes the old order now fails.
That failure is the point — it is a signal that a contract changed — but it is also work. The mitigation is to keep the expectation definitions small and named, so a workflow change touches one constant rather than twenty test methods. In the example above, REQUIRED_ORDER is the single place the order lives.
A reasonable rule: if a workflow change requires editing more than a handful of expectations, the expectations are too coupled to implementation detail. Move them up a level.
Further reading
- Durable Agent Workflows: State, Retries and Merge Gates
- Routing LLM Requests by Constraint Structure: A Practical Guide to