Quickstart
A scripted flow is a customer flow whose conversation you write step by step, as a graph the simulated customer follows with the exact lines you authored. Define a scripted flow in code (recommended), or build it on the canvas. This one is a short IVR: an opening line said word for word, a keypad step inside a required IVR Phone Auth stage, a menu that branches on the key pressed, both branches meeting again, and a last step that ends the call.steps are a step’s next steps, so two of them make a branch, and mergeInto joins a step to the one named by that ref. Each apply replaces the whole graph. endsCall takes effect with adherence: STRICT.
Create it with the SDK
In the REST API and the SDKs a scripted flow hastype: 'SCRIPTED' and its steps go in graph, with mergeIntoNodeIds naming the ref to join. replaceGraph swaps the whole graph of an existing flow.
- Node
Overview
A scripted flow is a customer flow whose conversation you write yourself, step by step, instead of a brief the simulated customer improvises from. You draw it on a full-screen canvas as a graph of steps: what the customer says, what your agent should say back, keys the caller presses, pauses, and where the conversation branches. Every run walks your graph with the exact lines you authored, and each route through it becomes its own variant. Reach for a scripted flow when the conversation has to go a precise way:- IVR menus and keypad entry. Navigate a phone tree, press digits, enter an account number.
- Deterministic routing. Check that a given answer leads your agent down the branch you expect.
- Turn-by-turn checks. Hold your agent to specific lines, and decide what happens when it says something else.

The scripted graph
In scripted mode you build the conversation as a directed graph that starts at Start. Click the + under a step and pick a kind from Insert step. Above the kinds, Connection says how the new step joins the graph:- Continue (Slip into this path) puts the new step between this step and the next one. Branch (Fork alongside) adds it as another next step, starting a new path. You get this choice on a step with exactly one next step. On the last step of a path the + simply adds the next step, and on a step that already branches it adds another branch.
- Merge (Converge downstream) adds no step: it links this step to one already on the canvas, so two paths meet again. Click Merge, then the step to join. It shows only when this step has a step it can join: one that isn’t its own next step and doesn’t come before it, since a loop isn’t allowed. So on some steps, as in the picture below, the + offers only Continue and Branch.
- The + under Start offers Continue (goes first instead) and New opening: another way into the call, which runs as its own path.

Step kinds
The picker groups steps by who acts.Over the API and in config as code the step types are
AGENT_TURN (Expected response), AGENT_DTMF (Expected DTMF), CUSTOMER_TURN (Speak), CUSTOMER_VERBATIM_TURN (Say exactly), CUSTOMER_HANDOFF, CUSTOMER_DTMF, CUSTOMER_SILENCE, CUSTOMER_AUDIO and SCENARIO_LINK (Link to flow). CUSTOMER_FIRST_MESSAGE is the retired name for an opening exact line: it is still accepted, and stored and returned as CUSTOMER_VERBATIM_TURN.Looking for the Voicemail step? Voicemail is a run template now, not a step. See Voicemail Testing. A voicemail has no conversation to graph and only one meaningful variable (which greeting plays), so the template runs Roark’s recordings directly. Flows that already contain a Voicemail step keep working; you just can’t add new ones.
#) that change the caller’s emotion, language or surroundings at that step, or make it cut in while the agent speaks.
Graph rules
- Branching is allowed: give a step multiple outgoing edges to fork the conversation. Over the API, a step’s children are its
steps: one child continues the conversation, and several children (including several top-level entries ingraph) are alternative branches. - Merges are allowed: branches can rejoin.
- Cycles are blocked: the graph must be a DAG, so a conversation always terminates.
Stages
A stage groups the steps that come before the real test, such as an IVR menu or a login. Pick or create one under Stage in a step’s inspector; the canvas draws it as a frame around its steps.

