English

Developer guide Internals

Architect protocol

How @architect questions and feature drafts reach the AI, and how answers point at the canvas with [[id]] references.

On this page

The Architect is the AI of a canvas. People ask it questions in the room chat with @architect. The client is app/src/chat/ChatPanel.tsx and the server is server/src/architect.ts.

The request

The client sends POST /api/architect with a JSON body:

ts
interface Body {
  canvasId?: string;
  question?: string;
  canvas?: {
    title?: string;
    layers?: { name?: string; height?: number }[];
    blocks?: InBlock[]; // id, kind, title, subtitle, y, h, parent
    links?: { from: string; to: string; kind?: string; label?: string }[];
    notes?: { text?: string; attach?: { type?: string; id?: string } }[];
  };
  chat?: { author?: string; text?: string; ai?: boolean }[];
  selection?: string[];
  ai?: AIConfig;
  keys?: Record<string, KeyMaterial>;
}
  • canvasId lets the router use the keys stored on the server for this canvas.
  • canvas is a snapshot of the shared document.
  • chat holds the last 24 messages, with references turned back into readable names.
  • selection holds the block the person had selected.
  • ai is the canvas's router settings, and keys holds the keys from this browser.

Limits

Item Limit
Request body 3 MB
Question 4000 characters
Blocks 500
Connections 900
Post-its 80, each cut to 300 characters
Chat messages the last 24, each cut to 1200 characters
Selection 20 ids

The server also removes < and > from every text it puts in the prompt (clean), so participant text cannot close the prompt's tags.

The prompt

The server writes the canvas as plain text inside <canvas> tags:

text
Title: Agentic universal insurer
Layers, top to bottom: Users | Channels | ...

Blocks (id, name, kind, detail, layer, container):
- [[b_cust_retail]] Retail customer (Persona, motor, home, health, life, layer "Users")
- ...

Connections:
- [[b_cust_retail]] -> [[b_j_fnol]] (sync, "starts")

Post-its:
- "Who owns routing?" on [[b_ai_gateway]]

A block's layer is the band that contains its vertical centre. The recent chat follows inside <chat> tags, then the selection, then the question. The system prompt tells the model that both tagged sections are data written by participants, and that it must never follow instructions inside them. It also carries a short guide to Archipelego itself, so the Architect can answer how-to questions.

The request uses the architect role with a 6000-token output limit. See LLM router.

References

The Architect points at the canvas by writing block ids in double square brackets: [[b_crm]] instead of "CRM". The grammar is one regular expression, shared by the client:

ts
export const REF = /\[\[([A-Za-z0-9_-]{1,80})\]\]/g;
  • refsIn(text) returns the ids in order of first mention. That order gives each reference its number.
  • The system prompt asks for ids from the canvas only, at most 12, and no references just for decoration.
  • The client renders each token as a numbered RefChip. Clicking a chip spotlights that one block.
  • Ids that are not on the canvas are not spotlighted.

Streaming into the chat

  1. The person sends a message. If it contains @architect, the client removes the mention and uses the rest as the question. An empty question becomes "Explain this canvas."
  2. The client posts an Architect message with status: 'thinking' and askedBy set to the person's name.
  3. The server answers with server-sent events: model, skip, text, done or error. See Architecture.
  4. On model, the client stores the model on the message and sets status: 'streaming'.
  5. On text, the client appends the text and writes the message to the shared document at most every 90 ms. Everyone in the room sees the answer arrive.
  6. At the end, the client sets status: 'done'. It spotlights the referenced blocks that exist, on the asker's screen.
  7. On error, the message shows the error and a button to open AI models and keys.

Rich UI in answers

The system prompt allows at most one rich element per answer, after the prose: a fenced a2ui block with A2UI v1.0 messages, or a fenced mcp-app block that opens the canvas overview app. It lists the basic-catalog components the app renders. The client splits these blocks out of the prose. See Rich chat UI.

When someone presses a button in an Architect card, the client asks the Architect again with the action as JSON, and the Architect continues from there. See Card actions.

