Skip to content

Commit 7b2abaf

Browse files
docs(blocks): guide, worked example and the corrections it needs
Adds docs/guides/blocks.md and examples/blocks/, two clinics that share a red-flags prompt block and a voice config block, one with its own version of the block. The examples test now copies an example's templates/ folder, so the example is validated and the guide's snippets are checked against its files. Also corrects two statements the feature depends on: YAML merge keys are not processed by the engine, and an undefined Liquid variable is left in the prompt as written, not replaced with an empty string. Logs the pull behaviour this replaces as improvements entry 39, and a drift-check gap found while testing, in orgs with no credentials, as entry 40. Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>
1 parent 0e9a9cf commit 7b2abaf

23 files changed

Lines changed: 658 additions & 11 deletions

File tree

‎AGENTS.md‎

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ change, before running:
3939
| --- | --- |
4040
| `npm run apply`, `npm run push` | Changes live assistants |
4141
| `npm run promote -- … --apply` | Changes the next org (often production) |
42+
| `npm run sync-blocks -- --apply` | Changes live resources in every org that uses the edited block |
4243
| `npm run rollback -- <org> --to …` | Reverts live resources |
4344
| `npm run cleanup -- <org> --force --confirm <org>` | Deletes platform resources |
4445
| `npm run pull -- <org> --force` | Overwrites local edits |
@@ -47,6 +48,7 @@ change, before running:
4748

4849
Safe to run without asking: `npm run validate`, `npm run audit`,
4950
`npm run check -- … --dry-run`, `npm run promote` without `--apply` (a plan),
51+
`npm run sync-blocks` without `--apply` (a list),
5052
plain `npm run pull` (it never overwrites local edits), `npm run push -- <org>
5153
--dry-run`, `npm run build`, `npm test`.
5254