stage is a name ("IVR Phone Auth") or an object: { name, required, analyze }.
Ending the call
When an improv flow opens with this scripted flow, every path hands over to the improv at its last step. In a flow that waits for each expected line, set End the call here on the last step of a path to end the call there instead, as an IVR does after saying goodbye (endsCall: true over the API and in config as code).
Paths derive variants
Every unique route through the graph from start to finish is a path, and when you save the flow, Roark derives one variant per path. Each path card in the right rail shows a generated description of its route. You don’t hand-author scripted variants; you shape the graph and the variants follow. You can still control who runs each path: Add variant for path creates an extra copy of a path that runs it with a different persona or environment. The rail marks the flow’s default variant with a Default badge and groups the rest under Edge cases, with Make default and Delete variant available per variant. How those paths turn into calls is a separate choice, covered next in Branching.Branching: how paths become calls
A branching graph can be run two ways, chosen with the Branching control at the top of the variant rail. Both modes speak the exact lines you authored. The choice decides only when a branch is picked and how many calls a run places. Neither mode changes how metrics or agent expectations grade.
Take a caller asking for a Tuesday appointment, where the agent’s own answer forks the conversation. The info icon next to Branching opens How branching works, which runs this example both ways:

Personas multiply calls in both modes. Adapt to your agent collapses a flow’s paths into one call per persona, not one call outright. Five paths across three personas run as three calls. On a collapsed call, variable values come from the primary variant; the sibling variants contribute their path shape, not their own values. Sibling-only variable names are still detected and prompted for, so they don’t vanish silently.
Adapt to your agent is not looser grading, and it is not goal-level authoring. Both branching modes speak your exact scripted lines. To have the agent checked against intent (“confirms the caller’s name”) rather than a script, use an Improv flow with agent expectations.
Over the API and in config as code this is
branchingMode: DETERMINISTIC (Simulate every path) or ADAPTIVE (Adapt to your agent).
Script adherence: loose or strict
Script adherence, the control under Branching in the variant rail, decides how closely each call follows the script. Branching decides how many calls a graph places; adherence decides how each of those calls is walked.
At a strict Agent step, everything your agent has said since the step began is checked against the expected line (and, at a branch, against each alternative’s line) by an LLM judge. A line your agent delivers across two utterances matches on the second. Each utterance that leaves the line still not delivered is one off-script attempt. Where the step expects your agent to press keys, a key press that matches none of the step’s options is an attempt too.
Over the API this is
scriptAdherence (LOOSE or STRICT) on the customer flow, and the policy below is offScriptPolicy. In config files they are adherence and offScript.When your agent goes off script
With Wait for each expected line selected, the variant rail shows When your agent goes off script: the policy for every Agent step in the flow. An Agent step can set its own under When the agent goes off script here in the inspector, and that one wins at that step.
The reaction on each attempt:
- Stay silent (
STAY_SILENT): the simulated customer says nothing and keeps listening. - Repeat my last line (
REPEAT): it says its last scripted line again. - Respond, but hold position (
RESPOND): it answers once, in character, in a sentence or two, without moving the conversation forward or mentioning anything later in the script. - Say a line (
SAY): it says the line you give it (sayLine).
A step where your agent is expected to press keys does not follow the flow’s policy. Without a policy of its own it waits for keys until just before the run’s silence timeout and then hangs up, and the call still counts. Its own policy can only Stay silent or Repeat my last line, and end with Hang up, Hang up and invalidate the run or Move on to the next step.
Where an off-script moment shows up
Over the API, the call’s transcript marks each off-script moment where it happened.offScript is only used for simulations: it appears on entries of GET /v1/call/{callId}/transcript for a simulation call that followed a strict scripted flow, never on production calls or chats. An entry has it only when it was one of these, and has no offScript key otherwise:
- An attempt (
part: "ATTEMPT"), on your agent’s entry: it said or pressed something other than what the step expects, or stayed silent.causeisAGENT_SAID,AGENT_PRESSEDorSILENCE.reactionis what the simulated customer did next when your agent got another try, andactionis what the policy did when this attempt ended the step:HANG_UP,HANG_UP_INVALIDATE,MOVE_ONorADAPT. The last attempt carries the action. - A reaction (
part: "REACTION"), on the simulated customer’s entry: it was reacting to an attempt rather than following its script.reactionisREPEAT,RESPOND,SAYorSTAY_SILENT, andstep,attemptandoccurredAtare those of the attempt it answers.
step it happened at (its nodeId in the flow and its expected line, or null for a branch step the call’s path does not carry), attempt and maxAttempts, and occurredAt, when the attempt was judged off script. Silence at an Agent step is not a counted attempt, so its attempt is null. At a keypress step each wait for keys is one attempt, and the prompt played again is a REPEAT.
A moment with no speech gets an entry of its own, in time order, with empty text and startOffsetMs equal to endOffsetMs, so it adds nothing to talk time: your agent’s silence, keys your agent pressed that have no transcript line, and the simulated customer staying silent. Keys that already have a line ([DTMF: 1 2]) are marked on that line.
offScript on a production call, a chat, a simulation that did not follow a strict flow, or one where your agent stayed on script. Calls from before reactions were recorded have their attempts marked, but no spoken turn marked as a reaction. The transcript route needs the transcript:read permission.
A hang-up by the policy ends the call with endedStatus CUSTOMER_ENDED_CALL, as any hang-up by the simulated customer does. The last attempt’s action (HANG_UP or HANG_UP_INVALIDATE) tells the two apart.
Hang up and invalidate the run also sets invalidation on the job, with reason: "SCRIPT_DIVERGED" and a detail sentence naming the step’s text and what your agent said. See Calls that don’t count.
In the app, every attempt and every outcome is recorded against the step it happened at, with what your agent said (or that it said nothing):
-
Transcript tab of the call: a line with a warning icon at the moment it happened, in the order of the conversation. For a flow set to Repeat my last line, 2 attempts, then Continue loosely:
Off script: expected "Can I have your account number?" but got "How can I help you today?", repeating (attempt 1/2)Off script: expected "Can I have your account number?" but got "Are you calling about a bill?", continued loosely (attempt 2/2)
Off script: expected "…" but got nothing, hung up. - Simulation tab of the call: the script that ran, step by step, with when each step was reached and the same off-script lines under the step they happened at. A moment on a branch alternative that is not on the call’s path is listed under On a branch step.
- Calls list of the run: a call that Hang up ended shows Went off script as its ending, and its detail says what your agent said or that it stayed silent. The Simulation tab names the step it happened at. An invalidated call shows Went off script with one sentence naming the step’s text and what your agent said.

