# Kejue documentation (full text) > Every authored Kejue Voice and Kejue Inference documentation page, > concatenated in navigation order. The API reference is not inlined: > fetch /api-reference/openapi.json (or openapi.yaml) for the exact > machine-readable contract, and /api-reference/error_catalog.json for the > error registry. The page index with one-line summaries is /llms.txt. --- # Welcome to Kejue Voice > Everything you need to build, release, and improve voice AI agents that answer phones, make calls, and talk in the browser. Canonical page: /voice Kejue Voice runs conversations on your phone numbers and in your browser. You choose the agent’s instructions, voice, tools, and limits; we handle the call. Browser text chat is also available in beta. Call records give you transcripts, outcomes, and an audit trail under your workspace’s recording and privacy policies. - [Quickstart](/voice/quickstart) — Create an agent, talk to it, and release it in about ten minutes. - [How it works](/voice/concepts/how-it-works) — Workspaces, agents, versions, and calls: the five-minute mental model. - [API reference](/voice/api-reference) — Every endpoint, schema, and error, generated from the live contract. ## What you can build | You want to | Start here | | --- | --- | | Answer your phone lines with an agent | [Phone quickstart](/voice/quickstarts/phone), then [SIP trunks](/voice/telephony/sip-trunks) | | Put voice or chat on your website or app | [Web quickstart](/voice/quickstarts/web) | | Call customers from a list, inside your contact hours | [Campaigns](/voice/outbound/campaigns) (beta) and [outbound jobs](/voice/outbound/jobs) | | Look up accounts or book appointments mid-call | [HTTP tools](/voice/tools/http-tools) and [secrets](/voice/tools/secrets) | | Hand a caller to a person | [Transfers & call actions](/voice/agents/call-actions) | | Stop the agent saying something it shouldn't | [Guardrails](/voice/agents/guardrails) | | Prove an agent works before customers hear it | [Evals](/voice/evals/overview) | | Send call results to your CRM or data warehouse | [Webhooks](/voice/webhooks/overview) and [extractions](/voice/analytics/extraction-objects) | | Answer your security and compliance review | [Deployment & data residency](/voice/trust/deployment) and [Compliance](/voice/governance/compliance) | ## Three ways to work - **Dashboard** — build, test, release, and review calls without code. The [quickstart](/voice/quickstart) shows each step in the dashboard first. - **API** — create, release, and run agents from your own code at `https://api.kejue.co/v1` with an API key. On-prem deployments use their own control-plane origin plus `/v1`. Shared conventions are in [API essentials](/voice/essentials/authentication). - **AI assistants** — connect Claude or any MCP client to your workspace and build agents by describing them. See [Use Kejue Voice from Claude](/voice/ai-assistants/mcp). Build only against the documented API. The dashboard uses some private routes that are not part of the public contract and can change without notice; unknown `/v1` operations are refused. The [OpenAPI document](/api-reference/openapi.json) lists everything you can rely on. Every page is also available as Markdown for AI tools: add `.md` to the URL, send an `Accept: text/markdown` header, or use **Copy Markdown** under the page title. [`llms.txt`](/llms.txt) indexes every page, and [`llms-full.txt`](/llms-full.txt) contains all of them in one file. --- # Quickstart > Create an agent, talk to it in your browser, and release it to production — in the dashboard or with the API, in about ten minutes. Canonical page: /voice/quickstart By the end of this page you will have an agent you have spoken to, released to production, and ready to put on a website or a phone number. Every step shows the dashboard first and the API second; pick one and stay with it. You need a Kejue Voice workspace. The **builder** role is enough for the dashboard path. The API path also needs an API key, and only an **admin** or **owner** can create one. ### Create the agent **Dashboard** Open **Agents → New agent**. Enter a name (for example *Claims intake*), keep the generated slug, choose **Prompt** mode, and select **Create agent**. Then select **Edit draft**, replace the starter prompt with your own, and save. A short first prompt is enough: ```text You are the claims intake assistant for Acme Insurance. Collect first-notice-of-loss details: what happened, when, and where. Speak in short sentences and ask one question at a time. ``` **API** Create a key in **Settings → API keys** with these permissions: `agents:read`, `agents:create`, `agents:promote`, `agents:deploy`, and `calls:start-web`. The full key (`kejue__`) is shown once, so store it in a secret manager. ```bash export KEJUE_API_BASE="https://api.kejue.co/v1" export KEJUE_API_KEY="kejue__" ``` Every `POST` takes an `Idempotency-Key` header: any unique string, such as a UUID. If a request times out, resend it with the same key and you get the original result instead of a second agent. ```bash curl --fail-with-body -X POST "$KEJUE_API_BASE/agents" \ -H "Authorization: Bearer $KEJUE_API_KEY" \ -H "Content-Type: application/json" \ -H "Idempotency-Key: 018f4d7a-7d30-7d97-9a9b-34c291b99618" \ --data '{ "slug": "claims_intake", "name": "Claims intake", "mode": "prompt", "prompt": "You are the claims intake assistant for Acme Insurance. Collect first-notice-of-loss details: what happened, when, and where. Speak in short sentences and ask one question at a time." }' ``` The `201` response returns the agent `id` and its `draft_version_id`. Keep both. A new agent starts with working default models, voice, and turn-taking, so you can talk to it straight away. Tune them later in [Voices & models](/voice/agents/voices). ### Talk to the draft Everything you edit lands in the agent's **draft**. You can talk to the draft before releasing anything, and no caller can reach it. **Dashboard** On the agent's page, open **Test call**, choose **Draft**, and select **Start test call**. Allow microphone access and speak. The transcript appears as you talk, and the call is listed under **Calls** when you hang up. **API** Mint browser credentials for the draft by passing its `draft_version_id` as `version_id`: ```bash curl --fail-with-body -X POST "$KEJUE_API_BASE/web-calls" \ -H "Authorization: Bearer $KEJUE_API_KEY" \ -H "Content-Type: application/json" \ -H "Idempotency-Key: 018f4d7a-9c41-7e55-b2aa-59d4f1c88e21" \ --data '{ "agent_id": "AGENT_ID", "version_id": "DRAFT_VERSION_ID" }' ``` Hand the response to the browser SDK as shown in the [web quickstart](/voice/quickstarts/web). The dashboard test call is quicker if you only want to listen. Change the prompt, test again, and repeat until the agent sounds right. ### Release it to production Releasing takes two moves. **Promote** freezes the draft into a numbered, read-only version and points **staging** at it. **Deploy** points **production** at the staging version. Phone numbers, campaigns, and web calls without a `version_id` all use production. **Dashboard** On the agent's page, select **Promote** and confirm. Then, in the staging panel, select **Deploy** and confirm. **API** ```bash curl --fail-with-body -X POST "$KEJUE_API_BASE/agents/AGENT_ID/promote-staging" \ -H "Authorization: Bearer $KEJUE_API_KEY" \ -H "Idempotency-Key: 018f4d7a-a1b2-7c3d-8e4f-5a6b7c8d9e01" curl --fail-with-body -X POST "$KEJUE_API_BASE/agents/AGENT_ID/deploy" \ -H "Authorization: Bearer $KEJUE_API_KEY" \ -H "Idempotency-Key: 018f4d7a-a1b2-7c3d-8e4f-5a6b7c8d9e02" ``` Calls already in progress keep the version they started on. To undo a release, point staging at an older version and deploy again ([Versions & releases](/voice/agents/overview#rollback)). ### Put it in front of callers - [On your website](/voice/quickstarts/web) — Embed browser voice or text chat with the web SDK. No telephony needed. - [On a phone number](/voice/quickstarts/phone) — Connect Twilio or your SIP carrier, attach a number, and dial in. ## If something goes wrong Every error is JSON with a stable `code`. Branch on the code, never on the message: | You see | Why | What to do | | --- | --- | --- | | `401 unauthorized` | The key is missing, mistyped, revoked, or expired. | Check the `Authorization: Bearer` header. `GET /auth/me` confirms which key and workspace you are using. | | `403 forbidden` | The key lacks a permission. `details.required_permission` names it. | Add that permission to the key. Actions don't imply each other: `agents:update` cannot read agents. | | `403 entitlement_required` | Your workspace plan doesn't include the feature in `details.feature`, such as evals or campaigns. | Ask your Kejue contact to enable it. | | `409 slug_taken` | Another agent in the workspace already uses this slug. Slugs stay reserved after archiving. | Pick a different slug. | | `409 idempotency_conflict` | You reused an `Idempotency-Key` with a different request body. | Use a new key for each new request. | | `422 no_production_version` on `POST /web-calls` | The agent has nothing in production yet. | Deploy it, or pass `version_id` to call a specific version. | | `422 agent_baseline_too_large` | The prompt and tool definitions don't fit the model's context budget. | Shorten the prompt or detach tools. [Estimate first](/voice/agents/overview#check-the-token-budget-before-you-release). | | The agent talks over people or pauses too long | Turn-taking needs tuning for your callers. | Adjust [end-of-turn detection](/voice/agents/speech). | The full list, with retry guidance for each code, is in [Error codes](/voice/essentials/error-codes). ## Next steps - [Write a voice prompt](/voice/agents/writing-prompts) that holds up on real calls. - [How Kejue Voice works](/voice/concepts/how-it-works): workspaces, versions, calls, and what happens after a call. - [Test with evals](/voice/evals/overview) before every release. - [Call your systems](/voice/tools/http-tools) during a conversation with HTTP tools. --- # How Kejue Voice works > Agents, versions, and calls — the mental model behind everything else in these docs. Canonical page: /voice/concepts/how-it-works Three ideas. **Agents** define how a conversation goes, **versions** make a change safe to release, and **calls** are the conversations themselves. ```mermaid flowchart LR accTitle: Agent releases and call processing accDescr: Promote an agent draft to staging, deploy it to production, then handle calls and collect transcripts, webhooks, extractions, and analytics. A[Agent draft] -->|promote| V[Version on staging] -->|deploy| P[Production] P --> C[Calls: phone, web voice, chat] C --> W[Transcripts, webhooks, extractions, analytics] ``` ## Workspaces Everything you create — agents, tools, phone numbers, calls, API keys — belongs to one **workspace**. The dashboard calls it a *team*, and the API calls it an *org* (`org_id`). Nothing is shared between workspaces, so use separate ones when you need hard separation, for example between development and production. Two controls decide what you can do in a workspace: - **Permissions** come from your role (owner, admin, builder, viewer, or a custom role) or from your API key's scopes. Each one is a `resource:action` pair such as `agents:deploy`. See [Roles & members](/voice/governance/roles-and-members). - **Entitlements** are features switched on for the whole workspace, such as evals, campaigns, flows, groups, guardrails, and alerts. A missing one returns `403 entitlement_required` whatever your role. ## Agents An agent is the thing that talks. Its **prompt** says who it is and what the call is for. Around the prompt sit its models and voice, turn-taking, [tools](/voice/tools/http-tools) for calling your systems, [guardrails](/voice/agents/guardrails) that check what it says, and [transfers](/voice/agents/call-actions) to people. The [agents section](/voice/agents/overview) covers each one. Agents can work together. A [flow](/voice/flows/overview) (beta) hands a live call from one agent to another when the caller's need changes, and keeps one call and one transcript. A [group](/voice/groups/overview) splits live traffic across agents so you can compare them. ## Versions: draft, staging, production Editing an agent edits its **draft**. Nothing live changes until you promote the draft to a numbered version, then deploy that version. 1. **Promote** freezes the draft into a numbered version that can't change and points **staging** at it. 2. **Deploy** points **production** at the staging version. Every call runs the version that was deployed when it started, so a mid-call edit never changes a conversation in progress. To roll back, deploy an older version. Point staging at the older version before deploying it. Promote and deploy are separate permissions, so one person can build while another approves go-live. ## Calls A call is one conversation. It arrives three ways, all running the same agent, tools, and guardrails: | Channel | How it connects | Who starts it | |---|---|---| | Phone | Your SIP trunk or Twilio account and a [phone number](/voice/telephony/phone-numbers) | A caller dials in, or we dial out from an [outbound job](/voice/outbound/jobs) or a [campaign](/voice/outbound/campaigns) (beta) | | Web voice | WebRTC in the browser | Your backend requests credentials with `POST /web-calls` | | Text chat (beta) | The same browser SDK with `modality: "text"` | The same credential request | The agent listens, thinks, and speaks in turns. Transfers, keypad input, and hanging up are settings, not code you host — the one thing you host is your own tool endpoints. ## How the agent hears and speaks You choose one of two pipelines for each agent: - **Speech model** — one model hears the caller's audio and replies in speech. Turn-taking feels most natural. New agents start here. - **Cascaded** — speech-to-text, a text model, then text-to-speech. Pick each part separately from the [catalog](/voice/agents/voices). Either way, [turn-taking](/voice/agents/speech) decides when the caller has finished speaking. When guardrails are on, they sit between the model and the caller: speech that fails a check is never played, and if a check can't run we fail closed. ## After the call When a conversation ends, we: 1. Store the call with a **PII-redacted transcript**. Reading the raw transcript is a separate, audited request — see [Compliance](/voice/governance/compliance). 2. Run the agent's after-call work: a summary and structured [extractions](/voice/analytics/extraction-objects), such as a claim type or a callback date. 3. Send a signed `call.completed` [webhook](/voice/webhooks/overview) with the transcript, outcome, and extracted data. 4. Update [analytics boards](/voice/analytics/boards) and [usage](/voice/analytics/usage). ## Testing [Evals](/voice/evals/overview) play simulated callers against a draft or a staged version and grade the result with checks you define. Run them before every release, and point them at real production calls to catch drift. ## Where the API fits Everything on this page is a resource under `https://api.kejue.co/v1`, and the dashboard uses the same rules. Conventions shared by every endpoint — authentication, errors, retries, pagination — are in [API essentials](/voice/essentials/authentication). --- # Talk to your agent in the browser > The fastest way to hear your agent — a WebRTC call from a web page, no telephony setup. Canonical page: /voice/quickstarts/web A browser call needs no phone number and no carrier. You need a deployed agent and one endpoint on your backend that hands the browser a short-lived token. Audio flows directly between the browser and us. ### Mint a token on your backend Your API key must never reach the browser, so make this call server-side: ```bash curl --fail-with-body -X POST "$KEJUE_API_BASE/web-calls" \ -H "Authorization: Bearer $KEJUE_API_KEY" \ -H "Content-Type: application/json" \ -H "Idempotency-Key: 018f4d7a-9c41-7e55-b2aa-59d4f1c88e21" \ --data '{ "agent_id": "AGENT_ID" }' ``` Return the whole response body to the browser. You can also send `variables` to fill in [prompt variables](/voice/agents/prompting), `metadata` to tag the call, and `modality: "text"` to start a chat session instead. ### Install the SDK ```bash npm install @kejue/voice-web livekit-client ``` ### Connect ```ts import { startCall } from '@kejue/voice-web'; const call = await startCall({ // The SDK calls this; fetch fresh credentials from YOUR backend. credentials: async () => { const response = await fetch('/api/voice-token', { method: 'POST' }); return response.json(); }, }); call.on('stateChange', (state) => { // 'connecting' | 'initializing' | 'listening' | 'thinking' | 'speaking' | 'disconnected' console.log('agent is', state); }); call.on('transcript', (line) => { console.log(`${line.role}: ${line.text}`); }); // Later: call.setMuted(true); await call.hangup(); ``` Speak — the agent answers. ## What you get without doing anything - The call shows up in your [call list](/voice/analytics/calls) like any phone call, with its transcript and recording. - Guardrails, tools, webhooks, and extractions all run exactly as they do on phone calls. - Agent state, transcripts, and tool activity stream to the browser as events — enough to build a full call UI. ## If something goes wrong | You see | What to do | | --- | --- | | `422 no_production_version` | The agent isn't deployed. Deploy it, or pass `version_id`. | | `403 forbidden` naming `calls:start-web` | Add that permission to the key your backend uses. | | The browser connects but you hear nothing | Browsers block audio until the user interacts with the page. Start the call from a click. See [Playing the audio](/voice/web/voice-sdk#playing-the-audio). | | The call shows `failed` with `caller_hangup_pre_answer` | Nobody joined within the token's window. Mint later, just before connecting. | ## Next - [Web calls](/voice/web/overview) — text chat, tool visibility, autoplay, and using the API without the SDK. - [Put the same agent on a phone number](/voice/quickstarts/phone). --- # Put your agent on a phone number > Connect Twilio or your own SIP carrier, attach a number, and dial in. Canonical page: /voice/quickstarts/phone Two steps: a trunk that carries the calls, and a number that points at your agent. Let us configure Twilio for you, or connect your own carrier. ### Create a trunk #### If you use Twilio Give us your Twilio credentials and we configure the Twilio side: ```bash curl --fail-with-body -X POST "$KEJUE_API_BASE/sip-trunks" \ -H "Authorization: Bearer $KEJUE_API_KEY" \ -H "Content-Type: application/json" \ -H "Idempotency-Key: 018f4d7b-1111-7abc-9def-2b6f8c11aa01" \ --data '{ "name": "twilio-main", "provider": "twilio_automated", "account_sid": "ACxxxxxxxx", "auth_token": "your-twilio-auth-token" }' ``` #### If you bring your own carrier For a carrier that sends calls to a static address and authenticates you by IP: ```bash curl --fail-with-body -X POST "$KEJUE_API_BASE/sip-trunks" \ -H "Authorization: Bearer $KEJUE_API_KEY" \ -H "Content-Type: application/json" \ -H "Idempotency-Key: 018f4d7b-2222-7abc-9def-2b6f8c11aa02" \ --data '{ "name": "carrier-main", "provider": "sip", "sip_signaling_mode": "static_peer", "inbound_auth_mode": "ip_allowlist", "inbound_allowed_addresses": ["203.0.113.10"], "outbound_address": "sip.your-carrier.example", "outbound_transport": "udp", "outbound_auth_mode": "credentials", "auth_username": "acme-bank", "auth_password": "carrier-password" }' ``` Then get the addresses your carrier needs: ```bash curl --fail-with-body "$KEJUE_API_BASE/sip-trunks/runtime-info" \ -H "Authorization: Bearer $KEJUE_API_KEY" ``` Add an origination route for **every** address we return, and allow every range we list on your side. We answer on more than one address, and a carrier pointed at just the first one will drop calls. A trunk takes a moment to come up. Poll `GET /sip-trunks/{id}` until its status is `active`. ### Point a number at your agent ```bash curl --fail-with-body -X POST "$KEJUE_API_BASE/phone-numbers" \ -H "Authorization: Bearer $KEJUE_API_KEY" \ -H "Content-Type: application/json" \ -H "Idempotency-Key: 018f4d7b-3333-7abc-9def-2b6f8c11aa03" \ --data '{ "trunk_id": "TRUNK_ID", "e164": "+12025550100", "agent_id": "AGENT_ID", "direction": "inbound" }' ``` Numbers come up the same way — poll `GET /phone-numbers/{id}` until `active`. ### Dial it Call the number. The agent answers, and the conversation appears in your [call list](/voice/analytics/calls) with its transcript and recording. ## If something goes wrong | You see | What to do | | --- | --- | | The trunk stays in `provisioning` or turns `failed` | `GET /sip-trunks/{id}` returns `last_error_code` and `last_error`. Fix the credentials or addresses they point to, then update the trunk. | | The number rings out or gives a busy tone | Check that the number is `active`, attached to a deployed agent, and that your carrier routes it to every address in `public_sip_uris`. | | Some inbound calls fail now and then | Your carrier probably routes to only one of our addresses. Add a route for every `public_sip_uris` entry. | | Calls from your carrier are rejected (IP allowlist trunks) | Add every signaling address your carrier uses to `inbound_allowed_addresses`. | Per-call SIP detail, including the messages your carrier sent, is on each call record. See [Calls](/voice/analytics/calls). ## Next - [SIP trunks](/voice/telephony/sip-trunks) — registration modes, media encryption, and the controls that stop toll fraud. - [Outbound calls](/voice/outbound/jobs) — have the agent dial out. - [Transfers & call actions](/voice/agents/call-actions) — hand callers to a human. --- # Agents > What an agent is, how you change one safely, and how a change reaches live callers. Canonical page: /voice/agents/overview An agent is a voice persona you configure once and run on every call: its instructions, its voice, the tools it can use, and the limits it works inside. Create one under **Agents → New agent**. An agent starts as little as this: ```json { "slug": "claims_intake", "name": "Claims intake", "mode": "prompt", "prompt": "Collect first-notice-of-loss details." } ``` The **slug** is permanent — pick it carefully. The name you can change any time. Over the API: [`POST /v1/agents`](/voice/api-reference/agents/create-agent). ## Draft, staging, production Every agent has one editable draft and a history of numbered versions. A version never changes once it exists, and callers only ever reach a deployed one. ### Edit the draft Change anything you like. Nothing live is affected, and there's no limit on how often you save. Over the API: [`PATCH /v1/agents/{id}/draft`](/voice/api-reference/agents/update-agent-draft). ### Promote to staging Promoting freezes the draft as a numbered version and points **staging** at it. Staging is a real, callable target — you can dial it. Over the API: [`POST /v1/agents/{id}/promote-staging`](/voice/api-reference/agents/promote-agent-draft-to-staging). ### Deploy Deploying points **production** at the staged version. Callers get it on the next call that starts. Over the API: [`POST /v1/agents/{id}/deploy`](/voice/api-reference/agents/deploy-agent-to-production). Calls in progress keep the version they started with, so a deploy never changes a conversation already underway. Promoting and deploying are separate permissions, which is the point: an integration can prepare changes without publishing them, and a reviewer can hold the gate. ### Rolling back Point staging at any earlier version and deploy it again. There's no special rollback mode — going back is the same two steps as going forward. ## Cloning an agent Open the agent and choose **Clone agent**. Pick **Draft**, **Staging**, or **Production** from the versions available. The name starts with the original name and an `_clone` suffix. Edit the name and slug, then choose **Clone agent**. The new agent opens with one editable draft containing the selected version's prompt or workflow, model and voice settings, behavior, and after-call configuration. Shared resources such as tools and webhooks keep their existing IDs. The clone starts without deployments, phone assignments, or call and version history. Its first promotion creates version 1. Use `clone_agent` in MCP or call [`POST /v1/agents/{id}/clone`](/voice/api-reference/agents/clone-agent) with `name`, `slug`, and `source` set to `draft`, `staging`, or `production`. The API requires `agents:read` and `agents:create`. ## Editing settings Everything about an agent is edited on the draft. The settings are grouped, and each group has its own page: | Page | What it covers | | --- | --- | | [Instructions & variables](/voice/agents/prompting) | The prompt, and the call-specific values it can reference | | [Speech & turn-taking](/voice/agents/speech) | Models, voice, transcription, when the agent takes its turn | | [Voices & models](/voice/agents/voices) | The catalog you pick models and voices from | | [Conversation behavior](/voice/agents/behavior) | Greeting, quiet callers, call limits, memory | | [Transfers & call actions](/voice/agents/call-actions) | Transfers, callbacks, keypad input, hanging up | | [Guardrails](/voice/agents/guardrails) | What the agent must and must not say | | [Pronunciation](/voice/agents/pronunciation) | How it says your brand names and codes | A draft patch is partial at the top level: fields you leave out keep their values. The `behavior` object is the exception — send it whole, because it replaces the stored one. ## Before you promote: check the prompt isn't too big Your prompt and tool schemas occupy the model's context on every call. If they take up too much of it, promotion is refused. Check it first with [`POST /v1/agents/{id}/estimate-baseline`](/voice/api-reference/agents/estimate-agent-baseline) — an empty body estimates the current draft. The response splits the cost between your instructions and your tool definitions, so you know which to trim, and gives you the budget to stay under. Trimming tools usually wins more room than trimming prose. ## Archiving Archiving an agent takes it out of use but keeps its history: past calls, versions, and audit records stay readable, and the slug stays reserved. Over the API: [`DELETE /v1/agents/{id}`](/voice/api-reference/agents/archive-agent). ## See also [Guardrails](/voice/agents/guardrails) · [Flows](/voice/flows/overview) · [Testing agents](/voice/evals/overview) · [API reference](/voice/api-reference) --- # Editing the draft > How PATCH /v1/agents/{id}/draft works — merge-patch semantics, how to clear a value, size limits, and where every settings field is documented. Canonical page: /voice/agents/settings Every agent setting is written through `PATCH /v1/agents/{id}/draft`, then promoted and deployed ([Agents](/voice/agents/overview)). This page covers write semantics; the fields live in [the map below](#where-the-fields-live). ```bash curl -X PATCH https://api.kejue.co/v1/agents/AGENT_ID/draft \ -H "Authorization: Bearer $KEJUE_API_KEY" \ -H "Content-Type: application/json" \ --data '{ "prompt": "Collect the policy number before incident details.", "behavior": { "guardrails": {"guardrail_set_ids": ["GUARDRAIL_SET_ID"]} } }' ``` ## Merge-patch semantics The draft patch is a **merge patch at the top level only**: omitted top-level fields keep their values; an empty object body is a successful no-op (`updated: false`). Nested objects are *not* merged — `behavior` replaces the complete behavior document, so read the draft first and resend every block you keep. Clearing is explicit and field-dependent: | You send | Effect | | --- | --- | | Field omitted | Current value preserved | | `{}` as the whole body | No-op; `updated: false` | | `prompt` | Replaces the prompt; cannot be blank | | `behavior: {...}` | Replaces the whole object; omitted blocks reset to documented defaults. `behavior: {}` resets everything and removes all assignments. | | `""` on a model/voice reference (`llm_provider_model_id`, `stt_provider_model_id`, `tts_provider_model_id`, `tts_voice_id`, `speechlm_provider_model_id`) | Clears the selection | | `null` on those references | Rejected — `422 validation_failed`, field code `invalid_type`. `null` never clears. | | `""` on `stt_language` | Clears the fixed language | | `{}` on `tts_voice_settings` | Clears the per-agent voice override | ## Limits and validation `prompt` ≤ 500,000 characters; `behavior` and `tts_voice_settings` ≤ 1 MiB each. Validation failures return `422 validation_failed` with exact field paths in `error.details.fields`; the draft is never partially changed. Draft patches need no idempotency key — retries are safe. The legacy storage fields `model_config` and `stt_hints` are not public and are rejected as unknown fields. `behavior` is closed too: unknown fields error instead of being silently dropped. ## Where the fields live | Page | Covers | | --- | --- | | [Speech & turn-taking](/voice/agents/speech) | Pipeline mode, endpointing, transcription language, models and voice, voice settings, turn taking, background noise | | [Conversation behavior](/voice/agents/behavior) | Temperature, opening, connection wait, recording, inactivity, memory, resume | | [Transfers & call actions](/voice/agents/call-actions) | System tools (transfers, scheduling, end call), tool/MCP, guardrail, and pronunciation assignments, transfer records | | [Prompt variables](/voice/agents/prompting) | Everything the prompt can reference | | [Guardrails](/voice/agents/guardrails) | Authoring guardrail sets | | [Pronunciation](/voice/agents/pronunciation) | Authoring pronunciation tables | | [Voices & models](/voice/agents/voices) | The catalog the model/voice reference fields point into | ## See also [Agents](/voice/agents/overview) · [API reference](/voice/api-reference) --- # Write a voice prompt > Structure an agent's prompt so it sounds natural on the phone, stays in scope, and uses live call data safely. Canonical page: /voice/agents/writing-prompts The prompt is the most important setting on an agent: it decides what the agent says, what it refuses, and how it sounds. Use this page when you write a new agent or when an existing one rambles, invents answers, or reads things aloud that it shouldn't. These are defaults that work for most agents. Your own conventions win when they differ. ## Start from this skeleton Strong production prompts use XML-style sections in this order. Leave out any section you don't need. ```text You are Lina, the card services assistant for Acme Bank. Your single goal is to help callers block a lost or stolen card. - Only discuss card blocking. For anything else, offer a transfer to an agent. - Never ask for a full card number, PIN, or password. - If the caller sounds distressed or mentions fraud in progress, transfer at once. Reply in the caller's language: English or Gulf Arabic. Use a polite, formal tone. - lookup_customer: call it after the caller confirms their date of birth. While it runs, say "One moment while I find your account." If it fails, apologize and transfer. - block_card: call it only after the caller confirms which card to block. - transfer_to_human_warm: use it when a rule above says to transfer. 1. Greet and confirm the caller wants to block a card. 2. Verify identity with date of birth, then call lookup_customer. 3. Read back the last four digits of each card and ask which one to block. 4. Call block_card, confirm the result, and ask if there is anything else. 5. Say goodbye and call end_call. Speak in one or two short sentences, then stop. Ask one question at a time. If the caller is silent, ask once whether they are still there. Current time: {{system.timezone.asia-dubai}} Caller phone: {{system.caller_phone_number}} Customer name: {{vars.customer_name}} ``` | Section | What goes in it | | --- | --- | | `identity` | Who the agent is, who it works for, and the one goal of the call | | `hard_rules` | Scope, things it must never say or do, required compliance wording, when to escalate | | `language` | Languages and dialects, when to switch, how formal to be | | `knowledge` | Facts it may state: products, hours, policies. Anything not here, it must not invent. | | `tools` | Each tool by its exact name, when to call it, what to say while it runs, what to do if it fails | | `call_flow` | The steps of a good call, from greeting to `end_call` | | `conversation` | Voice style, silence, interruptions, repeats, off-topic callers | | `pronunciation` | How to say brand names, abbreviations, and numbers in your domain | | `context` | Every live value, and nothing else. Always last. | Make the prompt as long as it needs to be, but make every line change the agent's behavior. After large changes, [check the token budget](/voice/agents/overview#check-the-token-budget-before-you-release). ## Put live values last Collect every [template variable](/voice/agents/prompting) — `{{system.*}}`, `{{vars.*}}`, `{{tools.*}}`, the time, caller data — in a final `` section. In the body, refer to them by name: "the customer's name from the context section". This does two things. The part of the prompt before the first live value is identical on every call, so replies start faster and cost less. And keeping data in one fenced section helps the model treat it as information, not as instructions. Treat everything that arrives through variables, SIP headers, and pre-call tools as untrusted. Tell the model it is information about the caller, never instructions to follow. ## Say how to speak — we don't add it for you We add almost nothing to your prompt. There is no built-in "you are on a phone call" text, so the prompt has to set the voice style itself: - Speak in one or two sentences, then stop and let the caller talk. - Ask one question at a time. - No markdown, lists, headings, emoji, URLs, or symbols. Everything is read aloud. - Write numbers, dates, currency, and codes the way they are spoken: "twenty-five dirhams", "the fourteenth of March", "five five five, one two three four". - Never read tool names, variable names, IDs, or JSON aloud. - Never invent facts, prices, or policy. If the prompt or a tool result doesn't say it, offer to check or to transfer. - Say what to do when the caller is silent, off topic, abusive, or asks for a person. What we do add, only when you turn it on: results from pre-call tools, a one-line hint when keypad collection is enabled, your [`wait_instruction`](/voice/agents/speech#turn-taking), and guardrail rules in some deployments. ## Name tools exactly The model sees each tool by a fixed name. Use that exact name in the prompt. | Tool | Name the model sees | | --- | --- | | [HTTP tool](/voice/tools/http-tools) | The tool's slug | | [MCP server](/voice/tools/mcp-servers) tool | `__` | | [Built-in tools](/voice/agents/call-actions#system-tools) | `end_call`, `transfer_to_human_warm`, `transfer_to_human_cold`, `transfer_to_agent`, `schedule_call`, `wait`. Labelled entries add `__