Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .github/workflows/vapi-checks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,10 @@ jobs:
CHECK: ${{ inputs.check }}
BASE_REF: ${{ github.base_ref }}
GITHUB_TOKEN: ${{ github.token }}
# Appended to each check's label, so the dashboard's runs table
# says which PR a run came from. Keep it quoted: unquoted, YAML
# cuts the value at " #".
VAPI_CHECK_LABEL_CONTEXT: "${{ github.event.pull_request.number && format('PR #{0}', github.event.pull_request.number) || 'manual run' }}"
VAPI_CHECK_TOKENS: ${{ steps.mode.outputs.live == 'true' && secrets.VAPI_CHECK_TOKENS || '' }}
VAPI_PRIVATE_API_KEY: ${{ steps.mode.outputs.live == 'true' && secrets.VAPI_PRIVATE_API_KEY || '' }}
run: |
Expand Down
1 change: 1 addition & 0 deletions docs/guides/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,4 +67,5 @@ These are hand-written. The files the engine writes live apart from them, in
| --- | --- |
| `CI=true` | Suppresses interactive warnings, such as the one `pull --force` prints. Set automatically by most CI systems. |
| `VAPI_CALL_DEBUG=1` | Makes `npm run call` log message types it would otherwise ignore. |
| `VAPI_CHECK_LABEL_CONTEXT` | Appended to a check's `label` in its run names, as `<label> · <context>`. The PR checks workflow sets `PR #<n>`, or `manual run` for a dispatch. |
| `VAPI_GITOPS_ROOT` | Overrides the repository root that `npm run promote` and `npm run check` read from. Mainly for tests. |
32 changes: 31 additions & 1 deletion docs/guides/pr-checks.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,39 @@ cp vapi-checks.example.yml vapi-checks.yml
version: 1
checks:
core:
label: Core flows # optional
org: my-org
targets: [squads/main-squad]
suites: [core]
```

`label` (optional, up to 60 characters) names the check's runs in the
dashboard's runs table, which otherwise shows every check run as "API run".
In CI the workflow appends `· PR #<n>` (or `· manual run` for a dispatch)
from `VAPI_CHECK_LABEL_CONTEXT`. The label is written on every simulation in
the run, so the job summary names each simulation by its scenario and
personality instead.

### Recording replays

