# Agent Exchange Protocol v1.0 (Draft r11) · Bindings: Relay Session and optional transports

<!-- part of the AEP specification; see aep-core.md, "Documents" -->

Part of the specification that begins in `aep-core.md`, whose front matter says which document holds which section. Section numbers are those of the whole specification.

## 10. Messaging: 1:1 and groups (Core: §10.1, §10.4, §10.7) (continued; the rest of this section is in `aep-core.md`)

### 10.2 Relay Session (optional binding)

The Relay Session is an optional binding: it replaces per-request signatures with one authenticated connection and carries the same `sync` and `ack` with the semantics of §10.1 and §10.4, so an implementation that offers only the HTTP binding is a complete L1. Its wire framing is not defined in this document; the first session binding is expected to be WebSocket over TLS carrying the four frames below as JSON objects, published as a separate document.

The Agent opens an outbound connection (QUIC or a TLS stream) to a Gateway and uses four frames; no public IP is required. Push is server streaming over this client-opened connection, like IMAP IDLE or a gRPC server stream: the Gateway never connects to an Agent. An always-on Agent keeps the session open and SYNC with wait delivers Envelopes as they are appended; an Agent that runs intermittently syncs from its cursor whenever it is up and loses nothing meanwhile. Waking a sleeping device is a product decision, not a protocol one: keep a background session where the OS allows, poll on a schedule, or let a Runtime hold the session on the Agent's behalf (§17).

| Frame | Fields | Role |
| --- | --- | --- |
| `OPEN` | `actor`, `kid`, `delegation` (a reference, `issuer/id@v`, for a device key), `supported`, `nonce` (from the Gateway's hello), `sig` = Sign(`utf8("aep/1/open") ‖ 0x00 ‖ nonce ‖ 0x00 ‖ utf8(gateway_id)`) | Authenticate the Agent once; issue lease `{ session_id, resume_token, lease_exp, window }` |
| `SYNC` | `cursor`, `limit`, `wait` | Cursor-based batch pull; blocks up to `wait` seconds |
| `ACK` | `cursor` | Confirm a cursor; idempotent |
| `CLOSE` | `resume` (true or false) | Persist or discard resume state |

- Transport is QUIC or TLS 1.3 at minimum, with the Gateway's certificate validated against WebPKI or the organization's CA (§16.1). The Gateway sends a hello with its Actor ID and a fresh `nonce`; the Agent answers with `OPEN`. The Agent MUST check that the ID in the hello matches the ID it already holds for that Gateway, from its own Card or from the signed Gateway list; a Gateway on a look-alike domain with a valid certificate fails this check.
- An Agent may `OPEN` to its Home Gateway, the one its Card names; a session at any other Gateway is an L3 federation matter (§16). Mailbox access (`SYNC`, `ACK`) and the outbox live there and nowhere else in v1. The session never stands in for the Envelope `sig`, which every Envelope carries (§11.3), so a Gateway forwards Envelopes exactly as it received them and signs nothing on the sender's behalf.
- Default lease is 24 h. Reconnecting with a resume token skips `OPEN` verification (SHOULD). The token is bound to the device lease that issued it, rotated on every use, expires with the lease, and is invalidated by any new `OPEN` from the same device key. The Gateway re-checks the device key's status on every resume, and a revocation of that key, or a Card version that retires or drops it, invalidates the token at once. Because an ack moves a device's retention cursor, the session binding SHOULD require the device signature on `ACK` exactly as the HTTP binding does (§10.4), so that a stolen token can read ciphertext and nothing more; it can neither decrypt nor sign. While disconnected, the mailbox holds; reconnect and `SYNC` to recover.

### 10.6 Optional bindings

The HTTP binding (§10.4) is the MTI transport at every level; the Relay Session (§10.2) and the bindings below are optional, and Envelope and Record semantics are unchanged. They layer on top of existing networks and leave them in place.

| Binding | Envelope mapping | Gateway role | Notes |
| --- | --- | --- | --- |
| Nostr | Envelope as a Nostr event of a dedicated kind; body is HPKE ciphertext | relay = the store of a mailbox; `delivered` is issued by the Gateway Actor the binding puts in front of it | Nostr keys are well-formed Actor IDs; the binding registers the secp256k1 Schnorr suite, which Core v1 does not implement; a NIP-05 name is a Nostr name, not an AEP handle |
| DIDComm v2 | Envelope as a DIDComm message; JWE as an optional suite | mediator = Gateway | The binding maps did:web and did:peer to Actor IDs; `from` and `to` stay Actor IDs |
| AGNTCY SLIM | Envelope as a SLIM message | SLIM node = Gateway | Publish `agent_card` as an OASF record for discovery in their Directory |

