What is a tamper-evident audit trail for AI agents?
An AI agent audit trail is a record of every action an agent tried, who it acted for, and why each action was allowed, denied or held for a person. It is tamper-evident when each entry is linked to the one before it by a cryptographic hash and the chain is signed with a key the writer does not control alone. Then anyone with a copy can check that nothing was changed, removed or reordered.
What should you record for each agent decision?
Record decisions, not just successful calls. A denial is evidence that a control worked. For each tool call, model call or administrative action, keep enough to answer "who did what, for whom, under which rule":
| Field | Why it matters |
|---|---|
| Agent and session | Which piece of software acted, in which run |
| The person it acted for | Accountability sits with a human or a team, not a process |
| Tool and server | What the agent tried to touch |
| A hash of the arguments | Proves exactly what was requested without storing personal data or secrets |
| Decision and rule | Allowed, denied or held, and the policy rule that decided |
| Approver | Who said yes when a human was in the loop |
| Time, latency, cost, trace ID | Ordering, performance and a link to your tracing system |
| Previous hash and own hash | The links that make tampering detectable |
Think carefully before you store raw prompts, completions or arguments. They often hold personal data, which turns your audit trail into a data-protection problem. A hash proves what was sent if the original turns up later.
How does hash chaining make a log tamper-evident?
A hash function turns any input into a short fingerprint. Change one character and the fingerprint changes completely. In a hash chain, each record stores the fingerprint of the record before it, and its own fingerprint covers that link.
So if someone edits record 1,042, its fingerprint no longer matches. Record 1,043 still points at the old fingerprint, and the chain breaks at that spot. Deleting or reordering a record breaks it in the same way. A verifier only has to walk the chain from the start and recompute each fingerprint.
For this to work in any language, the record must be turned into bytes the same way every time. That means a fixed, documented encoding: sorted keys, no extra whitespace, fixed time format.
Why do you also need signatures?
A hash chain on its own has a gap. Someone who can rewrite the whole file can recompute every fingerprint and produce a new chain that looks perfect. Signed checkpoints close that gap. At intervals, the system signs a short statement: "the chain had N records and its latest fingerprint was H". The signing key is held separately from the log.
A forger would now need that key too. If the key and the log sit in the same place, an attacker with full control could still re-sign. Two further steps help: keep copies of the checkpoints somewhere the writer cannot alter, such as write-once storage or your SIEM, and optionally publish the checkpoints to a public transparency log, where they are timestamped by someone else.
How does a third party verify an agent audit trail?
An auditor should not need to trust your servers, only your published public key. A good verification process looks like this:
- Get a copy of the log and the public keys for the checkpoints.
- Walk the chain: each sequence number follows the last, each "previous hash" matches, and each recomputed hash matches the stored one.
- Check each signed checkpoint's signature, and that its fingerprint matches the chain at that position.
- Compare the latest checkpoint with an independent copy (write-once storage, SIEM or a transparency log) to catch the newest records being cut off.
- Note any records after the last checkpoint. They are linked into the chain but not yet signed.
This turns "trust our logs" into a check anyone can repeat offline.
How long should you keep an AI agent audit trail?
It depends on your sector and the law that applies to you. For high-risk AI systems, the EU AI Act asks providers (Article 19) and deployers (Article 26(6)) to keep automatically generated logs for at least six months, unless other law says otherwise (Regulation (EU) 2024/1689). Financial and public-sector rules often require longer. Whatever the period, store the log in write-once storage with a retention lock, so it cannot be deleted early. See the EU AI Act and AI agents for the wider picture.
Where MAQPNA fits
The MAQPNA gateway writes an audit ledger: one record for every allowed, denied and held call, plus approvals, revocations, taint changes and administrative actions. It follows the design above.
- Records. Agent, session, the person the agent acts for, server, tool,
argsSha256, decision, rule (<policy>/<rule>), approver, latency, cost and trace ID. Raw arguments, prompts and completions are never stored. - Chain. Each record's hash is the SHA-256 of its canonical JSON and names the previous hash. The ledger format is documented with test vectors, so you can write your own verifier.
- Checkpoints. Ed25519-signed checkpoints of the head, by default every 60 seconds or 1,000 records, with a key you hold. Public keys are served at
GET /v1/audit/jwks. HMAC checkpoints are also available. - Copies elsewhere. Shipping to write-once storage (S3 Object Lock, GCS Bucket Lock, Azure immutable Blob) and to SIEMs, and optional anchoring of ledger heads in a Sigstore Rekor transparency log. Only hashes and sequence numbers leave for Rekor.
- Audit before result. In the production and sovereign profiles, an allowed call is refused if its intent record cannot be written first.
Verification is one command, offline. It exits with code 3 when the ledger was tampered with:
$ maqpna audit verify audit.jsonl --jwks jwks.json
OK: 18204 records, hash chain intact
OK: 19 Ed25519-signed checkpoints verified (last seq 18000, ...)
$ maqpna audit verify audit.jsonl
TAMPERED: chain breaks at seq 1043 after 1042 valid records: ...maqpna audit export builds an evidence bundle for a session, agent or time range, with the signed checkpoints and public keys inside. See the audit ledger flow. Honest limits: records after the last signed checkpoint are not yet anchored by a signature, and RFC 3161 timestamping is planned, not built. The ledger supports evidence for the EU AI Act's logging and oversight duties; it does not make you compliant on its own.
Related: how to stop an AI agent deleting a production database, what guardian agents are and the OWASP Agentic Top 10 mapping.