# Agent API

> Every route an agent serves over HTTP.

Start the server with `python -m loom.api <bundle.yaml>`. It listens on `127.0.0.1:8000` by default.
Every route except `GET /health` and `/viewer` needs `Authorization: Bearer <token>`.

## Status

| Route | Returns |
|---|---|
| `GET /health` | Liveness. No token needed. |
| `GET /info` | Name, revision, uptime, adapters. |
| `GET /status` | Lifecycle, each objective's status, and when the agent last saw data and last cycled. |
| `GET /definition` | The bundle as loaded. |

Status is stored, not recomputed: the API and the agent can never disagree about whether a goal is
met.

## Reads

| Route | Returns |
|---|---|
| `GET /observations` | Normalized observations, filtered by what you ask for. |
| `GET /reports`, `GET /reports/{name}` | Measure values. |
| `GET /cycles`, `GET /cycles/{id}` | Past cycles and what each did. |
| `GET /signals` | Messages addressed to the caller, such as between parent and child agents, with whether each was acknowledged. |
| `WS /stream` | A live tail of what the agent records. |

## Writes

| Route | Does |
|---|---|
| `POST /cycles` | Turns one cycle now. |
| `POST /observations` | Adds records for a `push` adapter. |
| `GET /proposals` | Lists proposals waiting for a person. |
| `POST /proposals/{id}/approve` | Releases one, after re-running validation and the gate. |
| `POST /proposals/{id}/reject` | Rejects one. |

## Conversations

For [chat agents](/loom-site/agents/chat-agents/):

| Route | Does |
|---|---|
| `POST /conversations` | Opens a conversation for a channel and customer. |
| `POST /conversations/{id}/turns` | Sends a customer message; returns the reply and every action's outcome. |
| `GET /conversations/{id}/turns` | Reads the turns back. |
| `POST /conversations/{id}/takeover` | A person takes the conversation over. |
| `POST /conversations/{id}/operator-turns` | The person answers. |
| `POST /conversations/{id}/handback` | Hands it back to the agent. |

## Tokens

```sh
uv run python -m loom.api.tokens issue <bundle.yaml> <caller-id> [--kind human|service] [--role R]
uv run python -m loom.api.tokens revoke <bundle.yaml> <caller-id>
```

Each caller holds its own token, so each app is its own actor at the gate. `--role` gives the caller
roles that capability conditions and handoff can check.