offScript (see above). Stay silent adds no spoken turn.
How metrics treat off-script turns
No metric checks for off-script moments. Every metric reads the call’s transcript as it was recorded, so off-script turns are scored like any other turn:- Repeat my last line, Respond, but hold position, Say a line: each reaction is a caller turn. Your agent’s reply to it counts toward its Response Time, Turn Duration, Latency Spike Count and the other timing metrics exactly as a reply to a scripted line does, and Comprehension Failure grades that caller turn and your agent’s reply like any other.
- Stay silent: there is no caller turn. When your agent speaks again after a pause, that is the same speaker going on, so no Response Time or Latency Spike is measured for the pause. A pause longer than 3 seconds starts a new agent turn for Turn Duration and Turn Count. Comprehension Failure grades caller turns only, so there is nothing for it to grade.
- The time the simulated customer takes before it reacts counts toward the simulated customer’s own timing metrics, not your agent’s.
- After Move on to the next step or Continue loosely, the rest of the call is scored normally. After Hang up, the call is scored on what happened up to the hang-up. After Hang up and invalidate the run, nothing scores the call.
Next steps
Customer flows
Variants, expectations, labels and composing flows
Flow sequences
Run several flows in order for the same customer
Multiple callers
Hand the phone to another persona mid-call
Flows in config as code
Declare scripted graphs in YAML or TypeScript