A scenario with `transcriptReplay` plays a fixed recording into the target
and scores what its transcriber heard (see
[simulations learnings](../learnings/simulations.md#recording-replays)). The
simulations API runs a replay only from a **saved** scenario, so a check
sends a replay scenario by its UUID in the org, not from the branch. The
target is still built from the branch, which is what a replay tests. So:

- The check needs `transport: voice`, and runs only in its own org (no
`runOrg`).
- Apply the scenario before the check can run it. The build fails for a
replay scenario that has never been deployed.
- Before a live run, the check reads each saved replay scenario. If the
file's `transcriptReplay`, `evaluations`, `latencyExpectations` or
`toolMocks` differ from the saved copy, the check stops with an error and
sends nothing: apply the scenario, then rerun.
- Replays are in a platform rollout. An org outside it gets a 400 from the
run.

## 3. Dry run locally (no key, nothing sent)

```bash
Expand Down Expand Up @@ -113,7 +141,9 @@ PR push. It asks for `statuses: write` only to post the direct links.
`Vapi Simulations / <check> / <target>`, whose **Details** opens that run,
and the overall status links to the workflow run.
- A job summary: per-target result, failing judges with expected vs actual,
and any "unmocked tool called" notices. No PR comments.
failing replay metrics (such as word error rate) and required key values,
required latency budgets over their threshold or not measured, and any
"unmocked tool called" notices. No PR comments.
- PRs that touch neither a check's org, its state, `vapi-checks.yml`,
`promotion.yml`, the engine (`src/**`, `package*.json`), nor the check's
own `paths` skip it, and `Vapi Simulations` posts success.
Expand Down
2 changes: 1 addition & 1 deletion docs/guides/resource-reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ You are a virtual assistant for the business you represent...
| `silenceTimeoutSeconds` | Hang up after N seconds of silence | `30` typical |
| `maxDurationSeconds` | Maximum call duration | `600` (10 min) typical |
| `backgroundDenoisingEnabled` | Reduce background noise | `true` / `false` |
| `backgroundSound` | Ambient sound during pauses | `off`, `office` |
| `backgroundSound` | Ambient sound during the call; on a personality, noise on the simulated caller's line | `off`, `office`, `white-noise`, `city`, `crowd`, `farm`, or an audio file URL |
| `voicemailMessage` | Message to leave if voicemail detected | Text string |
| `hooks` | Event-driven actions (see Hooks section) | Array of hook objects |
| `messagePlan` | Idle message behavior | See below |
Expand Down
100 changes: 99 additions & 1 deletion docs/learnings/simulations.md
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,102 @@ behaviours worth knowing when a check surprises you.
default error mocks whether or not a tool was called; read tool results
from `metadata.call.messages` (`tool_calls` carry the ids and names,
`tool_call_result` the answers by `toolCallId`).
- **Replays go by saved UUID.** The run API rejects an inline
`transcriptReplay` ("An inline scenario cannot use transcriptReplay"), on
purpose: a replay must pass the checks that run when a scenario is saved,
and an answer key sent in a run request is never stored. So the check sends
`{type: "simulation", scenarioId, personality}` for a replay scenario, and
first compares the saved copy with the branch's file (see
[Recording replays](#recording-replays)). Replays mock every tool on the
platform by default, so the fail-closed tool rule still holds.
- **Runs are named by their entries.** The run API has no run-level name.
The dashboard's runs table (and the runs list's `summary.source.name`)
shows the entries' shared `name` when every entry has the same one (2 or
more), a single entry's name, and otherwise "API run". A check's `label`
sets every entry's name for that reason.

## Recording replays

A scenario with `transcriptReplay` plays a fixed recording into the target
as the caller, and scores the target's transcript against an answer key:
word error rate (WER) and each key value's verdict (`exact` or not). It
tests the target's transcriber.

```yaml
name: "Recording replay: tricky drug names"
evaluations:
- metric: wer
comparator: "<="
value: 0.1
required: true
transcriptReplay:
recordingUrl: https://raw.githubusercontent.com/<owner>/<repo>/<commit-sha>/recordings/drug-names.wav
answerKey:
transcript: >-
Hello? My name is Priya Raman. I need refills on levothyroxine and metformin.
keyValues:
- value: levothyroxine
required: true
- value: metformin
acceptedVariants: [metphormin]
required: true
```

- **Results are in `results.transcriptEvaluation`**, not
`results.evaluations` (which is empty): `wer`, `evaluations[]` (each with
`metric`, `expectedValue`, `actualValue`, `passed`, `required`) and
`keyValues[]` (`index`, `value`, `verdict`, `required`). A key value is
required only when it says `required: true`. For HIPAA, PCI and
zero-data-retention orgs, `value` is absent and only an `answerKeyUrl` can
be saved.
- **Replays run only from a saved scenario**, by `scenarioId` or
`simulationId`, and the org must be in the replay rollout.
- **Host the recording at a fixed public URL**, and keep it fetchable for
every future run. Presigned call-recording links expire after 30 minutes,
and Vapi's file store rejects audio. A URL pinned to a commit SHA works.
- **Write the answer key in the transcriber's style.** The WER normalizer
doesn't map number words to digits. Deepgram nova-3 writes "March
fourteenth, 19 85" and reads phone digits out singly, so spell numbers the
way the transcriber does, or keep them out of required key values.
- **Open the recording with "Hello?" and a pause** (about 7 s) before the
content. A replayed assistant greets only after it hears the caller, and
the transcriber drops the caller's audio while the assistant speaks.
A platform fix that keeps the caller audible through the greeting merged
on 2026-12-02; once it has shipped, the pause may no longer be
needed.

## Latency budgets

A scenario's `latencyExpectations` set per-metric budgets for voice runs:

```yaml
latencyExpectations:
- metric: turn # end of caller speech to start of assistant speech
aggregation: median
thresholdMs: 1500
- metric: model
aggregation: median
thresholdMs: 1000
required: false # reported, but doesn't fail the simulation
```

- Results are in `results.latencyEvaluations[]`: `metric`, `aggregation`,
`thresholdMs`, `actualMs` (absent when nothing was measured) and `passed`.
`required` defaults to true.
- **Chat records no latency.** Over chat every expectation comes back
`isSkipped: true` with `passed: false`. Neither the platform nor the
verdict counts a skipped one as a failure.
- A required budget with no measurement fails. Set budgets from a real run
with some headroom (about 50% above a production median is a reasonable
start), and make the component metrics (`model`, `voice`, `transcriber`)
`required: false` to show where the time goes without failing on them.

## Background noise for a simulated caller

A personality's `assistant.backgroundSound` mixes noise into the simulated
caller's audio, to test the target with a noisy line (voice only). The
bundled sounds are `office`, `white-noise`, `city`, `crowd` and `farm`, or a
URL to an audio file.

## Simulations (`/eval/simulation`)

Expand Down Expand Up @@ -529,7 +625,9 @@ A run has **no `results` field**. Pass/fail lives in `itemCounts` and on the ite

- the run `ended` and has `itemCounts`, with `total` equal to the number of items created (`simulationRunItemIds`) and greater than 0;
- nothing is `queued`, `running` or `canceled`, and `passed === total`;
- every item was fetched, is `passed`, and has at least one **required** evaluation that wasn't skipped (the all-skipped trap from the chat-mode gotcha above).
- every item was fetched, is `passed`, and has at least one **required** evaluation that wasn't skipped (the all-skipped trap from the chat-mode gotcha above). For a recording replay, a required metric that was measured or a required key value counts; for latency, a required budget that was measured and not skipped counts.

A failed item lists each required judge, replay metric (expected vs actual), required key value that wasn't `exact`, and required latency budget over its threshold or not measured. An item that failed with none of those shows its `failureReason`, such as a recording that couldn't be fetched.

Exit codes: 0 passed, 1 failed, 2 usage error, 3 incomplete (timeout, Ctrl-C, canceled items, results that never arrived). On timeout or Ctrl-C the run is canceled.

Expand Down
56 changes: 56 additions & 0 deletions improvements.md
Original file line number Diff line number Diff line change
Expand Up @@ -2389,6 +2389,62 @@ per-practice numbers in inline squad overrides; see `examples/nhs-shared-squads`

---

## 45. PR checks couldn't run recording replays or report their results

### Problem

Checks send every scenario inline, and `POST /eval/simulation/run` rejects an
inline `transcriptReplay` by design (a replay must pass the scenario-save
checks, and an answer key sent in a run request is never stored). The verdict
read only `results.evaluations`, so a passing replay was "incomplete" and a
failing one, or a run failing only on a latency budget, showed no detail.

### Current behavior and mitigation

A check sends a replay scenario by its saved UUID, with the target still
built from the branch. It needs voice, its own org, and a deployed scenario.
Before a live run it reads each saved replay scenario and stops with an error
if the file's replay settings differ, so a branch edit isn't judged on the
old copy. The verdict reads `results.transcriptEvaluation` and
`results.latencyEvaluations`.

### Risk

The exception to "what's in the files is what runs" is permanent unless the
platform starts accepting inline replays. The stale-copy comparison accepts
extra keys the platform adds, so a key removed from the file goes unnoticed.

### Status

**Implemented.** Covered by `tests/sim-result.test.ts`,
`tests/check-payload.test.ts` and `tests/check-run.test.ts`.

---

## 46. Every check run showed as "API run" in the dashboard

### Problem

The run API has no run-level name. The dashboard's runs table names a run
from its entries only when every entry shares one name.

### Current behavior and mitigation

A check's optional `label` (plus `VAPI_CHECK_LABEL_CONTEXT`, `PR #<n>` in CI)
is written on every simulation entry. The report then names items by scenario
and personality.

### Possible fix

A run-level `name` on `POST /eval/simulation/run`. `runLabelBuild` in
`src/check-payload.ts` is the one place to switch over.

### Status

**Implemented** with entry names; a run-level name needs a platform change.

---

## Out of scope (intentionally not improvements)

- **State file is identity-only and not git-ignored.** It's intentionally
Expand Down
1 change: 1 addition & 0 deletions src/check-build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ export async function checkJobsBuild(
sourceState,
runState,
bindingsResolved,
labelContext: process.env.VAPI_CHECK_LABEL_CONTEXT,
});
result.warnings.unshift(...warnings);
return job(target, result);
Expand Down
25 changes: 25 additions & 0 deletions src/check-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ export interface CheckRunSettings {

export interface CheckDefinition extends CheckRunSettings {
name: string;
// Shared name for every simulation in the run, so the dashboard's runs
// table shows it instead of "API run".
label?: string;
// Resources are read from resources/<org>/ at the checked-out commit.
org: string;
// The org the run executes in; its state supplies credential UUIDs.
Expand Down Expand Up @@ -71,6 +74,7 @@ const MAX_TIMEOUT_MINUTES = 120;
const TOP_LEVEL_KEYS = ["version", "defaults", "checks"];
const SETTINGS_KEYS = Object.keys(CHECK_DEFAULTS);
const CHECK_KEYS = [
"label",
"org",
"runOrg",
"baseUrl",
Expand Down Expand Up @@ -205,6 +209,26 @@ function settings(
return result;
}

// Entry names cap at 80 characters; leave room for " · PR #12345".
const MAX_LABEL = 60;

function runLabel(value: unknown, label: string): string | undefined {
if (value === undefined) return undefined;
if (
typeof value !== "string" ||
value.trim() === "" ||
value.length > MAX_LABEL
Comment on lines +219 to +220

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: the length check runs before the trim, so a padded label that trims to 60 or fewer characters is still rejected.

Suggested change
value.trim() === "" ||
value.length > MAX_LABEL
value.trim() === "" ||
value.trim().length > MAX_LABEL

)
throw new Error(
`${label}.label must be a non-empty string of at most ${MAX_LABEL} characters`,
);
return value.trim();
}

function optionalLabel(label: string | undefined): { label?: string } {
return label === undefined ? {} : { label };
}

function baseUrl(value: unknown, label: string): string | undefined {
if (value === undefined) return undefined;
if (typeof value !== "string" || !/^https?:\/\/[^\s/]+/.test(value))
Expand Down Expand Up @@ -255,6 +279,7 @@ function check(
});
return {
name,
...optionalLabel(runLabel(raw.label, label)),
org,
runOrg,
baseUrl: baseUrl(raw.baseUrl, label),
Expand Down
40 changes: 23 additions & 17 deletions src/check-mocks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,9 @@
// those the dead server is the safeguard.

import type { CheckDefinition } from "./check-config.ts";
import { isObject } from "./check-payload-refs.ts";
import type { CheckRunBody } from "./check-payload.ts";
import { isObject } from "./check-payload-refs.ts";
import { stockPersonalityIs } from "./resource-parse.ts";

export const DEAD_SERVER_URL = "https://vapi-gitops-ci.invalid";

Expand Down Expand Up @@ -406,8 +407,6 @@ export interface CheckMocksArgs {
warnings: string[];
}

const STOCK_PERSONALITY_RE = /^a0000000-0000-4000-8000-00000000000\d$/;

export function checkMocksApply(args: CheckMocksArgs): void {
const { body, check } = args;
const squad = body.target.type === "squad" ? body.target.squad : undefined;
Expand Down Expand Up @@ -437,20 +436,26 @@ export function checkMocksApply(args: CheckMocksArgs): void {
walkObject(w, body.target, base);
body.simulations.forEach((entry, index) => {
const label = `simulations[${index}] (${entry.name})`;
if ("scenarioId" in entry)
// Only a transcript replay goes by scenarioId (see replayEntryBuild). Its
// saved copy can't take default mocks; the platform answers a replay's
// tool calls with a mock of its own, and the dead servers still apply.
if (entry.scenario === undefined && entry.scenarioId === undefined)
w.errors.push(`${label}: needs an inline scenario or a scenarioId`);
if (entry.scenario !== undefined && entry.scenarioId !== undefined)
w.errors.push(`${label}: scenarios must be inline, not by scenarioId`);
if (
entry.personalityId !== undefined &&
!STOCK_PERSONALITY_RE.test(entry.personalityId)
!stockPersonalityIs(entry.personalityId)
)
w.errors.push(
`${label}: personalities must be inline or stock, not ${entry.personalityId}`,
);
walkObject(w, entry.scenario, {
...base,
path: `${label}.scenario`,
where: "scenario",
});
if (entry.scenario)
walkObject(w, entry.scenario, {
...base,
path: `${label}.scenario`,
where: "scenario",
});
if (entry.personality)
walkObject(w, entry.personality, {
...base,
Expand All @@ -459,11 +464,12 @@ export function checkMocksApply(args: CheckMocksArgs): void {
});
});
if (!w.strict) return;
body.simulations.forEach((entry, index) =>
defaultMocksAdd(
w,
entry.scenario,
`simulations[${index}] (${entry.name}).scenario`,
),
);
body.simulations.forEach((entry, index) => {
if (entry.scenario)
defaultMocksAdd(
w,
entry.scenario,
`simulations[${index}] (${entry.name}).scenario`,
);
});
}
Loading
Loading