# PSMR Workflow Runtime Specification v0.1

**版本：** v0.1  
**日期：** 2026-09-15

**作者：** Neo.K  
**機構：** EveMissLab／一言諾科技有限公司  

---

## 0. 目的

Workflow Runtime 負責將 Operator 組成可執行、可暫停、可恢復、可驗證的 DAG。

它不是單純 Agent log。

其工作流本身是一級語義物件。

---

# 一、Workflow Definition

$$
\Pi
=
(
V_O,
E_O,
K,
P
)
$$

其中：

- $V_O$：Operator invocations；
- $E_O$：dependency；
- $K$：workflow constraints；
- $P$：policy。

---

# 二、Workflow Schema

```json
{
  "workflow_id": "wf_...",
  "schema": "psmr-workflow-0.1",
  "inputs": [],
  "nodes": [],
  "edges": [],
  "policies": [],
  "outputs": []
}
```

---

# 三、Node

```json
{
  "node_id": "n1",
  "operator": "pbsio.impact",
  "parameters": {},
  "capabilities": [],
  "retry_policy": null
}
```

---

# 四、Edge

```json
{
  "from": "n1",
  "to": "n2",
  "condition": "completed"
}
```

---

# 五、Execution State

Workflow Run：

```text
created
running
paused
blocked
completed
failed
cancelled
```

---

# 六、Checkpoint

每個完成 node 可產生 checkpoint：

$$
CP_i
=
(
W_i,
O_i,
Y_i,
E_i
)
$$

---

# 七、Resume

若 workflow 中斷，Runtime 從最近合法 checkpoint 恢復。

已完成 pure Operator 不應重跑。

---

# 八、Effect Barrier

Effectful Operator 前應建立：

$$
\boxed{
\text{Effect Barrier}
}
$$

檢查：

- capability；
- human approval；
- policy；
- idempotence；
- rollback。

---

# 九、Human Approval Node

人類批准是一種正式 Operator：

```text
human.approve
```

輸出：

```text
approved
rejected
modified
```

---

# 十、AI Planning

AI 可以產生：

$$
\Pi_{\mathrm{proposal}}
$$

但 workflow plan 預設 authority 為：

```text
ai_proposal
```

Runtime 仍需驗證 Operator type / capability compatibility。

---

# 十一、Dynamic Workflow Expansion

某 Operator 可產生新的 workflow fragment：

$$
\Pi
\rightarrow
\Pi'
$$

但 expansion 必須記錄：

```text
generated_by
reason
added_nodes
added_edges
```

---

# 十二、Retry

Retry policy：

```json
{
  "max_attempts": 3,
  "backoff": "exponential",
  "only_if": ["TRANSIENT_ERROR"]
}
```

---

# 十三、Cache

對 cacheable Operator：

$$
K_O
$$

命中時可直接回用 result。

但 cache hit 必須成為 workflow event：

```text
operator_skipped_by_cache
```

不能讓 provenance 斷裂。

---

# 十四、Branch

Workflow 可以有條件：

```text
if validation failed
→ repair
else
→ finish
```

---

# 十五、Loop

Loop 必須有 boundary：

```text
max_iterations
convergence_condition
stop_condition
```

禁止無限制 Agent 自循環。

---

# 十六、Workflow Provenance

每個 run 應能回答：

```text
Who initiated?
What inputs?
Which operators?
Which versions?
Which cache hits?
Which capabilities?
Which external effects?
Which outputs?
Which unresolved items?
```

---

# 十七、Modification Workflow

建議標準工作流：

```text
Intent
→ Locate Semantic Region
→ Impact
→ Load Contracts
→ Propose Semantic Delta
→ Validate Delta
→ Project Patch
→ Run Tests
→ Rebuild Workspace
→ Semantic Diff
→ Verify
→ Human Approval
```

---

# 十八、Understanding Workflow

```text
Input
→ Observe
→ Build Workspace
→ Slice
→ Retrieve Evidence
→ Explain
```

---

# 十九、PR Review Workflow

```text
Base
+
Head
→ Build / Reuse CISG
→ Semantic Diff
→ Impact
→ New Findings
→ Review Fingerprint
→ Human Review
```

---

# 二十、Runtime Reconciliation Workflow

未來：

```text
Static Graph
+
Runtime Trace
→ Runtime Graph
→ Reconcile
→ Drift
→ New Unknowns / Conflicts
```

---

# 二十一、Workflow Validation

執行前驗證：

$$
\operatorname{Valid}(\Pi)
$$

至少檢查：

- type compatibility；
- cycle；
- missing capability；
- impossible dependency；
- missing effect barrier。

---

# 二十二、Failure Isolation

單一 Operator failure 不應污染整個 Workspace。

結果應：

```text
failed node
preserved prior checkpoint
typed failure
partial outputs if safe
```

---

# 二十三、Workflow Identity

定義：

$$
\operatorname{ID}(\Pi)
=
H(
N(\Pi)
)
$$

可用於：

- cache；
- audit；
- reproducibility；
- comparison。

---

# 二十四、Workflow Diff

可比較：

$$
\Pi_1
\rightarrow
\Pi_2
$$

回答：

> AI 的做事方式改了什麼？

這也是 AI-native system 的重要可觀測性。

---

# 二十五、結論

Workflow Runtime 把「Agent 做事過程」從不可重現的 conversational trace，提升成：

$$
\boxed{
\text{Typed}
+
\text{Executable}
+
\text{Checkpointable}
+
\text{Auditable}
+
\text{Verifiable}
}
$$

的 Semantic Workflow Graph。

這是 PSMR 從 analyzer 升級成真正 runtime 的核心。
