Skip to content
mentoor

Topic 5 of 5 · 5 min read

Audit trails for agent actions

Goal: Check an agent action log for the fields needed to explain and reverse a specific action.

Write an audit record for every action an agent takes in the world, with enough fields to answer three questions later: who or what allowed it, exactly what it did, and how to undo it.

Check yourself · 1 of 3

Which question can an audit record for an agent action NOT be expected to answer by itself?

Choose one answer

Why it matters

When a customer asks "why did your system cancel my order?", or a regulator asks who approved a data export, "the AI did it" is not an answer. Support needs to find the action. Engineers need to reproduce it. Compliance needs to show it was authorised. And someone may need to reverse it today. A trace of model calls is not enough, because it records thinking, not effects.

What each record holds

  1. Identity. A unique action id, the run id, a timestamp, the agent and its version.
  2. Authority. On whose behalf it acted (the user), and what allowed it: a permission, a policy rule, or an approval by a named reviewer with their id.
  3. The action. The tool name and the arguments, with secrets and personal data redacted or referenced by id.
  4. The result. Success or error, the response, and the ids of the objects created or changed.
  5. Reversal. The inverse action and its arguments, or a note that the action is irreversible. Irreversible actions are good candidates for human approval.
  6. Integrity. Records are append-only. People and agents should not be able to edit them.
{
  "actionId": "act_8821",
  "runId": "run_3307",
  "at": "2026-11-30T09:14:02Z",
  "agent": "support-agent@v14",
  "onBehalfOf": "user_552",
  "authorisedBy": { "type": "approval", "reviewer": "rev_19", "ruleId": "refund_over_100" },
  "tool": "create_refund",
  "args": { "orderId": "ord_7712", "amount": 140.00 },
  "result": { "status": "ok", "refundId": "rf_4409" },
  "reverse": { "tool": "cancel_refund", "args": { "refundId": "rf_4409" } }
}

Before and after

Before: the log line reads refund created ord_7712 140.00. Nobody can tell which run did it, whether anyone approved it, or how to reverse it. After: the record above answers all three in one lookup.

Keep it useful and safe

Store the record in your own database, not only in a vendor's trace tool. Set a retention period that matches your legal needs. Keep personal data out of the args when an id will do. Never store secrets or full request bodies.

What goes wrong

  • Logging the model's reasoning but not the effect. You know what it thought, not what changed.
  • No authority field. You cannot show the action was allowed.
  • No reversal data. Undoing means reading code and guessing.
  • Editable logs. A record that can be rewritten proves nothing.

Examples

Answering a support ticket

A customer says a subscription was cancelled by mistake. Support searches for the order and finds act_9034: cancel_subscription, run run_4120, on behalf of the customer's own session, authorised by policy self_service_cancel, with the reverse reactivate_subscription. In two minutes they see the customer asked for it in chat, and the reversal is one click.

A record that fails the check

{ "at": "2026-11-30T09:14:02Z", "tool": "delete_records", "result": "ok" }

There is no run id, no arguments, no authority and no reversal. Nobody can say what was deleted or who allowed it.

Key points

  • Record every action with identity, authority, inputs, result and reversal, not only the model's reasoning.
  • The authority field names the user, and the permission, rule or approval that allowed the action.
  • Store the inverse action, or mark the action irreversible and require approval for it.
  • Make audit records append-only and keep them in a store you control.
  • Redact secrets and personal data, and store ids instead of full payloads where possible.

Common mistakes

  • Keeping only model traces and treating them as the audit log.
  • Leaving out who approved the action, so authorisation cannot be shown.
  • Logging full request bodies with secrets or personal data.
  • Letting operators or the agent itself edit past records.

Check yourself · 2 of 3

A log line says: refund created, order 7712, 140.00. Which field is the most important one missing for compliance?

Choose one answer

Check yourself · 3 of 3

Why should audit records be append-only?

Choose one answer

Practice items, not counted towards your mastery.

Start here

More for this topic