|
| 1 | +--- |
| 2 | +summary: "CLI reference for metadata-only agent run and tool action audit records" |
| 3 | +read_when: |
| 4 | + - You need to answer who ran an agent or tool, when it ran, and how it ended |
| 5 | + - You need a bounded, redaction-safe activity export |
| 6 | +title: "Audit records" |
| 7 | +--- |
| 8 | + |
| 9 | +# `openclaw audit` |
| 10 | + |
| 11 | +Query the Gateway's metadata-only audit ledger for agent runs and tool actions. |
| 12 | + |
| 13 | +Recording is on by default; set [`audit.enabled: false`](/gateway/configuration-reference#audit) |
| 14 | +to stop new writes. Existing records stay queryable until they expire (30 days). |
| 15 | +The ledger is separate from conversation transcripts: it records identity, |
| 16 | +ordering, provenance, action, status, and normalized error codes, but never |
| 17 | +stores prompts, messages, tool arguments, tool results, command output, or raw |
| 18 | +error text. |
| 19 | + |
| 20 | +The Gateway writes records to the shared OpenClaw state database through a |
| 21 | +bounded background writer. Queries never return records older than 30 days, |
| 22 | +and the ledger is capped at 100,000 rows. Expired rows are deleted during |
| 23 | +Gateway startup, hourly maintenance, and later writes. |
| 24 | + |
| 25 | +```bash |
| 26 | +openclaw audit |
| 27 | +openclaw audit --agent main --status failed |
| 28 | +openclaw audit --session "agent:main:main" --after 2026-07-01T00:00:00Z |
| 29 | +openclaw audit --run 8c69f72e-8b11-4c54-98d5-1a3dd67450c3 |
| 30 | +openclaw audit --kind tool_action --limit 50 --json |
| 31 | +``` |
| 32 | + |
| 33 | +## Filters |
| 34 | + |
| 35 | +- `--agent <id>`: exact agent id |
| 36 | +- `--session <key>`: exact session key |
| 37 | +- `--run <id>`: exact run id |
| 38 | +- `--kind <kind>`: `agent_run` or `tool_action` |
| 39 | +- `--status <status>`: `started`, `succeeded`, `failed`, `cancelled`, |
| 40 | + `timed_out`, `blocked`, or `unknown` |
| 41 | +- `--after <timestamp>` / `--before <timestamp>`: inclusive ISO timestamp or |
| 42 | + Unix milliseconds |
| 43 | +- `--limit <count>`: page size from 1 to 500; default `100` |
| 44 | +- `--cursor <sequence>`: continue a previous newest-first query |
| 45 | +- `--json`: print the bounded page as JSON |
| 46 | + |
| 47 | +Text output shows time, kind, status, agent, run, and action. Tool actions also |
| 48 | +show the tool name. JSON output is a safe bounded export of the same metadata |
| 49 | +and includes `nextCursor` when another page exists. Pass that value to |
| 50 | +`--cursor` to continue without reordering records that arrive during paging. |
| 51 | + |
| 52 | +## Recorded events |
| 53 | + |
| 54 | +The Gateway projects existing agent event streams into four actions: |
| 55 | + |
| 56 | +- `agent.run.started` |
| 57 | +- `agent.run.finished` |
| 58 | +- `tool.action.started` |
| 59 | +- `tool.action.finished` |
| 60 | + |
| 61 | +Every record has a stable event id, a monotonically increasing ledger sequence, |
| 62 | +the original run event sequence, lifecycle timestamp when the runtime provides |
| 63 | +one (otherwise observation time), agent/run provenance, actor, and a |
| 64 | +`redaction: "metadata_only"` marker. Terminal records distinguish success, |
| 65 | +failure, cancellation, timeout, and policy blocks with closed status and error |
| 66 | +codes. `unknown` is an explicit non-success result when an upstream runtime |
| 67 | +does not expose an authoritative terminal outcome. Tool call ids are exported |
| 68 | +only as stable one-way fingerprints. Tool names must match the compact |
| 69 | +model-facing name contract; other values become `unknown`. Session ids, session |
| 70 | +keys, run ids, and retained tool names are operator metadata; protect exports |
| 71 | +as operational records. |
| 72 | + |
| 73 | +The audit ledger does not replace transcripts, task history, cron run history, |
| 74 | +or logs. It provides a small cross-run index for operator questions without |
| 75 | +copying conversation content into another store. |
| 76 | + |
| 77 | +## Gateway RPC |
| 78 | + |
| 79 | +`audit.list` requires `operator.read` and accepts the same filters. Example: |
| 80 | + |
| 81 | +```bash |
| 82 | +openclaw gateway call audit.list --params '{"agentId":"main","status":"failed","limit":50}' |
| 83 | +``` |
| 84 | + |
| 85 | +The result is `{ "events": AuditEvent[], "nextCursor"?: string }`. Results are |
| 86 | +newest first and limited to 500 records per request. |
| 87 | + |
| 88 | +## Related |
| 89 | + |
| 90 | +- [Gateway protocol](/gateway/protocol#audit-ledger-rpc) |
| 91 | +- [Sessions](/cli/sessions) |
| 92 | +- [Tasks](/cli/tasks) |
| 93 | +- [Cron jobs](/automation/cron-jobs) |
0 commit comments