Skip to content

Programming Basics

Although the Gendial platform allows you to create simple intelligent agent workflows with a drag-and-drop, no-code approach, if you understand the following basic programming concepts and techniques, your intelligent agents will be able to handle complex business logic more flexibly, achieving functionality that previously required fully customized development.

Variables

On the Gendial platform, you can define variables to store the output content of nodes, and then reference them in later nodes using the format , or store them in the backend database for archival purposes. Variables are always of string type, similar to natural language conversation between people. For more details, refer to the Variables section.

Initial Value of Variables

Sometimes variables need to be set with initial values, such as a variable n used to control a loop. You can set the initial value of the variable in the start node.

alt text

Environment Variables

You can also set environment variables for the intelligent agent in the start node, such as an API key or other variables used to control the workflow. Environment variables are also referenced using .

alt text

Assignment

Most nodes can define output variables. All output from the node will be stored in this variable, which is equivalent to assigning a value to the variable.

Multiple nodes can define the same output variable name, which is like assigning a value to the same variable multiple times in programming.

If you need to assign specific content to a variable, you can use the "Original Text Output" mode in output/blank nodes. For example, the following means storing the image link uploaded by the user in a variable called currentImage.

alt text

You can also use a code node to perform calculations on a variable and then assign a value. For example, the following node adds 1 to n:

alt text

The format will directly replace the variable’s content (string) in the prompt or code. So the code in the image will be replaced with:

javascript
// Assume the current value of n is 100
let n = 100 + 1;
process.stdout.write(n.toString());

After executing the code, 101 will be assigned to the variable n.

String Handling

As mentioned earlier, referencing {{variable_name }} in a prompt or code will directly replace the content of the variable (string) into the prompt or code. If you want to treat the content of the variable as a string that can be processed by code, how should you do it? You can use the following JavaScript code to represent it in the following way:

javascript
// Use `` or "" or '' to surround the variable
const str = `{{var}}`;

Using Python, you can do it like this:

python
str = "{{var}}"

💡 Tip: Sometimes you may need to handle JSON objects generated by large models in the code node. Large models tend to add ```json at the beginning and end of JSON objects, causing issues when using `` to load strings. In such cases, you can use " " or ' ' to handle it, or instruct the model not to add the markdown format at the beginning and end. For example, you can use the following prompt:

Your output must be a complete JSON object, without any extra explanation or text, and should not be wrapped with markdown format like ```json.

Branching

In the Gendial platform, you can use decision nodes to implement program branching, which is similar to IF-ELSE and SWITCH-CASE statements. Additionally, decision nodes can handle fuzzy semantic judgments.

Decision nodes can handle various types of judgment logic and scenarios.

Fuzzy Semantic Judgments

Using the capabilities of large language models, you can make semantic decisions to choose the appropriate branch. For example, based on the user's question, you can decide whether they need order information, product information, return/exchange services, etc.

Clear Logical Judgments

Unlike semantic judgments, some conditions are very clear-cut, and using a large model for judgment might not be suitable:

  1. The output of large models is unstable; in some cases, even very simple logic might be judged incorrectly, such as "Which is larger, 9.11 or 9.9?"
  2. Judgment by large models incurs additional token and time costs.

In such cases, you can use boolean functions (similar to IF-ELSE) or branching statements (similar to SWITCH-CASE) to handle fixed and clear logical judgments.

For boolean function-type decision nodes, the true/false value returned will determine the branch. The content of the decision node is the function body of the boolean function, which does not require a function name, just the internal code, and the final return statement should return a true or false value. For example, in a boolean function decision node, you can judge "Which is larger, 9.11 or 9.9?" like this:

javascript
return 9.11 > 9.9

alt text

For branching statement-type decision nodes, the value of the selected variable will determine the branch. The variable must be a custom variable output by previous flow nodes. The value of the variable will be compared as a string with the preset values of each branch's exit edge, and the branch with the matching value will be selected. The following flowchart shows selecting the corresponding branch based on input from the selection input node.

alt text

Loops

On the Gendial platform, you can easily implement various loops, which are similar to For loops, while loops, etc.

For example, by using the previously mentioned assignment and decision nodes, we can implement a For loop like this.

alt text

💡 Tip:

  1. You can set the initial value of the loop control variable in the starting node.
  2. What if you accidentally define a dead loop in your flow? Don’t worry, the platform has a default setting that the agent can execute up to 20 nodes without interaction. So even if you define a dead loop, it will be forcibly interrupted after 20 nodes are executed. If your business explicitly requires automated processing of large amounts of data and continuous execution of many nodes, you can adjust this default value to an appropriate size:

alt text

Concurrency

The Gendial platform supports concurrent process handling, which is particularly useful for handling asynchronous requests. For example, you can query multiple databases/business systems simultaneously, greatly improving processing speed; or use different prompts to summarize the same paragraph of text, and then combine the results for a better response from the large language model. This approach is common in data science. For example, in Boosting algorithms, we often use a set of simple models, each of which is slightly different and makes a small decision. At the end, we combine the results. This method is usually very effective.

Enabling concurrent flows is also very simple: just create multiple branches in a preceding node (the preceding node cannot be a decision node), and these branches will be processed concurrently. For the results of concurrent processing, you need to use a decision node to consolidate them. This decision node needs to choose Concurrent Subsequent Condition type, and you can select whether to wait for all branches to complete or any branch to complete.

alt text

💡 Tip: What should you do if you want to perform concurrent operations immediately after a decision node? In this case, you can use a blank node (also called a dummy node) after the decision node to initiate concurrent operations. The blank node's generation method should be selected as Original Text, and the prompt can be left empty or contain any text. This node functions as a no-op statement in programming, meaning - No Operation.

alt text

Last updated: