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

# Tests

> Write and manage simulated conversation test cases in the PolyAI ADK, and understand how testing fits into the local workflow.

Agent Studio test cases are simulated conversations that run your agent end-to-end in the sandbox environment. They are managed locally as YAML files under `test_suite/` and pushed to Agent Studio with `poly push`.

Each test case describes a scenario for a simulated user and a set of assertions to evaluate against the resulting conversation. Then, the tests run inside Agent Studio against the pushed branch.

## Where tests fit in the workflow

Tests sit between validation and merge in the standard [CLI working pattern](https://docs.poly.ai/adk/reference/cli.md). Edit locally, validate with `poly validate`, push, then trigger and inspect the test suite with `poly test`.

> [card] Validation
>
> Use `poly validate` to check project configuration before pushing.

> [card] Simulated conversations
>
> Define test cases under `test_suite/` and run them with `poly test run`.

> [card] Interactive review
>
> Use `poly chat`, `poly test show`, and Agent Studio to spot-check behavior on the pushed branch.

## Location

Test cases are defined as one YAML file per test under:

```text theme={"theme":{"light":"github-light","dark":"github-dark"}}
test_suite/
├── greeting_flow_test.yaml
└── webchat_smoke_test.yaml
```

The directory is optional. Create it only when you have test cases to define.

> [!NOTE]
>
> **Filename must match the test name**
>
> The filename (without `.yaml`) must match the normalized form of the `name` field: lowercased, with punctuation replaced by underscores. `Greeting flow test` becomes `greeting_flow_test.yaml`. `poly push` rejects mismatched names.

## What a test case contains

| Field | Required | Description |
| - | - | - |
| `name` | Yes | Human-readable test name. Must match the filename when normalized. |
| `scenario` | Yes | Natural-language description of what the simulated user does. Drives the simulator turn-by-turn. |
| `channel` | Yes | `voice` or `webchat`. |
| `language` | Yes | BCP 47 language tag (e.g. `en-GB`). Must be a configured language in the project. |
| `variant` | No | Name of a variant from `config/variant_attributes.yaml`. Defaults to the project default variant. |
| `simulated_at` | No | Test clock — the point in time the conversation is simulated at, as an ISO 8601 datetime (e.g. `2026-01-15T09:30:00Z`). Defaults to the time the run is triggered. |
| `tags` | No | List of strings used to group, filter, or schedule tests. Usable with `poly test run --tag`. |
| `caller_number` | No | The number the simulated call arrives from. See [mock call context](#mock-call-context). |
| `sip_headers` | No | SIP headers a carrier would send with an inbound call. |
| `integration_attributes` | No | Attributes a channel or connector passes in. |
| `agent_memory` | No | The Agent Memory profile the agent sees as `conv.memory`. Absent means not mocked, and `{}` means a first-time caller. See [mock agent memory](#mock-agent-memory). |
| `api_mocks` | No | Mocked responses for [API integration](https://docs.poly.ai/adk/reference/resources/api_integrations.md) operations. See [API mocks](#api-mocks). |
| `prompt_assertions` | No | List of natural-language statements that must hold about the agent's behavior. Each is evaluated by an LLM judge. |
| `function_call_assertions` | No | List of expected function calls and their argument values. |

At least one of `prompt_assertions` or `function_call_assertions` should be set — a test with no assertions runs but cannot pass or fail.

## Test clock

`simulated_at` pins the agent's notion of "now" for the duration of the simulated conversation. Use it to make time-dependent behavior deterministic — out-of-hours routing, "tomorrow" date resolution, or a seasonal greeting — instead of depending on when the suite happens to run.

```yaml theme={"theme":{"light":"github-light","dark":"github-dark"}}
name: Out of hours test
scenario: Ask to speak to an agent.
channel: voice
language: en-GB
simulated_at: 2026-01-15T22:30:00Z
prompt_assertions:
  - The agent explains the contact centre is closed
```

Values are parsed as ISO 8601 and normalized to UTC when written back by `poly pull`, so `2026-01-15T22:30:00+00:00` and `2026-01-15T23:30:00+01:00` both round-trip as `2026-01-15T22:30:00Z`. An offset-less value such as `2026-01-15T22:30:00` is treated as UTC. Omit the field to run against the real clock; removing it from a file that had one clears the test clock on the next push.

## Mock call context

A real conversation arrives carrying more than the caller's words: the number it came from, the SIP headers a carrier attached, the attributes a channel passed in. Three optional fields simulate that, so a flow that branches on any of it can be tested without placing a real call.

```yaml theme={"theme":{"light":"github-light","dark":"github-dark"}}
name: VIP caller routing
scenario: Ask to speak to someone about my order.
channel: voice
language: en-GB
caller_number: "+447700900000"
sip_headers:
  x-dnis: "441234567890"
  x-call-id: abc-123
integration_attributes:
  tier: gold
  retry_count: 2
  vip: true
  account:
    region: uk
```

### caller\_number

The number the call arrives from, always text. The agent reads it as `conv.caller_number`.

Leave it out to simulate a withheld or anonymous number — a real production case worth testing, so no format validation is applied beyond trimming whitespace.

**Quote it.** YAML reads an unquoted number as an integer *and drops a leading `+`*:

```yaml theme={"theme":{"light":"github-light","dark":"github-dark"}}
caller_number: +447700900000     # becomes 447700900000 — the + is lost
caller_number: "+447700900000"   # correct
```

`poly push` rejects an unquoted number rather than converting it, because the two cases are indistinguishable once YAML has parsed them and silently sending a different number would make the test lie.

### sip\_headers

Headers a carrier would send with an inbound call. The agent reads them as `conv.sip_headers`.

Header names are case-sensitive — match exactly what your telephony integration sends. Values are always text on the wire, so a YAML `true` is sent as `"true"` and a number as its digits. Quote anything you want preserved exactly.

Headers can be set on a `webchat` test, but a real webchat conversation never receives them, so the test would cover a state production cannot reach.

### integration\_attributes

Attributes a channel or connector passes in. The agent reads them as `conv.integration_attributes`.

Unlike SIP headers, these **keep their type**, so a flow branching on `retry_count > 2` sees a number rather than the text `"2"`. Text, numbers, `true`/`false`, `null`, lists, and nested maps are all supported.

Types come from YAML, which means quoting matters:

| YAML | Reaches the agent as |
| - | - |
| `retry_count: 2` | number |
| `retry_count: "2"` | text |
| `vip: true` | boolean |
| `vip: "true"` | text |
| `expiry: "2026-08-12"` | text |

Dates must be quoted. An unquoted `expiry: 2026-08-12` is a YAML date, which the agent cannot receive, and `poly push` rejects it rather than guessing what you meant.

## Mock agent memory

`agent_memory` sets the Agent Memory profile the agent sees, read as `conv.memory`, so returning-caller and first-time-caller paths each get a test case of their own. When it is set, it **replaces** `conv.memory` for the whole run, and nothing stored for the caller is read.

```yaml theme={"theme":{"light":"github-light","dark":"github-dark"}}
name: Returning caller skips the name question
scenario: Book a table for Friday at 7pm.
channel: voice
language: en-GB
agent_memory:
  first_name: Sam
  last_booking:
    date: "2026-08-14"
    party_size: 2
prompt_assertions:
- The agent greets the caller as Sam without asking for their name
```

There are three states, and each one means something different:

| YAML | Meaning |
| - | - |
| field absent | Not mocked. The run reads whatever profile is stored for the caller's identifier. |
| `agent_memory: {}` | A first-time caller, with nothing on file. |
| `agent_memory:` with fields | A returning caller with exactly those fields. |

A flow that branches on `conv.memory` wants both a returning-caller case and a first-time-caller case. `caller_number` alone doesn't make a returning caller, so use `agent_memory` for that.

Values follow the same type rules as `integration_attributes`: they keep their YAML type, nested maps and lists are supported, and dates must be quoted. Use synthetic values only, never real customer data.

Pulling, renaming and pushing a case keep `{}` and an absent field distinct.

## API mocks

A flow that branches on an [API integration](https://docs.poly.ai/adk/reference/resources/api_integrations.md)'s response — a booking that's available vs. full, a lookup that succeeds vs. errors — needs that response to be deterministic to test reliably. `api_mocks` intercepts calls to a named integration operation during simulation and returns the mocked response instead of calling the real API.

Mocks are keyed by integration name, then operation name, then a list of response rules tried in order:

```yaml theme={"theme":{"light":"github-light","dark":"github-dark"}}
name: Slot negotiation retries once then succeeds
scenario: Book a table for 4 at 7pm.
channel: voice
language: en-GB
api_mocks:
  reservations_api:
    check_availability:
      - respond:
          status: 503
        repeat: 1
      - respond:
          status: 200
          body:
            available: true
            table_id: 42
          headers:
            content-type: application/json
prompt_assertions:
  - The agent retries and confirms the booking
```

Each rule has:

| Field | Description |
| - | - |
| `respond.status` | HTTP status code (100–599). |
| `respond.body` | Optional response body. Reaches the flow exactly as written: `2` stays an integer and `2.0` stays a decimal. Quote dates; only text, numbers, `true`/`false`, `null`, lists, and nested maps are supported. A text body is returned as the raw response text. |
| `respond.headers` | Optional response headers, always sent as text. |
| `repeat` | Optional. How many times to return this response before moving to the next rule in the list. Omit it to respond once. Set it to `-1` to respond with this rule forever — only valid on the last rule in a list. `0` and other negative values are rejected. |

Once a list's rules are exhausted (no trailing `-1` rule), further calls to that operation fall through to the real API.

> [!NOTE]
>
> **Operation names aren't cross-checked at push time**
>
> The integration name must match an existing `api_integration` resource; `poly push` rejects an unknown one. Operation names are not validated against the integration's configured operations — instead, renaming or deleting the underlying operation automatically cascades to any mocks that reference it, the same way the platform handles the rest of the integration/operations relationship.

## Prompt assertions

Each prompt assertion is a free-text statement evaluated against the full conversation by an LLM judge. Write them as observable behaviors, not internal reasoning.

```yaml theme={"theme":{"light":"github-light","dark":"github-dark"}}
prompt_assertions:
  - The agent confirms the caller's booking reference before continuing
  - The agent does not ask for the caller's date of birth
```

## Function call assertions

Each function call assertion checks that a function was called and, optionally, with specific argument values.

| Field | Description |
| - | - |
| `name` | Function name. Must match a global function in `functions/` or a flow function in `flows/<flow>/functions/`. |
| `arguments` | List of argument assertions. May be empty to check only that the function was called. |

Argument assertion fields:

| Field | Description |
| - | - |
| `parameter_name` | Parameter as defined on the function. |
| `expected_value` | Expected value, expressed as a string. When set, it must not be blank and must read as its `value_type`. |
| `value_type` | One of `string`, `integer`, `float`, `boolean`. |

```yaml theme={"theme":{"light":"github-light","dark":"github-dark"}}
function_call_assertions:
  - name: lookup_booking
    arguments:
      - parameter_name: booking_reference
        expected_value: "ABC123"
        value_type: string
      - parameter_name: party_size
        expected_value: "4"
        value_type: integer
```

Only function name and argument values are asserted. The function does not have to be the only call in the conversation, and the order of calls is not checked.

## Example

```yaml theme={"theme":{"light":"github-light","dark":"github-dark"}}
name: Greeting flow test
scenario: Ask for help with booking.
channel: voice
language: en-GB
tags:
  - booking
  - smoke
prompt_assertions:
  - The agent offers to help with booking
function_call_assertions:
  - name: lookup_booking
    arguments:
      - parameter_name: booking_reference
        expected_value: "ABC123"
        value_type: string
```

A minimal webchat smoke test with only a prompt assertion:

```yaml theme={"theme":{"light":"github-light","dark":"github-dark"}}
name: Webchat smoke test
scenario: Say hello on webchat.
channel: webchat
language: en-GB
tags:
  - smoke
prompt_assertions:
  - The agent greets the user
```

## Validation

`poly validate` checks each test case:

* `channel` must be `voice` or `webchat`
* `scenario` is required and non-empty
* `tags` must be unique
* `language` is required and must be one of the project's configured languages (`default_language` or `additional_languages`)
* `variant`, if set, must reference a variant declared in `config/variant_attributes.yaml`
* `simulated_at`, if set, must be a valid ISO 8601 datetime
* `caller_number`, if set, must be text — an unquoted number is rejected rather than converted
* `integration_attributes` values must be text, numbers, `true`/`false`, `null`, lists, or nested maps; an unquoted date is rejected with the quoted form to use instead; keys must be text
* `agent_memory`, if set, must be a map; its values follow the same type rules as `integration_attributes`
* `api_mocks`: the integration name must match an existing `api_integration` resource; each operation must have at least one response rule; each rule's `respond.status` must be a valid HTTP status code (100–599); `respond.body`, if set, follows the same type rules as `integration_attributes`; `repeat`, if set, must be a positive integer or `-1` (respond forever), and `-1` is only allowed on the last rule for an operation
* each `function_call_assertions[*].name` must match a global function under `functions/` or a flow function under `flows/<flow>/functions/`
* each argument's `value_type` must be one of `string`, `integer`, `float`, `boolean`
* each argument's `expected_value`, when set, must not be blank and must read as its `value_type`
* the filename must match the normalized `name`

Validation runs automatically as part of `poly push`.

## Push and run

Test cases follow the standard ADK lifecycle:

1. edit YAML files under `test_suite/` locally
2. validate with `poly validate`
3. push with `poly push` to sync to Agent Studio
4. trigger and monitor the suite with `poly test run`

`poly push` creates, updates, or deletes test cases on Agent Studio to match local state, including `prompt_assertions` and `tags`. Use `poly test run` to trigger execution and `poly test show` / `poly test list` to inspect results — all without leaving the terminal. See [`poly test`](https://docs.poly.ai/adk/reference/cli/test) for the commands and their flags.

> [!TIP]
>
> **Tests are branch-scoped**
>
> Tests are pushed to the current branch and run against that branch's agent. Use a branch per scenario when iterating on flows or topics so test results map cleanly to the change under review.

## What to cover

Good coverage of a project usually includes:

* the happy path of every flow and major topic
* key error paths — missing booking, invalid input, unavailable slot
* function call shape — confirm the agent calls the right function with the right arguments for each branch of logic
* state transitions across turns — confirm later turns reference earlier user input
* behavior on the channels your project actually ships on (voice, webchat, or both)

## Best practices

* write `scenario` as a short, concrete user goal — "Ask to cancel a booking with reference ABC123" — not a script
* prefer prompt assertions for behavior, function call assertions for integration correctness
* keep each test case focused on one outcome; split combined scenarios into multiple files
* use `tags` consistently (`smoke`, `regression`, `<flow_name>`) so suites can be filtered with `--tag`
* cover error paths, not only success cases
* add a webchat and a voice variant of any critical path that runs on both channels
* validate as part of the normal edit loop, not just before merge
* combine the suite with `poly chat` and interactive review in Agent Studio when behavior depends on the full conversation flow

## Related pages

> [card] [CLI reference](https://docs.poly.ai/adk/reference/cli.md)
>
> `poly validate`, `poly push`, `poly chat`, and `poly test` — the commands used in the test workflow.

> [card] [Functions](https://docs.poly.ai/adk/reference/resources/functions.md)
>
> Reference for the functions named in function call assertions.

> [card] [API integrations](https://docs.poly.ai/adk/reference/resources/api_integrations.md)
>
> Define the integrations and operations that `api_mocks` intercepts.

> [card] [Variants](https://docs.poly.ai/adk/reference/resources/variants.md)
>
> Define the variants referenced by the `variant` field.

> [card] [Languages](https://docs.poly.ai/adk/reference/resources/languages.md)
>
> Configure the languages a test case can target.

> [card] [Working locally](https://docs.poly.ai/adk/development/working-locally.md)
>
> How tests fit into the daily edit / validate / push loop.
