Audit trails for AI agents: attributing actions to autonomous systems
An agent books a refund, deletes a record, or ships a config change, and three weeks later someone asks why. Your audit log says the action was performed by svc-support-agent. That is true and useless. It does not say which customer-support rep asked the agent to act, whether the agent was operating within the authority that rep delegated, or whether the agent went off-script. When autonomous systems act on behalf of people, a single-actor audit record is a liability: it either over-blames the human for something the agent did unprompted, or it hides the human behind the machine entirely.
Three things every agent action must record
A defensible audit trail for delegated action captures a chain, not a single actor:
- The agent — the non-human identity that actually performed the action, including its version or model, because agent behavior changes between releases.
- The delegating principal — the human (or upstream service) on whose behalf the agent acted.
- The authority — the specific grant that made the action legitimate: the scope, the token, the policy, or the explicit user confirmation that authorized this class of action.
Record all three on every event and you can answer the only questions that matter after the fact: who wanted this done, what did the machine do, and was it allowed to.
A record shape that holds the chain
Model the actor as a delegation chain rather than a flat field. OAuth's token-exchange and "actor" concepts (RFC 8693) give you the vocabulary: a sub (the party the action is for) and an act (the party actually acting), nestable to any depth.
{
"event_id": "evt_9f2c1a",
"timestamp": "2026-07-21T14:32:07Z",
"action": "refund.issue",
"resource": "order/88213",
"outcome": "success",
"on_behalf_of": {
"sub": "user/rep_4471",
"name": "support rep",
"auth_method": "sso"
},
"actor": {
"sub": "agent/support-copilot",
"type": "ai_agent",
"model": "copilot-2026.06",
"token_id": "tok_7731",
"scopes": ["refunds:issue"]
},
"authority": {
"grant": "delegated",
"confirmation": "user_approved",
"constraint": "amount <= 200.00",
"actual_amount": 149.00
}
}Note the authority block. It does more than name a scope: it records the constraint the grant carried and the actual value the action used, so a reviewer can confirm the agent stayed inside its mandate without re-deriving the policy.
Dynamic linking: bind the record to the specifics
Prompt provenance, within reason
You will be tempted to log the full prompt and the model's reasoning for every action. Capture enough to reconstruct intent — the user instruction and the tool call arguments — but treat raw model output and chain-of-thought as sensitive and often noisy. A stable reference to the triggering request plus the structured tool call is usually more useful in an investigation than pages of generated text, and far less of a data-retention problem.
Keep the log trustworthy
An audit trail is evidence, so it must resist the people and systems it records:
- Append-only. The agent's credential must be able to write events, never to edit or delete them. Separate the write path from any administrative path.
- Tamper-evident. Chain each record to the previous one with a hash so a deletion or edit breaks the chain. For high-stakes logs, periodically anchor the chain head somewhere the operators of the log cannot quietly rewrite.
- Clock-disciplined. Use a single trusted time source; a delegation chain is meaningless if you cannot order the events in it.
-- Reconstruct everything one agent did on behalf of one user
SELECT timestamp, action, resource, outcome,
authority->>'constraint' AS mandate,
authority->>'actual_amount' AS used
FROM audit_events
WHERE actor->>'sub' = 'agent/support-copilot'
AND on_behalf_of->>'sub' = 'user/rep_4471'
AND timestamp >= now() - interval '30 days'
ORDER BY timestamp;What good looks like in an investigation
When a regulator, a customer, or your own incident responder asks about an agent action, the answer should be a single query that returns: the action and its exact parameters, the human behind it, the authority that permitted it, the constraint on that authority, and whether the action respected it. If any of those five is missing, the trail has a hole that someone will eventually fall into.
Retention and the right to explain
Agent audit trails collide with two opposing pressures. Security and compliance want long retention and rich detail; privacy law and storage cost want the opposite. Resolve it by separating the accountability record from the diagnostic context. The accountability record — action, parameters, delegating principal, authority, outcome — is small, structured, and worth keeping for your full compliance horizon. The diagnostic context — prompts, retrieved documents, model output — is large and often contains personal data; keep it shorter, reference it by ID from the accountability record, and purge it on a schedule you can defend.
This split also answers the question customers increasingly ask: "why did your agent do that to my account?" With the accountability record you can state what happened and under whose authority in seconds; with a short-lived, referenced context you can, within its retention window, explain how — without having turned your audit store into an indefinite archive of everyone's personal data a model once saw.
Autonomous systems do not remove humans from the loop of responsibility; they lengthen the chain, and your audit log has to represent the whole chain or it misrepresents who did what. Owning the identity and audit layer that both your humans and your agents authenticate through is what lets you keep that chain complete and the log tamper-evident on your own terms. The alternative is reconstructing accountability from a vendor's export after the fact.
Run it yourself
Bastionary is free, open-source software. Follow the quick start to have it running on your own server, or browse the releases on Git.