# Follow what an agent did

> Read every token an agent was issued or refused, every exchange, every policy decision and every status change, per agent or per user.

After the fact, security and compliance teams and agent owners ask *what did this agent do?*, and users ask *what
did agents do for me?* The realm's audit trail answers both, one agent or one user at a time.

**Before you start:**

- **Who can do it:** to read anyone's trail but your own, a realm administrator or a member of a group holding
  `RealmViewer`; any user reads their own.
- **Where:** the API, one principal at a time ([Call the API](/develop/api/) shows how to get `$CVYUH_SESSION`). In
  the dashboard, **Audit → Authentication** lists the realm's authentication records, tokens included, and
  **Audit → Config** its changes, agents' included.
- **What you need:** the agent's or the user's id, the `id` their record carries.

## Read the trail

<Steps>

1. Read one agent's trail:

   ```sh
   curl "https://foobar.cvyuh.com/api/v0/am/audit/v1/trail?agent=6f1c2a9e-4b7d-4e3a-9c51-2d8f0b7a1e44" \
     -H "Cookie: x-cvyuh-token=$CVYUH_SESSION"
   ```

2. Or one user's, which includes what agents did in their name:

   ```sh
   curl "https://foobar.cvyuh.com/api/v0/am/audit/v1/trail?person=9d4e2a71-0c3b-4f5e-8a6d-1b7c9e2f0a34" \
     -H "Cookie: x-cvyuh-token=$CVYUH_SESSION"
   ```

   A user reads their own at `https://foobar.cvyuh.com/api/v0/am/audit/v1/trail/me`. Both answer a page at a time, chosen with `page` and
   `pageSize`.

</Steps>

## What the trail shows

| Entry | Says |
|---|---|
| Token issued | which grant, what was asked, what was granted, for which API, the token's id, the agents acting |
| Token refused | what was asked, and why it was refused |
| Exchange | the user, the agents outermost first, the token it came from and the one issued, or why refused |
| Policy decision | allow or deny, on what, for whom |
| Status change | `AGENT_QUARANTINED`, `AGENT_RELEASED`, `AGENT_KILLED` or `AGENT_RETIRED`, with before and after, and who made it |
| Revocation | `TOKEN_REVOKED` (a client revoked a token), `APP_TAKEN_BACK` or `AGENT_TAKEN_BACK` (a user removed an app or an agent), always recorded |

Each entry carries the ids that tie it to the rest of the same piece of work, such as the token's id and the
sign-in's `sid`, so you can follow one request from a token to every exchange made from it. A refused token request
says which error the agent got, such as `invalid_client`; the reason behind an `invalid_client` isn't recorded, so
read the agent's chain to find it ([AI agents](../../../agents/ai-agents/#troubleshooting)).

## Record every decision

By default the trail keeps every deny and every decision involving an agent. To add each user's own allowed
requests too:

```sh
curl -X PATCH https://foobar.cvyuh.com/api/v0/am/objects/v1/authorizationSettings/authorizationSettings \
  -H "Cookie: x-cvyuh-token=$CVYUH_SESSION" \
  -H "Content-Type: application/json" \
  -d '{ "auditDecisions": "all" }'
```

That's a record per request, and it grows fast.

<Aside type="note" title="Gateway decisions">
  The gateway's own decisions aren't on this trail yet. See
  [Gateway decisions on the trail](/audit-reports/audit-trail/whats-next/#gateway-decisions-on-the-trail).
</Aside>

## Check it worked

The answer's `events.totalCount` counts every record about the principal. A brand-new agent has none until its first
token request; a status change you just made shows at the top of `events`, and in `changes` for an agent.

## Related

- [Audit trail](../../../../audit-reports/audit-trail/): everything the trail records.
- [Stop an agent](../stop-an-agent/): the status changes you'll find here.
- [Let an agent act for a user](../agent-acts-for-a-person/): the exchanges you'll find here.
