An AI agent audit trail is a record of every case the agent handled: what came in, what the agent read, which rule decided the outcome, what it changed in which system, and who approved it. The test is simple. Six months from now, someone picks one invoice, one ticket or one order and asks why it ended up the way it did. If the log answers that without anyone rerunning the agent or asking the person who built it, the trail is good enough.
Most agent logs fail that test. They hold the model's text, a timestamp and maybe an error. That is enough to debug a prompt. It is not enough to explain a booking to an auditor or a refund to a customer.
I build agents for companies of 20 to 250 people, and every build I deliver includes an audit trail. What follows is how I set one up, not a report from a client project.
The questions the log has to answer
Write these down before you decide on any field. Each one comes from someone outside the build team.
- The finance lead. Why was this invoice booked to this account, and who released the payment?
- The customer. Why did I get this reply, and did a person see it before it went out?
- The auditor. Which version of the rules applied on that day, and can the record have been changed since?
- The team lead. Which cases did the agent hand to a person, and how long did they wait?
- The person who owns the agent. What changed in the week the error rate went up?
If a question on your list has no field behind it, add the field. If a field answers none of the questions, drop it.
What to log for every case
One case is one unit of work: an invoice, an email, an order. Every case gets one record with a stable ID, and every step inside it points back to that ID.
| Field | What it holds | Why |
|---|---|---|
| Case ID | One ID from intake to close | Lets you follow one invoice across systems |
| Input | The original email or file, stored unchanged, or a pointer to where it is kept | Shows what the agent saw, not what someone later thinks it saw |
| Records read | Which master data, orders or tickets it looked up, with their values at that moment | The supplier's bank details may have changed since |
| Versions | The prompt version, the model name and the version of the rule set | Explains why the same input got a different result last month |
| Decision | The outcome and the rule or threshold that produced it | "Amount within 2% of the order" is a reason, a paragraph of model text is not |
| Action | Each write: system, record, field, old value, new value | Shows exactly what the agent changed |
| Approval | Who approved, when, and what they changed in the draft | Separates the agent's work from the person's |
| Hand-off | Whether the case went to a person, why, and when it was picked up | Measures the queue and the reasons it fills |
| Errors | Failed calls, timeouts, retries and refusals | A blocked action should be as visible as a completed one |
Two of these deserve a closer look.
Old and new values. "Updated supplier record" tells you nothing. "Changed payment terms on supplier 40112 from 30 days to 14 days" tells you what to undo. Log the values on both sides of every write.
The rule behind the decision. Models can write an explanation for anything, and that explanation is not always why the code acted. If a hard limit in code blocked a payment, log the limit and its value. I write about why those limits belong in code in a prompt is a request, a guardrail is a wall. The log should name the same rules the code enforces.
What not to put in it
An audit trail is often the largest store of copied business data in the whole setup. Keep it lean.
- Secrets. API keys, tokens and passwords never go into a log, not even in an error message. Mask them before they are written.
- More personal data than the case needs. Store a pointer to the original email instead of a second copy where you can. Set a retention period and a deletion job on the day you build the log, not the day someone asks.
- Every token the model produced. Keep the final output and the decision. Full model traces help while you tune the agent. Keep them for a short period and in a separate store, so the audit record stays readable.
Where the log lives
Three rules decide this.
In your accounts. The log belongs in your cloud account or your database, not only in a dashboard at the agent vendor. If you change vendors, the history stays with you.
Out of the agent's reach. The agent can add entries and nothing else. It cannot edit or delete earlier ones. Write the log to storage where the agent's credentials only allow appending, and keep a second copy somewhere the agent has no access to at all.
Readable without the builder. The finance lead should be able to search by invoice number in a tool they already use: a database view, a spreadsheet export or a page in your existing reporting. If every question has to go through the person who built the agent, nobody will ask until it is too late.
Who reads it, and when
A log nobody reads only proves something after the damage is done. Give it a schedule.
Weekly, the owner. Look at the hand-off rate, the reasons cases went to people and the five slowest cases. The escalation queue and the audit trail come from the same records, so the queue's numbers should match the log.
Monthly, a sample. Someone outside the build team draws twenty cases at random and checks each one against the source system. Did the record show what really happened? A mismatch here matters more than any error rate on a dashboard.
On every change. When the prompt, the model or a rule changes, the version field changes with it. Compare the week before and the week after.
Build it before go-live
The audit trail is not an add-on for later. Start it on the first day of shadow mode. In shadow mode the agent writes nothing to your systems, but it logs every decision it would have made. That log is how you compare its work with your team's. If the trail is missing then, you have nothing to judge the go-live on.
Pick one case the agent would handle and write down the five questions someone will ask about it in six months. If you want a second view of which fields your workflow needs, bring that list to a thirty-minute scoping call.