This page requires Python familiarity. It is a reference for developers writing functions inside Agent Studio.
Attributes
id
id
Description: Unique identifier of the conversation.Example:
account_id
account_id
Description: PolyAI account ID that owns this project. This is the same account ID visible in your Studio URL:
https://studio.poly.ai/account/{account_id}/...Example:project_id
project_id
Description: Project ID of the current agent. This is the same project ID visible in your Studio URL:
https://studio.poly.ai/account/{account_id}/project/{project_id}/...Example:env
env
Description: Current environment.Values: “sandbox”, “pre-release”, “live”Example:
channel_type
channel_type
Description: Type of channel the conversation is taking place on.Possible values:
"VOICE"– Voice calls (telephony)"sms"– SMS text messages"sip.polyai"– SIP-based voice calls- Integration-specific identifiers (e.g.,
"webchat.polyai","chat.polyai")
attachments
attachments
Description: List of file attachments received or queued for sending (list[Attachment]).Attachment object structure:
content_url(str) – URL where the file content is hostedtitle(str) – Title or name of the attachmentpreview_image_url(str, optional) – URL for a preview image of the attachmentcall_to_action(str, optional) – Action label associated with the attachment (e.g., “View document”)
sip_headers
sip_headers
Description: Dictionary of SIP headers (dict[str, str]) provided by the carrier.Example:
integration_attributes
integration_attributes
Description: Metadata passed from an external integration (dict[str, Any]). These attributes are defined per project and per integration during setup.Supported integrations:
- DNIs Pooling – Provides
shared_idfor correlating conversation outcomes
start_function to handle missing data appropriately.Example:caller_number
caller_number
Description: The caller’s identifier.For inbound calls: The phone number of the person calling in, in E.164 format (e.g.,
+14155551234 for USA numbers).For outbound calls: The phone number being called by the agent.For chat channels: This may be an email address or integration-provided user ID.Example:callee_number
callee_number
Description: Number dialled by the caller.Example:
state
state
Description: Dictionary-like store that persists values across turns.Example:
current_flow
current_flow
Description: Name of the flow currently executing, or None.
current_step
current_step
Description: Step name currently executing within the active flow.Example:
sms_queue
sms_queue
Description: List of
OutgoingSMS / OutgoingSMSTemplate objects queued for dispatch at turn end.metrics_queue
metrics_queue
Description: List of custom metrics queued for analytics.
metric_events
metric_events
Description: List of metric event objects queued for analytics.Example:
variant_name
variant_name
Description: Name of the active variant, or None.
variants
variants
Description: Dictionary of all variant definitions (dict[str, Variant]).
variant
variant
Description: Variant object for the active variant, or None.Example:
sms_templates
sms_templates
Description: Dictionary of SMS templates (dict[str, SMSTemplate]).Example:
voice_change
voice_change
Description: Pending TTSVoice change requested this turn, or None.
language
language
Description: ISO-639 language code configured for the project (e.g. “en”).
history
history
Description: Chronological list of UserInput and AgentResponse events so far.Example:
handoffs
handoffs
Description: Dictionary of configured hand-off destinations (dict[str, HandoffConfig]).Example:
transcript_alternatives
transcript_alternatives
Description: List of transcription alternatives (list[str]) for the last user utterance, including the primary transcription.Example:
real_time_config
real_time_config
Description: Returns a dictionary of real-time configuration values defined in Configuration Builder.Example:
memory
memory
Description: Dictionary of memory fields previously stored for the caller, retrieved from Agent Memory.Customer identification: Memory is retrieved using
caller_number for voice calls or the integration-provided user identifier for chat channels. This allows the agent to recognize returning customers and recall previous interactions.Example:entities
entities
Description: Dictionary of entity validation results collected from the conversation (dict[str, EntityValidationResult]).Example:
functions
functions
Description: Executor for calling other functions defined in the project. Access functions using dot notation.Example:
api
api
Description: Executor for calling configured API integrations. Access APIs using
conv.api.{integration_name}.{operation_name}().
Example:generic_external_events
generic_external_events
Description: List of external events initiated by
generate_external_event. Each event contains ext_event_id, send_to_llm, created_at, data, and content_type.Example:translations
translations
Description: Proxy for accessing localized translations. Access translation keys as attributes to get the translated text for the current language.Example:
response_suggestions
response_suggestions
Description: List of quick-reply suggestions for the next agent message. Only supported on webchat channels.Example:
agentic_dial
agentic_dial
Description: Agentic dial data for the conversation, used for advanced dialing scenarios.
Methods
say
say
Description: Override the next utterance.Example:
randomize_voice
randomize_voice
Description: Randomly choose a voice based on weighted probabilities.Parameters:
- voice_weightings (list[VoiceWeighting]) – list of VoiceWeighting objects, each containing a voice and weight.
polyai.voice module (e.g., ElevenLabsVoice, CartesiaVoice, PlayHTVoice, RimeVoice). See Voice classes for the full list of available voices and their IDs.Example:goto_flow
goto_flow
Description: Transition to another flow at turn end.Example:
exit_flow
exit_flow
Description: Exit the current flow.Example:
set_variant
set_variant
Description: Manually set the active variant.Example:
add_attachments
add_attachments
Description: Attach one or more files to the current conversation record.Example:
discard_recording
discard_recording
Description: Prevents saving the current call recording, e.g. when sensitive data is detected.Example:
generate_external_event
generate_external_event
Description: Generates a unique external event ID linked to the current conversation. Use this ID to receive webhook data from an external provider via the
/v1/external-events/webhook endpoint. The webhook payload is then accessible through conv.generic_external_events.Parameters:- send_to_llm (bool, keyword-only, optional) – if
True, the webhook payload is also sent to the LLM as a system prompt. DefaultFalse.
log_api_response
log_api_response
Description: Logs an external API response for visibility in Conversation Review → Diagnosis and the analytics pipeline.Where logs appear:
- Conversation Review: View API responses in the Diagnosis tab for debugging
- Analytics pipeline: API response data is available for reporting and analysis
send_content_template
send_content_template
Description: Sends a WhatsApp or SMS template message via Twilio’s Content API. Requires the content template to be pre-approved in your Twilio account.Parameters:
WhatsApp messaging requires a configured Twilio integration and is not a native PolyAI channel. Contact your PolyAI representative for setup.
- messaging_service_id (str) – Twilio messaging service ID.
- to_number (str) – recipient phone number.
- content_id (str) – alphanumeric ID of the approved message template.
- content (str, optional) – text content. Default
"". - whatsapp (bool, optional) – set to
Trueto send over WhatsApp. DefaultFalse. - content_variables (dict, optional) – variables to pass to the message template.
send_sms
send_sms
Description: Queue a plain-text SMS.Example:
send_sms_template
send_sms_template
Description: Queue a pre-configured SMS template.Example:
write_metric
write_metric
Description: Write a custom metric to the analytics pipeline.Parameters:
- name (str) – metric key, as defined in your project’s metrics configuration.
- value (str, int, float, bool, or None) – the metric value. Must match the type defined in the metric spec.
- write_once (bool, optional) – if
True, the metric can only be written once per conversation. Subsequent calls with the same name are ignored. DefaultFalse.
call_handoff
call_handoff
Description: Transfer the call to a configured handoff destination.Parameters:Where it shows up: In flows using builtin-handoff or using functions; visible in Conversation Review and API.
- destination (str) – handoff target key, as defined in your handoff configuration.
- reason (str, optional) – escalation reason. Defaults to the destination name.
- utterance (str, optional) – message for the agent to say before transferring.
- sip_headers (dict[str, str], optional) – SIP headers to pass through. Merged with any headers configured in the handoff config, with passed headers taking precedence.
- route (str, optional) – phone number or route to override the configured route.
utils
utils
Description: Provides helper functions for extracting data, validating entities, and accessing secrets.Available utilities:See Conversation utilities for the full list of available helpers and detailed documentation.
get_secret(name)– Retrieve a stored secret by nameextract_address()– Extract postal addresses from user inputextract_city()– Extract city references from user inputprompt_llm()– Perform a standalone LLM requestvalidate_entity()– Validate a value against an entity config (email, phone, date, etc.)geocode_address()– Geocode a full address string
NotImplementedError, contact your PolyAI representative to enable it for your account.Example:set_voice
set_voice
Description: Change the TTS voice for the current conversation moving forward.Parameters: voice (TTSVoice) – the voice configuration to use.Example:
set_language
set_language
Description: Change the language for the current conversation moving forward.Parameters: language (str) – ISO 639 language code (e.g., “en-US”, “es-ES”, “fr-FR”).Example:
set_asr_biasing
set_asr_biasing
Description: Dynamically configure ASR keywords and custom biases for improved speech recognition. Biasing persists across turns until cleared.
Parameters:
- keywords (list[str], optional) – list of keywords to bias ASR recognition toward.
- custom_biases (dict[str, float], optional) – dictionary mapping phrases to bias weights. Example:
clear_asr_biasing
clear_asr_biasing
Description: Clear any previously set ASR biasing for future turns.Example:
goto_csat_flow
goto_csat_flow
Description: Trigger a transition to the CSAT (Customer Satisfaction) survey flow for voice calls.Example:
send_email
send_email
Description: Send an email from the function.SMTP configuration: Emails are sent through a managed delivery service. For custom email delivery requirements, contact your PolyAI representative.Delivery considerations:
This function sends outbound emails from within a conversation (e.g., confirmations or notifications). Email is not a supported inbound channel for PolyAI agents.
- Emails are sent asynchronously after the turn completes
- Delivery failures are logged but do not interrupt the conversation
- For high-volume sending, consider rate limits and reputation management
- to (str) – recipient email address.
- body (str) – raw body of the email.
- subject (str) – subject line.
set_response_suggestions
set_response_suggestions
Description: Set quick-reply suggestions that appear as clickable options for the user. Only supported on webchat channels.
Parameters: suggestions (list[str]) – list of suggested responses.
Example:

