Get Started

Using Code Nodes (Python)

Using Code Nodes (Python)

Using Code Nodes (Python)

The ability guide tutorial covers the most basic yet essential processes for newcomers to Agentria.

In this tutorial, you will create and run an Ability that takes a wake-up time as input, uses a Python node to calculate the reverse sleep schedule, and provides a recommended bedtime.


Before You Begin


To get started, create a project in Agentria, then enter the Ability Canvas.

For detailed steps on accessing the canvas, refer to Step 1 (Create a Project & Select a Composer) in the 3-Step Core Guide.


By completing this tutorial, you will be able to:

  1. Add nodes

  2. Declare variables in the Start Node

  3. Connect nodes

  4. Write Python code

  5. Use the Python Code Generator

  6. Send Python output values to the End Node

  7. Run an Ability Test to check workflow results


Step 1: Declare Input Variables



On the Agentria canvas, a Start Node and an End Node are placed by default.


  • The Start Node initiates the workflow.

  • The End Node concludes the workflow.


To build the “Recommended Bedtime Guide” workflow, you first need to declare the required variable in the Start Node.

Double-click the Start Node to open the Node Editor. Here, you can configure the variable’s data type, name, and description.



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

After declaring the variable, return to the canvas.


Step 2: Add a Python Node



Next, add the Python node that will calculate the sleep schedule.

Click +Add Node at the bottom of the canvas, then drag and drop the Python node from the Code category.

In a Python node, you can write your own code or use the Code Generator, which automatically produces code based on a short prompt.


Step 3: Connect Nodes with an Edge



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

This connecting line is called an Edge.

Connect the Start Node’s Out-Pin (on the right) to the Python Node’s In-Pin (on the left).

This transfers the input value into the Python node.


Step 4: Write Python Code



Double-click the Python node to open the Node Editor.

If you see WakeUpTime in the Input section, the nodes are connected correctly.

Now, write the script that calculates the recommended sleep time in the Python code editor.


Example:

wake_up_time = int()

time_minus_9 = (wake_up_time - 9) % 12

time_minus_7 = (wake_up_time - 7) % 12

time_minus_9 = 12 if time_minus_9 == 0 else time_minus_9

time_minus_7 = 12 if time_minus_7 == 0 else time_minus_7

recommended_sleep_time = f"{time_minus_9}시~{time_minus_7}시"

return {"output": recommended_sleep_time}


Step 5: Bind Variables via Drag and Drop



In Agentria, you can easily insert variables without writing code—simply drag and drop.

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



  • int(WakeUpTime)



Step 6: Use the Code Generator



No programming experience? No problem.

The Python node supports a Code Generator, which automatically produces code based on your prompt.



Click the generator icon, write a short prompt describing the code you need, then click Generate.

If you want to use the generated code, click Accept to apply it.


Example:

Please create a Python script that takes WakeUpTime as an integer and calculates the recommended sleep time.


Step 7: Run a Node Test



After writing the code, click the TEST button in the Input section to perform a Node Test.

A Node Test checks the Python node independently before connecting it to others.

This helps ensure the node is configured correctly and reduces errors when building the full workflow.

For example, if you enter 07 as the WakeUpTime and the result outputs:

"output": "10~12"

then the node is working correctly.


Step 8: Using the Function Feature



The blue pin on a Python node is a Function Pin.

Function mode allows the node to create conditional execution paths by running a function only when certain conditions are met.

This prevents unnecessary computation and increases workflow efficiency.

This tutorial does not use the function feature.

For more information, refer to the Function Node section in Node Types.


Step 9: Connect the End Node



Now pass the calculated output 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 editor, then add a variable named SleepTime with the type String.

Select or drag the Output variable from the Python node and bind it to SleepTime.

Your “Recommended Bedtime Guide” workflow is now complete.


Step 10: Run the Full Workflow with an Ability Test



Click RUN TEST at the bottom right of the canvas to execute the completed workflow.

Enter a wake-up time just like during the Node Test, and the final SleepTime value will display the recommended bedtime.


Example output:

"SleepTime": "10~12"


Next Steps



🎉 Congratulations! You’ve successfully built the “Recommended Bedtime Guide” workflow using Agentria.

Try different input values, or adjust your Python script to further improve the workflow.


Agentria is a place where ideas become reality—your workflow can expand infinitely with your creativity.