|
| 1 | +# Blocks: shared prompt text and config |
| 2 | + |
| 3 | +A block is a piece of prompt text or config that lives in one file and is |
| 4 | +used by many resources. Change the block and every assistant and squad that |
| 5 | +includes it changes with it, in every org. |
| 6 | + |
| 7 | +There are two kinds: |
| 8 | + |
| 9 | +| Kind | File | Included with | Use it for | |
| 10 | +| --- | --- | --- | --- | |
| 11 | +| Prompt block | `templates/blocks/<name>.md` | a line that says `@include <name>` in a system prompt | Wording several assistants share: safety rules, tone, a closing script | |
| 12 | +| Config block | `templates/config/<name>.yml` | a `$include: <name>` key in any mapping | Settings several resources share: voice, transcriber, model settings, squad overrides | |
| 13 | + |
| 14 | +The engine expands blocks when it loads a resource file, before `validate`, |
| 15 | +`apply`, `push` and PR checks. Vapi only ever receives the finished resource: |
| 16 | +blocks do not exist on the platform or in the dashboard. |
| 17 | + |
| 18 | +Every snippet below is a file from [`examples/blocks/`](../../examples/blocks/), |
| 19 | +two clinics that share a red-flags block and a voice. CI checks that the |
| 20 | +snippets match the files and that the example passes `validate`. |
| 21 | + |
| 22 | +## Prompt blocks |
| 23 | + |
| 24 | +Put the shared text in a Markdown file: |
| 25 | + |
| 26 | +```markdown |
| 27 | +<!-- examples/blocks/templates/blocks/red-flags.md --> |
| 28 | +# Emergencies |
| 29 | + |
| 30 | +If the caller mentions chest pain, difficulty breathing or signs of a stroke, |
| 31 | +stop what you are doing and tell them to hang up and call 999 now. Then offer |
| 32 | +to connect them to {{practice_name}} reception. |
| 33 | +``` |
| 34 | + |
| 35 | +Then write `@include red-flags` on a line of its own wherever the text |
| 36 | +belongs in a system prompt: |
| 37 | + |
| 38 | +```markdown |
| 39 | +<!-- examples/blocks/resources/north-clinic/assistants/triage.md --> |
| 40 | +--- |
| 41 | +name: Triage |
| 42 | +firstMessage: Thanks for calling {{practice_name}}. What can I help you with today? |
| 43 | +model: |
| 44 | + provider: openai |
| 45 | + model: gpt-4.1 |
| 46 | + temperature: 0.3 |
| 47 | +voice: |
| 48 | + $include: voice |
| 49 | +--- |
| 50 | + |
| 51 | +# Identity |
| 52 | + |
| 53 | +You are the triage assistant for {{practice_name}}. You find out what the |
| 54 | +caller needs and pass them to the right assistant. |
| 55 | + |
| 56 | +@include red-flags |
| 57 | + |
| 58 | +# Flow |
| 59 | + |
| 60 | +1. Ask what the caller needs help with today. |
| 61 | +2. For a repeat prescription, pass them to the Pharmacy assistant. |
| 62 | +3. For anything else, take a short message for the reception team. |
| 63 | +``` |
| 64 | + |
| 65 | +- The marker must be the only thing on its line. `@include` in the middle of |
| 66 | + a sentence is left as ordinary text. |
| 67 | +- It works in every system prompt: the Markdown body of an assistant, a |
| 68 | + `role: system` message in a `.yml` assistant, and a system message inside |
| 69 | + a squad's `assistantOverrides` or `membersOverrides`. Other text fields, |
| 70 | + such as `firstMessage`, are not expanded. |
| 71 | +- The name is the file's path under `templates/blocks/` without `.md`, so |
| 72 | + `templates/blocks/safety/red-flags.md` is `@include safety/red-flags`. |
| 73 | +- A block can include other blocks. A block that ends up including itself is |
| 74 | + an error. |
| 75 | +- A block has no parameters. What differs per call belongs in a Liquid |
| 76 | + variable (next section); what differs per org belongs in an org's own |
| 77 | + block (see [Lookup order](#lookup-order-shared-blocks-and-an-orgs-own)). |
| 78 | + |
| 79 | +### Liquid variables |
| 80 | + |
| 81 | +Nothing inside a block is interpreted. `{{practice_name}}`, |
| 82 | +`{% if … %}` and every other Liquid expression reach Vapi exactly as written, |
| 83 | +and Vapi fills them on each call, the same as if you had typed the block's |
| 84 | +text into the prompt. |
| 85 | + |
| 86 | +The marker is deliberately not Liquid. Vapi's call-time Liquid has no file |
| 87 | +access: it renders `{% include %}`, `{% render %}` and `{% layout %}` as |
| 88 | +nothing, so a prompt that relied on them would silently lose that text on a |
| 89 | +live call. `validate` warns when a system prompt contains one of those tags. |
| 90 | + |
| 91 | +## Config blocks |
| 92 | + |
| 93 | +A config block is a YAML file: |
| 94 | + |
| 95 | +```yaml |
| 96 | +# examples/blocks/templates/config/voice.yml |
| 97 | +provider: 11labs |
| 98 | +voiceId: sarah |
| 99 | +``` |
| 100 | +
|
| 101 | +Any mapping can pull it in with a `$include` key. In the assistant above, |
| 102 | +`voice:` with `$include: voice` becomes the two fields of that file. A squad |
| 103 | +can do the same, and a block can include another block: |
| 104 | + |
| 105 | +```yaml |
| 106 | +# examples/blocks/templates/config/call-settings.yml |
| 107 | +silenceTimeoutSeconds: 20 |
| 108 | +maxDurationSeconds: 900 |
| 109 | +voice: |
| 110 | + $include: voice |
| 111 | +``` |
| 112 | + |
| 113 | +```yaml |
| 114 | +# examples/blocks/resources/north-clinic/squads/front-desk.yml |
| 115 | +name: Front Desk |
| 116 | +members: |
| 117 | + - assistantId: triage |
| 118 | + - assistantId: pharmacy |
| 119 | +membersOverrides: |
| 120 | + $include: call-settings |
| 121 | + variableValues: |
| 122 | + practice_name: North Clinic |
| 123 | +``` |
| 124 | + |
| 125 | +### How a block and the file's own keys combine |
| 126 | + |
| 127 | +The mapping that holds `$include` can set keys of its own. The rule is |
| 128 | +always: **the file wins**. |
| 129 | + |
| 130 | +| The block has | The file sets, beside `$include` | Result | |
| 131 | +| --- | --- | --- | |
| 132 | +| a key | nothing for that key | the block's value | |
| 133 | +| a key | the same key, a plain value | the file's value | |
| 134 | +| a mapping | the same key, a mapping | merged key by key, by these same rules | |
| 135 | +| a list | the same key, a list | the file's list replaces the block's list whole. Lists are never joined. | |
| 136 | +| anything | the same key, a different kind of value | the file's value | |
| 137 | + |
| 138 | +So, with the voice block above: |
| 139 | + |
| 140 | +```yaml |
| 141 | +voice: |
| 142 | + $include: voice |
| 143 | + voiceId: burt # provider comes from the block, voiceId from here |
| 144 | +``` |
| 145 | + |
| 146 | +`$include` takes one name or a list of names: |
| 147 | + |
| 148 | +```yaml |
| 149 | +membersOverrides: |
| 150 | + $include: [call-settings, transcriber] |
| 151 | +``` |
| 152 | + |
| 153 | +A block whose content is a list (or a single value) can be included only on |
| 154 | +its own, as the whole value of a field: |
| 155 | + |
| 156 | +```yaml |
| 157 | +model: |
| 158 | + toolIds: |
| 159 | + $include: standard-tools # templates/config/standard-tools.yml is a list |
| 160 | +``` |
| 161 | + |
| 162 | +### What is refused |
| 163 | + |
| 164 | +These fail at load, so `validate`, `apply` and PR checks all stop with a |
| 165 | +message naming the file: |
| 166 | + |
| 167 | +| Case | Why | |
| 168 | +| --- | --- | |
| 169 | +| A block that does not exist, in the org's folder or the shared one | A missing block must never become empty text or missing settings. The message lists both places it looked. | |
| 170 | +| Blocks that include each other in a loop | No finished text exists. The message shows the chain. | |
| 171 | +| Two blocks in one `$include` list that set the same field to different values | The result would depend on the order of the list. Set the field in one block, or in the file. | |
| 172 | +| A list block included beside other keys or other blocks | There is no sensible way to merge a list with keys. | |
| 173 | +| `$include` in the same mapping as a YAML merge key (`<<`) | Two merge mechanisms in one place. The engine does not process `<<` at all (see below). | |
| 174 | +| `$include` with an empty value, a non-text value, or the same name twice | Almost certainly a typo. | |
| 175 | + |
| 176 | +### YAML anchors and merge keys |
| 177 | + |
| 178 | +Don't use them for sharing. An anchor only reaches inside one file, and |
| 179 | +`pull` writes files back with every alias expanded. A merge key |
| 180 | +(`<<: *defaults`) is not processed by the engine at all: it is sent to Vapi |
| 181 | +as a field named `<<`. `validate` warns when it finds one. |
| 182 | + |
| 183 | +## Lookup order: shared blocks and an org's own |
| 184 | + |
| 185 | +A name is looked up in two places, in this order: |
| 186 | + |
| 187 | +1. `resources/<org>/templates/`, the org's own blocks |
| 188 | +2. `templates/` at the repository root, shared by every org |
| 189 | + |
| 190 | +So an org replaces a shared block by having a file of the same name. An |
| 191 | +org's block that includes its own name gets the shared one, which lets it |
| 192 | +add to the shared block rather than copy it: |
| 193 | + |
| 194 | +```markdown |
| 195 | +<!-- examples/blocks/resources/south-clinic/templates/blocks/red-flags.md --> |
| 196 | +@include red-flags |
| 197 | +
|
| 198 | +{{practice_name}} has a walk-in centre next door, open until 8pm. If the |
| 199 | +caller is not sure it is an emergency, tell them they can go there. |
| 200 | +``` |
| 201 | + |
| 202 | +Config blocks work the same way. This org file keeps everything in the |
| 203 | +shared `voice` block and changes one field: |
| 204 | + |
| 205 | +```yaml |
| 206 | +# resources/south-clinic/templates/config/voice.yml |
| 207 | +$include: voice |
| 208 | +voiceId: burt |
| 209 | +``` |
| 210 | + |
| 211 | +## Rolling a block change out |
| 212 | + |
| 213 | +A block edit changes what many resources send to Vapi, but it changes none |
| 214 | +of their files. Three things follow from that. |
| 215 | + |
| 216 | +**1. See what it reaches.** |
| 217 | + |
| 218 | +```bash |
| 219 | +npm run sync-blocks # every org; reads files, changes nothing |
| 220 | +npm run sync-blocks -- --org acme # one org |
| 221 | +``` |
| 222 | + |
| 223 | +It lists every resource whose blocks have changed since that resource was |
| 224 | +last pushed, with the block that changed. An org with its own version of a |
| 225 | +block is not listed for an edit to the shared version. |
| 226 | + |
| 227 | +**2. Push it.** |
| 228 | + |
| 229 | +```bash |
| 230 | +npm run sync-blocks -- --apply |
| 231 | +``` |
| 232 | + |
| 233 | +For each org this runs `npm run apply -- <org> <the listed files>`, so it |
| 234 | +needs each org's API key, like any deploy, and it goes through the same |
| 235 | +validate → pull → push path. A resource that someone edited in the dashboard |
| 236 | +is refused by the drift check, exactly as with `apply`; the command says |
| 237 | +which resources were left behind and exits 1. Resolve the edit (see |
| 238 | +[Dashboard edits](#dashboard-edits-to-a-file-that-uses-blocks)) and run it |
| 239 | +again. |
| 240 | + |
| 241 | +Plain `npm run apply -- <org>` also pushes them: to the engine a block edit |
| 242 | +looks like a local edit to every file that includes the block. |
| 243 | + |
| 244 | +**3. Commit the record.** The engine knows what each resource was last pushed |
| 245 | +with from `resources/<org>/.vapi-blocks.json`. Push updates it; commit it |
| 246 | +with your other changes, as you do the state file. Don't edit it by hand. If |
| 247 | +it is missing, every resource that uses a block is listed until it is pushed |
| 248 | +once. |
| 249 | + |
| 250 | +### With promotion |
| 251 | + |
| 252 | +When orgs are linked by a [promotion](promotion.md) pipeline (for example |
| 253 | +one org per site, or dev → production), promotion carries block edits to the |
| 254 | +orgs it deploys: |
| 255 | + |
| 256 | +- A shared block is one file for every org, so there is nothing to copy. The |
| 257 | + plan shows each destination resource that uses the changed block as |
| 258 | + `sync`, and `--apply` pushes it. |
| 259 | +- An org's own blocks are not copied to the next org. Each org is expanded |
| 260 | + with its own blocks, then the shared ones. |
| 261 | +- The promotion workflow runs when `templates/**` changes, as it does for |
| 262 | + `resources/**`. |
| 263 | +- Promotion deploys destination orgs only. The first org of a pipeline, and |
| 264 | + any org outside a pipeline, gets a block edit from `sync-blocks` or |
| 265 | + `apply`. |
| 266 | + |
| 267 | +Promotion pushes with `--resolve=ours`, as it does for every file it |
| 268 | +promotes: a dashboard edit in a destination org is overwritten, not refused. |
| 269 | + |
| 270 | +### With PR checks |
| 271 | + |
| 272 | +A change under `templates/` selects every [PR check](pr-checks.md), and a |
| 273 | +change to an org's own blocks selects that org's checks. The check builds |
| 274 | +its payload from the branch's files, so it tests the new block text. |
| 275 | + |
| 276 | +## Dashboard edits to a file that uses blocks |
| 277 | + |
| 278 | +The dashboard shows the finished prompt, with the block's text in place of |
| 279 | +the marker. If `pull` wrote that back to your file, the marker would be |
| 280 | +replaced by a copy of the block and the file would stop following later |
| 281 | +block edits. So `pull` never rewrites a file that uses blocks: |
| 282 | + |
| 283 | +| Situation | An ordinary file | A file that uses blocks | |
| 284 | +| --- | --- | --- | |
| 285 | +| File and dashboard agree | Rewritten in pull's own format | Left exactly as written | |
| 286 | +| Only the dashboard changed | Overwritten with the dashboard version | Kept. The dashboard version is saved beside it, and the edit stays flagged as drift | |
| 287 | +| `pull --force` | Overwritten | Kept. The dashboard version is saved beside it | |
| 288 | +| Both changed, `--resolve=theirs` | Overwritten | Kept. The dashboard version is saved beside it, and the conflict stays open | |
| 289 | + |
| 290 | +"Saved beside it" means a `<name>.<timestamp>.bkp.md` (or `.yml`) file next |
| 291 | +to yours, which git and the engine ignore. To resolve a dashboard edit: |
| 292 | + |
| 293 | +1. Compare the saved copy with your file and find what was changed. |
| 294 | +2. If the change is in text that comes from your file, make the same change |
| 295 | + in your file. If it is in text that comes from a block, change the block |
| 296 | + (every resource that uses it changes too) or give this org its own block. |
| 297 | + To discard the dashboard edit, change nothing. |
| 298 | +3. Run `npm run apply -- <org> --resolve=ours <file>`. It pushes your |
| 299 | + version over the dashboard's. |
| 300 | + |
| 301 | +## Limits |
| 302 | + |
| 303 | +- The drift check compares the dashboard with the last state *your* checkout |
| 304 | + saw (see [sync behavior](../learnings/sync-behavior.md)). A fresh clone |
| 305 | + has no such baseline, so its first push is not refused. This is the same |
| 306 | + for every push, with or without blocks. |
| 307 | +- An org with no credentials stored in Vapi gets no drift check at all: |
| 308 | + `push` re-syncs such an org's state before every run, which resets the |
| 309 | + baseline to whatever the dashboard holds. This also predates blocks (see |
| 310 | + `improvements.md`, entry 42). |
| 311 | +- Blocks are expanded in `.md`, `.yml` and `.ts` resources. As with any |
| 312 | + `.ts` resource, `pull` and drift detection skip `.ts` files. |
| 313 | +- A pull request shows a block's diff once. Run `npm run sync-blocks` on the |
| 314 | + branch to see every resource and org it reaches. |
| 315 | +- `templates/` is not a resource folder. Nothing in it is pushed on its own, |
| 316 | + and `cleanup` and `audit` don't look there. |
0 commit comments