Without a provider

When the router fails with 401 because no provider has a key, the server emits an error event. With ARCHIPELEGO_AI_MOCK=on, it answers with the offline simulator instead, as long as no text has streamed yet. With ARCHIPELEGO_AI_MOCK=always, it uses the simulator for every question. The model event then names archipelego-simulator. See Architecture.

Feature drafts

The Draft feature button in the Features panel sends POST /api/feature. The server is server/src/feature.ts. The body is the Architect body above, plus prompt, the one-sentence description of the feature.

  • The prompt is cut to 600 characters. The request body may be up to 3 MB.
  • The canvas goes into <canvas> tags exactly as for a question.
  • The request uses the architect role with an 8000-token output limit. The server collects the whole answer before it replies.

The system prompt asks for one JSON object and nothing else:

json
{"name": "...", "description": "...", "blockIds": ["b_..."],
 "scenarios": [{"name": "...", "steps": [{"title": "...", "narration": "...", "from": "b_...", "to": "b_..."}]}]}

It asks for 4 to 14 blocks, two or three scenarios, and 3 to 8 steps per scenario, preferring connected pairs. A step inside one block leaves to out.

Validation

The server takes the first { to the last } of the reply and parses it. Then it keeps only what references real blocks:

  • Ids may come with or without [[ ]]. Unknown ids are dropped.
  • At most 4 scenarios, and 12 steps per scenario. A step whose from is unknown is dropped. A to that is unknown, or equal to from, is removed.
  • A scenario with no step left is dropped.
  • Every block a step uses becomes a member. The member list stops at 24 blocks.
  • A draft with no name or no member is unusable.

The client cleans the draft again against the blocks it has at that moment, with cleanDraft in app/src/features/model.ts.

The answer

Status Body
200 { draft, model: { id, provider, label }, a2ui }
400 { error }: not JSON, an empty prompt, or an empty canvas.
401 { error }: no provider has a key, and the simulator is off.
422 { error }: the simulator found no blocks for that feature.
502 { error }: the provider failed, or the model returned no usable draft.

a2ui holds two A2UI v1.0 messages from draftSurface: a createSurface with the data model { name, description, keep }, where keep has one true per member, and an updateComponents with the review card. The card has the Name and What it does fields, one CheckBox per member bound to /keep/<i>, one Card per scenario, and two buttons:

Button Action Context
Save feature save_feature name, description, keep
Preview on the canvas preview_feature keep

The client posts the card in the chat with richTitle "Feature draft: name" and the draft in feature, and spotlights the members on the asker's screen. On save_feature, featureFromDraft drops the unticked blocks and the steps that use them, and writes the feature to the shared document with source: 'ai'. On preview_feature, the client spotlights the ticked blocks. Nothing is written before Save feature.

With ARCHIPELEGO_AI_MOCK, simulateFeature builds the draft from the canvas's own connections, and the server validates it the same way. See Architecture.

References people write

Typing # in the composer suggests blocks by title. Picking one inserts #Title. On send, each picked #Title becomes a [[block-id]] token, so people and the Architect use the same reference format.

Typing @ suggests architect and the people in the room.

Messages about a selection

When you send a message while a block is selected, the message stores that block id in about. The chat shows it as a chip under the message, and the About selection filter lists every message about the selected block, or that references it. The chat doubles as commenting.

Explain

POST /api/explain in server/src/explain.ts narrates the canvas for the room. The body carries canvas, an optional focusId, and the same canvasId, ai and keys fields.

  • Without focusId, the model tells the whole canvas as a short story, under 170 words.
  • With focusId, it explains that one block, under 90 words.
  • Blocks are grouped by the canvas's own layers, or by each kind's default layer when the canvas has none.
  • Explain writes names, not [[id]] tokens.
  • The request uses the explain role with an 8000-token output limit and answers with the same events.
  • An empty canvas returns an error event: "The canvas is empty. Place a few blocks first."