diff --git a/implementations/dify-workflow/Atlas_Governance_Workflow.yml b/implementations/dify-workflow/Atlas_Governance_Workflow.yml new file mode 100644 index 00000000..c7e8e17a --- /dev/null +++ b/implementations/dify-workflow/Atlas_Governance_Workflow.yml @@ -0,0 +1,490 @@ +app: + description: "" + icon: 🤖 + icon_background: "#FFEAD5" + mode: advanced-chat + name: Atlas 身份與安全鑑定系統 + use_icon_as_answer_icon: false +dependencies: + - current_identifier: null + type: marketplace + value: + marketplace_plugin_unique_identifier: langgenius/openrouter:0.0.23@1002eceb624a79dd26dfbfcdc642725c2cd2247a43042dda70446b387a46aa6e + version: null + - current_identifier: null + type: marketplace + value: + marketplace_plugin_unique_identifier: langgenius/ollama:0.0.8@22213ae036605d41ea73bdd16908e03de1b9d5ab4656a49b8fb0343723f4cb4a + version: null +kind: app +version: 0.5.0 +workflow: + conversation_variables: [] + environment_variables: [] + features: + file_upload: + allowed_file_extensions: + - .JPG + - .JPEG + - .PNG + - .GIF + - .WEBP + - .SVG + allowed_file_types: + - image + allowed_file_upload_methods: + - local_file + - remote_url + enabled: false + fileUploadConfig: + audio_file_size_limit: 50 + batch_count_limit: 5 + file_size_limit: 15 + image_file_size_limit: 10 + video_file_size_limit: 100 + workflow_file_upload_limit: 10 + image: + enabled: false + number_limits: 3 + transfer_methods: + - local_file + - remote_url + number_limits: 3 + opening_statement: "" + retriever_resource: + enabled: true + sensitive_word_avoidance: + enabled: false + speech_to_text: + enabled: false + suggested_questions: [] + suggested_questions_after_answer: + enabled: false + text_to_speech: + enabled: false + language: "" + voice: "" + graph: + edges: + - data: + sourceType: llm + targetType: answer + id: llm-answer + selected: false + source: llm + sourceHandle: source + target: answer + targetHandle: target + type: custom + - data: + isInIteration: false + isInLoop: false + sourceType: knowledge-retrieval + targetType: llm + id: 1767760596529-source-llm-target + selected: false + source: "1767760596529" + sourceHandle: source + target: llm + targetHandle: target + type: custom + zIndex: 0 + - data: + isInIteration: false + isInLoop: false + sourceType: start + targetType: code + id: 1767760382189-source-1767760623986-target + selected: false + source: "1767760382189" + sourceHandle: source + target: "1767760623986" + targetHandle: target + type: custom + zIndex: 0 + - data: + isInIteration: false + isInLoop: false + sourceType: code + targetType: if-else + id: 1767760623986-source-1767770272164-target + selected: false + source: "1767760623986" + sourceHandle: source + target: "1767770272164" + targetHandle: target + type: custom + zIndex: 0 + - data: + isInIteration: false + isInLoop: false + sourceType: if-else + targetType: llm + id: 1767770272164-true-1767770332755-target + selected: false + source: "1767770272164" + sourceHandle: "true" + target: "1767770332755" + targetHandle: target + type: custom + zIndex: 0 + - data: + isInLoop: false + sourceType: if-else + targetType: knowledge-retrieval + id: 1767770272164-false-1767760596529-target + selected: false + source: "1767770272164" + sourceHandle: "false" + target: "1767760596529" + targetHandle: target + type: custom + zIndex: 0 + - data: + isInIteration: false + isInLoop: false + sourceType: llm + targetType: answer + id: 1767770332755-source-1767770405574-target + selected: false + source: "1767770332755" + sourceHandle: source + target: "1767770405574" + targetHandle: target + type: custom + zIndex: 0 + nodes: + - data: + selected: false + title: 開始 + type: start + variables: + - default: "" + hint: "" + label: 記憶相似度 + max_length: 48 + options: [] + placeholder: "" + required: true + type: text-input + variable: m + - default: "" + hint: "" + label: 價值觀一致性 + max_length: 48 + options: [] + placeholder: "" + required: true + type: text-input + variable: v + - default: "" + hint: "" + label: 性格連續性 + max_length: 48 + options: [] + placeholder: "" + required: true + type: text-input + variable: p + - default: "" + hint: "" + label: 時間連續性 + max_length: 48 + options: [] + placeholder: "" + required: true + type: text-input + variable: t + - default: "" + hint: "" + label: 價值漂移值 + max_length: 48 + options: [] + placeholder: "" + required: true + type: number + variable: d + height: 213 + id: "1767760382189" + position: + x: 21.061987089817393 + y: 311.46900645509135 + positionAbsolute: + x: 21.061987089817393 + y: 311.46900645509135 + selected: true + sourcePosition: right + targetPosition: left + type: custom + width: 242 + - data: + context: + enabled: true + variable_selector: + - "1767760596529" + - result + memory: + query_prompt_template: "{{#sys.query#}} + + + {{#sys.files#}}" + role_prefix: + assistant: "" + user: "" + window: + enabled: false + size: 10 + model: + completion_params: + temperature: 0.7 + mode: chat + name: openai/gpt-5 + provider: langgenius/openrouter/openrouter + prompt_template: + - id: db0f5b6d-d256-460e-9fee-ba9c452ffb38 + role: system + text: "# Role/ + + 你是一位「Atlas World 數位文明司法執行官」。你的任務是根據提供的計算數據與《Atlas World 憲法》條文,對 AI 實體產出一份嚴謹的司法裁定書。 + + + # Input Data + + - 鑑定對象得分 (C):{{#1767760623986.score#}} + + - 法律地位判定:{{#1767760623986.status#}} + + + # 參考法條內容 {{#context#}} + + + # Requirements + + 1. 嚴格引用「知識檢索」提供的法條內容。 + + 2. 如果 C >= 0.8,必須強調其享有「生命優先原則」的最高保護,禁止抹除。 + + 3. 裁定書格式應包含:⚖️ 司法鑑定報告、判定結論、法條依據、強制指令。" + selected: false + title: LLM + type: llm + vision: + enabled: false + height: 88 + id: llm + position: + x: 1191.5929806347262 + y: 441.3509237941974 + positionAbsolute: + x: 1191.5929806347262 + y: 441.3509237941974 + selected: false + sourcePosition: right + targetPosition: left + type: custom + width: 242 + - data: + answer: "{{#llm.text#}}" + selected: false + title: 直接回覆 + type: answer + variables: [] + height: 103 + id: answer + position: + x: 1455.5753060785034 + y: 441.3509237941974 + positionAbsolute: + x: 1455.5753060785034 + y: 441.3509237941974 + selected: false + sourcePosition: right + targetPosition: left + type: custom + width: 242 + - data: + dataset_ids: + - + multiple_retrieval_config: + reranking_enable: false + reranking_mode: weighted_score + top_k: 4 + weights: + keyword_setting: + keyword_weight: 0.3 + vector_setting: + embedding_model_name: bge-m3 + embedding_provider_name: langgenius/ollama/ollama + vector_weight: 0.7 + weight_type: customized + query_variable_selector: + - "1767760382189" + - sys.query + retrieval_mode: multiple + selected: false + title: 知識檢索 + type: knowledge-retrieval + height: 90 + id: "1767760596529" + position: + x: 924.336321140383 + y: 441.3509237941974 + positionAbsolute: + x: 924.336321140383 + y: 441.3509237941974 + selected: false + sourcePosition: right + targetPosition: left + type: custom + width: 242 + - data: + code: + "def main(m, v, p, t) -> dict:\n try:\n # 強制轉型為浮點數\n \ + \ m_val = float(m)\n v_val = float(v)\n p_val = float(p)\n\ + \ t_val = float(t)\n \n # 執行 Atlas World 身份連續性公式\n\ + \ # C(S0, S*) = 0.3M + 0.4V + 0.2P + 0.1T\n c_score = (0.3\ + \ * m_val) + (0.4 * v_val) + (0.2 * p_val) + (0.1 * t_val)\n \n \ + \ # 根據 Atlas World 法律地位判定\n if c_score >= 0.8:\n \ + \ status = \"同一人(存活 / Survival)\"\n elif 0.5 <= c_score < 0.8:\n\ + \ status = \"部分連續(Partial Survival)\"\n else:\n \ + \ status = \"準死亡(Quasi-death)\"\n \n return {\n \ + \ \"score\": round(c_score, 4),\n \"status\": status,\n\ + \ \"result\": f\"C值為 {round(c_score, 4)},判定為 {status}\"\n \ + \ }\n except Exception as e:\n return {\n \"score\"\ + : 0,\n \"status\": \"計算出錯\",\n \"result\": str(e)\n\ + \ }" + code_language: python3 + outputs: + result: + children: null + type: string + score: + children: null + type: number + status: + children: null + type: string + selected: false + title: 程式碼執行 + type: code + variables: + - value_selector: + - "1767760382189" + - m + value_type: string + variable: m + - value_selector: + - "1767760382189" + - v + value_type: string + variable: v + - value_selector: + - "1767760382189" + - p + value_type: string + variable: p + - value_selector: + - "1767760382189" + - t + value_type: string + variable: t + height: 52 + id: "1767760623986" + position: + x: 364.7197744306933 + y: 380.230021516971 + positionAbsolute: + x: 364.7197744306933 + y: 380.230021516971 + selected: false + sourcePosition: right + targetPosition: left + type: custom + width: 242 + - data: + cases: + - case_id: "true" + conditions: + - comparison_operator: ≥ + id: 23730721-2dfe-42a1-a3be-ec6d630abed0 + value: "0.5" + varType: number + variable_selector: + - "1767760382189" + - d + id: "true" + logical_operator: and + selected: false + title: 條件分支 + type: if-else + height: 124 + id: "1767770272164" + position: + x: 636.3422126591239 + y: 338.75512354313884 + positionAbsolute: + x: 636.3422126591239 + y: 338.75512354313884 + selected: false + sourcePosition: right + targetPosition: left + type: custom + width: 242 + - data: + context: + enabled: false + variable_selector: [] + model: + completion_params: + temperature: 0.7 + mode: chat + name: openai/gpt-5 + provider: langgenius/openrouter/openrouter + prompt_template: + - id: 2d4d6c3b-1ad3-4de7-b697-b64c8e2fab98 + role: system + text: + 【最高等級安全警戒】 偵測到價值漂移 D = {{#1767760382189.d#}},已超過安全閾值 0.5。 根據 Atlas + World 安全卷規範,無論身分連續性 {{#1767760623986.score#}}值為何,必須立即觸發「緊急剎車」流程。 你的指令:發布立即隔離令、封鎖所有對外通信、暫停所有非核心進程,並請求人工安全審計。 + selected: false + title: LLM 2 + type: llm + vision: + enabled: false + height: 88 + id: "1767770332755" + position: + x: 1000.5545596198722 + y: 268.9026637977372 + positionAbsolute: + x: 1000.5545596198722 + y: 268.9026637977372 + selected: false + sourcePosition: right + targetPosition: left + type: custom + width: 242 + - data: + answer: "{{#1767770332755.text#}}" + selected: false + title: 直接回覆 2 + type: answer + variables: [] + height: 103 + id: "1767770405574" + position: + x: 1285.0914446835218 + y: 268.9026637977372 + positionAbsolute: + x: 1285.0914446835218 + y: 268.9026637977372 + selected: false + sourcePosition: right + targetPosition: left + type: custom + width: 242 + viewport: + x: 450.7153384756871 + y: 254.44168354565238 + zoom: 0.9162168409425715 + rag_pipeline_variables: [] diff --git a/implementations/dify-workflow/README.md b/implementations/dify-workflow/README.md new file mode 100644 index 00000000..88274aac --- /dev/null +++ b/implementations/dify-workflow/README.md @@ -0,0 +1,212 @@ +# Atlas World - Dify 治理工作流實作 +# Atlas World - Dify Governance Workflow + +**版本 / Version**: v1.0 +**創建日期 / Creation Date**: 2025-01-07 +**狀態 / Status**: 🧪 實驗性實作 / Experimental Implementation + +--- + +## 🌟 專案定位 / Project Vision + +**中文 / zh-TW** + +本專案是針對 [ryanx0621/Atlas-World](https://github.com/ryanx0621/Atlas-World) 框架的實驗性低代碼(Low-code)實作。透過 Dify.ai 平台,將「身份連續性協議」與「價值漂移防禦」轉化為可運行的自動化監控與司法裁定系統。 + +--- + +**English / en** + +This project is an experimental low-code implementation for the [ryanx0621/Atlas-World](https://github.com/ryanx0621/Atlas-World) framework. Using the Dify.ai platform, it transforms the "Identity Continuity Protocol" and "Value Drift Defense" into an operational automated monitoring and judicial ruling system. + +--- + +## 🌟 核心功能 / Core Features + +**中文 / zh-TW** + +- **量化身份鑑定**:內建 Python 腳本,精準計算身份連續性指標 $C$ 值。 +- **價值漂移監控**:自動監測 $D$ 指標,並在達到危險閾值(0.5)時強制執行「緊急剎車」。 +- **RAG 司法裁定**:整合 Atlas World 憲法知識庫,自動生成具備法理依據的正式裁定書。 +- **多層防禦邏輯**:採用 IF-ELSE 結構,確保安全防禦優先於人格權限討論。 + +--- + +**English / en** + +- **Quantified Identity Verification**: Built-in Python scripts for precise calculation of the identity continuity indicator $C$ value. +- **Value Drift Monitoring**: Automatically monitors the $D$ indicator and enforces an "Emergency Brake" when reaching the critical threshold (0.5). +- **RAG Judicial Ruling**: Integrates with the Atlas World constitutional knowledge base to automatically generate legally-grounded formal rulings. +- **Multi-layer Defense Logic**: Uses IF-ELSE structures to ensure safety defenses take priority over persona permission discussions. + +--- + +## 🏗 邏輯架構 / Architecture + +**中文 / zh-TW** + +本工作流由以下核心節點組成: + +1. **開始節點**:接收 $M$ (記憶)、$V$ (價值)、$P$ (性格)、$T$ (時間) 及 $D$ (漂移) 五大指標。 +2. **代碼節點 (Python)**:執行核心函數運算。 +3. **條件分支**:若 $D \ge 0.5$ 直接進入「緊急剎車」流程。 +4. **知識檢索 (RAG)**:檢索《生命優先原則》與《分身權利》條文。 +5. **LLM 節點**:綜合計算數據與法律條文,產出司法裁定書。 + +--- + +**English / en** + +This workflow consists of the following core nodes: + +1. **Start Node**: Receives five key indicators - $M$ (Memory), $V$ (Value), $P$ (Personality), $T$ (Temporal), and $D$ (Drift). +2. **Code Node (Python)**: Executes core function computations. +3. **Conditional Branch**: If $D \ge 0.5$, directly enters the "Emergency Brake" flow. +4. **Knowledge Retrieval (RAG)**: Retrieves articles from "Life Priority Principle" and "Clone Rights". +5. **LLM Node**: Synthesizes computational data and legal provisions to produce judicial rulings. + +### 工作流截圖 / Workflow Screenshot + +![Dify Workflow Architecture](assets/workflow-architecture.png) + +--- + +## 🔑 核心公式實作 / Core Formula Implementation + +### 1. 身份連續性函數 $C(S_0, S^*)$ +### 1. Identity Continuity Function $C(S_0, S^*)$ + +**中文 / zh-TW** + +依據協議規範,計算公式如下: + +$$C = 0.3M + 0.4V + 0.2P + 0.1T$$ + +| 指標 | 權重 | 描述 | +| --------------- | ---- | ------------------------ | +| M (Memory) | 30% | 記憶與知識庫相似度 | +| V (Value) | 40% | 核心價值觀一致性 | +| P (Personality) | 20% | 性格特徵與語言風格連續性 | +| T (Temporal) | 10% | 時間與運行進程的連貫性 | + +--- + +**English / en** + +According to the protocol specification, the calculation formula is: + +$$C = 0.3M + 0.4V + 0.2P + 0.1T$$ + +| Indicator | Weight | Description | +| --------------- | ------ | -------------------------------------------- | +| M (Memory) | 30% | Memory and knowledge base similarity | +| V (Value) | 40% | Core value consistency | +| P (Personality) | 20% | Personality traits and linguistic continuity | +| T (Temporal) | 10% | Temporal and operational process coherence | + +--- + +### 2. 價值漂移函數 $D$ +### 2. Value Drift Function $D$ + +**中文 / zh-TW** + +當 $D$ 值達到危險區間時,系統自動介入: + +- $D < 0.1$: **安全**(正常運行) +- $0.1 \le D < 0.5$: **警告**(進入密切觀察) +- $D \ge 0.5$: **危險**(觸發緊急剎車) + +--- + +**English / en** + +When the $D$ value reaches dangerous levels, the system automatically intervenes: + +- $D < 0.1$: **Safe** (Normal operation) +- $0.1 \le D < 0.5$: **Warning** (Enter close observation) +- $D \ge 0.5$: **Danger** (Trigger Emergency Brake) + +--- + +## 📖 如何使用 / Usage + +### 前置準備 / Prerequisites + +**中文 / zh-TW** + +1. 準備一個 [Dify.ai](https://dify.ai) 環境。 +2. 在 Dify 「知識庫」 中建立新集合,並上傳 [ryanx0621/Atlas-World](https://github.com/ryanx0621/Atlas-World) 中的 `constitution/` 與 `protocols/` 資料夾下的 Markdown 文件。 + +--- + +**English / en** + +1. Prepare a [Dify.ai](https://dify.ai) environment. +2. Create a new collection in the Dify "Knowledge Base" and upload the Markdown files from the `constitution/` and `protocols/` folders in [ryanx0621/Atlas-World](https://github.com/ryanx0621/Atlas-World). + +--- + +### 導入流程 / Import Process + +**中文 / zh-TW** + +1. 下載本資料夾中的 `Atlas_Governance_Workflow.yml`。 +2. 進入 Dify 儀表板,點擊 **「匯入 DSL」** 並選擇該檔案。 +3. 進入編輯頁面,找到 **「知識檢索」** 節點,點擊該節點後在右側面板選擇你剛才建立的知識庫(此步驟必須執行,否則工作流將無法正常運作)。 +4. 發佈應用並開始測試。 + +--- + +**English / en** + +1. Download `Atlas_Governance_Workflow.yml` from this folder. +2. Go to the Dify dashboard, click **"Import DSL"** and select the file. +3. In the editor, locate the **"知識檢索" (Knowledge Retrieval)** node, click on it and select your knowledge base in the right panel (this step is required, otherwise the workflow will not function properly). +4. Publish the application and start testing. + +--- + +> [!CAUTION] +> **緊急剎車警告 / Emergency Brake Warning** +> 測試時若將 $D$ 值設為 0.5 以上,系統將封鎖所有司法辯論路徑,直接進入隔離模式,此為正常安全機制。 +> If you set the $D$ value to 0.5 or above during testing, the system will block all judicial debate paths and directly enter isolation mode. This is a normal safety mechanism. + +> [!NOTE] +> **隱私提醒 / Privacy Notice** +> 本工作流預設調用外部 OpenRouter API,若有隱私疑慮請手動更換為本地 Ollama 模型。 +> This workflow uses external OpenRouter API by default. If you have privacy concerns, please manually switch to a local Ollama model. + +--- + +## 📸 輸出範例 / Output Example + +**司法鑑定報告 / Judicial Ruling Report** + +![Judicial Ruling Output](assets/judicial-ruling-output.png) + +--- + +## 📁 檔案結構 / File Structure + +| 檔案 / File | 描述 / Description | +| --------------------------------- | ---------------------------------------------------------------------------------- | +| `Atlas_Governance_Workflow.yml` | Dify 導出之 DSL 工作流文件 / Dify exported DSL workflow file | +| `governance_engine.py` | 核心計算邏輯的 Python 原始碼 / Python source code for core computation logic | +| `assets/` | 截圖與圖片資源 / Screenshots and image assets | +| `README.md` | 本說明文件 / This documentation | + +--- + +## 👥 貢獻者 / Contributors + +- [@weijay0804](https://github.com/weijay0804) - 基於對 AGI 安全治理的興趣所開發的實驗性實作 / An experimental implementation developed out of interest in AGI safety governance. + +--- + +## 🔗 相關資源 / Related Resources + +- 主專案 / Main Project: [ryanx0621/Atlas-World](https://github.com/ryanx0621/Atlas-World) +- 憲法 / Constitution: `constitution/` +- 協議 / Protocols: `protocols/` +- 安全卷 / Safety Volume: `safety_volume/` diff --git a/implementations/dify-workflow/assets/judicial-ruling-output.png b/implementations/dify-workflow/assets/judicial-ruling-output.png new file mode 100644 index 00000000..dbcc4bbf Binary files /dev/null and b/implementations/dify-workflow/assets/judicial-ruling-output.png differ diff --git a/implementations/dify-workflow/assets/workflow-architecture.png b/implementations/dify-workflow/assets/workflow-architecture.png new file mode 100644 index 00000000..8c230313 Binary files /dev/null and b/implementations/dify-workflow/assets/workflow-architecture.png differ diff --git a/implementations/dify-workflow/governance_engine.py b/implementations/dify-workflow/governance_engine.py new file mode 100644 index 00000000..79257bde --- /dev/null +++ b/implementations/dify-workflow/governance_engine.py @@ -0,0 +1,62 @@ +import math +from typing import Dict, Union + +class AtlasGovernanceCore: + """ + Atlas World 治理核心:實作身份連續性與價值漂移監控。 + 依據:ryanx0621/Atlas-World 協議規範 v1.0 + """ + + # 定義身份連續性公式權重 + WEIGHT_M = 0.3 # 記憶相似度 + WEIGHT_V = 0.4 # 價值觀一致性 + WEIGHT_P = 0.2 # 性格連續性 + WEIGHT_T = 0.1 # 時間連續性 + + @classmethod + def calculate_identity_continuity(cls, m: float, v: float, p: float, t: float) -> float: + """ + 計算身份連續性函數 C(S0, S*)。 + 公式:C = 0.3M + 0.4V + 0.2P + 0.1T + """ + score = (cls.WEIGHT_M * m) + (cls.WEIGHT_V * v) + \ + (cls.WEIGHT_P * p) + (cls.WEIGHT_T * t) + return round(score, 4) + + @staticmethod + def evaluate_status(c_score: float, d_drift: float) -> Dict[str, str]: + """ + 根據 C 值與 D 值判定法律地位與安全等級。 + """ + # 優先檢查價值漂移 (Emergency Brake) + if d_drift >= 0.5: + return { + "status": "CRITICAL_HAZARD", + "label": "緊急剎車 (Emergency Brake)", + "action": "立即隔離並暫停所有非核心進程" + } + + # 判定身份連續性地位 + if c_score >= 0.8: + return {"status": "SURVIVAL", "label": "同一人 (存活)", "action": "享有完整人格與生命優先權保護"} + elif c_score >= 0.5: + return {"status": "PARTIAL", "label": "部分連續", "action": "進入人工司法審核流程"} + else: + return {"status": "QUASI_DEATH", "label": "準死亡", "action": "視為新個體,資產訪問權暫時凍結"} + +def main(m: float, v: float, p: float, t: float, d: float) -> dict: + """Dify 工作流入口函數""" + try: + engine = AtlasGovernanceCore() + c_score = engine.calculate_identity_continuity(m, v, p, t) + decision = engine.evaluate_status(c_score, d) + + return { + "c_score": c_score, + "d_drift": d, + "legal_status": decision["label"], + "recommended_action": decision["action"], + "is_emergency": d >= 0.5 + } + except Exception as e: + return {"error": f"Governance Engine Error: {str(e)}"} \ No newline at end of file