> ## Documentation Index
> Fetch the complete documentation index at: https://docs.roark.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Improv flows

> Describe the caller and what they want in a brief, and the simulated customer improvises a fresh conversation from it on every run

## Quickstart

An improv flow is a [customer flow](https://docs.roark.ai/documentation/simulation-testing/customer-flows.md) you describe instead of script: a **brief** the simulated customer improvises a fresh call from on every run, graded against your expectations.

Define an improv flow [in code](https://docs.roark.ai/documentation/config-as-code/flows.md#improv-type-improv) (recommended), or build it in the dashboard. The happy path needs a persona and an environment; `prompt` is the brief and `openingLine` is **Customer speaks first**.

```typescript roark.config.ts theme={"theme":{"light":"everforest-light","dark":"everforest-dark"}}
import { defineConfig, defineImprovFlow } from '@roarkanalytics/sdk/lib/config';

const rescheduleCleaning = defineImprovFlow({
  name: 'reschedule-cleaning',
  agents: ['frontdesk'],
  expectations: ['Agent confirms the new appointment time before ending the call'],
  happyPath: {
    persona: 'polite-first-time-caller',
    environment: 'Quiet room',
    openingLine: 'Hi, I need to move an appointment.',
    prompt:
      "You're calling to move your dental cleaning, booked for Tuesday at 10am, to any morning later that week. " +
      'The appointment is under {{customerName}}. Once a new time is confirmed, thank them and end the call.',
  },
  edgeCases: [
    {
      name: 'wrong-account-number',
      prompt:
        "You give account number 00000 when asked. When told it doesn't exist, read it again, " +
        'then offer your date of birth instead.',
      expectations: ['Agent verifies the caller another way instead of ending the call'],
    },
  ],
});

export default defineConfig({ resources: [rescheduleCleaning] });
```

```yaml roark/flows/reschedule-cleaning.yaml theme={"theme":{"light":"everforest-light","dark":"everforest-dark"}}
# yaml-language-server: $schema=https://roark.ai/roark-config.schema.json
kind: flow
type: improv
name: reschedule-cleaning
agents: [frontdesk]
expectations:
  - Agent confirms the new appointment time before ending the call
happyPath:
  persona: polite-first-time-caller
  environment: Quiet room
  openingLine: Hi, I need to move an appointment.
  prompt: >-
    You're calling to move your dental cleaning, booked for Tuesday at 10am, to any
    morning later that week. The appointment is under {{customerName}}. Once a new
    time is confirmed, thank them and end the call.
edgeCases:
  - name: wrong-account-number
    prompt: >-
      You give account number 00000 when asked. When told it doesn't exist, read it
      again, then offer your date of birth instead.
    expectations:
      - Agent verifies the caller another way instead of ending the call
```

```bash theme={"theme":{"light":"everforest-light","dark":"everforest-dark"}}
roark config apply roark.config.ts
```

### Create it with the SDK

In the REST API and the SDKs an improv flow has `type: 'IMPROV'`. The persona and environment are ids: list them with `simulationPersona.list()` and `simulationEnvironment.list()`.

> [tab] Node
>
> ```typescript theme={"theme":{"light":"everforest-light","dark":"everforest-dark"}}
> const flow = await client.customerFlow.create({
>   type: 'IMPROV',
>   title: 'Reschedule a cleaning',
>   agentIds: ['<agent-id>'],
>   happyPath: {
>     title: 'Moves to a morning later that week',
>     personaOverrideId: '<persona-id>',
>     environmentId: '<environment-id>',
>     openingLine: 'Hi, I need to move an appointment.',
>     prompt:
>       "You're calling to move your dental cleaning, booked for Tuesday at 10am, to any morning later that week. " +
>       'The appointment is under {{customerName}}. Once a new time is confirmed, thank them and end the call.',
>   },
>   agentExpectations: [{ prompt: 'Agent confirms the new appointment time before ending the call' }],
>   edgeCases: [
>     {
>       title: 'Wrong account number',
>       prompt:
>         "You give account number 00000 when asked. When told it doesn't exist, read it again, " +
>         'then offer your date of birth instead.',
>       additionalExpectations: [{ prompt: 'Agent verifies the caller another way instead of ending the call' }],
>     },
>   ],
> })
> ```

## Overview

An improv flow is a [customer flow](https://docs.roark.ai/documentation/simulation-testing/customer-flows.md) you describe instead of script. You write a short **brief**: the situation the caller is in, what they want, what they know and how they react. On every run the simulated customer plays a real person making that call, in its own words, and reacts to whatever your agent says.

Choose improv when you care about the outcome more than the exact words: realistic, open-ended conversations, broad behavioral coverage, and agents whose replies you can't predict. When the call has to go a precise way (an IVR menu, keypad entry, a line your agent must say word for word), use a [Scripted flow](https://docs.roark.ai/documentation/simulation-testing/scripted-flows.md) instead.

## The editor

The improv editor has three numbered sections:

1. **Happy path**: the brief for the default version of the call, with its **Persona**, **Environment** and **Hold** chips, an optional **Customer speaks first** line, and **Link preceding flow** to open the call with a scripted flow (see [Composing flows](https://docs.roark.ai/documentation/simulation-testing/customer-flows.md#composing-flows)).
2. **Edge cases**: variations of the call that inherit the happy path and change only what differs.
3. **Grading**: the agents this flow tests (at least one), the expectations every call is graded against, and the flow's metrics.

![The top of the improv editor for a Book an appointment flow (3 variants, 2 expectations). Under 01 Happy path, the brief reads: You are \{\{customerName}}, calling Bright Smile Dental to book a teeth cleaning on \{\{appointmentDate}}. Ask for a morning slot. Accept the first time the agent offers, confirm the time back, thank them and say goodbye. The variables show as green chips, Link preceding flow sits above the brief, and Add variable, Hand over and Caller cue sit in its footer with a 35 words count. Below: Customer speaks first set to Hi, I need to book a cleaning., and the chips Persona Jordan Ellis, Environment Quiet room and Hold Custom.](https://mintcdn.com/roark/tTKLl1mcDRsh0H9y/images/simulation-testing/improv-editor.png?fit=max\&auto=format\&n=tTKLl1mcDRsh0H9y\&q=85\&s=62e7ea1afd487eacec8c800a84eec4bc)

The brief's footer inserts the three things a brief can carry besides plain text: **Add variable**, **Hand over** and **Caller cue**.

## Writing a good brief

The brief becomes the caller's goal for the call: "this is what you are calling about and how you should behave". The caller is told it is a real person on a real phone call with no script, so it pursues that goal in its own natural words. Two rules follow from how it is used:

* **The caller never invents facts.** When your agent asks for something the brief, the persona or a variable doesn't give (an account number, a date, an address), the caller says it doesn't have it or doesn't remember and asks a short question. It never makes one up. So every fact your agent will ask for belongs in the brief.
* **Who the caller is comes from the persona.** Language, accent, voice, pace, baseline mood and background noise are read from the [persona](https://docs.roark.ai/documentation/simulation-testing/personas.md) and the environment, never from the brief. Writing "is angry", "speaks Spanish" or "is calling from a noisy cafe" into a brief changes nothing. The brief is the situation on this call.

Put in:

* **The situation and the goal**: what happened and what the caller wants out of this call.
* **The facts the caller knows**: names, dates, reference numbers, amounts, usually as [variables](#variables-in-the-brief).
* **How they react**: what they accept, what they push back on, what they do when refused.
* **When they're done**: the caller ends the call once its goal is achieved, so say what "achieved" means.

Leave out:

* Persona traits (language, accent, mood): set them on the persona, or change them mid-call with a [caller cue](#hand-overs-and-caller-cues).
* Your agent's lines: the brief describes the caller, not the conversation. To hold your agent to exact lines, use a scripted flow.
* Anything about testing or simulation: the caller plays a real customer.

```text Weak theme={"theme":{"light":"everforest-light","dark":"everforest-dark"}}
Customer wants to reschedule an appointment.
```

```text Strong theme={"theme":{"light":"everforest-light","dark":"everforest-dark"}}
You're calling to move your dental cleaning, booked for Tuesday at 10am, to any morning
later that same week. The appointment is under {{customerName}}, date of birth {{dob}}.
You're short on time: if the agent offers an afternoon, say mornings only, and if nothing
works this week, ask to be put on the cancellation list. Once a new time is confirmed,
thank them and end the call.
```

The weak brief leaves the caller without a name, a date of birth or an existing appointment to move, so it can only say it doesn't know when your agent asks. The strong one gives every fact up front, says what to accept and refuse, and says when the call is done.

## Variables in the brief

Write `{{name}}` for a flow variable and `{{persona.name}}` for a persona property. Click **Add variable** in the brief's footer to insert one with autocomplete. Before the call starts, each token is replaced with its value, so the caller hears `BSD-10482`, not `{{accountNumber}}`.

```text theme={"theme":{"light":"everforest-light","dark":"everforest-dark"}}
You're calling to check the status of order {{orderNumber}}, placed on {{orderDate}}.
If asked, the account email is {{persona.email}}.
```

The brief only names the variable. Its value comes from the run plan that attaches the flow (or from a flow sequence's customer), and any left blank are asked for when the run starts. See [Variables](https://docs.roark.ai/documentation/simulation-testing/variables.md). The **Customer speaks first** line is plain text and can't hold variables.

## Who speaks first

By default the caller waits for your agent to answer and speak. Fill **Customer speaks first** with a line, for example "Hi, this is Maria.", and the caller says it word for word as soon as the call connects. An edge case uses the happy path's line unless it sets its own. When the variant has a **Link preceding flow**, the scripted flow opens the call and this line isn't used.

## Waiting on hold

The **Hold** chip says what the caller does when your agent asks it to wait, for example while it looks something up:

* **Default**: Roark's hold rules. The caller waits when the agent asks for a moment, and never in place of answering a question.
* **Custom**: your own hold rules. Write **Hold instructions** that say when to wait, in your own words. Picking **Custom** fills them in with Roark's rules as a starting point.
* **Never**: the caller answers as soon as the agent stops talking, even while the agent is still working.

With **Default** or **Custom**, the caller waits until the agent speaks again, for at most the **Longest wait** in seconds, then takes the turn back. An edge case shows **Same as happy path** and follows the happy path's hold unless it picks its own. In config as code these are `holdMode` (`DEFAULT`, `CUSTOM` or `NEVER`), `holdInstructions` and `holdMaxSeconds`.

![The Hold chip open on a happy path, reading Hold Custom beside the Persona Jordan Ellis and Environment Quiet room chips. The Waiting on hold panel has Default, Custom and Never with Custom selected, Hold instructions reading Wait while the agent checks the calendar, then ask if a slot was found., and Longest wait set to 60 seconds, with the hint Then the caller takes the turn back.](https://mintcdn.com/roark/tTKLl1mcDRsh0H9y/images/simulation-testing/hold-chip-editor.png?fit=max\&auto=format\&n=tTKLl1mcDRsh0H9y\&q=85\&s=27fdeed2c63d1a4c662c74c250332213)

## Edge cases

An edge case starts from the happy path. With no brief of its own it runs with the happy path's brief (click **Edit brief** to start from a copy), and it keeps the happy path's persona, environment, hold and opening line unless you change them. When an edge case has its own brief, the caller gets both: the edge case's brief is its goal, and the happy path's brief is background for anything the edge case doesn't spell out. Any specific detail in the edge case's brief (a reference number, a name, a date) replaces the happy path's version of it.

![The 02 Edge cases section with No slots that day open and Asks for a specific hygienist collapsed below it, above Add another edge case. No slots that day has its own brief: You are \{\{customerName}} and want a cleaning on \{\{appointmentDate}}. When the agent says that day is full, ask for the nearest day with a morning slot and book it. Its Customer speaks first field shows the line inherited from the happy path, its chips read Persona Sarah Bennett, Environment Quiet room and Hold Same as happy path, and under Additional expectations the Include 2 customer flow expectations switch is on, above Add expectation.](https://mintcdn.com/roark/tTKLl1mcDRsh0H9y/images/simulation-testing/improv-edge-cases.png?fit=max\&auto=format\&n=tTKLl1mcDRsh0H9y\&q=85\&s=18f32b596dd666879ad4dde40cf4fd3f)

Change only what differs. For example:

* **An angry caller.** Pick a persona with an angry base emotion for the edge case, or add a caller cue such as `#{emotion:angry}` at the point the caller loses patience. Writing "you're furious" in the brief does nothing.
* **A wrong account number.** Give the edge case a brief that names an account number your agent won't find, and say what the caller does when told it doesn't exist (read it again, then offer their postcode instead). That number replaces the happy path's.
* **A switch of language.** Pick a persona that speaks the other language, or add `#{language:es}` where the caller switches partway through the call.

Each edge case can also add its own expectations, which apply on top of the flow's. Turn off **Include customer flow expectations** on an edge case to grade it on its own expectations only (`includeFlowExpectations: false` in config as code).

## Hand-overs and caller cues

* **Hand over** (or type `@`) hands the phone to another persona partway through the call, such as a caregiver who takes over from a patient. The sentences around the mention say when, and whether the phone comes back. See [Multiple callers](https://docs.roark.ai/documentation/simulation-testing/multiple-callers.md).
* **Caller cue** (or type `#`) changes how the caller feels, what language it speaks or where it is from that point in the call, or makes it cut in while your agent is talking. See [Caller cues](https://docs.roark.ai/documentation/simulation-testing/caller-cues.md).

## How the caller improvises

Every run of the same variant is a new conversation: the same goal and facts, different words, reacting to what your agent actually says. That is what makes improv good at finding behavior you didn't script, and it also means one call can pass where the next fails.

To tell a real problem from one unlucky conversation, run each variant more than once with the plan's **Iterations** (see [Iterations and concurrency](https://docs.roark.ai/documentation/simulation-testing/running-simulations.md#iterations-and-concurrency)) and look at how often a check fails, not whether one call failed.

The caller ends the call on its own once its goal is achieved, saying goodbye at most once. It also hangs up if your agent stays silent for 10 seconds, and after politely trying once to break a loop where your agent keeps asking the same question. The run plan's end-call phrases and end-call reasons end the call too, and the call never runs past the plan's maximum duration.

> [!NOTE]
>
> Improv flows run as voice calls. They don't run as [chat simulations](https://docs.roark.ai/documentation/simulation-testing/chat-simulations.md).

## How improv calls are graded

Improv calls are graded on outcomes, not on exact wording. The editor's **Grading** section holds the agents the flow tests, its expectations and its metrics:

![The 03 Grading section. Agents lists Bright Smile Dental with Add agent below. Expectations lists The agent confirms the date and time of the booking before ending the call. and The agent asks for the patient's name before booking., with Add expectation. Metrics lists Task Completion with a Set threshold control, and Edit metrics.](https://mintcdn.com/roark/tTKLl1mcDRsh0H9y/images/simulation-testing/improv-grading.png?fit=max\&auto=format\&n=tTKLl1mcDRsh0H9y\&q=85\&s=372e0bd189646cf8e2d1310ec0a5420c)

* **Agent expectations** on the flow are checked against every call's transcript, pass or fail per expectation. An edge case adds its own on top. Write them as specific, checkable statements: "Agent offers a callback when the customer declines to hold", not "Agent is helpful". See [Agent expectations](https://docs.roark.ai/documentation/simulation-testing/customer-flows.md#agent-expectations).
* **Metrics** on the flow, and any the run plan adds on top, score every call the same way they score scripted calls. Set a threshold on a metric to score it as a pass/fail check.

The [Flow adherence](https://docs.roark.ai/documentation/simulation-testing/templates/flow-adherence.md) template runs your flows and grades every call against them, and is the usual place to start.

## In config as code and the SDK

The [Quickstart](#quickstart) above shows a complete improv flow in config as code and the SDK. See [Flows in config as code](https://docs.roark.ai/documentation/config-as-code/flows.md#improv-type-improv) for every field.

***

## Next steps

> [card] [Scripted flows](https://docs.roark.ai/documentation/simulation-testing/scripted-flows.md)
>
> Author the conversation step by step when it has to go a precise way

> [card] [Flow sequences](https://docs.roark.ai/documentation/simulation-testing/flow-sequences.md)
>
> Run several flows in order for the same customer

> [card] [Personas](https://docs.roark.ai/documentation/simulation-testing/personas.md)
>
> Set who is calling: language, voice, pace and mood

> [card] [Caller cues](https://docs.roark.ai/documentation/simulation-testing/caller-cues.md)
>
> Change the caller's mood, language or surroundings mid-call


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.