When your agent flow contains components like Python blocks or tool blocks, you need to define agent flow variables to pass information between the components. You can also use a variable to pass information to an agent's planning prompt. You can create Boolean, floating point, integer, or string variables.
Create a variable to store the input or output for a Python block or a tool block. You can also use a variable in the planning prompt of an agent block. To reference the variable in a planning prompt, use the following syntax: {variableName}
You can assign a default value to a variable when you create it. You can update variable's value using an assignment block. A Python or tool block in the flow can also update the value of a variable. An agent block can't assign a value to a variable.
Example: Using a variable in a planning prompt
You're designing an AI agent that needs to use the contents of an Amazon S3 file in the planning prompt. To do this, you perform the following steps:
1In the agent flow, click Variables on the tool bar and create the following variables:
Name
Type
Default value
fileName
String
Enter the path and name of the file you want to read.
fileContents
String
Don't assign a default value.
2Add a tool block to the flow and select the S3 File Parser and Loader connection.
In the Input Parameters section, select the FileName variable. In the Output Parameters section, select the fileContents variable.
When the AI agent runs this tool block, it passes the file specified in the fileName variable to the tool. It receives the file's contents from the tool and stores them in the fileContents variable.
3Add an agent block to the flow, select the model connection, and enter the planning prompt.
In the planning prompt, reference the variable by enclosing the variable name in curly brackets. For example, you might enter the following text in the prompt:
Use this information to help answer the user's query: {fileContents}.
Alternatively, if you have the Variables dialog box open, you can drag the variable into the planning prompt.
Example: Passing a variable to a Python block
You are designing an agent flow and you want to pass the file contents of an Amazon S3 file to a Python block for further processing. To do this, you create variables to store the file name, file contents, and Python query result.
Add a Python block to the flow and select the tool that contains the code you need. In the Input Parameters section, select the variable you created to store the file contents. In the Output Parameters section, select the variable you created to store the query results.
When the AI agent runs the Python block, it takes the the file contents as its input and returns the query results in the variable that you created to store the query results.
Default values
You can assign default values to agent flow variables when you create them. The values you can assign vary based on the data type.
You can assign the following values to a variable based on its data type:
Boolean
A Boolean variable can have the value True or False. The value is case sensitive, so true and TRUE are not valid values.
Float
Enter a decimal value, for example, 1.23. You can also enter a valid Python expression that evaluates to a floating point number.
Integer
Enter an integer, for example, 1024 or -6. You can also enter a valid Python expression that evaluates to an integer.
String
Enter a string value. For example, This is the value of my string variable. You don't need to enclose the value in quotation marks.
If you don't assign a default initial value, the value is null. To explicitly assign a null value, set the variable value to None. If the variable is a string variable, you can also set the variable to an empty string, for example, '' or "".
Creating agent flow variables
To create agent flow variables, click Variables on the toolbar. You can add variables one at a time using the table mode, or quickly define several variables at once using the code mode.
1Click Variables on the toolbar.
The Variables dialog box opens. You can add variables using the table mode or the code mode.
2To add variables using the table mode, complete the following steps:
aClick Table.
bClick + to add a new variable.
cEnter the variable name, choose the data type, optionally assign a default value, and click Save.
Ensure that the name isn't a Python keyword like def, global, or import. If the variable name is a Python keyword, the AI agent can't be deployed.
dTo add a description, click >, enter the description, and click Save.
eRepeat steps b - d to add other variables.
3To add variables using the code mode, complete the following steps:
aClick Code.
bAdd each variable on its own line using the following format:
isDefined: bool = False #Boolean variable with default value isVerified: bool = #Boolean variable without default value salesTaxRate: float = 9.25 #Floating point variable with default value totalCost: float = #Floating point variable without default value count: int = 0 #Integer variable with default value numItems: int = #Integer variable without default value email: str = '' #String variable without default value contactMethod: str = 'text' #String variable wita default value
Ensure that the variable name isn't a Python keyword like def, global, or import. If the variable name is a Python keyword, the AI agent can't be deployed.
4Click X to close the Variables dialog box.
Deleting agent flow variables
You can delete an agent flow variable after you create it.
Tip: Check the agent flow and ensure that the variable isn't being used. If you delete a variable that's being used, the agent flow becomes invalid.
1Click Variables on the toolbar.
The Variables dialog box opens. You can delete variables using the table mode or the code mode.
2To delete a variable using the table mode, click Table, and then click the delete icon in the row that contains the variable.
3To delete a variable using the code mode, click Code, and then delete the line that contains the variable.