# Agent changes and undo

> Lydie records which agent made each change and for whom, and can undo everything one agent session did in one step.

Lydie treats agents as their own kind of author. People can see what an agent changed and undo it
without losing their own work.

## Who made a change

Every write records an actor:

| Actor  | Recorded as                  | Example                     |
| ------ | ---------------------------- | --------------------------- |
| User   | The user id                  | A person typing in the app  |
| Agent  | `agent:<app>:<id>:<user id>` | An API token, an MCP client |
| System | `system:<id>`                | Lydie itself                |

The `app` of an agent is `api-token` for personal API tokens, or the client's name for OAuth apps.
`<user id>` is the person the agent acts for. This value is what `createdBy` and `updatedBy` hold
on documents.

## Sessions

Changes made over [MCP](https://developers.lydie.co/mcp.md) are grouped into a session, one per credential. Each API token is one
session, and so is each app you approved with OAuth. The session stays the same when an OAuth app
refreshes its token.

| MCP tool               | REST                                                             |
| ---------------------- | ---------------------------------------------------------------- |
| `list_sessions`        | [List agent sessions](https://developers.lydie.co/api/history/list-agent-sessions.md)          |
| `list_session_changes` | [List a session's changes](https://developers.lydie.co/api/history/list-a-sessions-changes.md) |
| `undo_session`         | [Undo a session](https://developers.lydie.co/api/history/undo-a-session.md)                    |

The MCP server tells the agent its session id when it connects, so an agent can review its own
work.

## Undo a session

Undoing a session reverts its changes newest first, as one step that can itself be undone. If
someone else has since changed something the agent touched, that change is skipped and reported,
so their work is kept.

Most changes can be undone; the reference marks those that can. Permanent deletions (purging a
document, emptying the trash) cannot be undone.
