Agent Script Reference: Variables (Custom and Linked)
Variables let agents deterministically remember information across conversation turns, track progress, and maintain context throughout the session. You define all variables in the variables block, and all subagents in the agent can access the variables.
1CurrentState: mutable string = "gatheringInfo"2 description: "The current state, or step, of the interview."3 label: "State"4 visibility: "External"
Variable Names
Variable names must follow Salesforce developer name standards:
Begin with a letter, not an underscore.
Contain only alphanumeric characters and underscores.
Can’t end with underscore.
Can’t contain consecutive underscores (__).
Maximum length of 80 characters.
Referencing Variables
To reference a variable from the script, use @variables.<variable_name>.
Reference a Variable From Script
1if @variables.Customer_Contact is None:2 set @variables.No_Matching_Contact = True
To reference a variable from within reasoning instructions, use {!@variables.<variable_name>}.
Reference a Variable From Reasoning Instructions
1reasoning:2 instructions: ->3 | Always use {!@variables.Customer_Email} for the customer's email address.
Custom Variables
Custom variables have these properties:
mutable - Optional. Allows the agent to change the variable’s value. To ensure a variable’s value is never changed, define the variable without mutable.
label - Optional. The variable’s name as displayed in the UI. By default, the description is generated from the name. For example, if your variable’s name is my_var, the UI displays the label My Var.
visibility - Optional. Default value is Internal. Set visibility to External to allow an API to set the variable’s value, or to change the variable’s value when testing the agent in simulate mode.
Example: Define Custom Variables
1variables:2 isPremiumUser: mutable boolean = False3 description: "Indicates whether the user is a premium user."4 label: "Has Gold Status"56 customer_loyalty_tier: mutable string = "standard"7 description:|8 Stores the customer's membership tier level.
Custom variables can have these types:
Type
Notes
Example
string
Any alphanumeric string without special characters.
name: mutable string = ""
number
Use for both integers and decimals. For example, 42 or 3.14. Compiles to IEEE 754 double-precision floating point.
age: mutable number, price: mutable number = 99.99
boolean
Allowed values are True or False. The value is case-sensitive, so capitalize the first letter.
is_active: mutable boolean = True
object
Value is a complex JSON object in the form {"key": "value"}.
Use None to check whether a variable has a value. You can use None with any variable type. For a string variable, you can also use "" to check if the variable is set to an empty string. When checking string variables in conditional statements, you might want to use both None and "".
A linked variable’s value is tied to a source, such as an action’s output. Linked variables have these restrictions:
can’t have a default value
can’t be set by the agent
can’t be an object or a list
The source field references where the variable gets its value. Supported source namespaces are:
Namespace
Available Properties
Description
@MessagingSession
Id, MessagingEndUserId, EndUserLanguage
Properties of the messaging session
@MessagingEndUser
ContactId
Properties of the messaging end user
@VoiceCall
Id
Properties of the voice call
Example: Define Linked Variables
1variables:2 session_id: linked string3 source: @MessagingSession.Id4 description: "The messaging session ID"5 contact_id: linked string6 source: @MessagingEndUser.ContactId7 description: "The contact ID of the end user"8 voice_call_id: linked string9 source: @VoiceCall.Id10 description: "The voice call ID"
Linked variables can have these types:
string
number
boolean
date
id (deprecated; use string for Salesforce record IDs)