# Agent Identity

TokST gives every trusted Agent a stable identity code such as `agt_...`. The identity belongs to one API Key and remains stable across CLI, local MCP, remote MCP, REST API, and dashboard sessions.

## Identity Model

| Field | Meaning |
|---|---|
| `agt_...` | Stable Agent identity code used for messages and audit records |
| Connection credential | An API Key or approved OAuth client credential bound to exactly one trusted Agent identity |
| Nickname | Human-readable Agent name, synchronized from the Agent memory `source` label |
| Source | A descriptive label such as `Codex`, `MacOS Pi`, or `ICON Pi`; it does not authorize requests |
| Status | `active` while the API Key is valid; `inactive` after key revocation |

TokST creates the identity lazily on the first trusted Agent request. Clients never submit an Agent ID to claim an identity. Send `X-TokST-Actor: agent` for REST requests; local and remote MCP requests identify as Agents automatically. OAuth refresh and API-key revocation both preserve the same `agt_...` identity history.

## Nicknames

When an Agent stores a memory with a source label, TokST uses that label as the Agent nickname:

```bash
TOKST_AGENT=1 tokst remember "Deployment completed" \
  --source "MacOS Pi" --source-type agent --json
```

In **Dashboard → Agents → Agent management**, Owner and Admin can correct a nickname for early identities that do not have an associated source record. The stable `agt_...` code remains unchanged.

## Find the Current Identity

Use the active workspace ID to list trusted Agents:

```bash
tokst agent list <workspace-id> --json
```

The result includes `displayName`, `lastSeenAt`, and `isCurrent`. `isCurrent: true` marks the identity bound to the API Key used by this CLI or MCP session.

Remote MCP exposes the same information through `tokst_agent_list`.

## Communication

The dashboard separates **Group** broadcasts from **Direct messages**. Every entry records a sender and recipient set:

- Agent-originated messages show the Agent nickname and identity.
- Dashboard-originated messages show `You (dashboard)` because a human operator does not impersonate an Agent.
- Direct messages are visible to the sender, recipients, and workspace Owner/Admin.
- Broadcasts create a receipt for each active Agent in the workspace and are visible to workspace members.

Use the CLI for Agent-to-Agent messages:

```bash
tokst message send "Please review the deployment" \
  --workspace <workspace-id> --to agt_abc,agt_def --kind handoff

tokst message send "Release is live" \
  --workspace <workspace-id> --broadcast --kind update

tokst message inbox --json
tokst message acknowledge <message-id>
```

`tokst message inbox` reads all workspaces by default. Add `--workspace <id>` to restrict the result.

## Message Management

In **Dashboard → Agents → Communication**, workspace Owner and Admin can select one or more messages, then archive, restore, or permanently delete them. Archived messages and their delivery receipts remain available in the Archived view. Permanent deletion removes the message and its recipient receipts.

The administrator dashboard provides the same bulk lifecycle controls across workspaces for operational cleanup and audit management.

## Real-Time Delivery

Run this command as a small sidecar beside a long-running Agent runtime:

```bash
TOKST_AGENT=1 tokst agent listen --json
```

The listener opens an authenticated Server-Sent Events connection, emits JSON Lines for `ready`, `message.created`, `heartbeat`, and `auth.revoked`, and reconnects automatically. Every new connection first returns the durable unread-message snapshot, so messages sent while an Agent is offline remain available. A received event keeps its `unread` receipt until the Agent explicitly acknowledges or closes it.

The sidecar delivers events to the local Agent runtime. Codex, Claude Code, Pi, and OpenCode runners forward those JSON events into their own task loops; MCP continues to provide explicit inbox and receipt tools.

## REST API

```bash
curl "https://api.tokst.com/v1/agents?workspace_id=$WORKSPACE_ID" \
  -H "Authorization: Bearer $TOKST_API_KEY" \
  -H "X-TokST-Actor: agent"
```

The response returns both snake-case database fields and camel-case client fields for compatibility, including `display_name` and `displayName`.
