Build and publish an agent
Summary
An agent has one draft that you edit and numbered versions that you publish; a publish freezes the complete draft into a version and makes it live for new calls in one step. This guide creates an agent with its voice, edits its draft and a variable, validates and publishes it, lists its versions and rolls back. It does not cover authored tools, Knowledge, credentials or starting a call; see Tools and MCP servers, Knowledge and Start a call.
Facts
Steps
1. Choose a voice
Supported voices depend on the voice model an agent is assigned. Before your first agent exists,
list without agent_id: the answer is the catalogue of the voice model a new agent starts on.
The default voice comes first. Set VOICE_ID to the id of the voice you choose. Each voice
carries grammatical_gender (female, male, an unknown future value, or null when none is
recorded); match a draft’s grammatical gender with it, never with the voice name or ID. A voice has
no languages field.
To change the voice of an existing agent, list with ?agent_id=$AGENT_ID instead: an existing
agent keeps the voice model it is assigned, which can differ from the one a new agent gets. A
next_cursor from one list does not page the other.
2. Create the agent
The answer is 201 with the agent and its identity ETag. Set AGENT_ID to its id. With
initial_draft, the identity and these draft fields are stored in one transaction; the agent is
not published. The initial block can set the prompt, voice, settings and built-in-tool policy.
Variables, authored tools, Knowledge and credentials use their own operations. Without
initial_draft, the draft has the platform’s initial defaults: read it before you edit it.
The create checks the voice against the voice model the new agent actually gets. A refused initial field, such as an unsupported voice, leaves no agent and no idempotency claim; a voice is never substituted.
To find an agent you created before, list GET /agents?resource_key=support-line: a
resource_key lookup also finds an archived agent. GET /agents lists every agent except archived
ones, newest first; repeat agent_id to read several, and add state=archived for archived ones.
GET /agents/{agent_id} answers the agent’s identity and its live pointer, live_version_id.
3. Read the draft and its ETag
Set ETAG to the ETag of the answer. It is the publication token, and it equals the body’s
revision. Variables marked pii or confidential read as "value": null, "redacted": true; a
null value without the marker is a real null. GET /agents/{agent_id}/draft/diff shows what a
publish would change against the live version, as JSON pointers with sensitive values suppressed,
and GET /agents/{agent_id}/variables lists the variables.
4. Edit the draft
The answer is the draft with its new ETag; set ETAG to it. A PATCH merges settings one
level deep, and an array replaces its field. Draft edits do not change live calls. This edit also
makes the agent leave a message on a voicemail (Voicemail).
5. Set a variable default
Set ETAG to the ETag of the answer. A write with "value": null clears the stored default and
keeps the variable declared with its description and sensitivity; each call then supplies the
value in dynamic_variables (Start a call). pii and confidential
values are never returned.
6. Validate the draft
The body is a draft patch applied over the draft for the check, and it must name at least one
field ({} is refused). To check the draft as it stands, send one field with its current value.
validateAgentDraft runs every check a publish would make, then discards the result: nothing is
saved, published or called. It answers valid, a list of errors and warnings (each with its
field, code and message) and the agent’s readiness. It is not a simulated call and does not prove
that a call will be admitted. Warnings never make a draft invalid or block a publish.
A variable name in single braces in the prompt or an opening message ({customer_name}) is filled
in like {{customer_name}} when the call has that variable. A single-brace name that the agent
does not declare, and that is not a built-in (agent_name, language), is filled in only when a
call passes it, so validation answers a single_brace_variable warning for it. Without a value,
the agent reads it as written.
7. Publish the draft
A publish freezes the whole draft (prompt, settings, variables, default-tool policy, tools with
their pinned credential versions, MCP connections and eligible direct-library knowledge) and makes
it live for new calls in one step. Ready library sources are frozen as retrieval data or bounded
prompt context (Knowledge). The answer names the version, whether it was
created (false when identical content reused an existing version) and the live_version_id.
Calls already admitted keep their version.
Two publishes of the same token make one version. A replay returns the original publication receipt; it never activates an older version again. A refused publish leaves the previous version live and the draft unchanged (Errors, below).
8. List the versions
Versions are numbered, newest first. GET /agents/{agent_id}/versions/{version_id} reads one, and
GET /agents/{agent_id}/versions/{version_id}/diff?from_version_id=<older id> compares two. A
version is immutable: its tools are frozen safe descriptors with credential references only, its
default_tools is the frozen built-in policy, and sensitive variables read redacted.
9. Roll back
Set VERSION_ID to the id of the version to activate, and LIVE_VERSION_ID to the agent’s
current live_version_id.
The answer is an activation receipt: from_version_id, to_version_id and warnings. Rollback
activates an existing version by its ID and records a new activation. It never creates a version,
and it keeps the draft and admitted calls unchanged. A replay returns the original activation.
A rollback never restores a revoked credential: warnings lists, under credential_unavailable,
the tools of the activated version whose pinned credential version is revoked, and those tools are
refused when a call uses them. A rollback also does not restore model placements that are no longer
available.
Rules
- MUST send the draft ETag in
If-Matchon every draft write, variable write, validation and publish, and a newIdempotency-Keyon every write except validation. - MUST read the draft again after
409 draft_conflict, review it and send the change with the new ETag. See Revisions and ETags. - MUST send the agent’s identity ETag from
GET /agents/{agent_id}, not the draft ETag, toPATCH /agents/{agent_id}. That operation changes only the name and description. - MUST use
english,hindiorhinglishforsettings.languageininitial_draft, anden,hiorhinglishin later draft edits. - MUST NOT copy a redacted null from a read into a write.
- MUST NOT start a variable key with
system__. - MUST NOT expect a refused voice or setting to be substituted: it is refused, never replaced.
- An agent name is stored without its outer spaces. A name that is blank after that, or holds a control character such as a tab, is refused.
- Repeating a create with the same
Idempotency-Keyand body returns the same201body withIdempotent-Replayed: true.
Built-in tools: the default-tool policy
The draft’s default_tools decides the two built-in tools, and each publish freezes it into the
version:
- End call is on unless you disable it. It has no other settings. It cannot be disabled while IVR hang-up or voicemail detection is on, because those rely on it.
- Transfer is off until you enable it with 1 to 10 named
destinations, or one E.164destination_number. An enabled transfer without a destination is refused. A disabled transfer may keep its destinations for later. See Configure call transfers for destination types and carrier setup. - A
PATCHmerges field by field: a tool or field you leave out keeps its setting. The merged result must still give an enabled transfer a destination. - Writing
destinationsreplaces the whole list. Preserve each existing destination’sidwhen editing it. MUST NOT writedestinationsanddestination_numbertogether. - A draft that never set the policy reads as end-call on and transfer off, and so does a version published before the policy existed.
- After you disable end-call and publish, nothing answers to
end_callduring that version’s calls. External hang-up, the inactivity timer and call duration limits are separate and keep working. end_call,transferandtransfer_to_numberare reserved: no authored tool can take those names (Tools and MCP servers).
The built-in tools never appear in the tool list; the draft and each version show them under
default_tools. GET /tools/catalog describes them.
Voicemail
When settings.voicemail_detection is on and the agent reaches a voicemail, settings.voicemail_action decides what it
does:
hang_upends the call at once.leave_messagespeakssettings.voicemail_message, then ends the call.
An agent that never set voicemail_action reads hang_up.
A call that reached a voicemail ends with end_reason voicemail_detected, with either action. The
same end_reason follows when the carrier reports a machine. dial_outcome can still be
answered, because the carrier connected the call before the mailbox answered. Read end_reason
to find a voicemail.
voicemail_message holds at most 500 characters. It can name call variables as {{name}}, and
the agent fills them in once for each call. MUST send a message that is not blank with
leave_message: the API refuses a blank message with invalid_request on voicemail_message.
Draft and version reads always include voicemail_action and voicemail_message. Read
voicemail_action as an open list, and keep an unknown value.
Readiness
GET /agents/{agent_id}/readiness answers state and reasons. Readiness is a snapshot, not a
reservation. Reason codes include agent_not_published, agent_not_live, agent_archived,
credential_unavailable (the live version pins a revoked credential version) and
no_ready_placement (a serving model is not ready).
Archived agents
Archived agents are left out of agent lists unless you ask for state=archived, and read with
state: archived. An archived agent refuses every draft edit, validation, publish and rollback
with 409 agent_archived. Starting a call with it answers agent_not_live with
details.state = "archived". See Archive and restore an agent.
Verify
Expected output after step 7: the agent with state: live and the published version in
live_version_id.
Errors
A publish is also refused when a selected knowledge source is no longer eligible. An empty voice list means that no voice model is ready for that agent, or for new agents.