变量系统
变量系统是 Block 间数据传递的核心机制。每个 Block 执行后产生输出变量,后续 Block 可以引用这些变量来获取数据。
Block name 是变量引用和 Run API 使用的外部身份,必须在全文档内唯一,也不能与另一 Block 的内部 id 相同。内部 block id 用于稳定关联、引用统计和发布分析;Markdown IR 的 @{blockName.path} 会在解析后绑定为 mention:<blockId>。内部 ID 不能替代公开名称。
例如 Input 的 name 为 message、内部 id 为 input_x:页面使用 @message,Markdown IR 使用 @{message},内部引用保存 id: "mention:input_x"、value: "@message"。把名字改为 question 后显示值变为 @question,绑定仍是 mention:input_x。用户不需要知道内部 ID,@{input_x} 不会被当成 message 的别名。
系统在写入与运行前检查活动引用是否有唯一目标,以及稳定 ID 与显示名称是否一致。历史异常文档仍可打开修正;删除目标后保留的失效引用可保存并在撤销时恢复,运行只保留其字面文本。
引用语法
在文档中通过 Mention 节点引用变量,有两种形式:
默认变量引用
@blockName引用 Block 的默认输出(__default__ 变量)。例如 @generation_1 引用第一个 Generation Block 的文本输出。
具名变量引用
@blockName > variableName引用 Block 的特定输出变量。例如 @loop_1 > item 引用 Loop Block 的当前迭代项。
这里的 generation_1、loop_1 都指公开名称。Markdown IR 对应 @{generation_1}、@{loop_1.item};完整字段路径及数组下标在正文、代码和条件提示词中保持一致。
名称本身可含中文、空格、点号、>、前导 @ 和正则特殊字符,按完整字面名识别。已有绑定以 Block ID 确定目标,改名保留字段后缀;无绑定表达式若能解释为多个名称与路径组合,会提示歧义。
ValueSource 数组、Structure 的 variable.blockId 与 Output binding 是内部结构化引用,仍以稳定 ID 关联,不受公开名称语法替换。
密钥引用
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)
- Flow Block:根据目标文档的输出结构动态生成变量
- Tools / Allow Tools Block:只声明后续 AI 可用的工具,不产生输出变量
各 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 | 无 | - | - | 终止执行,无输出 |