变量系统
变量系统是 Block 间数据传递的核心机制。每个 Block 执行后产生输出变量,后续 Block 可以引用这些变量来获取数据。
引用语法
在文档中通过 Mention 节点引用变量,有两种形式:
默认变量引用
@blockName引用 Block 的默认输出(__default__ 变量)。例如 @generation_1 引用第一个 Generation Block 的文本输出。
具名变量引用
@blockName > variableName引用 Block 的特定输出变量。例如 @loop_1 > item 引用 Loop Block 的当前迭代项。
密钥引用
secrets:keyName引用项目级或团队级的密钥值。例如 secrets:api_token。
变量类型
| 类型 | 说明 | 示例 |
|---|---|---|
string | 文本值 | Generation 的文本输出 |
number | 数值 | Loop 的 count、index |
boolean | 布尔值 | Database 的 success、If-Else 的 condition |
array | 数组 | Database 的 rows、Code 的 logs |
object | 对象 | Database 的 row、Flow 的默认输出 |
any | 任意类型 | Code 的 output |
dynamic | 动态类型 | Structure 的默认输出(根据 Schema 推断) |
变量作用域
变量的可见范围由 checkShow 属性决定:
after 作用域
变量在 Block 执行完成后,在文档中该 Block 之后的任意位置可引用。这是大多数 Block 的默认行为。
[Generation Block] ← 产生 __default__ 变量
↓
[Code Block] ← 可以引用 @generation_1
↓
[另一个 Block] ← 也可以引用 @generation_1inside 作用域
变量仅在容器节点内部可引用,外部不可见。目前仅 Loop Block 使用此作用域。
[Loop Block 开始]
├── item, index, count ← 仅这里可见
├── [子 Block A] ← 可以引用 @loop_1 > item
└── [子 Block B] ← 可以引用 @loop_1 > index
[Loop Block 结束]
[后续 Block] ← 无法引用 item/index/count动态变量
部分 Block 支持根据配置动态暴露变量:
能力感知变量(Generation)
Generation Block 根据所选模型的能力决定是否暴露特定变量:
| 变量 | 条件 |
|---|---|
thinking | 模型支持 thinking 或 thinking_controllable 能力 |
tool_calls | Block 配置了 tools ability |
image / images | Block 配置了 image ability |
操作型变量(Database)
Database Block 根据操作类型暴露不同变量:
| 操作 | 可用变量 |
|---|---|
query | rows、total |
count | total |
insert / update | row |
delete | success、deletedId |
Schema 驱动变量(Structure)
Structure Block 解析 JSON Schema 的 properties,为每个字段生成独立变量。支持嵌套对象和数组类型。
工厂函数变量(Flow、Tools)
- Flow Block:根据目标文档的输出结构动态生成变量
- Tools Block:根据配置的工具列表生成每个工具的输出变量
各 Block 输出变量汇总
| Block | 变量名 | 类型 | 作用域 | 说明 |
|---|---|---|---|---|
| Generation | __default__ | string | after | AI 生成的文本 |
| Generation | thinking | string | after | 思考过程(需模型支持) |
| Generation | tool_calls | any | after | 工具调用结果 |
| Generation | image / images | any | after | 生成的图片 |
| Structure | __default__ | dynamic | after | 完整 JSON 对象 |
| Structure | Schema 字段 | dynamic | after | 每个字段的值 |
| Code | __default__ | any | after | 代码返回值 |
| Code | output | any | after | 代码输出 |
| Code | logs | array | after | console.log 输出 |
| Code | errors | array | after | 错误信息 |
| Ask | __default__ | string | after | 用户回答 |
| Ask | question | string | after | 问题内容 |
| Ask | answer | string | after | 用户回答 |
| Loop | count | number | inside | 当前循环计次 |
| Loop | item | any | inside | 当前迭代项 |
| Loop | index | number | inside | 当前索引 |
| If-Else | condition | boolean | after | 条件结果 |
| If-Else | result | any | after | 分支执行结果 |
| Promise | __default__ | array | after | 所有分支结果 |
| Promise | count | number | after | 完成的分支数 |
| Promise | status | string | after | 执行状态 |
| Promise | failed | array | after | 失败的分支 |
| Promise | cancelled | array | after | 取消的分支 |
| Database | __default__ | any | after | 操作结果 |
| Database | rows | array | after | 查询结果行(query) |
| Database | total | number | after | 总数(query/count) |
| Database | row | object | after | 单行数据(insert/update) |
| Database | success | boolean | after | 操作是否成功(delete) |
| Database | deletedId | string | after | 删除的记录 ID(delete) |
| Flow | __default__ | object | after | 子文档执行结果 |
| Exit | 无 | - | - | 终止执行,无输出 |