# Undo what the agent did

URL: /agents/undo-what-the-agent-did · Id: `guide:undo-what-the-agent-did` · Status: `live`

> Undo a done Action: what it created is deleted and stays restorable, what it changed goes back, and money returns through a new Action.

[Undo](/business/nouns/action/undo) reverses a done [Action](/business/nouns/action): each record it created is deleted and stays restorable, and each change it made goes back. Money it moved returns through a new Action, and a sent [Message](/business/nouns/message) stays sent.

**Before it runs**

- You leave the chat: Never.

## What you get
- 1 undone Action, linked to every record it removed and every change it put back (Action)
- 1 soft delete of each record the Action created, so each one can come back (Thing)
- 1 reversing Action for any money it moved, such as a refund, recorded in your books (Action)

## Your agent does
**For agents**

- Guide: `guide:undo-what-the-agent-did`, status `live`. Page: [/agents/undo-what-the-agent-did.md](/agents/undo-what-the-agent-did.md).
- Approval: none. Run it when the founder asks.
- Leaves the chat: never.
- Run: call the steps in order, each through the API, SDK, CLI or MCP tab below; a later step passes the `$id` an earlier one returns. Each value marked example is the sample business’s: pass the founder’s own.

| Step | Verb | Inputs (type, required, this guide’s value) | Returns |
| --- | --- | --- | --- |
| 1 | [`Action.undo`](/business/nouns/action/undo) (`verb:Action.undo`) | `action` Action (an id), required: the `$id` of the first Action `Action.list` returns for `where: status = done` | `action` Action |

Returns: the last call answers with its `action`, whose `status` is `done`, `pending` (waiting on an Approval or a Worker), `failed`, `canceled` or `refused`:

```json
{
  "api": "https://api.sb/leaseline.app",
  "action": {
    "$id": "https://api.sb/leaseline.app/actions/act_br07HsG8MG",
    "$type": "Action",
    "status": "done",
    "mode": "try",
    "operation": "Action.undo"
  },
  "links": {
    "self": "https://api.sb/leaseline.app/actions/act_br07HsG8MG"
  }
}
```

Next: offer “Bring back one record the undo removed”, or “Show me everything the agent did today”.

Calls: `Action.undo`

Ask:

```text
Undo what the agent did.
Take back the last thing the agent did.
Roll back the last thing support did.
```

API:

```bash
# Look up the Action: Action.list
ACTION=$(curl "https://api.sb/leaseline.app/actions?where=status%20%3D%20done&limit=1" \
  -H "Authorization: Bearer $STARTUP_BUILDER_API_KEY" | jq -r '.actions[0]["$id"] | split("/") | last')

# Action.undo
curl -X POST https://api.sb/leaseline.app/actions/$ACTION/undo \
  -H "Authorization: Bearer $STARTUP_BUILDER_API_KEY"
```

SDK:

```ts
import { $ } from 'startup-builder'

const [action] = await $.Action.list({ where: 'status = done', limit: 1 })
await $.Action.undo({ action: action.$id })
```

CLI:

```bash
ACTION=$(npx startup-builder do Action.list --json '{"where":"status = done","limit":1}' | jq -r '.actions[0]["$id"] | split("/") | last')
npx startup-builder do Action.undo --json '{"action":"'"$ACTION"'"}'
```

MCP:

```json
{
  "name": "do",
  "arguments": {
    "code": "const [action] = await $.Action.list({ where: 'status = done', limit: 1 })\nreturn await $.Action.undo({ action: action.$id })"
  }
}
```

## Change it
- Bring back one record the undo removed.
- Show me everything the agent did today.
- Ask me before the agent publishes anything.

## Under the hood
- Systems: [Work queue](/agents/work-queue), [Ledger](/systems/ledger)
- Nouns: [Action](/business/nouns/action), [Thing](/business/nouns/thing), [Event](/business/nouns/event)
- Events: [`Action.undone`](/business/events/Action.undone)