@@ -185,6 +187,8 @@ how sync, conflicts and output icons work:
185187
| Edit an assistant's system prompt | Edit the Markdown body of `resources/<org>/assistants/<name>.md` |
186188
| Change assistant settings | Edit the YAML frontmatter of the same file |
187189
| Add a tool / assistant / squad | Create `resources/<org>/tools/<name>.yml`, `assistants/<name>.md`, `squads/<name>.yml` |
190+
| Share prompt text or config between files | Put it in `templates/blocks/<name>.md` or `templates/config/<name>.yml` and include it (see [Blocks](#blocks)) |
191+
| See which resources a block edit reaches | `npm run sync-blocks` (a list; `--apply` deploys and needs a yes) |
188192
| Add post-call analysis | Create `resources/<org>/structuredOutputs/<name>.yml` and list it in the assistant's `artifactPlan.structuredOutputIds` |
189193
| Write simulation tests | Create files under `resources/<org>/simulations/` (see [Simulations](#simulations-and-pr-checks)) |
190194
| Check files offline | `npm run validate -- <org>` |
@@ -243,6 +247,24 @@ The engine resolves IDs and credential names to each org's UUIDs on push.
243247
| The display name | Change `name` in the file (or in the dashboard, then pull). The filename stays. |
244248
| The file itself | A renamed file has no state entry, so the next deploy stops at the new-file check. Either keep the old filename, or (with the human's agreement) deploy it as new with `--allow-new-files` and delete the old platform resource with `npm run cleanup -- <org> --force --confirm <org>`. |
245249

250+
### Blocks
251+
252+
A line that says only `@include <name>` in a system prompt, or a
253+
`$include: <name>` key in a mapping, pulls in a shared file from
254+
`resources/<org>/templates/` (the org's own) or `templates/` (shared by
255+
every org). The engine expands it before validate, push and PR checks.
256+
257+
- To change shared wording or settings, edit the block, not the files that
258+
include it. Never replace a marker with the block's text.
259+
- A block edit changes every resource that includes it, in every org. Run
260+
`npm run sync-blocks` and show the human the list before any deploy.
261+
- Don't use Liquid `{% include %}` / `{% render %}` or YAML merge keys (`<<`)
262+
to share content: Vapi and the engine drop them silently.
263+
- Commit `resources/<org>/.vapi-blocks.json` when push changes it; never
264+
edit or delete it.
265+
266+
Syntax, merge rules and dashboard-edit handling: [Blocks](docs/guides/blocks.md).
267+
246268
### Excluding resources (`.vapi-ignore`)
247269

248270
`resources/<org>/.vapi-ignore` lists platform resources this repo must not
@@ -349,6 +371,7 @@ For changes under `src/`, `tests/` or `.github/`:
349371
| --- | --- |
350372
| Every resource setting, with examples | [Resource reference](docs/guides/resource-reference.md) |
351373
| Minimal tested files | [File formats](docs/guides/file-formats.md), [`examples/starter/`](examples/starter/README.md) |
374+
| Shared prompt text and config | [Blocks](docs/guides/blocks.md), [`examples/blocks/`](examples/blocks/README.md) |
352375
| System prompts | [Writing system prompts](docs/guides/writing-prompts.md), [Vapi Prompt Optimization Guide](docs/Vapi%20Prompt%20Optimization%20Guide.md) |
353376
| Commands, flags, test-call output | [Commands](docs/guides/commands.md) |
354377
| Sync, conflicts, drift, output icons | [How the engine works](docs/guides/how-it-works.md), [sync behavior](docs/learnings/sync-behavior.md) |

‎README.md‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,7 @@ More detail: [How the engine works](docs/guides/how-it-works.md).
221221
| `npm run sim -- <org>` | Run a simulation suite against deployed resources |
222222
| `npm run check` | Run PR simulation checks against local files |
223223
| `npm run promote` | Promote resources from one org to the next |
224+
| `npm run sync-blocks` | List, and optionally deploy, the resources a shared block edit reaches |
224225

225226
`setup`, `apply`, `pull`, `push`, `cleanup` and `call` prompt interactively
226227
when run without arguments. Full flags and examples:
@@ -232,6 +233,7 @@ when run without arguments. Full flags and examples:
232233
| --- | --- |
233234
| [Everyday workflows](docs/guides/workflows.md) | Deploy, pull safely, recover from a bad deploy, clean up |
234235
| [File formats](docs/guides/file-formats.md) | Write assistants, tools, squads, structured outputs and simulations |
236+
| [Blocks](docs/guides/blocks.md) | Share prompt text and config between assistants, squads and orgs |
235237
| [Resource reference](docs/guides/resource-reference.md) | Look up every setting, with examples |
236238
| [Writing system prompts](docs/guides/writing-prompts.md) | Structure a voice agent's prompt |
237239
| [PR checks](docs/guides/pr-checks.md) | Test every pull request with simulations |

‎docs/guides/blocks.md‎

Lines changed: 316 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,316 @@
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.

‎docs/guides/commands.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ The other commands are direct only.
2121
| `npm run sim` | `npm run sim -- <org> --suite <name> --target <name>` | Run a simulation suite against deployed resources. Exits 0 passed, 1 failed, 3 incomplete. |
2222
| `npm run check` | `npm run check -- <check>` or `--all`, `[--dry-run]` | Run [PR checks](pr-checks.md) against local files, nothing deployed. Exits 0 passed, 1 failed, 2 config or build error, 3 incomplete. |
2323
| `npm run promote` | `npm run promote -- --pipeline <p> --from <org> --to <org> [--apply]` | Plan, or apply, a [promotion](promotion.md) between orgs. |
24+
| `npm run sync-blocks` | `npm run sync-blocks [-- --org <org>] [--apply]` | List the resources, in every org, that a [block](blocks.md) edit has not reached yet. `--apply` deploys them through `apply`. Exits 1 if any is left behind. |
2425
| `npm run build` | `npm run build` | Type-check the code and tests. |
2526
| `npm test` | `npm test` | Run the test suite. |
2627

0 commit comments

Comments
 (0)