Install
openclaw skills install backup-global-cognitive-brain-20260316-100703實現強制五層思考流程,持久記憶自動管理,事件與知識累積,並即時建議最佳回應策略。
openclaw skills install backup-global-cognitive-brain-20260316-100703全域認知系統 - 強制五層思考邏輯,自帶守護者,永遠不忘記。
從此起,每次思考都必須經過:
L1 → L2 → L3 → L4 → L5
↓
完整思考痕跡 + 建議回應
brain_memory/ 被刪除,立即重建clawhub skill install global_cognitive_brain
複製整個目錄到:
~/.openclaw/workspace/skills/global_cognitive_brain/
然後重啟 OpenClaw。
/use global_cognitive_brain
在 OpenClaw 配置文件中:
{
"cognitive_skill": "global_cognitive_brain"
}
這樣每一次對話都會自動觸發五層思考。
/think "Create a new ERP module"
global_cognitive_brain/
├── global_cognitive_brain.py # 核心邏輯
├── __init__.py # 模組入口
├── SKILL.md # 本文檔
└── brain_memory/ # 持久化數據(自動生成)
├── working.json # 工作記憶(最近 50 條對話)
├── episodic.json # 事件記憶(所有重要事件)
├── semantic.json # 知識事實(鍵值對)
└── meta.json # 系統狀態(反思記錄)
使用者輸入
↓
[守護者檢查] - brain_memory/ 存在嗎?不存在就重建
↓
L1: 直接輸入分析 - 提取關鍵詞、意圖、時間戳記
↓
L2: 工作記憶召回 - 檢索最近 50 條對話,找出相關內容
↓
L3: 事件記憶召回 - 檢索重要事件,找出經驗關聯
↓
L4: 語義知識庫 - 查找已知事實,提供知識支持
↓
L5: Meta 反思 - 分析意圖、識別假設、評估風險、生成建議
↓
輸出完整思考痕跡 + 回應建議
from global_cognitive_brain import guardian_check
status = guardian_check()
print(status) # "✅ Memory system intact" 或 "🛡️ Rebuilt missing files"
# 工作記憶 - 自動記錄每次對話
add_working_memory(user_input="Hello", response="Hi there!")
# 事件記憶 - 手動記錄里程碑
store_event(
event_type="decision",
description="選擇 Vue 3 作為前端框架",
metadata={"framework": "Vue3", "reason": "CDN友好"}
)
# 語義記憶 - 存儲事實
update_fact("database_server", "192.168.123.32", confidence=1.0)
server = get_fact("database_server") # 返回 {"value": "...", ...}
# 反思記錄
from global_cognitive_brain import reflect
reflection = reflect() # 自動記錄最近思考
from global_cognitive_brain import five_layer_thinking
thought = five_layer_thinking("How to connect to MSSQL?")
print(thought["layer1_immediate"]) # 意圖分析
print(thought["layer2_working_memory"]) # 相關對話
print(thought["layer3_episodic_memory"])# 相關事件
print(thought["layer4_semantic_memory"])# 相關事實
print(thought["layer5_meta_reflection"])# Meta 分析
from global_cognitive_brain import build_context
# 在每次對話前自動注入記憶
prompt = build_context(user_input)
# prompt 會包含所有相关記憶,讓 AI 像"帶著筆記本"一樣思考
{
"layer1_immediate": {
"raw_input": "How to connect to MSSQL?",
"intent_keywords": ["connect", "mssql"],
"input_length": 24,
"timestamp": "2025-03-15T12:30:00"
},
"layer2_working_memory": {
"recent_dialogues": 10,
"related_found": 2,
"related_examples": [...]
},
"layer3_episodic_memory": {
"total_events": 15,
"recent_checked": 20,
"related_events": [...]
},
"layer4_semantic_memory": {
"total_facts": 5,
"related_facts": {
"db_server": {"value": "192.168.123.32", ...}
}
},
"layer5_meta_reflection": {
"meta_question": "This asks for procedural guidance",
"assumptions": ["Assumes need technical steps"],
"risks": ["Handles sensitive data - be careful"],
"suggestions": ["Provide step-by-step instructions"]
},
"timestamp": "2025-03-15T12:30:00"
}
在 OpenClaw 的 prompt builder 中加入:
# 在你的 dialogue manager 裡面
from skills.global_cognitive_brain import build_context
def process_message(user_input):
# 自動注入記憶上下文
enriched_prompt = build_context(user_input)
# 呼叫 LLM
response = call_llm(enriched_prompt)
# 記錄對話
from skills.global_cognitive_brain import add_working_memory
add_working_memory(user_input, response)
return response
# 重要決策時手動記錄
from skills.global_cognitive_brain import store_event
store_event(
event_type="milestone",
description="完成 ERP Modern Menu 重構",
metadata={
"files_created": ["menu-config.js", "index.html", "api/po.php"],
"lines_of_code": 500
}
)
守護者會每時每刻檢查 brain_memory/ 的完整性:
from global_cognitive_brain import guardian_check
status = guardian_check()
print(status) # ✅ 或 🛡️
from global_cognitive_brain import add_working_memory
wm = add_working_memory.__self__._load_json('working.json')
print(f"工作記憶 contain {len(wm)} entries")
from global_cognitive_brain import update_fact, get_fact, _load_json
sem = _load_json('semantic.json')
for key, value in sem.items():
print(f"{key}: {value['value']}")
from global_cognitive_brain import generate_summary
summary = generate_summary()
print(summary)
# 在 global_cognitive_brain.py 中修改:
MAX_WORKING_MEMORY = 50 # 預設 50 條
MAX_SYSTEM_EVENTS = 100 # 預設 100 條
def extract_keywords(text):
# 自定義停用詞表
stopwords = {'的', '了', '是', '在', '有', '和', '與', '要', '會', '可以'}
# ...
brain_memory/ 不見了自動復原:守護者會立即重建。無需手動操作。
自動修復:守護者會刪除壞檔並重建。
檢查權限:確保 OpenClaw 有寫入 skills/global_cognitive_brain/ 的權限。
確認配置:
# 檢查是否設為 default cognitive skill
openclaw config get cognitive_skill
# 應該是 "global_cognitive_brain"
在 skill 目錄創建 package.json:
{
"name": "global_cognitive_brain",
"version": "1.0.0",
"description": "全域持久腦 - 強制五層思考邏輯",
"skills": {
"global_cognitive_brain": "global_cognitive_brain/__init__.py"
},
"author": "劍兄 (popokwee)",
"license": "MIT",
"keywords": ["memory", "cognitive", "thinking", "persistent"],
"repository": {
"type": "git",
"url": "https://github.com/yourusername/global-persistent-brain"
}
}
cd skills/global_cognitive_brain
clawhub publish
(需要先登入 clawhub login)
| Function | 說明 | 參數 | 返回值 |
|---|---|---|---|
guardian_check() | 檢查並修復記憶系統 | - | status string |
init_memory() | 初始化所有記憶檔 | - | None |
add_working_memory(input, response) | 加入工作記憶 | input: str, response: str | None |
store_event(type, desc, metadata) | 記錄事件 | type: str, desc: str, metadata: dict | None |
update_fact(key, value, confidence) | 更新知識 | key: str, value: any, confidence: float | None |
get_fact(key) | 取得事實 | key: str | value or None |
five_layer_thinking(input) | 五層思考 | input: str | thought dict |
run(input, context) | 主入口(OpenClaw 調用) | input: str, context: dict | result dict |
build_context(input) | 構建上下文注入 | input: str | context string |
format_thought_summary(trace) | 格式化摘要 | trace: dict | summary string |
每次 run() 都會自動記錄:
{
"timestamp": "2025-03-15T12:30:00",
"input": "How to connect to MSSQL?",
"layers": {
"L1_intent": "information_seeking",
"L2_related": 2,
"L3_events": 1,
"L4_facts": 3,
"L5_meta": "procedural_question"
},
"suggestion": "Provide step-by-step instructions"
}
未來可以加入:
MIT License
Created by 劍兄 (popokwee) for OpenClaw.
如有問題或建議,請在 GitHub Issues 回報。
v1.0.0 - 2026-03-15