Reference Variables
Learn how to use reference variables to store and reuse data from function responses
Reference variables let you store and reuse specific data returned from a function response.
Reference variables offer a powerful way to condition your GenerativeAgent tasks and functions on real data returned by your APIs—all without requiring code edits.
By properly naming, key-pathing, and optionally transforming your variables, you can build flexible, dynamic flows that truly adapt to each user’s situation.
Once a reference variable is created, you can use it to:
- Conditionally make other Functions available
- Set conditional logic in prompt instructions
- Compare values across different parts of your GenerativeAgent workflow
- Control Function exposure based on data from previous function calls.
- Toggle conditional instructions in your Task s prompt depending on returned data
- Extract and transform values without hard‐coding logic into prompts or code
Reference variables can be configured in the GenerativeAgent Tooling Function edit page under the “Reference vars ” option.
Define a Reference Variable
To create a reference variable in the GenerativeAgent UI:
- Navigate to the Function’s settings
- Find the “Reference vars (Optional)” section and click “Add”
- Configure the following fields:
- Name
- Response Keypath
- Transform Expression (Optional)
Name
This is the identifier you’ll use to reference this variable in Jinja expressions.
Response Keypath
This is the JSON path where the data will be extracted from, using dot notation.
Transform Expression (Optional)
This is a Jinja expression to transform the extracted value. Common patterns include:
Once saved, GenerativeAgent will automatically update these variables whenever the Function executes successfully and returns data matching the specified keypath.
Reference variable names are not unique across the entire system.
If more than one Function defines a reference variable with the same name, whichever Function is called last may overwrite a variable’s value.
Reference variables are also used at runtime, meaning GenerativeAgent extracts the specified response data from each API call that returns successfully and updates the variable accordingly.
Example Condition
The following example calls a Condition on a CheckRoomAvailability
Function.
- Suppose a Reference Variable named
rooms_available
and defined with:- Response Keypath:
response.available_rooms
- Transform:
val is not none and val|length > 0
- Response Keypath:
- The
rooms_available
variable will be True whenever the returned list has a length greater than zero. You can then write: - In a Function’s conditions (to make a function available for use, conditioned on the reference variable):
- In Task instructions using Jinja:
Tips and Best Practice
Here are some tips to enhance your experience with Reference Variables:
Was this page helpful?