Function Node - Automate Script Executions¶
Function nodes let you write custom scripts using JavaScript or Python to process context variables or other variables used in the tool flow.
Add and Configure a Function Node¶
Setting up a Function node in a tool flow involves adding the node at the appropriate location in the flow and configuring various node properties.
Steps to add and configure the node:
-
On the Tools tab, click the name of the tool to which you want to add the node. The Tool flow page is displayed.
-
Click Go to flow to edit the in-development version of the flow.
-
In the flow builder, click the “+” icon on any existing node on the canvas and select Function from the pop-up menu. (Alternatively, drag the Function node from the Assets panel onto the canvas.)
-
Click the added node to open its properties dialog box. The General Settings for the node are displayed.
-
Enter or select the following information:
-
Custom Name: Enter an appropriate name for the node.
-
Define a Script: You can define a script using Javascript or Python to process/parse the given input or the output of the previous node. Click anywhere in the Define a Script field to open the Script Editor dialog box.
-
In the top-left corner, choose the appropriate scripting language - Javascript or Python. Enter the script in the box. You can use variables or context variables in the Script Editor. For example, to read an input variable, use the following syntax:
To call a function, use the following syntax:context.<UserDefined-Variable-Name>= UserDefined-Function-Name(context.steps.<startNode-Name>.<inputVariable-name>)
Note
You cannot import packages in the Function node. However, you can use pre-existing libraries such as pandas or numpy. Learn more.
-
You can use the Context input or output feature to use a variable from the previous node or when testing a function.
- Context Input: Add the required variable; dummy input values can be given to test the defined function.
- Context Output: Shows the results of the function from the given input.
- Log: Monitor the state of the function and view the values.
-
Click Run to test the script. Once the script is resolved successfully, the results are displayed in the Log section.
- Close the Script Editor.
-
-
-
Click the Connections icon in the left navigation and select Go to Node for success and failure conditions.
- On Success > Go to Node: After the current node is successfully executed, go to a selected node in the flow to execute next. For example, you can go to an AI node to use the processed data from the Function node.
- On Failure > Go to Node: If the execution of the current node fails, go to an appropriate node having a custom error message configured for this node.
-
Finally, test the flow and fix any issues found.
Standard Errors
You can see compilation and runtime errors, if any, during the execution of the script/node.
Test the Flow¶
After adding and configuring the node as mentioned here, follow the steps below to test the flow:
Step 1: Define and Test the Function Code¶
To define the logic and flow of the script, follow the steps below:
-
In the Define a Script window, click the Expand icon to view and edit your code in the script editor.
-
Use these syntaxes to define the code in JavaScript or Python. You can add static or dynamic input variables in the code to generate the output.
The script editor has the following tabs representing the code components:
-
Context Input: Displays the context input(s) fetched from the Start node or the static inputs in the code.
-
Context Output: Displays the output generated by the script.
-
Log: Displays the code execution log, including the output or error(s).
Using Static or Dynamic Values in the Script¶
Define Static Input Variables¶
- In the script editor, select the coding format from the dropdown.
- Define the input variables and their values as shown below.
Define Dynamic Input Variables¶
- In the script editor, select the coding format from the dropdown.
- Define the input variables and define dynamic values using context variables in the defined format, as shown below.
JavaScript
Python
Step 2: Test the Flow using Static or Dynamic Inputs¶
Static Inputs¶
To run the flow for static inputs, follow the steps below:
Note
In this case, you do not need to add input variables using the Start node.
- Add/edit your script in the editor by defining static variables. Learn more.
- Click the Run Flow button at the top-right corner of the flow builder.
Dynamic Inputs¶
To run the flow for dynamic inputs, follow the steps below:
- Click the Input tab of the Start node, and click Add Input Variable to configure the input for the flow’s test run. Learn more.
- Add the Name(key) value, select the data type for Type, and provide a description in the Enter input variable window. For example, in the banking flow, to get the sum of two balances, one in Q3 and the other in Q4, you must define two input variables, “Q3balance” and “Q4balance,” as shown below.
- Click Save.
Once you define the input variables, you must add the output variable(s) and run the flow.
Important
- You can use the Start node’s input variables as context variables in the script editor to accept dynamic values and generate the output. To refer to the input variable, follow the syntax mentioned here.
- Once you run the node’s flow, the result gets stored in the output variable of the Start node. Additionally, this key is mapped to the End node, where you can define its value.

Add the Output Variable¶
To define the output variable, follow the steps below:
- Click Add Output Variable.
- Enter the value for Name (key) and select the data type for Type.
- Click Save.

Run the Flow¶
To run and test the flow, follow the steps below:
-
Click the Run Flow button at the top-right corner of the flow builder.
-
(Optional) Provide input to test the flow if you have configured it in the Start node. Otherwise, go directly to the next step.
-
Click Generate Output.
The Debug window generates the flow log and results for the given input(s), as shown below. Learn more about running the tool flow.
Access the AI Node’s Output¶
The node’s output is stored in a context variable. You can access the variable using the syntax: {{context.steps.<<Functionnodename>>.output}
For example, context.steps.Bankingnode.output
Note
Agent Platform can automatically recognize variables and outputs. To do so, type "context.steps.
" and you will see the available variables, nodes, and node outputs.
Context Variables for Dynamic Inputs¶
Before you run the flow, provide clear instructions for the model to follow by adding the input variable(s) using context variables. Context variables allow you to include dynamic values in the script that a node executes to generate its output. The JSON code editor supports both JavaScript and Python formats.
Syntaxes for the Context Input¶
JavaScript
The recommended syntax to fetch dynamic variables using JS in the context input is: {{context.steps.Start.variable-name}}
For example, context.steps.Start.Q3balance
Python
The recommended syntax to fetch dynamic variables using Python in the context input is: {{context["steps"]["Start"]["variable-name"]}}
For example, context["steps"]["Start"]["Q3balance"]
The above syntaxes fetch the variable “Q3balance” that you define in the Start node. Learn more.