# Tests

A test is a customer's message, with what should happen to it. Run your tests before you change how the agent works, and you know the change didn't break what already worked. Admins keep them under **Agent → Tests**.

## What a test checks

The agent runs on the message as it would on a live ticket, with its settings, knowledge and connectors. Nothing is sent to anyone, no action is taken, and no ticket is made. What it did is then checked two ways.

**What happened to the ticket** is checked exactly. A test can say that the agent:

- Replies to the customer
- Sends the reply on its own
- Leaves the reply for approval
- Hands off to a person
- Closes it as spam

**What the reply or handoff says** is checked against checks you write in your own words, each one something it **should** or **shouldn't** do: should "say refunds take 5 business days", should "link to the billing page", shouldn't "promise a refund". They're two short lists, one check a row: type in the empty row at the foot of either, and **Enter** goes on to the next. Empty a row to remove it, or use its **×**. A second, smaller model reads what the agent wrote and answers each check, with its reason. Up to 6 of each.

A test that says nothing about what should happen passes whenever the agent finishes. The test of a [memory](https://answerable.co/docs/knowledge/memory.md) also checks that the reply does what the memory says.

A check that fails is run once more before it counts, since the agent doesn't write the same reply twice. A test that fails and then passes is **Flaky**: it counts as passed, and is worth a look. One that fails twice is **Failed**.

## Write and try a test

Tests are written and run in the same place as any message you try on the agent: **Try agent** (`t`), at the top of every Agent tab. Try agent runs a message once; a test is one you keep, to run again before every publish.

1. Open **Try agent**, or **Add a test** under **Agent → Tests**.
2. Write the customer's message, or start from a recent ticket or an example. With the customer's email in **From**, the agent can look up that customer, as it would.
3. Open **What should happen** and say what the agent should do with the ticket, and what its reply should and shouldn't do. Closed, it says in a line what the test expects.
4. **Run test.** You see each step as it happens, then every check with whether it held, what the agent decided, and its reply. **How it got there** keeps the steps.
5. **Save as test** keeps it. You don't have to: a message can be tried and thrown away, as before.

You can also say what should happen after a run. A run that checked nothing offers **Say what should happen**: it opens the section with what the agent just did as the outcome, so the test keeps it doing that. Add checks, then **Run again** to see them checked, or **Save as test**.

A saved test opens in the same panel, from the list or from **Start from a test**. Change it and **Save changes**, or run it with your changes first to see how they'd go. Run as it's saved, its result is kept as its latest.

A real ticket makes a good test. **Save as a test**, in a ticket's ⋯ menu, keeps the customer's latest message with its subject and their address, and so does **Save as test** on a recent ticket in the panel. A recent ticket in the panel can say what should happen before you save it, and its run checks it, reading the conversation up to that message as the agent did. A ticket saved from its ⋯ menu opens with **What should happen** to fill in.

## Run them all

**Run all** under **Agent → Tests** runs every test in the background, a few at a time, and each row shows how its test went, with the first check that didn't hold. While you have unpublished changes, they run with those changes. **Stop** ends a run: tests that haven't started don't, and the ones running finish. One run at a time in a workspace. A test's menu runs it alone.

## Before you publish

Once you have tests, the tray's button for [publishing the agent's draft](https://answerable.co/docs/agent.md#draft-try-publish) is **Test and publish** (⌘P): it runs every test on the draft, and publishes when none of them broke. The menu beside it has **Publish without testing**, for a quick change, and says about what the run uses.

A test **breaks** a publish when it fails now and didn't the last time it ran on published settings. A test that was already failing doesn't stop you, and the tray says how many those are. A test that couldn't be run does, since nothing says it would pass.

When a publish stops, the tray lists the tests that broke, with what didn't hold. Open one to look, change the draft and **Run the tests again**, or **Publish anyway**. If you changed the draft while the tests ran, they're not about what's there now, so nothing is published on their word: run them again, or publish without.

Memory, knowledge and integrations apply as soon as they're saved, without a publish. Run the tests from **Agent → Tests** after changing those.

## What it costs

Each run of a test uses half a credit, whether it's one message in Try agent or one of twenty in a run: it's the agent's full work on a message, then the short check. A test run twice because it failed the first time is charged once. The Tests tab and the publish menu say about what a whole run uses before you start it. [Plan and credits](https://answerable.co/docs/workspace/plan.md) has more.

A workspace keeps up to 50 tests.

## With an agent

An agent connected to Answerable's [MCP server](https://answerable.co/docs/developers/mcp.md) reads the tests with `get_agent_tests`, each with its latest result, and adds, changes, removes and runs them with `update_agent_tests`, with the **Configure the agent** permission (`agent:configure`), as an admin. `run: true` starts a run on the agent's current settings and returns it; `wait` waits for it, and `get_agent_tests` with its `runId` reads it later. So an agent that changes your settings with `update_agent` can run the tests afterwards and tell you what broke. `ticket` saves a ticket's latest customer message as a test. The [REST API](https://answerable.co/docs/developers/api.md) has the same under `/workspaces/{workspace}/agent/tests`.
