# Execution Context

> 当前运行、正在执行的工作流与节点的 id，以及环境。

Source: https://docs.sommatic.ai/zh/expressions/reference/execution-context/

每个示例都在已部署的表达式引擎上、基于页面末尾的[示例上下文](#example-context)运行过。

## `$execution`

对象 · `object` · 来源: `Sommatic AI expression engine`

```javascript
$execution
```

运行的身份标识。在消息、任务和日志中写入 `$execution.id`，任何人都能据此把一个案例追溯到对应的运行。当运行由 [`workflow.chain`](/zh/nodes/workflow.chain/) 启动时，`id` 是根运行的 id，因此链中所有工作流共用这个值；`run_flow_instance_result_id` 则保留本次运行自身的 id。

### 成员

| 签名 | 类型 | 说明 |
| --- | --- | --- |
| `$execution.id` | `string` | 运行的主 id：链的根运行的结果 id；没有链时为本次运行的结果 id。 |
| `$execution.flow_instance_result_id` | `string \| null` | 主结果 id（与 `id` 的值相同）。 |
| `$execution.root_flow_instance_result_id` | `string \| null` | 链的根运行的结果 id。 |
| `$execution.run_flow_instance_result_id` | `string \| null` | 本次运行的结果 id，在链中同样适用。 |
| `$execution.flow_instance_id` | `string \| null` | 流程实例的 id。 |
| `$execution.flow_definition_id` | `string \| null` | 工作流定义的 id。 |
| `$execution.flow_version_id` | `string \| null` | 正在运行的已发布版本的 id。 |
| `$execution.flow_slug` | `string \| null` | 工作流的 slug。 |
| `$execution.mode` (保留) | `string` | 保留：用于区分测试运行与生产运行；目前始终为 `'manual'`。 |
| `$execution.resumeUrl` (保留) | `undefined` | 保留：用于恢复已暂停的运行；目前始终为 `undefined`。 |
| `$execution.customData` (保留) | `object` | 保留：始终为 `{}`。 |

### 示例

```javascript
Case received. Reference: {{ $execution.id }}
```

结果 (string):

```json
"Case received. Reference: fir-xxxx"
```

```javascript
{{ ({ run: $execution.id, workflow: $execution.flow_slug, version: $execution.flow_version_id }) }}
```

结果 (object):

```json
{
  "run": "fir-xxxx",
  "workflow": "order-intake",
  "version": "fv-xxxx"
}
```

保留成员：每次运行的值都相同。

```javascript
{{ $execution.mode }}
```

结果 (string):

```json
"manual"
```

### 说明

- 本次运行不具备的字段为 `null`。id 是不透明文本：只做比较，切勿解析。
- 节点自身的 `execution` 配置字段（其重试设置）与 `$execution` 无关。

在 JSONata 中: `$$execution.id`

## `$workflow`

对象 · `object` · 来源: `Sommatic AI expression engine`

```javascript
$workflow
```

正在执行的工作流。请使用 `slug` 和 `version`；`id`、`name` 和 `active` 为保留成员，目前保存固定值（如需定义的 id，请读取 `$execution.flow_definition_id`）。

### 成员

| 签名 | 类型 | 说明 |
| --- | --- | --- |
| `$workflow.slug` | `string \| null` | 工作流的 slug。 |
| `$workflow.version` | `string \| null` | 标识正在运行的版本（目前为已发布版本的 id）。请将其视为不透明值，而非数字。 |
| `$workflow.id` (保留) | `string` | 保留：目前始终为 `'unknown'`。请使用 `$execution.flow_definition_id`。 |
| `$workflow.name` (保留) | `string` | 保留：目前始终为 `'Untitled'`。 |
| `$workflow.active` (保留) | `boolean` | 保留：目前始终为 `false`。 |

### 示例

```javascript
{{ $workflow.slug + '@' + $workflow.version }}
```

结果 (string):

```json
"order-intake@fv-xxxx"
```

完整对象，包括保留成员。

```javascript
{{ $workflow }}
```

结果 (object):

```json
{
  "id": "unknown",
  "name": "Untitled",
  "active": false,
  "slug": "order-intake",
  "version": "fv-xxxx"
}
```

在 JSONata 中: `$$workflow.slug`

## `$node`

对象 · `object` · 来源: `Sommatic AI expression engine`

```javascript
$node
```

正在执行的节点的元数据。它不能用来读取其他节点；如需读取，请使用 [`$('Node label')`](#node-accessor)。

### 成员

| 签名 | 类型 | 说明 |
| --- | --- | --- |
| `$node.id` | `string` | 节点的 `node_id`。 |
| `$node.label` | `string \| null` | 节点的标签，与画布上显示的一致。 |
| `$node.name` | `string \| null` | 与 `label` 的值相同。 |

### 示例

```javascript
Created by {{ $node.label }} in {{ $workflow.slug }}
```

结果 (string):

```json
"Created by Notify customer in order-intake"
```

```javascript
{{ $node.id }}
```

结果 (string):

```json
"node-notify"
```

在 JSONata 中: `$$node.label`

## `$env`

变量 · `object` · 保留 · 来源: `Sommatic AI expression engine`

> **保留.** 引擎尚未填充它：目前始终为 `{}`。

```javascript
$env
```

用于存放为工作流运行所在环境声明的变量。引擎目前尚未填充它：它始终是空对象，并且绝不会暴露服务自身的环境。请通过触发器输入或 [Git Sync 环境](/zh/git-sync/environments-and-tokens/)传递特定于环境的值，通过绑定到节点的凭据传递机密。

### 示例

```javascript
{{ $env }}
```

结果 (object):

```json
{}
```

在它为空时，默认值可让表达式照常工作。

```javascript
{{ $ifEmpty($env.API_BASE_URL, 'https://api.example.com') }}
```

结果 (string):

```json
"https://api.example.com"
```

在 JSONata 中: `$$env`

## `$vars`

变量 · `object` · 保留 · 来源: `Sommatic AI expression engine`

> **保留.** 不会被填充：目前始终为 `{}`。

```javascript
$vars
```

为工作流变量保留。它始终是空对象。切勿把机密放进变量：请改为给节点绑定凭据。

### 示例

```javascript
{{ $vars }}
```

结果 (object):

```json
{}
```

在 JSONata 中: `$$vars`

## `$nodeVersion`

变量 · `number` · 保留 · 来源: `Sommatic AI expression engine`

> **保留.** 目前始终为 `1`。

```javascript
$nodeVersion
```

用于表示执行当前节点的算子的版本。无论节点的 `operator_version` 是什么，它始终为 `1`。算子版本是工作流文件中节点定义的一部分。

### 示例

```javascript
{{ $nodeVersion }}
```

结果 (number):

```json
1
```

在 JSONata 中: `$$nodeVersion`

## 示例上下文

示例基于以下数据运行：当前节点的输入（`$json`）、已运行的节点（`$(…)`）、本次运行的 ID 以及当前节点。时钟固定为 `2026-11-26T14:30:00.000Z`，服务器时区为 UTC，因此各页面中 `$now` 与 `$today` 的值都相同。

```json
{
  "$json": {
    "body": {
      "order_id": "ord_1042",
      "email": "ana.perez@example.com",
      "customer": {
        "name": "Ana Pérez",
        "segment": "gold"
      },
      "priority": "",
      "items": [
        {
          "sku": "A-100",
          "qty": 2,
          "price": 10.5
        },
        {
          "sku": "B-200",
          "qty": 0,
          "price": 4
        },
        {
          "sku": "C-300",
          "qty": 1,
          "price": 25
        }
      ],
      "tags": [
        "new",
        "web",
        "new"
      ],
      "created_at": "2026-11-25T09:15:00Z"
    },
    "headers": {
      "content-type": "application/json"
    },
    "query": {},
    "method": "POST"
  },
  "nodes": {
    "Webhook Receiver": "= $json",
    "Normalize input": {
      "correlation_id": "c-7f3a",
      "channel": "web"
    },
    "Classify": {
      "label": "billing",
      "confidence": 0.92
    }
  },
  "run": {
    "$flow_instance_result_id": "fir-xxxx",
    "$flow_instance_id": "fi-xxxx",
    "$flow_definition_id": "fd-xxxx",
    "$flow_version_id": "fv-xxxx",
    "$flow_slug": "order-intake"
  },
  "node": {
    "node_id": "node-notify",
    "label": "Notify customer"
  }
}
```

串联工作流的示例基于第二个上下文运行：一个由 `workflow.chain` 启动的工作流，其 `workflow.trigger` 节点的标签为 `Chain Entry Point`。

```json
{
  "$json": {
    "order_id": "ord_1042",
    "customer_email": "ana.perez@example.com",
    "amount": 46,
    "chain_context": {
      "caller_flow_definition_id": "fd-caller-xxxx",
      "caller_flow_instance_id": "fi-caller-xxxx",
      "caller_flow_slug": "order-intake",
      "caller_node_id": "node-chain-billing",
      "correlation_id": "chain-7Hq2Lw9sKd3pXa1mZr4t",
      "root_flow_instance_result_id": "fir-root-xxxx"
    }
  },
  "run": {
    "$flow_instance_result_id": "fir-hop-xxxx",
    "$flow_instance_id": "fi-hop-xxxx",
    "$flow_definition_id": "fd-billing-xxxx",
    "$flow_version_id": "fv-billing-xxxx",
    "$flow_slug": "billing-review",
    "$input": {
      "data": {
        "order_id": "ord_1042",
        "customer_email": "ana.perez@example.com",
        "amount": 46
      },
      "chain_context": {
        "caller_flow_definition_id": "fd-caller-xxxx",
        "caller_flow_instance_id": "fi-caller-xxxx",
        "caller_flow_slug": "order-intake",
        "caller_node_id": "node-chain-billing",
        "correlation_id": "chain-7Hq2Lw9sKd3pXa1mZr4t",
        "root_flow_instance_result_id": "fir-root-xxxx"
      }
    }
  },
  "node": {
    "node_id": "node-create-task",
    "label": "Create review task"
  }
}
```

示例运行所基于的编排器提交 31e874b.
