This page requires Python familiarity. Variables are set and read in Python functions.
conv.state object within a function. You can choose a name for your variable
and update its value to anything you want like so:
Built-in state keys
Theconv.state object comes pre-populated with system-managed keys. These are set automatically by the platform and available in every conversation:
| Key | Type | Description |
|---|---|---|
from_ | str | Caller’s phone number (note the trailing underscore — from is a Python reserved word) |
to | str | Called number (callee) |
call_sid | str | Unique call session identifier |
asr_lang_code | str | Active ASR language code (e.g., "en-US") |
tts_lang_code | str | Active TTS language code (e.g., "en-US") |
shared_id | str | Shared identifier for correlating conversations across systems |
handoff | object | Handoff configuration object (destination, reason, SIP method) |
disable_recordings | bool | Whether call recording is disabled |
stop_recording | bool | Whether recording has been stopped mid-call |
use_tts_for_responses | bool | Whether to use TTS instead of pre-recorded audio |
asr_provider | str or dict | Override the default ASR provider |
asr_config | dict | Custom ASR configuration |
listen_for_sms | bool | Whether SMS listening is enabled (default False) |
Prompt templating
Variables can be used within function calls and injected dynamically into prompts shown to the LLM. To inject a variable’s value into your prompt, use the syntax$variable_name. The system will replace this placeholder with the variable’s value wherever it matches.
Example:
In your start function, you can write:
$current_date.
…becomes:
The current date is September 06, 2024.
When using variable templating, ensure the stored value is readable by the LLM. Complex objects like dictionaries or datetime
will be stringified automatically.
Environment configuration
You can use theconv.env property to define environment-specific functions and activate test features in sandbox or
pre-release environments.
For example:
Dynamic updates
The value templated into the prompt is always kept up to date, so any updates will be reflected in the next turn sent to the LLM. Example:Deleting a variable
To delete a variable, remove it from the state within a function:Variables in the Conversations API
Allconv.state variables — both built-in keys and custom variables your agent writes — are returned in the state field of the Conversations API response. This means you can retrieve any state variable programmatically after a call ends.
For details on the API response structure, see the Conversations API overview.
Related pages
conv object
Full reference for conv.state and other conversation properties.
Start function
Initialize state variables before the greeting plays.
Flows
Use variables to pass data across flow steps.

