Get Started

Using Python Nodes : Sleep Time Calculation

Using Python Nodes : Sleep Time Calculation

Using Python Nodes : Sleep Time Calculation

The tutorial in the Getting Started Guide covers the most fundamental yet essential steps for newcomers to Agentria.

In this tutorial, you will create and run an ability that calculates your bedtime by inputting your wake-up time and using a Python node to reverse-calculate your recommended sleep duration.


Prerequisites

To begin, create a project in Agentria and enter the Ability Editor canvas.

For the canvas entry procedure, please refer to Step 1 (Project Creation and Editor Selection) of the 3-Step Core Guide.


Upon completing this tutorial, you will be able to perform the following tasks:

  1. Add nodes

  2. Declare variables in the Start node

  3. Connect nodes

  4. Write code in the Python node

  5. Use the Code Generator in the Python node

  6. Pass the Python node's output to the End node

  7. Verify workflow execution results via Run Test


Step 1: Declaring Input Variables


The Agentria canvas is pre-configured with one Start node and one End node.

The Start node initiates the entire workflow, while the End node concludes it.

Therefore, to build the ‘Sleep Time Calculation’ workflow, you must first declare the required variables at the Start node.

Double-click the Input node to open the node editor, where you can set the data type, name, and description.

Since this tutorial requires the wake-up time as input, we'll declare a variable with the data type set to String and the variable name set to WakeUpTime.

Once variable declaration is complete, return to the editor canvas.


Step 2: Add Nodes via Drag and Drop

Now it's time to add the Python node to calculate sleep time.

Click the +Add Node button at the bottom of the canvas. From the Code category, drag and drop the Python node onto the canvas.

The Python node allows you to write code directly or use the Code Generator feature, which supports automatic code generation from short prompts.


Step 3: Connecting Nodes with Edges


To use the WakeUpTime variable received from the Start node in the Python node, you must connect the two nodes.

This connecting line is called an edge.

Connect the Start node's right edge connector (Out-Connector) to the Python node's left edge connector (In-Connector) to pass the input value to the Python node.


Step 4: Writing Python Code


Double-click the Python node to open the node editor.

If the WakeUpTime variable appears in the Input area, the nodes are connected correctly.

Now write a script in the Python code field to calculate the sleep time.

Example:




Step 5: Binding Variables with Drag and Drop


In Agentria, you can easily import variables using drag and drop without writing separate code.

Place the WakeUpTime variable inside the int() parentheses on the first line of the script.


Step 6: Using the Code Generator


No prior programming experience is required.

Agentria's Python node supports automatic code generation via the Code Generator with just a short prompt.

Click the Code Generator icon and enter a description of the required code in the prompt editor that appears.

Press the Generate button to create the code. If you want to use that code, press the Accept button to apply it.

Example:




Step 7: Running Node Tests


After writing your code, you can individually test Python nodes by clicking the TEST button in the Input area within the editor.

Node testing is a verification task you can perform individually within the node editor.

This allows you to confirm the node is configured correctly. Connecting it to other nodes minimizes errors and ensures a stable flow.

For example, if entering 07 into WakeUpTime outputs the following result, it indicates the node is configured correctly



Step 8: Using Function Features


Using function features in Python nodes creates new execution paths by calling functions only when specified conditions are met through conditional branching.

This enhances workflow efficiency by limiting nodes from performing unnecessary operations.

Functions can be declared by clicking the + Create Function button at the bottom of the editor. Parameters must be specified by clicking the + Add Argument button.

Once a function is declared, the corresponding number of function edge connectors will appear on the node.

For detailed function descriptions, refer to []. For tutorials using functions, refer to [].


Step 9: Connecting the End Node


Now, pass the calculated sleep time result to the End node.

Return to the canvas and connect the Python node to the End node with an edge.

Double-click the End node to open the node editor and add a String-type SleepTime variable.

Select or drag and drop the Output variable containing the result from the Python node to connect it to the SleepTime variable.

This completes the ‘Sleep Time Calculation’ workflow.


Step 10: Run the Entire Workflow with Run Test


Click the Run Test button in the bottom-right corner of the canvas to execute the complete workflow.

Similar to testing a node, after entering your wake-up time and running the test, the SleepTime result will display your recommended bedtime.



Next Steps


🎉 Congratulations! You've completed your second Agentria workflow: ‘Sleep Time Calculation’.

Now experiment with different input values to see the results, and improve the workflow's performance by modifying the Python code.


Agentria is a space of possibilities where ideas become reality.

Your imagination can infinitely expand the workflow.


If you're curious about more introductory examples, check out the Getting Started Guide.