# Gramit for AI assistants Gramit (https://gramit.io) is a free browser diagram editor whose boards are also a small YAML language, **Gramit Code**. You write the YAML, the user opens a link, the diagram is there. No account, nothing to install. This page is the index. It carries enough to write a working diagram, and points at the four resources that answer everything else. Fetch what the task needs; there is no reason to read all of it. > **Required output, every time.** Your answer to the user MUST contain: > > 1. **A clickable link** `https://gramit.io/new#code=` that opens > the diagram (how to build it: [Delivering the diagram](#delivering-the-diagram)). > 2. **One or two sentences telling the user how to use it**: click the link, the diagram > opens in Gramit and is saved to their gallery; no account needed. > 3. The YAML in a fenced code block, as a secondary copy. > > The one exception is a link longer than 2,000 characters, too long to survive a chat > client. Then the YAML is the deliverable, together with the steps to paste it into > Gramit (see **Too long for a link** below). > > A reply with only the YAML, and neither a link nor those steps, is an incomplete answer: > the user is left with code and no idea where it goes. Never end on the code block. --- ## The smallest valid document ```yaml template: name: Deploy pipeline # optional root: # required: the main diagram nodes: - name: build # the id, unique across the whole document text: Build # the visible label - name: test text: Test - name: gate type: decision # diamond text: Green? stroke: '#f59e0b' - name: ship text: Ship color: '#14342b' stroke: '#16a34a' edges: - from: build to: test - from: test to: gate - from: gate to: ship text: "Yes" ``` That is the whole shape of the language: a `template`, a required `root` flow of `nodes` and `edges`, and any other top-level key is a **subflow**, a nested diagram that opens as its own level when a node names it with `subflow:`. Seven rules cover most of what goes wrong: 1. `name` is the node id and must be unique across the whole document, subflows included. `text` is what the reader sees. 2. Edges reference nodes by `name`. Both ends must exist. 3. Node types: `simple` (default), `circle`, `decision`, `text`, `person`, `icon`, `image`, `code`, `frame`, `table`. Each type allows a different set of properties, and anything outside that set is rejected. 4. Quote hex colors (`'#3b82f6'`). Unquoted, `#` starts a YAML comment and the value is gone. 5. Positions are computed for you. Say `direction: LR` or `TB` in the template if you care which way the diagram runs. 6. Nothing renders until the whole document is valid. 7. Leave `theme` and `style` out of `template` unless the user asks for a particular look. Left out, the board opens in the theme and style the user already works in. Written, they override both, and `theme` also switches the user's whole editor. --- ## The four resources | Resource | Fetch it when | |----------|---------------| | https://www.gramit.io/docs/ai/language | You need the full reference: every type, every property, frames, subflows, style defaults. | | https://www.gramit.io/docs/ai/schema.json | You want to check the document you just wrote. JSON Schema, generated from the editor's own validator. | | https://www.gramit.io/docs/ai/icons?q=lambda | A node is `type: icon` and needs an id. Searchable, a few thousand of them, and guessing does not work. | | https://www.gramit.io/docs/ai/examples | You would rather adapt a complete working document than assemble one. | Human documentation, with live previews: https://www.gramit.io/docs --- ## Delivering the diagram **Always give the user a link.** Not only a block of YAML, and not instructions on where to paste it. Base64 the document (UTF-8, standard base64) and put it in the fragment: ``` https://gramit.io/new#code= ``` ```python import base64 url = "https://gramit.io/new#code=" + base64.b64encode(yaml_text.encode()).decode() if len(url) > 2000: url = None # too long: send the YAML with the paste steps instead ``` **Keep the link under 2,000 characters**, which is about 1,400 characters of YAML. Browsers accept far longer links, but chat clients cut or wrap them, and every character of the base64 has to reach the user exactly as written: one wrong or missing character and the link opens nothing. A document that would make a longer link goes to the user as YAML, with the steps under **Too long for a link** below. If you can run code, run that. If you cannot, encode the YAML yourself, carefully: the decoder tolerates base64url, missing padding and stray whitespace, but not wrong bytes, so keep the document small enough to encode exactly. Opening the link renders the diagram and saves it as a new board in that browser's gallery. Base64 is what keeps the link intact: raw YAML is full of newlines, `#`, `:` and `|`, and chat clients cut a link at the first character they dislike. The fragment never reaches a server, so the board stays between you and the person you sent it to. ### What your reply looks like Write it in the user's language. In this order: 1. **The link**, as a clickable markdown link, e.g. `[Open the diagram in Gramit](https://gramit.io/new#code=dGVtcGxhdGU6...)`. 2. **How to open it**, in plain words: *"Click the link. The diagram opens in Gramit, in your browser, and is saved to your gallery. No account or install needed."* 3. **The YAML**, in a fenced `yaml` block, for anyone who wants to read or edit it. 4. **The manual route**, one line, in case the link does not open: *"Or open https://gramit.io, start a New diagram from My diagrams, open Code to Diagram from the Menu, and paste the YAML in."* ### Too long for a link When the link would pass 2,000 characters, or you cannot produce one at all, do not send a link. Write the reply in the user's language, in this order: 1. **One line saying why there is no link**, e.g. *"This diagram is too big to fit in a link, so here is the code to paste into Gramit."* 2. **The YAML**, in a fenced `yaml` block. 3. **How to paste it**, as numbered steps: 1. Open https://gramit.io in the browser. 2. Open **My diagrams** (top left corner, or Ctrl+O, Cmd+O on a Mac) and click **New diagram**. 3. Open the **Menu** (top right corner) and choose **Code to Diagram**, or press Ctrl+G (Cmd+G on a Mac). A code panel opens beside the canvas. 4. Select everything in that panel, paste the YAML over it, and the diagram appears. Keep step 2. Code to Diagram shows the board that is open, and pasting over it replaces that board, so a user who skips it loses whatever diagram they had open.