# Stop an agent

> Pause an agent, or stop it and every agent under it for good, with one change that takes effect at its next token request.

When an agent misbehaves, or its job is done, one change to its status stops it, and every agent created under it.
Each token request walks up from the agent to the user at the top of its chain, and any link that isn't active stops
it, so agents under a stopped one need no change of their own. This guide is for agent owners, security teams and
incident responders.

**Before you start:**

- **Who can do it:** a realm administrator (a group holding `RealmOwner`). A user can't stop an agent, but can stop it
  acting for them ([Let users remove agents](../people-remove-agents/)).
- **Where:** today this is done through the API, as
  below, with your session in `$CVYUH_SESSION` ([Call the API](/develop/api/)).
- **What you need:** the agent's id, here `invoice-agent`.

## Choose how far to go

| Change | Effect | Undo? |
|---|---|---|
| **Quarantine** | No new tokens for the agent or anything under it | Yes: set it back to `active` |
| **Kill** | No new tokens for the agent or anything under it, ever | No |
| **Retire** | As kill, for an agent you're done with | No |
| Deactivate the **user at the top** of its chain | Every agent under them stops | Reactivate the user |

The user at the top of a chain isn't always the agent's business owner. Deactivating an owner who isn't at the top
leaves their agents running, unless a provider you receive signals from reports the owner disabled
([Receive signals](../../../signals/receive-signals/)): stop those agents here.

## Stop it

<Steps>

1. To pause it, quarantine it:

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

2. To stop it for good, kill it, or retire it when it's simply done:

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

   Send `"retired"` to retire it.

</Steps>

<Aside type="danger" title="Killed and retired are final">
  A killed or retired agent can't be revived or moved to another parent. To replace it, create a new agent.
</Aside>

## Check it worked

- **New token requests** are refused from the moment the change is saved. The agent sees `invalid_client` on its
  next request, with no further detail.
- **Tokens already out** read inactive when an API checks them (see
  [Check a token at your API](../../../../gateway/guides/check-a-token-at-your-api/)).
- **The gateway** refuses them once its revocation list refreshes. Every agent that's no longer active, and every
  agent under it, is listed there.
- **Delegated tokens** in which the agent acts for a user end too.
- **Pending approvals.** An agent quarantined while it waits for its owner's approval collects nothing.
- **On the trail.** The change is recorded as `AGENT_QUARANTINED`, `AGENT_KILLED` or `AGENT_RETIRED`, with the status
  before and after and who made it ([Follow what an agent did](../follow-what-an-agent-did/)), and is sent to anyone
  following the agent through [Send signals](../../../signals/shared-signals/).

## Undo it

Only a quarantine can be undone. Set the agent back to `active` to release it, and the agents under it with it
(recorded as `AGENT_RELEASED`):

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

## Related

- [AI agents](../../../agents/ai-agents/): statuses, and the chain check at every token request.
- [Introspection](../../../applications/revoke-access/introspection/): how an API learns a token is inactive.
- [Requests and refusals](/gateway/protect-apis/requests-and-refusals/): where the gateway refuses stopped agents.
- [Follow what an agent did](../follow-what-an-agent-did/): the status change on the trail.
