Designing an audit trail for agent actions
Record and inspect an audit event in RedDB, and understand the work required to make an audit trail reliable.
On this page
An event is not the same thing as an audit guarantee
Agent actions often involve database writes and external side effects. A useful audit trail records who acted, what happened, when, and which operation it relates to. The record is useful only if its completeness, access controls, retention and recovery are designed and tested.
Try the examples locally
Start RedDB with its HTTP endpoint bound to your local machine:
red server --http-bind 127.0.0.1:5000 --path ./example.rdb --dev--dev disables authentication and is only for a trusted local environment. In a second terminal, define a helper to send a query. It requires curl and jq:
query() {
curl -fsS http://127.0.0.1:5000/query \
-H 'content-type: application/json' \
--data "$(jq -cn --arg query "$1" '{query: $query}')"
}The examples below were executed against RedDB 1.26.8. Use a fresh database for this walkthrough; reusing names from another example can change the results.
Write and read an event
query 'CREATE TABLE audit_events (id TEXT, action TEXT, subject_id TEXT)'
query "INSERT INTO audit_events (id, action, subject_id) VALUES ('event-1', 'task.completed', 'task-1')"
query "SELECT id, action, subject_id FROM audit_events WHERE subject_id = 'task-1'"The tested query returns the event written above. This is a basic record, not a ready-made hook, trigger, append-only ledger or proof that every action was logged. Assign stable IDs in the application and use parameterized queries when writing real values.
Connect events to actions safely
Identify every action that must be audited, who may write and read audit data, and what information must not be logged. Where an action and its audit event must commit together, verify the transaction semantics and client behavior of your deployed RedDB version with a failure test. The two commands in this article are separate requests and do not demonstrate an atomic transaction.
External actions, such as sending an email or calling a third-party API, cannot be made atomic merely by inserting a database row. Define idempotency keys, retry and reconciliation behavior, and observe failed deliveries. See cross-session task queues for a tested native queue example and its limitations.
Exercise failure and recovery
Test interrupted writes, duplicate requests, unauthorized reads, backup restoration and retention or deletion requirements. Ensure the audit system has monitoring and does not expose secrets or personal data unnecessarily. Do not describe an event table as tamper-proof or complete until those properties are established for your deployment.
Ready to build with RedDB?
Create an account and explore the Always Free database.
Create your account →