TL;DR — Key Takeaways

  • Every action counts: AI agent audit trails must capture approved and denied tool calls while protecting sensitive information through keyed cryptographic digests.

  • Hash chains have limitations: Without independently stored signed checkpoints, attackers can potentially rewrite or truncate audit records without detection.

  • Build evidence, not just logs: Separate trust domains, scheduled verification and reconciliation with downstream access records strengthen audit integrity and regulatory accountability.

Auditors ask two things about an agent action. What did it do, and can you show the record was not changed afterward? Most deployments answer the first with application logs and the second with access controls on the log store. That holds until the system writing the logs is also the system an attacker is trying to steer or until someone with database access has a reason to tidy up. The HIPAA Security Rule asks for both audit controls and integrity protection for systems that hold patient data, and the same logic applies in banking and insurance.

A hash chain is the usual answer to the second question, and it is easy to get wrong in ways that only show up when you try to break it. Here are the attacks a small reference implementation catches, and two it does not.

What Goes in an Entry

One entry per tool call, including the calls the policy layer denied. Denials matter as much as approvals: A run of denied calls against other patients’ records is the first sign that an agent has been redirected. Each entry records the agent’s own identity, the person it acted for, the tool, the policy decision and digests of the input and output.

body = {

"seq": n,

"ts": now,

"agent_id": agent_id, # the agent, not the clinician

"principal": principal, # the person it acted for

"tool": tool,

"args_digest": hmac_sha256(field_key, canonical(args)),

"decision": decision, # allow | deny | escalate

"reason": reason,

"result_digest": hmac_sha256(field_key, canonical(result)),

"prev_hash": last_entry_hash,

}

body["entry_hash"] = sha256(canonical(body))

Two choices need explaining. The log stores digests of arguments and results, not the data, so the audit trail does not become a second copy of it. Those digests are keyed: A plain SHA-256 of {“patient”: “p12”} can be reversed by hashing every plausible patient ID, which is how we noticed the problem in our first version.

What the Chain Catches

Each entry carries the hash of the one before it, so changing anything breaks every link after it. We ran eight attacks against a 1,000-entry log with a checkpoint every 100 entries:

Where a Bare Chain Fails

A hash chain proves the entries you have are consistent with each other. It cannot prove you have all of them, or that the chain is the original. Remove entries from the end and what remains is still valid. An attacker with write access can also edit an entry and recompute every later hash, because the hash function is public. Both attacks pass verification.

The fix is to put something outside the attacker’s reach. Periodically, here every 1,000 entries, sign the latest sequence number and entry hash and write that checkpoint to a separate store.

if (seq + 1) % 1000 == 0:

sig = sign(checkpoint_key, f"{seq}:{entry_hash}")

external_store.put({"seq": seq, "entry_hash": entry_hash, "sig": sig})

‘Separate’ means a different trust domain, not a different table: Credentials the agent platform and the log administrators do not hold, and a store with write-once retention. Sign with an asymmetric key in a KMS or HSM so verifiers need only the public half. (Our demo uses HMAC to stay in the standard library; do not copy that.) The same idea underlies the signed tree heads in Certificate Transparency, where independent monitors keep a log operator from quietly rewriting history.

Checkpoints narrow the window but do not close it. In our test, truncating 30 entries after the last checkpoint was not detected. The exposure is the checkpoint interval, so pick it by how much unverified tail you can tolerate. Time-based checkpoints, such as one every 60 seconds regardless of volume, bound the window in time rather than in entries.

Cost

On a developer laptop, single-threaded Python 3.9 appended 100,000 entries in about 1.1 to 1.5 seconds across runs (roughly 70,000 to 90,000 per second) and verified them in 0.57 seconds. Entries averaged 473 bytes, so 100,000 entries is about 47 MB. Hashing is not the constraint.

The real constraint is that a chain is sequential, since each append needs the previous hash. Either keep one chain per agent instance, each with its own checkpoints or run a small sequencer that assigns order. Per-agent chains are simpler; cross-agent ordering then relies on timestamps, so keep clocks disciplined.

What This Doesn’t Prove

Tamper evidence shows a record was not changed after it was written, not that it was right in the first place. If the gateway logs a call that never happened or misses one that did, the chain preserves the error. Log at the single enforcement point every tool call must pass, and reconcile the log against downstream systems’ own access records. Plan key rotation before the first checkpoint, since old public keys must stay trusted for old checkpoints.

Checklist

  • Log every tool call, denials included, with the agent’s own identity and the person it acted for.
  • Store keyed digests of arguments and results, not the data.
  • Chain entries and verify the chain on a schedule, not only during an incident.
  • Write signed checkpoints to a store the log administrators cannot modify.
  • Reconcile the log against downstream access records.

None of this needs exotic tooling. Start with the checkpoints: The chain is the easy part, and a signed checkpoint kept out of the log administrator’s reach is what turns it from a convenience into evidence. Then verify on a schedule, so you find tampering before an auditor does.