# 条件

Source: https://openflow.run/zh-cn/docs/nodes/condition/
Language: zh-CN
Product version: 0.1.0-beta.77

通过明确的比较规则，为固定值或可用数据选择具名执行分支。

条件节点（Condition）适合状态检查、阈值判断、空值判断和类别精确匹配等规则，不调用模型。

## 定义分支

每个分支有名称和 `when` 表达式。表达式可以用 `all` 或 `any` 组合。`match` 设为 `first` 时选择第一个匹配分支，设为 `all` 时选择所有匹配分支。

```json
{
  "op": "node.add", "as": "route", "type": "condition", "name": "Route a ticket",
  "config": {
    "match": "first",
    "branches": [{
      "name": "priority",
      "when": {
        "left": { "kind": "value", "value": "priority" },
        "operator": "==",
        "right": { "kind": "value", "value": "priority" }
      }
    }]
  }
}
```

操作数可以使用受支持的上游输出或变量，不必是固定值。可用运算符和操作数要求，以结构说明为准。

## 连接分支路径

连接执行线时指定分支名：

```json
{ "op": "edge.connect", "source": "$route", "branch": "priority", "target": "$escalate" }
```

没有分支匹配时选择 `otherwise`。设置 `match: "all"` 时，可以有多条分支继续执行；这些分支在下游汇合时，仍遵循普通前驱规则。

条件节点比较客户等级，选择优先处理分支或 otherwise 分支。

**输入**
参与比较的客户等级为 "priority"。

**预期结果**
选中 Priority queue。将等级改为其他值后，会选中 Standard queue。

**运行前准备**
导入或执行此案例需要 Open Flow 服务；预览本身可离线使用。

[下载工作流](https://openflow.run/docs/examples/route-by-value.openflow.json)

## 数据与执行控制

条件分支名表示执行选择，不是数据输出。下游业务数据仍需从实际的上游来源绑定。任务经过错误处理后的系统错误，也可以在这里比较，无需添加错误连线。

需要模型评估时，使用 [AI 决策](https://openflow.run/zh-cn/docs/nodes/decision/index.md)，再根据结构化结果选择路径。条件节点没有普通任务重试或错误处理配置。

## 资料来源

*   [docs/authoring/node-authoring.md](https://github.com/oomol-lab/open-flow/blob/e25a738d170322734572a0b8a1323cb00b9d355a/docs/authoring/node-authoring.md)
*   [docs/control/contracts/control-api.md](https://github.com/oomol-lab/open-flow/blob/e25a738d170322734572a0b8a1323cb00b9d355a/docs/control/contracts/control-api.md#execution-graphs-and-input-sources)
*   [packages/open-flow/src/workbench/browser/runtime/editor/addNodeOptions.ts](https://github.com/oomol-lab/open-flow/blob/e25a738d170322734572a0b8a1323cb00b9d355a/packages/open-flow/src/workbench/browser/runtime/editor/addNodeOptions.ts)
