Skip to content

Commit f3a91a4

Browse files
authored
docs(variable): variable document update (bytedance#463)
1 parent b0ebe56 commit f3a91a4

File tree

6 files changed

+649
-360
lines changed

6 files changed

+649
-360
lines changed

apps/docs/src/en/guide/advanced/variable/basic.mdx

Lines changed: 37 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,74 +1,80 @@
11
# Variable Basics
22

3-
## Business Context
3+
## What is a Variable?
44

5-
In workflow orchestration, information needs to be passed between nodes. To achieve this, we use **variables** to store and manage this information.
5+
Imagine you're building a complex Lego model where each module needs to connect precisely. In the world of Workflows, **variables** play a similar role as "connectors." They are the "messengers" used to pass information between different nodes.
66

7-
:::warning A variable consists of three main components:
7+
Simply put, a variable is a named container where you can store various things, such as user input, calculation results, or data retrieved from somewhere.
88

9-
1. **Unique Identifier**: The name of the variable, used to distinguish between different variables so they can be accurately referenced and used in the program. Examples: `userName` or `totalAmount`.
10-
2. **Value**: The data stored in the variable. Values can be of various types, such as numbers (e.g., `42`), strings (e.g., `"Hello!"`), booleans (e.g., `true`), etc.
11-
3. **Type**: The kind of data the variable can store. The type determines what values the variable can accept. For example, a variable can be an integer, float, string, boolean, etc.
9+
A variable typically consists of three parts:
1210

13-
:::
11+
- **Name (Unique Identifier)**: Like your name, it allows everyone to find this variable accurately. For example, `userName`, `orderId`.
12+
- **Value**: The content inside the container. It can be a number `123`, text `"Hello Flowgram!"`, or a switch state `true` / `false`.
13+
- **Type**: Specifies what kind of things this container can hold. For instance, some can only hold numbers, while others can only hold text.
1414

15-
Here’s an example of workflow orchestration: The WebSearch node retrieves knowledge and passes it to the LLM node for analysis via `natural_language_desc`.
15+
---
16+
17+
For example, in an "Intelligent Q&A" flow:
1618

1719
<div style={{display: 'flex', gap: '20px'}}>
1820
<img style={{width: "50%"}} loading="lazy" src="/variable/variable-biz-context-websearch-llm.png" />
1921
<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 knowledge base information (value) via the `natural_language_desc` identifier and passes it to the LLM node for analysis.</p>
23-
<p style={{marginTop: 5}}>3. The `natural_language_desc` variable is of type string, representing the content retrieved from the web, such as "DeepSeek released a new model today."</p>
22+
<p style={{marginTop: 10}}>1. **`WebSearch` Node**: Responsible for searching the web and putting the found knowledge (e.g., the answer to "What's the weather like today?") into a variable named `searchResult`.</p>
23+
<p style={{marginTop: 5}}>2. **`LLM` Node**: It takes the `searchResult` "messenger," reads its content, and then answers the user in a more natural and friendly way.</p>
24+
<p style={{marginTop: 5}}>3. In this process, the type of `searchResult` is "string" because it contains text content.</p>
2425
</div>
2526
</div>
2627

27-
## What is the Variable Engine?
28+
## Why Do You Need a Variable Engine?
29+
30+
As the complexity of workflows increases, so do the number and management difficulty of variables.
31+
32+
To address this challenge, Flowgram provides a powerful **Variable Engine**.
2833

29-
The variable engine is an optional built-in feature provided by Flowgram to help streamline **variable information orchestration** in workflow design more efficiently. It enables the following functionalities:
34+
It acts like a professional "data steward," systematically managing all variables to ensure the clarity and stability of the data flow.
35+
36+
Enabling the Variable Engine will bring you the following core advantages:
3037

3138
<div style={{ display: "grid", gridTemplateColumns: "1fr 1fr", gap: "25px" }}>
3239
<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 they are available within the appropriate range and avoiding unnecessary conflicts.</p>
40+
<b>Scope Constraints: Precise Data Access Control</b>
41+
<p className="rs-tip">The Variable Engine can precisely control the effective range (i.e., scope) of each variable. Like having specific keys for different rooms, it ensures that variables are only accessed within the intended nodes, effectively preventing data pollution and unexpected logical errors.</p>
3542
<div style={{display: "flex", gap: "25px"}}>
3643
<div>
3744
<img loading="lazy" src="/variable/variable-scope-feature-1.png" />
38-
<p style={{marginTop: '10px'}}>In the diagram, the `query` variable from the Start node can be accessed by subsequent LLM and End nodes.</p>
45+
<p style={{marginTop: '10px'}}>The `query` variable defined in the `Start` node can be easily accessed by the subsequent `LLM` and `End` nodes.</p>
3946
</div>
4047
<div>
4148
<img loading="lazy" src="/variable/variable-scope-feature-2.png" />
42-
<p style={{marginTop: '10px'}}>In the diagram, the LLM node is inside a Condition branch, while the End node is outside. Thus, the End node's variable selector cannot access the `result` variable from the LLM node.</p>
49+
<p style={{marginTop: '10px'}}>The `LLM` node is in a `Condition` branch, like being in a separate room. The `End` node outside naturally cannot access its `result` variable.</p>
4350
</div>
4451
</div>
4552
</div>
4653
<div>
47-
<b>Variable Information Tree Maintenance</b>
48-
<p className="rs-tip">The variable engine helps you build a clear variable information tree, making it easier to view and manage the state and relationships of all variables.</p>
54+
<b>Variable Structure Insight: Easily Understand Complex Data</b>
55+
<p className="rs-tip">When a variable becomes complex (e.g., an object with many levels), the Variable Engine allows you to explore its internal structure layer by layer, like peeling an onion, with all details at your fingertips.</p>
4956
<img loading="lazy" src="/variable/variable-tree-management.gif" />
50-
<p style={{marginTop: '10px'}}>The diagram shows output variables from multiple nodes and global configurations, with some variables containing multiple sub-variables forming a tree structure.</p>
57+
<p style={{marginTop: '10px'}}>In this diagram, you can see the output variables of all nodes and their hierarchical relationships, like a lush tree.</p>
5158
</div>
5259
<div>
53-
<b>Automatic Type Inference</b>
54-
<p className="rs-tip">The variable engine can automatically infer variable types based on context, reducing the need for manual type specification and improving development efficiency.</p>
60+
<b>Automatic Type Inference: A Spark of Genius</b>
61+
<p className="rs-tip">You no longer need to tell each variable what its type should be. The Variable Engine, like your "soulmate," will automatically infer its type based on the context.</p>
5562
<img loading="lazy" src="/variable/variable-batch-auto-infer.gif" />
56-
<p style={{marginTop: '10px'}}>In the diagram, 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>
63+
<p style={{marginTop: '10px'}}>For example, when the type of the `arr` variable in the `Start` node changes, the type of the `item` output by the `Batch` node will also be automatically updated to ensure type consistency.</p>
5764
</div>
5865
</div>
5966

60-
## Enabling the Variable Engine
67+
## How to Enable the Variable Engine?
6168

62-
[> API Detail](https://flowgram.ai/auto-docs/editor/interfaces/VariablePluginOptions.html)
69+
You can enable the Variable Engine with a simple configuration to experience its powerful features.
6370

64-
```tsx pure title="use-editor-props.ts" {3}
71+
[> View API Details](https://flowgram.ai/auto-docs/editor/interfaces/VariablePluginOptions.html)
6572

66-
// EditorProps
73+
```tsx pure title="use-editor-props.ts" {3}
74+
// Enable the Variable Engine in EditorProps
6775
{
6876
variableEngine: {
69-
/**
70-
* The variable engine must be enabled to use this feature.
71-
*/
77+
// Set to true to enable the Variable Engine
7278
enable: true
7379
}
7480
}

0 commit comments

Comments
 (0)