|
1 | 1 | # Use Variables |
2 | 2 |
|
| 3 | +## Business Background |
| 4 | + |
| 5 | +In Workflow orchestration, information needs to be passed between nodes. To achieve this, we use **variables** to store and manage this information. |
| 6 | + |
| 7 | +:::warning A variable consists of three main parts: |
| 8 | + |
| 9 | +1. **Unique Identifier**: The name of the variable, used to distinguish different variables so that they can be accurately referenced and used in the program. For example: `userName` or `totalAmount`. |
| 10 | +2. **Value**: The data stored by the variable. The value can be of various types, such as numbers (e.g., `42`), strings (e.g., `"Hello!"`), boolean values (e.g., `true`), etc. |
| 11 | +3. **Type**: The kind of data that the variable can store. The type determines what kind of values the variable can accept. For example, a variable can be an integer, float, string, or boolean, etc. |
| 12 | + |
| 13 | +::: |
| 14 | + |
| 15 | +Here is an example of a workflow orchestration: The WebSearch node retrieves knowledge and passes it to the LLM node for analysis through the `natural_language_desc`. |
| 16 | + |
| 17 | +<div style={{display: 'flex', gap: '20px'}}> |
| 18 | + <img style={{width: "50%"}} loading="lazy" src="/variable/variable-biz-context-websearch-llm.png" /> |
| 19 | + <div> |
| 20 | + In this example: |
| 21 | + <p style={{marginTop: 10}}>1. The WebSearch node stores the information (value) in a variable with the unique identifier `natural_language_desc`.</p> |
| 22 | + <p style={{marginTop: 5}}>2. The LLM node retrieves the information (value) from the knowledge base using the unique identifier `natural_language_desc` and passes it to the LLM node for analysis.</p> |
| 23 | + <p style={{marginTop: 5}}>3. The type of the `natural_language_desc` variable is a string, representing the content of the information retrieved from the web, such as "DeepSeek has released a new model today."</p> |
| 24 | + </div> |
| 25 | +</div> |
| 26 | + |
| 27 | +## What is the Variable Engine? |
| 28 | + |
| 29 | +The Variable Engine is an optional built-in feature provided by Flowgram that helps to efficiently implement **variable information orchestration** during workflow design. It can achieve the following functions: |
| 30 | + |
| 31 | +<div style={{ display: "grid", gridTemplateColumns: "1fr 1fr", gap: "25px" }}> |
| 32 | + <div style={{ gridColumn: "span 2" }}> |
| 33 | + <b>Scope Constraint Control</b> |
| 34 | + <p className="rs-tip">With the Variable Engine, you can control the scope of variables, ensuring that variables are available within the appropriate range and avoiding unnecessary conflicts.</p> |
| 35 | + <div style={{display: "flex", gap: "25px"}}> |
| 36 | + <div> |
| 37 | + <img loading="lazy" src="/variable/variable-scope-feature-1.png" /> |
| 38 | + <p style={{marginTop: '10px'}}>In the image, the query variable of the Start node can be accessed by the subsequent LLM node and End node.</p> |
| 39 | + </div> |
| 40 | + <div> |
| 41 | + <img loading="lazy" src="/variable/variable-scope-feature-2.png" /> |
| 42 | + <p style={{marginTop: '10px'}}>In the image, the LLM node is within the Condition branch, while the End node is outside the Condition branch; therefore, the variable selector of the End node cannot select the result variable from the LLM node.</p> |
| 43 | + </div> |
| 44 | + </div> |
| 45 | + </div> |
| 46 | + <div> |
| 47 | + <b>Maintenance of Variable Information Tree</b> |
| 48 | + <p className="rs-tip">The Variable Engine can help you build a clear variable information tree, making it easier to view and manage the status and relationships of all variables.</p> |
| 49 | + <img loading="lazy" src="/variable/variable-tree-management.gif" /> |
| 50 | + <p style={{marginTop: '10px'}}>The image shows multiple nodes + global configuration output variables; some variables contain multiple sub-variables, forming a tree structure.</p> |
| 51 | + </div> |
| 52 | + <div> |
| 53 | + <b>Automatic Type Inference of Variables</b> |
| 54 | + <p className="rs-tip">The Variable Engine can automatically infer the type of variables based on context, reducing the workload of manually specifying types and improving development efficiency.</p> |
| 55 | + <img loading="lazy" src="/variable/variable-batch-auto-infer.gif" /> |
| 56 | + <p style={{marginTop: '10px'}}>In the image, the Batch node processes the arr variable from the Start node; when the type of the arr variable changes, the type of the item variable output by the Batch node also changes accordingly.</p> |
| 57 | + </div> |
| 58 | +</div> |
| 59 | + |
3 | 60 | ## Enable Variable Engine |
4 | 61 |
|
5 | 62 | [> API Detail](https://flowgram.ai/auto-docs/editor/interfaces/VariablePluginOptions.html) |
|
0 commit comments