# Sequence Layout

> Participant lifelines with animated message arrows, self-calls, autonumbering, and participant notes.

Use `sequence` for API handshakes, authentication flows, multi-agent conversations, and protocol walkthroughs across 2–6 actors.

## Live Interactive Example

Press **Play** or click any message or note pill to step through the handshake in order:

```diagram
type: sequence
label: "Browser fetches a single-use WS ticket, connects over WebSocket, and streams tokens."
eyebrow: Streaming Handshake
numbered: true
actors:
  - { id: ui, title: Browser, note: "Web UI" }
  - { id: api, title: Server, note: "Auth & WS", highlight: true }
  - { id: agent, title: Agent, note: "LLM + tools" }
messages:
  - from: ui
    to: api
    label: "POST /api/auth/ws-ticket"
    description: "Requests a short-lived single-use ticket so long-lived keys never appear in WebSocket URLs."
  - from: api
    to: api
    label: "mint 60s token"
    description: "Self-call generating a cryptographically random ticket scoped to the session."
  - from: api
    to: ui
    label: "200 {ticket}"
    fallback: true
    description: "Returns the single-use ticket over HTTPS."
  - kind: note
    position: over
    actors: [api]
    label: "Single-use ticket expires in 60s"
  - from: ui
    to: api
    label: "WS /api/chat/ws?ticket=..."
    description: "Upgrades to WebSocket and immediately consumes the ticket."
  - from: api
    to: agent
    label: "run(prompt)"
    highlight: true
    code: "agent.start(prompt, stream=True)"
  - from: agent
    to: ui
    label: "stream tokens & events"
    description: "Streams text deltas, tool calls, and completion events live."
```

## Step-by-Step Guide

1. **Declare 2–6 `actors`** — each can be a string or `{ id, title, note, highlight }`.
2. **Add `messages`** in chronological order (`{ from, to, label, fallback, description, code }`).
3. **Add self-calls** by setting `from` and `to` to the same actor `id`.
4. **Add participant notes** anywhere in `messages` with `{ kind: note, position: over | left | right, actors: [id], label: "..." }`.
5. **Enable `numbered: true`** to number messages (`01`, `02`, ...) while keeping note pills unnumbered (matching Mermaid `autonumber`).

## Field Reference

| Field | Required | Description |
|---|---|---|
| `type` | Yes | Must be `sequence` |
| `label` | Yes | Accessible 1-sentence summary |
| `actors` | Yes | 2–6 actors (string or `{ id, title, note?, highlight? }`) |
| `messages` | Yes | Ordered messages or note items (`kind: note`) |
| `numbered` | No | `true` prefixes messages with `01`, `02`, ... |
| `eyebrow` | No | Uppercase header above actors |

## Related pages

- [Flow Layout](https://diagram.praison.ai/docs/layouts/flow.md)
- [Stack Layout](https://diagram.praison.ai/docs/layouts/stack.md)
- [Loop Layout](https://diagram.praison.ai/docs/layouts/loop.md)
