Skip to main content

Update Agent

Updates an existing agent's configuration in Ultravox and synchronizes the corresponding local agent_mappings record. Supports partial updates -- only the fields provided in the request body are updated. Local-only fields (client assignment, campaign assignment, default direction) are stored in the local database without touching the Ultravox API.

Endpoint

PropertyValue
Function Nameagents-update
HTTP MethodPATCH
AuthenticationSupabase JWT (Bearer token)
Required Roleagency_owner or agency_admin

Request

Headers

Authorization: Bearer <supabase_jwt_token>
Content-Type: application/json

Body

FieldTypeRequiredDescription
agent_idstringYesThe Ultravox agent ID to update.
namestringNoNew display name. Sanitized for Ultravox (alphanumeric, underscores, hyphens; max 64 chars).
system_promptstringNoUpdated system prompt.
voicestringNoUpdated voice identifier.
language_hintstringNoUpdated language hint.
temperaturenumberNoUpdated LLM temperature.
first_speaker_textstringNoUpdated first speaker text. Set to a falsy value to clear.
recording_enabledbooleanNoWhether call recording is enabled.
max_duration_secondsnumberNoUpdated max call duration in seconds.
toolsany[]NoUpdated tool definitions array.
client_idstring | nullNoClient to assign (local only). Set to null to clear.
campaign_idstring | nullNoCampaign to assign (local only). Set to null to clear.
default_direction"inbound" | "outbound" | nullNoDefault call direction (local only). Set to null to clear.

Response

Success (200)

{
"success": true,
"agent": {
"ultravox_agent_id": "uv-agent-abc123",
"name": "Updated_Agent",
"call_template": {
"systemPrompt": "Updated prompt...",
"voice": "terrence",
"temperature": 0.5,
"languageHint": "en",
"recordingEnabled": true
}
},
"mapping": {
"id": "uuid-of-mapping",
"client_id": "uuid-of-client",
"campaign_id": "uuid-of-campaign",
"last_synced_at": "2025-01-16T14:00:00Z"
}
}

If only local fields were updated (no Ultravox API call was needed) and the agent details were not already cached, the agent object contains only ultravox_agent_id. In that case, the function fetches the full agent details from Ultravox to include in the response.

If the local mapping does not exist, it is automatically created with managed_by_virsyn set to false (indicating an imported agent).

Error Responses

StatusCondition
400agent_id is missing from the request body
400client_id is invalid or does not belong to the agency
400campaign_id is invalid or does not exist
400Ultravox API key is not configured for the agency
401Missing or invalid authorization header
403User is not associated with an agency
403User role is not agency_owner or agency_admin
404Agent not found in Ultravox
405HTTP method is not PATCH
500Failed to retrieve API credentials
500Unexpected server error
502Ultravox API returned a non-404 error during the update

Behavior

  • Authenticates the user via Supabase JWT and verifies they belong to an agency with the agency_owner or agency_admin role.
  • Validates the required agent_id field and optional client_id/campaign_id relational fields.
  • Retrieves the agency's Ultravox API key by calling the get_agency_credentials RPC function.
  • Separates request fields into Ultravox fields (name, system_prompt, voice, language_hint, temperature, recording_enabled, max_duration_seconds, first_speaker_text, tools) and local-only fields (client_id, campaign_id, default_direction).
  • If any Ultravox fields are provided, builds a partial update payload and sends a PATCH request to https://api.ultravox.ai/api/agents/{agent_id}.
  • Sanitizes the name field for Ultravox constraints if provided (same rules as create).
  • Constructs a local mapping update payload containing all provided fields plus updated_at timestamp.
  • If the Ultravox update succeeds, sets last_synced_at and clears sync_error in the local mapping.
  • Checks for an existing local mapping. If one exists, updates it. If not, creates a new mapping with managed_by_virsyn set to false.
  • If no Ultravox update was needed (only local fields changed), fetches the full agent details from Ultravox via a separate GET request for the response.

Database Tables

TableOperationDescription
usersReadFetches user profile to determine agency_id and role
clientsReadValidates client_id belongs to the agency (if provided)
campaignsReadValidates campaign_id exists (if provided)
agent_mappingsReadChecks for existing mapping
agent_mappingsUpdateUpdates the existing mapping record
agent_mappingsInsertCreates a new mapping if none exists (for imported agents)

External APIs

APIMethodEndpointDescription
UltravoxPATCH/api/agents/{agent_id}Partially updates the agent in Ultravox
UltravoxGET/api/agents/{agent_id}Fetches full agent details (when only local fields were updated)