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

# Drafts and tests

> Change an agent without callers noticing, talk to the draft, and check it with simulated calls before publishing

## Drafts

What you change in an agent is kept as a **draft** as you type, shared by everyone in the workspace. Callers hear the published version until somebody presses **Publish**; **Discard** goes back to it. Published versions are kept in the agent's **Settings → Versions → History**, where one can be brought back into the draft. If the published agent changed after the draft was started (somebody else, or [the API](https://docs.lokutor.com/api-reference/agents.md)), Publish says so first.

The agent's knowledge, its success rules and the switches of its calendar and CRM are not part of the draft: they are saved at once.

Three things can run the draft:

* **Test**, next to Publish: choose **Draft** or **Published** and talk to it.
* **A phone number**: in the agent's **Phone** tab, set a number to **Draft** and call it. Use a number only your team knows.
* **Your app**: add `environment=staging` to the voice socket.

```
wss://api.lokutor.com/ws/agent?agent_id=…&environment=staging
```

It needs a session of the workspace that owns the agent; anyone else gets the published one. With no draft, staging is the published agent. Your own model's key is never in a draft: the published agent's is used. Conversations on a draft carry `"environment": "staging"` in their metadata.

## Tests

In the agent's **Tests** tab, a simulated caller talks to the agent by text and each call is checked against what you expect. A test is:

* **The caller**: who they are and what they want, in your words.
* **It passes when**: up to 12 checks, each judged on its own with a reason.
* **Its call**: whether they call or the agent does, the [data it brings](https://docs.lokutor.com/guides/call-settings.md#data-of-each-call), and whether nobody picks up a transfer.
* **What tools answer**, in that test only. Any other tool answers `ok`. Nothing is booked, sent or transferred.
* **Longest call**: 2 to 30 turns, 12 unless you change it.

**Write some for me** writes tests from the agent. In **Conversations**, a call's **Make a test of this** writes one that plays that call again, without the caller's details, so a problem you fixed does not come back.

Run one or all of them against the draft or the published agent. Past runs are kept, with each call. If the last run had failures, Publish says so first. A test checks what the agent says and does, with its instructions, workflow, models and tools; not how it sounds.

### What it costs

A test is [billed by its tokens](https://docs.lokutor.com/pricing.md#tests-the-assistant-and-the-text-test): about $0.04 with the default model, more with a dearer one or long instructions. Next to **Run all** is what running them all is expected to cost, and next to each result what it did. A run has up to 40 tests, and one expected to cost more than $10 asks first. A test stops at \$2, and a run that reaches what it may cost leaves the rest not played, and says so.

### API

Tests can be written through the [Agents API](https://docs.lokutor.com/api-reference/agents.md#knowledge-rules-and-tests) too. A test's `call.script` is what the caller says first, word for word, one turn each.

```
POST /agents/{id}/tests/run
{ "environment": "staging", "test_ids": ["…"], "max_usd": 10 }   → 202 { "run_id": "…", "total": 3, "estimate_usd": 0.13 }

POST /agents/{id}/tests/estimate
{ "environment": "staging", "test_ids": ["…"] }                  → 200 { "tests": 3, "estimate_usd": 0.13, "max_usd": 10 }
```

Both need `agents:write`. Leave out `test_ids` to run them all. `max_usd` is the most the run may cost; a run expected to cost more answers `409` [`tests.run_limit`](https://docs.lokutor.com/api-reference/errors#billing-errors) and runs nothing. Results appear in the dashboard as each test ends, each with its `cost_usd`.


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