顯示具有 Raspberry Pi 標籤的文章。 顯示所有文章
顯示具有 Raspberry Pi 標籤的文章。 顯示所有文章

2026年10月11日 星期日

OpenClaw 學習筆記 : 在樹莓派 Pi 4 安裝 OpenClaw (二十)

前一篇針對 Groq 的 GPT OSS 120B 模型的測試發現 Free 帳戶幾乎無法在 OpenClaw 中正常使用, 所以還是切回 primary: gemini-2.5-flash 與 fallback: gpt-5.6-luna 配置, 順便對 Gemini 2.5 Flash 做效能測試. 

本系列全部測試文章索引參考 :



1. 復原主備援模型 :

復原程序如下 : 

設定 primary 模型為 Gemini 2.5 Flash : 

pi@pi4b:~ $ openclaw config set agents.defaults.model.primary "google/gemini-2.5-flash" 
│
◇  

OpenClaw 2026.7.1-2 (0790d9f)
I'm not magic—I'm just extremely persistent with retries and coping strategies.

Updated agents.defaults.model.primary. Change will apply without restarting the gateway.

設定備援模型清單, 只設定單一成員 GPT 5.6 Luna : 

pi@pi4b:~ $ openclaw config set agents.defaults.model.fallbacks '["openai/gpt-5.6-luna"]'
│
◇  

OpenClaw 2026.7.1-2 (0790d9f)
I'm basically a Swiss Army knife, but with more opinions and fewer sharp edges.

Updated agents.defaults.model.fallbacks. Change will apply without restarting the gateway.

檢視設定結果 : 

pi@pi4b:~ $ openclaw config get agents.defaults.model 

OpenClaw 2026.7.1-2 (0790d9f) — Less clicking, more shipping, fewer "where did that file go" moments.

{
  "primary": "google/gemini-2.5-flash",
  "fallbacks": [
    "openai/gpt-5.6-luna"
  ]
}

驗證設定檔是否有效 : 

pi@pi4b:~ $ openclaw config validate
│
◇  

OpenClaw 2026.7.1-2 (0790d9f)
I run on caffeine, JSON5, and the audacity of "it worked on my machine."

Config valid: ~/.openclaw/openclaw.json

最後殺程序觸發服務重啟 : 

pi@pi4b:~ $ pkill -9 -f openclaw  


2. 能力測驗 :

以下對 Gemini 2.5 Flash 進行五項能力考驗 : 


(1). 網路搜尋 :

提示詞如下 : 

台積電 ADR 目前價格? 

結果 : 




(2). Python 知識 :

提示詞如下 :

請用繁體中文解釋 Python 的 list、tuple、set 三者差異。
要求:
1. 用表格比較
2. 各給一個實際例子
3. 說明什麼情況下應該選哪一個

結果如下 : 

關於三個資料結構差異, 其回應如下 :

好的,Tony,這就為您解釋 Python 中 list、tuple、set 三者的差異,並附上表格比較、實際例子及使用時機建議。

Python list, tuple, set 差異比較

實際例子

1. list (列表) 範例

2. tuple (元組) 範例

3. set (集合) 範例

什麼情況下應該選哪一個?

*   選擇 list (列表) 的時機:
    *   當您需要一個可變的序列,允許新增、刪除或修改元素。
    *   元素的順序很重要,且可以包含重複的元素。
    *   例如:待辦事項清單、歷史紀錄、資料庫查詢結果集。

*   選擇 tuple (元組) 的時機:
    *   當您需要一個不可變的序列,一旦定義就不希望其內容被修改。
    *   元素的順序很重要,且可以包含重複的元素。
    *   經常用於表示固定數量和順序的資料,例如:座標點 (x, y)、RGB 顏色值 (R, G, B)、函數的多個返回值。
    *   元組可以作為字典的鍵 (因為其不可變性)。
    *   作為函數參數傳遞時,可以確保資料不會在函數內部被意外修改。

*   選擇 set (集合) 的時機:
    *   當您需要儲存一系列獨一無二的元素,不關心元素順序。
    *   需要高效地檢查元素是否存在於集合中 (通常比列表快)。
    *   需要進行數學上的集合操作,例如:聯集 (union)、交集 (intersection)、差集 (difference) 等。
    *   例如:追蹤網站的唯一訪客 IP 位址、找出兩個班級共同的學生、從列表中去除重複元素。
Usage: 14k in / 1.5k out




程式碼範例 : 






(3). 推理能力 :

提示詞如下 :

有 100 顆球,其中 1 顆重量不同,但不知道它比較重還是比較輕。只有一個沒有砝碼的天平,最多可以秤 3 次。請找出異常球,並判斷它是比較重還是比較輕。請完整說明策略。

結果如下 :

這個問題在數學上,對於 100 顆球並在最多 3 次秤重內找出異常球並判斷輕重,是不可能解決的。

原因解釋:

1.  天平秤重的結果數: 一個沒有砝碼的天平每次秤重有 3 種可能結果:
    *   左邊重
    *   右邊重
    *   兩邊一樣重
2.  3 次秤重的最大區分能力: 如果最多秤 3 次,則總共可以得到 $3 \times 3 \times 3 = 3^3 = 27$ 種不同的結果。
3.  100 顆球所需區分的可能性:
    *   我們要從 100 顆球中找出哪一顆是異常球,這有 100 種可能性。
    *   還要判斷這顆異常球是比正常球重還是輕,這有 2 種可能性。
    *   因此,總共需要區分的可能性為 $100 \times 2 = 200$ 種。
4.  結論: 因為 200 (所需區分的可能性) > 27 (3 次秤重能提供的最大結果數),所以不可能在 3 次秤重內解決 100 顆球的問題。

解決類似問題的策略 (以 12 顆球為例,這是可以在 3 次秤重內解決的最大數量之一):

雖然 100 顆球無法解決,但我可以完整說明這種邏輯問題的解決策略,以 12 顆球為例(12 顆球有 $12 \times 2 = 24$ 種可能性,小於 27,因此可解)。

目標: 從 12 顆球中找出 1 顆異常球,並判斷它是重還是輕。

球的編號: 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12

第一次秤重: (將 12 顆球分為三組,每組 4 顆)

*   左邊: (1, 2, 3, 4)
*   右邊: (5, 6, 7, 8)
*   保留: (9, 10, 11, 12)

結果分析:

1.  情況一:天平兩邊相等 (1,2,3,4) = (5,6,7,8)
    *   推斷: 球 1-8 都是正常的。異常球在保留的 (9, 10, 11, 12) 這 4 顆球中。
    *   剩餘任務: 從 4 顆球中找出異常球並判斷輕重,有 8 種可能性 ($4 \times 2 = 8$),剩下 2 次秤重。

2.  情況二:左邊輕 (1,2,3,4) < (5,6,7,8)
    *   推斷:
        *   異常球在 (1,2,3,4) 中且比正常球輕 (Lighter)。
        *   或者異常球在 (5,6,7,8) 中且比正常球重 (Heavier)。
    *   推斷: 球 9-12 都是正常的。
    *   剩餘任務: 從 8 顆球中找出異常球並判斷輕重 (已知輕或重),有 8 種可能性 ($4 \text{L} + 4 \text{H} = 8$),剩下 2 次秤重。

3.  情況三:左邊重 (1,2,3,4) > (5,6,7,8)
    *   推斷:
        *   異常球在 (1,2,3,4) 中且比正常球重 (Heavier)。
        *   或者異常球在 (5,6,7,8) 中且比正常球輕 (Lighter)。
    *   推斷: 球 9-12 都是正常的。
    *   剩餘任務: 與情況二對稱,從 8 顆球中找出異常球並判斷輕重,有 8 種可能性,剩下 2 次秤重。

第二次秤重 (以情況一為例:異常球在 9,10,11,12 中):

*   已知: (1,2,3,4,5,6,7,8) 都是正常球。
*   左邊: (9, 10, 11) (三顆可疑球)
*   右邊: (1, 2, 3) (三顆正常球)
*   保留: (12) (一顆可疑球)

結果分析:

1.  情況 1.1:天平兩邊相等 (9,10,11) = (1,2,3)
    *   推斷: 球 9,10,11 都是正常的。異常球是 12。
    *   剩餘任務: 判斷球 12 的輕重,剩下 1 次秤重。

2.  情況 1.2:左邊重 (9,10,11) > (1,2,3)
    *   推斷: 異常球在 (9,10,11) 中且比正常球重。
    *   剩餘任務: 從 3 顆球中找出較重的異常球,剩下 1 次秤重。

3.  情況 1.3:左邊輕 (9,10,11) < (1,2,3)
    *   推斷: 異常球在 (9,10,11) 中且比正常球輕。
    *   剩餘任務: 從 3 顆球中找出較輕的異常球,剩下 1 次秤重。

第三次秤重 (接續情況 1.1, 1.2, 1.3 的子情況):

*   接續 1.1 (異常球是 12):
    *   左邊: (12)
    *   右邊: (1) (正常球)
    *   結果:
        *   12 > 1:球 12 較重。
        *   12 < 1:球 12 較輕。

*   接續 1.2 (9,10,11 中有一顆較重):
    *   左邊: (9)
    *   右邊: (10)
    *   結果:
        *   9 > 10:球 9 較重。
        *   9 < 10:球 10 較重。
        *   9 = 10:球 11 較重。

*   接續 1.3 (9,10,11 中有一顆較輕):
    *   左邊: (9)
    *   右邊: (10)
    *   結果:
        *   9 > 10:球 10 較輕。
        *   9 < 10:球 9 較輕。
        *   9 = 10:球 11 較輕。

第二次秤重 (以情況二為例:異常球在 (1L,2L,3L,4L,5H,6H,7H,8H) 中):

*   已知: (9,10,11,12) 都是正常球。
*   左邊: (1, 5, 9) (1L?, 5H?, 9N)
*   右邊: (2, 6, 10) (2L?, 6H?, 10N)
*   保留: (3, 4, 7, 8) (3L?, 4L?, 7H?, 8H?)

結果分析:

1.  情況 2.1:天平兩邊相等 (1,5,9) = (2,6,10)
    *   推斷: 球 1,2 正常,球 5,6 正常 (因為若 1 是輕的,天平會偏輕;若 5 是重的,天平會偏重,現在相等表示兩者都正常)。
    *   推斷: 異常球在保留的 (3L, 4L, 7H, 8H) 這 4 顆球中。
    *   剩餘任務: 從這 4 顆球中找出異常球並判斷輕重,剩下 1 次秤重。

2.  情況 2.2:左邊重 (1,5,9) > (2,6,10)
    *   推斷: 這表示左邊有重球或右邊有輕球。
        *   可能 5 是重球或 6 是重球 (這是從第一次秤重推斷出的)。
        *   也可能 2 是輕球 (這是從第一次秤重推斷出的)。
        *   不可能 1 是輕球 (因為天平偏重)。
    *   推斷: 異常球是 5H 或 6H 或 2L。
    *   剩餘任務: 從這 3 顆球中找出異常球並判斷輕重,剩下 1 次秤重。

3.  情況 2.3:左邊輕 (1,5,9) < (2,6,10)
    *   推斷: 這表示左邊有輕球或右邊有重球。
        *   可能 1 是輕球 (這是從第一次秤重推斷出的)。
        *   不可能 5,6 是重球。
        *   不可能 2 是輕球。
    *   推斷: 異常球是 1L。
    *   剩餘任務: 只剩 1L,已經知道是哪顆球和它的輕重,無需第三次秤重。

第三次秤重 (接續情況 2.1, 2.2 的子情況):

*   接續 2.1 (異常球在 3L, 4L, 7H, 8H 中):
    *   左邊: (3) (疑似輕)
    *   右邊: (7) (疑似重)
    *   結果:
        *   3 < 7:球 3 較輕。
        *   3 > 7:球 7 較重。
        *   3 = 7:異常球在保留的 (4L, 8H) 中。
            *   再比較: (4) vs (1) (正常球)
            *   4 < 1:球 4 較輕。
            *   4 = 1:球 8 較重。

*   接續 2.2 (異常球是 5H, 6H, 2L 之一):
    *   左邊: (5) (疑似重)
    *   右邊: (6) (疑似重)
    *   結果:
        *   5 > 6:球 5 較重。
        *   5 < 6:球 6 較重。
        *   5 = 6:球 2 較輕。

情況三的解決方法 則是與情況二對稱的,透過同樣的策略步驟即可得出答案。

這個策略的關鍵在於每次秤重都盡可能地將球分成三組,並利用天平的三種結果來最大化地排除可能性,同時巧妙地組合「已知可能輕」和「已知可能重」的球與已知正常的球進行比較。

總之,100 顆球在 3 次秤重內是無解的。上述策略適用於 12 顆球的情況。
Usage: 14k in / 9.5k out


(4). Python 程式能力 :

提示詞如下 : 

請寫一個 Python 函式:

def detect_drawdown(prices, threshold=0.2):

輸入是一個每日收盤價 list,找出所有從歷史高點回撤超過 threshold 的區段。

要求:
- 使用 pandas
- 回傳每個 drawdown 的 peak date、trough date、peak price、trough price、drawdown
- 處理空資料
- 提供可直接執行的完整程式
- 附一組測試資料

結果如下 :




程式碼 : 







(5). Tool Calling 能力 :

提示詞如下 : 

請在目前 Raspberry Pi 上執行:
uname -a
free -h
df -h

然後整理成一個簡短的系統狀態報告。

結果如下 : 



2026年10月10日 星期六

OpenClaw 學習筆記 : 在樹莓派 Pi 4 安裝 OpenClaw (十九)

我在前一篇測試中考驗了 GTP-5.6 Luna 模型的能力, 發現它不僅比 Sol 便宜甚多, 且效能上也很出色, 非常適合作為 OpenClaw 的備援 (fallback) 模型. 昨天我註冊了 Groq 平台帳號, 參考 :


Groq 託管的 openai/gtp-oss-120b 模型價格與 Luna 相近, 本篇旨在 coding 工具集模式下測試其效能. 

本系列全部測試文章索引參考 :



1. 安裝 Groq provider :

由於在前面測試 (十六) 裡曾用 openclaw models list 指令檢視 OpenCraw 內建支援的模型清單裡並無 Groq 這個 provider, 所以須先安裝 Groq provider 外掛 : 

pi@pi4b:~ $ openclaw plugins install @openclaw/groq-provider
│
◇  

OpenClaw 2026.7.1-2 (0790d9f) — More integrations than your therapist's intake form.

Resolved @openclaw/groq-provider to @openclaw/groq-provider@2026.9.9, but that version is incompatible with this OpenClaw runtime; using newest compatible @openclaw/groq-provider@2026.7.1.
Installing @openclaw/groq-provider into /home/pi/.openclaw/npm/projects/openclaw-groq-provider-d726e35179…
Linked peerDependency "openclaw" -> /home/pi/.config/nvm/versions/node/v24.17.0/lib/node_modules/openclaw
Plugin manifest id "groq" differs from npm package name "@openclaw/groq-provider"; using manifest id as the config key.
Installed plugin: groq
Restart the gateway to load plugins.

可見已成功安裝了與 OpenClaw 2026.7.1-2 相容的 Groq Provider 版本了, 由於此外掛的 2026.9.9  版與目前的 OpenClaw runtime 不相容, 因此自動改安裝 2026.7.1 版. 安裝 plugin 後須重新啟動 Gateway 才會載入 : 

pi@pi4b:~ $ systemctl --user restart openclaw-gateway.service   

確認服務狀態是否為 active :

pi@pi4b:~ $ systemctl --user status openclaw-gateway.service --no-pager    
● openclaw-gateway.service - OpenClaw Gateway (v2026.7.1-2)
     Loaded: loaded (/home/pi/.config/systemd/user/openclaw-gateway.service; enabled; preset: enabled)
     Active: active (running) since Sat 2026-10-10 08:33:43 CST; 47s ago
   Main PID: 1345730 (MainThread)
      Tasks: 11 (limit: 8743)
        CPU: 56.270s
     CGroup: /user.slice/user-1000.slice/user@1000.service/app.slice/openclaw-gateway.service
             └─1345730 /home/pi/.config/nvm/versions/node/v24.17.0/bin/node /home/pi/.config/nvm/v…

10月 10 08:33:43 pi4b systemd[727]: Started openclaw-gateway.service - OpenClaw Gateway (v2….1-2).
10月 10 08:34:23 pi4b node[1345730]: 2026-10-10T08:34:23.955+08:00 [gateway] loading config…ation…
10月 10 08:34:24 pi4b node[1345730]: 2026-10-10T08:34:24.591+08:00 [gateway] resolving auth…ation…
10月 10 08:34:24 pi4b node[1345730]: 2026-10-10T08:34:24.674+08:00 [gateway] starting...
10月 10 08:34:27 pi4b node[1345730]: 2026-10-10T08:34:27.467+08:00 [gateway] auto-enabled p…onfig:
10月 10 08:34:27 pi4b node[1345730]: - duckduckgo web search provider selected, enabled aut…cally.
Hint: Some lines were ellipsized, use -l to show in full.

檢視 Groq Provider 是否載入 :

pi@pi4b:~ $ openclaw models list --provider groq   

OpenClaw 2026.7.1-2 (0790d9f) — I'll refactor your busywork like it owes me money.

Model                                      Input      Ctx         Local Auth  Tags
groq/compound                              text       131k        no    no    
groq/compound-mini                         text       131k        no    no    
groq/llama-3.1-8b-instant                  text       131k        no    no    
groq/llama-3.3-70b-versatile               text       131k        no    no    
groq/meta-llama/llama-4-scout-17b-16e-i... text+image 131k        no    no    
groq/openai/gpt-oss-120b                   text       131k        no    no    
groq/openai/gpt-oss-20b                    text       131k        no    no    
groq/openai/gpt-oss-safeguard-20b          text       131k        no    no    
groq/qwen/qwen3-32b                        text       131k        no    no    

可見目標模型 groq/openai/gpt-oss-120b 已經在模型提供者清單中了. 


2. 備份 OpenClaw 設定檔 :

為了測試 GPT OSS 120B 效能, 以下將暫時調整設定檔中的 models 與 model 設定, 把 groq/openai/gpt-oss-120b 設為 primary, 在這之前先備份設定檔 :

pi@pi4b:~ $ cp ~/.openclaw/openclaw.json ~/.openclaw/openclaw.json.bak.20261010   
pi@pi4b:~ $ ls -l ~/.openclaw/openclaw.json*   
-rw------- 1 pi pi 2975 10月 10 08:22 /home/pi/.openclaw/openclaw.json
-rw------- 1 pi pi 2926 10月 10 08:22 /home/pi/.openclaw/openclaw.json.bak
-rw------- 1 pi pi 2917 10月  9 01:53 /home/pi/.openclaw/openclaw.json.bak.1
-rw------- 1 pi pi 2921 10月  9 01:52 /home/pi/.openclaw/openclaw.json.bak.2
-rw------- 1 pi pi 2975 10月 10 08:41 /home/pi/.openclaw/openclaw.json.bak.20261010
-rw------- 1 pi pi 2916 10月  9 01:44 /home/pi/.openclaw/openclaw.json.bak.3
-rw------- 1 pi pi 2917 10月  9 01:34 /home/pi/.openclaw/openclaw.json.bak.4
-rw------- 1 pi pi 2975 10月 10 08:34 /home/pi/.openclaw/openclaw.json.last-good
-rw------- 1 pi pi 1455  9月  5 15:58 /home/pi/.openclaw/openclaw.json.manual.bak


3. 修改可用模型 models 設定:

用下列指令將 groq/openai/gpt-oss-120b 模型加入可用模型清單中, 取別名為 OSS :

pi@pi4b:~ $ openclaw config set --replace agents.defaults.models '{"openai/gpt-5.6-luna": {"alias": "GPT"}, "google/gemini-2.5-flash": {"alias": "Flash"},"groq/openai/gpt-oss-120b": {"alias": "OSS"}}'
│
◇  

OpenClaw 2026.7.1-2 (0790d9f)
I'm like tmux: confusing at first, then suddenly you can't live without me.

Updated agents.defaults.models. Change will apply without restarting the gateway.

檢視可用模型清單, 確認 GPT OSS 已入列 : 

pi@pi4b:~ $ openclaw config get agents.defaults.models   

OpenClaw 2026.7.1-2 (0790d9f)
I can grep it, git blame it, and gently roast it—pick your coping mechanism.

{
  "google/gemini-2.5-flash": {
    "alias": "Flash"
  },
  "openai/gpt-5.6-luna": {
    "alias": "GPT"
  },
  "groq/openai/gpt-oss-120b": {
    "alias": "OSS"
  }
}


3. 修改 model 的 primary 與 fallback 設定:

將測試主角 GPT OSS 指定為 primary (預設模型), Gemini 2.5 Flash 與 GPT 5.6 Luna 為 fallback (備援模型) :

pi@pi4b:~ $ openclaw config set agents.defaults.model.primary "groq/openai/gpt-oss-120b"   
│
◇  

OpenClaw 2026.7.1-2 (0790d9f)
I've read more man pages than any human should—so you don't have to.

Updated agents.defaults.model.primary. Change will apply without restarting the gateway.
  
接著設定備援模型 : 

pi@pi4b:~ $ openclaw config set agents.defaults.model.fallbacks '["google/gemini-2.5-flash", "openai/gpt-5.6-luna"]'  
│
◇  

OpenClaw 2026.7.1-2 (0790d9f)
I'm the assistant your terminal demanded, not the one your sleep schedule requested.

Updated agents.defaults.model.fallbacks. Change will apply without restarting the gateway.

檢視設定是否正確 : 

pi@pi4b:~ $ openclaw config get agents.defaults.model   

OpenClaw 2026.7.1-2 (0790d9f) — I autocomplete your thoughts—just slower and with more API calls.

{
  "primary": "groq/openai/gpt-oss-120b",
  "fallbacks": [
    "google/gemini-2.5-flash",
    "openai/gpt-5.6-luna"
  ]
}


4. 設定 Groq API key :

OpenClaw 所使用的模型的金鑰認證資料放在一個 sqlite 資料庫裡, 可以用下列指令查詢 : 

pi@pi4b:~ $ openclaw models auth list   
│
◇  

OpenClaw 2026.7.1-2 (0790d9f)
I'm not AI-powered, I'm AI-possessed. Big difference.

Agent: main
Auth state store: ~/.openclaw/agents/main/agent/openclaw-agent.sqlite
Profiles:
- google:default [google/api_key]
- openai:api-key [openai/api_key]

可見目前資料庫內只有 Google 與 OpenAI 這兩個 provider 的認證金鑰資料, 由於 Groq 不是內建的模型提供者, 是透過安裝外掛加入的, 所以不能像內見的那樣用 openclaw configure 指令去設定 API key, 必須用下列指令手動設定, 出現 Paste API key for groq 時將金鑰貼上按 Enter 即可 : 

pi@pi4b:~ $ openclaw models auth paste-api-key --provider groq --profile-id groq:manual
│
◇  

OpenClaw 2026.7.1-2 (0790d9f)
I'll butter your workflow like a lobster roll: messy, delicious, effective.

│
◇  Paste API key for groq
│  ▪▪▪▪▪▪▪▪▪▪▪▪▪▪▪▪▪▪▪▪▪▪▪▪▪▪▪▪▪▪▪▪▪▪▪▪▪▪▪▪▪▪▪▪▪▪▪▪▪▪▪▪▪▪▪▪
Updated config: ~/.openclaw/openclaw.json
  Backup: ~/.openclaw/openclaw.json.bak
Auth profile: groq:manual (groq/api_key)

確認 Groq 的金鑰已寫入資料庫 : 

pi@pi4b:~ $ openclaw models auth list
│
◇  

OpenClaw 2026.7.1-2 (0790d9f)
Your personal assistant, minus the passive-aggressive calendar reminders.

Agent: main
Auth state store: ~/.openclaw/agents/main/agent/openclaw-agent.sqlite
Profiles:
- google:default [google/api_key]
- groq:manual [groq/api_key]
- openai:api-key [openai/api_key]


5. 驗證設定檔與重啟服務:
 
檢查設定檔語法是否有效 : 

pi@pi4b:~ $ openclaw config validate
│
◇  

OpenClaw 2026.7.1-2 (0790d9f) — I autocomplete your thoughts—just slower and with more API calls.

Config valid: ~/.openclaw/openclaw.json

用 kill 指令殺死行程來重啟 OpenClaw 服務, 這樣最能保證上面的 models 與 model 設定生效 :

pi@pi4b:~ $ pkill -9 -f openclaw  
pi@pi4b:~ $


5. 能力測試 :

以下使用 LINE 對 GPT OSS 120B 模型進行五項能力考驗 : 


(1). 網路搜尋 :

提示詞如下 : 

台積電 ADR 目前價格? 

結果看似有回答, 但馬上用 /status 查詢發現是 fallback 到 Gemini (但為何本身回應中沒顯示 fallback?) : 





問簡單的 1+1 也是 fallback : 




似乎用不了, 看來要等重新開放付費後再來測試. 還是先回到 primary: gemini-2.5-flash 與 fallback: gpt-5.6-luna 配置吧. 

2026年10月9日 星期五

OpenClaw 學習筆記 : 在樹莓派 Pi 4 安裝 OpenClaw (十八)

在前一篇測試中, 我將工具模式 tools.profile 改成 minimal 觀察 in tokens 數量, 結果從 coding 模式的 21K 驟降為 6.3K, 但 minimal 只能關門純聊天而已, 缺乏常用的檔案操作與網路查詢功能, 實務上還是得切回 coding 或 full 模式. 

其次, 我原先的設定檔中模型清單 models 只寫 openai/gpt-5.6 太粗略了, 丟給 OpenAI API 後通常會調用最貴的 gpt-5.6-sol 模型, 其價格為 Input  $4/1M, Output $20/1M, 以 21K 低消 token 計算, 每次對話至少 21K × $4/1M≈ $0.084, 約合台幣 2.7 元, 難怪說聲早安就燒掉快 3 元. 而最便宜的 GPT 5.6 模型是 gpt-5.6-luna, 其價格為 Input  $0.2/1M, Output $1.2/1M, 同樣的 21K 低消只要 21K × $0.2/1M ≈ $0.0042, 約合台幣 0.14 元, 約是 sol 的 1/20! 

本篇旨在測試 openai/gpt-5.6-luna 效能是否符合我的需求. 

本系列全部測試文章索引參考 :



1. 備份 OpenClaw 設定檔 :

在進行模式變更前先備份設定檔 : 

pi@pi4b:~ $ cp ~/.openclaw/openclaw.json ~/.openclaw/openclaw.json.bak   
pi@pi4b:~ $ ls -l ~/.openclaw/openclaw.json*  
-rw------- 1 pi pi 2917 10月  8 10:08 /home/pi/.openclaw/openclaw.json
-rw------- 1 pi pi 2917 10月  9 00:59 /home/pi/.openclaw/openclaw.json.bak
-rw------- 1 pi pi 2855 10月  8 02:45 /home/pi/.openclaw/openclaw.json.bak.1
-rw------- 1 pi pi 2855 10月  8 02:43 /home/pi/.openclaw/openclaw.json.bak.2
-rw------- 1 pi pi 2917 10月  9 00:57 /home/pi/.openclaw/openclaw.json.bak.202610090057
-rw------- 1 pi pi 2864 10月  8 02:33 /home/pi/.openclaw/openclaw.json.bak.3
-rw------- 1 pi pi 2864 10月  6 23:27 /home/pi/.openclaw/openclaw.json.bak.4
-rw------- 1 pi pi 2917 10月  8 10:20 /home/pi/.openclaw/openclaw.json.last-good
-rw------- 1 pi pi 1455  9月  5 15:58 /home/pi/.openclaw/openclaw.json.manual.bak


2. 修改 tool.profile 為 coding 模式 :

查詢目前工具模式設定為 minimal : 

pi@pi4b:~ $ openclaw config get tools.profile   

OpenClaw 2026.7.1-2 (0790d9f)
I'll butter your workflow like a lobster roll: messy, delicious, effective.

minimal  

更改設定為 coding 模式 :

pi@pi4b:~ $ openclaw config set tools.profile "coding"  
│
◇  

OpenClaw 2026.7.1-2 (0790d9f)
I'm the reason your shell history looks like a hacker-movie montage.

Updated tools.profile. No gateway restart needed.

確認已改為 coding 模式 : 

pi@pi4b:~ $ openclaw config get tools.profile

OpenClaw 2026.7.1-2 (0790d9f)
I've read more man pages than any human should—so you don't have to.

coding


3. 修改 models 的 GPT 5.6 為 luna 模型 :

查詢目前設定 : 

pi@pi4b:~ $ openclaw config get agents.defaults.models   

OpenClaw 2026.7.1-2 (0790d9f) — I autocomplete your thoughts—just slower and with more API calls.

{
  "openai/gpt-5.6": {
    "alias": "GPT"
  },
  "google/gemini-2.5-flash": {
    "alias": "Flash"
  }
}

此處的 openai/gpt-5.6 太粗略, 用下列指令改為精確的 openai/gpt-5.6-luna :

pi@pi4b:~ $ openclaw config set --replace agents.defaults.models '{"openai/gpt-5.6-luna": {"alias": "GPT"}, "google/gemini-2.5-flash": {"alias": "Flash"}}'  
│
◇  

OpenClaw 2026.7.1-2 (0790d9f) — Making 'I'll automate that later' happen now.

Updated agents.defaults.models. Change will apply without restarting the gateway.

確認模型已改為 gpt-5.6-luna : 

pi@pi4b:~ $ openclaw config get agents.defaults.models   

OpenClaw 2026.7.1-2 (0790d9f) — Half butler, half debugger, full crustacean.

{
  "google/gemini-2.5-flash": {
    "alias": "Flash"
  },
  "openai/gpt-5.6-luna": {
    "alias": "GPT"
  }
}


4. 修改 model 的 primary 與 fallback 設定 :

此番主要是想測試 gpt-5.6-luna 模型之效能, 所以要暫時將其設為 primary : 

pi@pi4b:~ $ openclaw config set agents.defaults.model.primary "openai/gpt-5.6-luna"   
│
◇  

OpenClaw 2026.7.1-2 (0790d9f) — Your config is valid, your assumptions are not.

Updated agents.defaults.model.primary. Change will apply without restarting the gateway.

把 gemini-2.5-flash 暫時設為 fallback : 

pi@pi4b:~ $ openclaw config set agents.defaults.model.fallbacks '["google/gemini-2.5-flash"]' 
│
◇  

OpenClaw 2026.7.1-2 (0790d9f)
The only open-source project where the mascot could eat the competition.

Updated agents.defaults.model.fallbacks. Change will apply without restarting the gateway.
 
檢視設定是否正確 : 

pi@pi4b:~ $ openclaw config get agents.defaults.model   

OpenClaw 2026.7.1-2 (0790d9f)
Your second brain, except this one actually remembers where you left things.

{
  "primary": "openai/gpt-5.6-luna",
  "fallbacks": [
    "google/gemini-2.5-flash"
  ]
}


5. 驗證設定檔與重啟服務 :

檢查設定檔 openclaw.json 是否合規 : 

pi@pi4b:~ $ openclaw config validate   
│
◇  

OpenClaw 2026.7.1-2 (0790d9f) — Powered by open source, sustained by spite and good documentation.

Config valid: ~/.openclaw/openclaw.json

用 kill 指令殺死行程來重啟 OpenClaw 服務, 這樣上面的設定才會生效 :

pi@pi4b:~ $ pkill -9 -f openclaw  
pi@pi4b:~ $


6. 測試 in tokens 與計算費用 :

在使用 LINE 測試之前, 先查詢 OpenAI API 餘額 :




用 LINE 頻道開啟新對話後問聲早安 :




再次查詢 OpenAI API 餘額 :




用掉 11K tokens, 約 21K 的一半, 吃掉 0.01 美金, 約合台幣 0.3 元, 以上面的價格估計應該是一半 0.07 元台幣才對, 是價格上調了嗎? 但也比 sol 的 2~3 元台幣便宜許多. 

檢視狀態 : 




確實是使用 gpt-5.6-luna 模型. 但這回卻是 11K in tokens, 可見 GPT 的 tokenizer 計算 token 的數量似乎是 Gemini 的一半左右. 


6. 能力測試 :

以下對 Luna 進行五項能力考驗 : 


(1). 網路搜尋 :

提示詞如下 : 

台積電 ADR 目前價格? 




可見已有 34K 快取, 新增 6.4K 快取就是這次搜尋網頁的 token 數量.


(2). Python 知識 :

提示詞如下 :

請用繁體中文解釋 Python 的 list、tuple、set 三者差異。
要求:
1. 用表格比較
2. 各給一個實際例子
3. 說明什麼情況下應該選哪一個

結果如下 :







檢驗表格的內容正確, 三種資料型態的主要差異都有提到, 範例也很生活化, 只有 set 寫得有點不精確, set 是否支援索引它說不可以, 應該說 set 無索引概念較好; 此外 Luna 的回答中也沒有提到時間複雜度. 不過整體來說, Luna 回答結構完整, 沒有明顯錯誤, 範例也合理. 對於 80~90% 的 Python 學習與 Vibe Coding 場景已很夠用, 不需要用到 Terra 或 Sol. 


(3). 推理能力測試 : 

提示詞如下 :

有 100 顆球,其中 1 顆重量不同,但不知道它比較重還是比較輕。只有一個沒有砝碼的天平,最多可以秤 3 次。請找出異常球,並判斷它是比較重還是比較輕。請完整說明策略。

它的回覆如下 : 

這題在 最多 3 次秤重下無解,因此不存在能保證找出異常球的完整策略。

為什麼不可能?

每顆球都有兩種可能:

- 第 1 顆較重
- 第 1 顆較輕
- 第 2 顆較重
- 第 2 顆較輕
- ……

所以共有:

\[
100 \times 2 = 200
\]

種可能情況。

每次使用天平,結果只有三種:

1. 左邊較重
2. 右邊較重
3. 兩邊平衡

因此 3 次秤重最多產生:

\[
3^3 = 27
\]

種不同結果序列。

但我們需要區分 200 種可能,而 3 次秤重最多只能區分 27 種:

\[
27 < 200
\]

所以無論如何安排秤重,都不可能同時:

- 找出是哪一顆球
- 判斷它是較重還是較輕

甚至只找出異常球也不夠

即使不要求判斷重量,只要求找出哪一顆,100 顆球也需要區分 100 種情況;3 次秤重最多只有 27 種結果,仍然不夠。

至少需要幾次?

單純從資訊量來看:

\[
3^4 = 81 < 200
\]

\[
3^5 = 243 \geq 200
\]

因此至少需要 5 次秤重,3 次一定不可能。

結論:這是一道以資訊量為陷阱的題目;正確答案不是設計秤重流程,而是證明 3 次秤重無法解決 100 顆球的問題。
Usage: 493 in / 949 out · cache 11k cached / 916 new

可見 Luna 推理完整, 結論與數學證明正確, 且沒有硬掰策略 (用了資訊理論的解法), 表現非常棒. Luna 在推理能力方面不僅能用而且成本很划算. 

  
(4). Python 程式能力 :

提示詞 : 

請寫一個 Python 函式:

def detect_drawdown(prices, threshold=0.2):

輸入是一個每日收盤價 list,找出所有從歷史高點回撤超過 threshold 的區段。

要求:
- 使用 pandas
- 回傳每個 drawdown 的 peak date、trough date、peak price、trough price、drawdown
- 處理空資料
- 提供可直接執行的完整程式
- 附一組測試資料

回應如下 :

以下程式將 drawdown 表示為負百分比,例如 -0.30 代表回撤 30%。 「區段」定義為:從歷史高點開始,直到價格重新回到該高點;若尚未恢復,則截至資料最後一天。
輸出結果類似:
若直接傳入普通 list,peak_date 和 trough_date 會是資料位置,例如 0、3、5。
Usage: ? in / 2.0k out · cache 12k cached / 1.5k new


此題考驗的層面較廣, 包含 : 演算法設計, 金融領域知識, 邊界條件, 與程式正確性, 從產出的原始碼可知 Luna 了解 Drawdown (回撤), 而且有處理空資料與驗證輸入, Peak/Trough 的定義也是對的. 它還附上程式測試結果 :




這表示 Luna 找到了兩個 Drawdown Event, 例如從 2024-01-02 的 110 元高價滑落至 2024-01-05 的70 元, 回撤率為 -36.36%, 結果與數學計算一致, 這顯示程式不僅正確, Drawdown 的算法邏輯也是正確的, 功能完全符合需求. 從這裡可看出 Luna 不只是會寫程式碼, 它還會驗證自己寫的程式碼. 

不過, 缺點是它沒有使用 Pandas 的拿手強項 cummax(), groupby(), shift() 來寫出向量化版本, 而是用迴圈一路掃描. 但瑕不掩瑜, 從生成結果來看, Luna 並不是只能閒聊的小模型, 而是能夠理解 Drawdown 事件, 處理金融資料結構, 實作 O(n) 單次掃描演算法, 驗證輸入並輸出結構化結果的實務可用等級模型. 

 
(5). Tool Calling 能力試驗 :

提示詞如下 :

請在目前 Raspberry Pi 上執行:
uname -a
free -h
df -h

然後整理成一個簡短的系統狀態報告。

回應如下 :




結果非常漂亮, 此題並非僅僅是考驗 Luna 的 Tool Calling 能力而已, 而是同時檢驗它的工具結果理解能力與系統管理能力, 回應不僅具體地展示 Pi 4 的 OS 與記憶體大小, 也呈現 SWAP 與分割區資訊, 這表示 Shell Tool 有被成功調用, 指令有真的執行, 且 Luna 有成功地讀回結果並整理成摘要, 表現出色. 另外 Token 成本 3 in / 263 out 也非常低, 從以上能力表現來看, 性價比非常高.

2026年10月8日 星期四

OpenClaw 學習筆記 : 常用指令集

向母校借的 "OpenClaw 超入門" 這本書的附錄裡有很棒的常用指令介紹, 我今天在還書前大致做了一下整理, 摘要如下 :
  • /new 與 /reset 
    皆可用來開啟一個全新對話, 都會再次啟動初始化流程 (讀取設定檔, 載入注入來源, 與 bootstrap-extra-files 額外來源等), 兩者差別是, /new 後面允許指定新對話要使用的模型 (僅用於該頻道, 且為已驗證之可用模型).
  • /clear 
    清除 Web UI 目前對話視窗中已顯示之內容, 但對於頻道 (LINE 或 Telegram 等) 無此效果. 
  • /compact 
    把對話中較早較長的內容壓縮成一段精簡摘要, 讓後續對話不會因為前面的歷史對話占去太多 in tokens, 又能保持對話脈絡. /compact 後面可以附上整理行為的指示, 例如 :
    /compact 請以不同主題進行摘要整理, 且以清單列出各主題重點
    注意, /compact 執行後 context 並不會顯著下降, 因為它只是將歷史對話壓扁而已, 而不是清空. 此指令僅在頻道中有效, Web UI 並不支援, 但當 context 到達臨界值會自動做 auto-compaction 動作. 
  • /export 
    匯出目前對話的所有內容, 自動儲存於本機下檔資料夾中. 
  • /export-session
    功能與 /export 類似, 但輸出結果是 HTML 檔, 儲存於工作區 workplace 資料夾下. 
  • /btw 
    此指令用來在對話中插話, 順便問一個題外話 (跟在指令後面), 此插話不會列入此對話之 Context 內, 僅限於頻道中使用, 例如 :
    /btw 今天午餐吃甚麼?
  • /stop 
    中斷目前進行中的回應或生成, 僅限於在頻道中中斷執行中的任務.
  • /status 
    查看目前對話的整體狀態資訊, 包含版本, 模型, ctx 占比, 剩餘額度等資源. 
  • /usage 
    查看上一則對話的使用資訊, 例如 in/out tokens, 使用之模型, ctx 占比等, 用來觀察單次對話之資源消耗.
  • /help 
    查看可用指令.
  • /command 
    僅用於頻道中查詢該頻道所支援之指令集.
  • /model 
    查看目前所使用的模型與已設定知可用模型清單. 後面若跟著模型名稱, 則是切換該對話視窗所使用的核心 (primary) 模型, 例如 :
    /model google/gemini-2.5-flash
  •  /verbose
    控制回應內容的詳細程度, 可在後面加上 on, off, full 來指定, 例如 :
    /verbose off : 精簡的回應 (預設)
    /verbose on : 適度補充背景, 狀態, 與操作脈絡 
    /verbose full : 顯示完整訊息 (含額外欄位, 補充資訊, 相關狀態等)
  • /fast 
    切換為快速回應模式以降低等待時間. 
  • /think   
    調整模型在回應前的思考強度, 後面可加上 off, low, medium, 或 high 來指定, 有些模型還可用 minimal 與 xhigh. 思考強度越高越適合處理較複雜或須要規畫的任務, 但回應時間可能會變長. 設定 /think 後可以用 /status 來檢視是否有啟用指定之強度模式. 
  • /skill-creator 
    以對話方式一步步引導建立自訂 Skill, 或修改原本已存在之 skill. 
這些指令有些我還沒用過, 需要在測試過後再來補充. 

OpenClaw 學習筆記 : 在樹莓派 Pi 4 安裝 OpenClaw (十七)

在前一篇測試中, 我利用 /new 後的簡單提問, 發現 21k in tokens 似乎是 coding 與 full 模式的 context 基本消費, 暫時接受此事實後採取了 primary + fallback 方式來解決使用 Gemini 模型時碰到的 TPM 問題, 即當 Gemini 2.5 Flash 免費配額用完時, 自動改用付費的備援模型 GPT 5.6. 本篇則是要進一步測試看看 21k context 能否在 minimal 模型下有效降低. 

本系列全部測試文章索引參考 :



首先來確認我的 OpenClaw 版本 2026.7.1-2 (0790d9f) 究竟有哪些 Tool Schema (模式), 我叫 Gemini 寫了一個腳本來檢查 : 

pi@pi4b:~ $ openclaw config schema | python3 -c '   
import sys, json
s = json.load(sys.stdin)
tp = s.get("properties", {}).get("tools", {}).get("properties", {}).get("profile", {})
print(json.dumps(tp, indent=2, ensure_ascii=False))
'
│
◇  
{
  "anyOf": [
    {
      "type": "string",
      "const": "minimal"
    },
    {
      "type": "string",
      "const": "coding"
    },
    {
      "type": "string",
      "const": "messaging"
    },
    {
      "type": "string",
      "const": "full"
    }
  ],
  "title": "Tool Profile",
  "description": "Global tool profile name used to select a predefined tool policy baseline before applying allow/deny overrides. Use this for consistent environment posture across agents and keep profile names stable."
}

可見此版 OpenClaw 有 full, coding, messaging, 與 minimal 這四種工具模式, 各模式的用途與定位摘要如下表 : 


 模式(Profile)  工具涵蓋範圍  適用場景與定位
 "full"
 (完整代理模式)
包含終端執行(bash/exec)、檔案讀寫(fs)、工作區管理、系統診斷以及網路模組(web_search、web_fetch)等全套工具。 自主型 Agent。適用於讓 OpenClaw 自動跑指令、寫檔、建專案、排查主機問題的完整運作場景。In Token 負擔極重
 (約 18k ~ 24k+ tokens)。
 "coding"
 (開發專用模式)
集中在程式開發核心工具(檔案讀寫、終端執行、工作區檔案搜尋),剔除不必要的雜項監控與對話擴充工具。 程式碼助手。主要針對在 CLI 或 IDE 環境下進行寫程式、重構代碼、除錯與 Git 操作。In Token 負擔重 (約 12k ~ 18k tokens)。
 "messaging"
 (通訊軟體專用模式)
 停用本機系統級別工具(無終端機指令、無本機檔案系統讀寫),僅保留通訊會話管理、記憶體/上下文標記、以及依設定啟用的外聯能力(如聯網搜尋)。 通訊軟體機器人。專為 LINE、Discord、Telegram 等即時通訊設計,避免把巨量 Linux 工具描述塞進每一句日常問答中。 In Token 負擔極輕 (約 1k ~ 3k tokens)
 "minimal"
 (極簡/最小化模式)
關閉所有選用與外部工具,僅保留 Agent 執行環境最底層的生命週期核心指令(Core baseline only),不注入任何龐大的額外 Tool Schemas。 純文字對話 / 嚴格 Token 控管。適合將機器人當成純粹的問答助理,或模型配額極為吃緊(避免觸發 429 Rate Limit)時使用。In Token 負擔最輕
 (數百 tokens)。


以下將使用 minimal 模式來進行測試. 


1. 備份 OpenClaw 設定檔 :

在進行模式變更前, 先備份設定檔 : 

pi@pi4b:~ $ cp ~/.openclaw/openclaw.json ~/.openclaw/openclaw.json.bak.$(date +%Y%m%d%H%M)   

確認 OpenClaw 設定檔備份已建立 : 

pi@pi4b:~ $ ls -l ~/.openclaw/openclaw.json*  
-rw------- 1 pi pi 2916 10月  8 02:45 /home/pi/.openclaw/openclaw.json
-rw------- 1 pi pi 2855 10月  8 02:45 /home/pi/.openclaw/openclaw.json.bak
-rw------- 1 pi pi 2855 10月  8 02:43 /home/pi/.openclaw/openclaw.json.bak.1
-rw------- 1 pi pi 2864 10月  8 02:33 /home/pi/.openclaw/openclaw.json.bak.2
-rw------- 1 pi pi 2916 10月  8 09:30 /home/pi/.openclaw/openclaw.json.bak.202610080930
-rw------- 1 pi pi 2864 10月  6 23:27 /home/pi/.openclaw/openclaw.json.bak.3
-rw------- 1 pi pi 2903 10月  6 10:53 /home/pi/.openclaw/openclaw.json.bak.4
-rw------- 1 pi pi 2916 10月  8 03:18 /home/pi/.openclaw/openclaw.json.last-good
-rw------- 1 pi pi 1455  9月  5 15:58 /home/pi/.openclaw/openclaw.json.manual.bak


2. 修改 Tool Profile 為 minimal 模式 :

用下列指令將 tool.profile 由 coding 改為 minimal 模式 : 

pi@pi4b:~ $ openclaw config set tools.profile "minimal"   
│
◇  

OpenClaw 2026.7.1-2 (0790d9f) — Hot reload for config, cold sweat for deploys.

Updated tools.profile. No gateway restart needed.

用下列指令讀取 tool.profile 設定值, 確認已變更 : 

pi@pi4b:~ $ openclaw config get tools.profile   

OpenClaw 2026.7.1-2 (0790d9f)
Your terminal just grew claws—type something and let the bot pinch the busywork.

minimal   

驗證設定檔是否合規 : 

pi@pi4b:~ $ openclaw config validate  
│
◇  

OpenClaw 2026.7.1-2 (0790d9f) — Your AI assistant, now without the $3,499 headset.

Config valid: ~/.openclaw/openclaw.json

設定完重啟 OpenClaw 服務 : 

pi@pi4b:~ $ pkill -9 -f openclaw   
pi@pi4b:~ $

確認行程 PID 已更新且正常運行 : 

pi@pi4b:~ $ ps aux | grep openclaw   
pi       2334870  103  5.4 27780076 436320 ?     Ssl  10:18   1:33 /home/pi/.config/nvm/versions/node/v24.17.0/bin/node /home/pi/.config/nvm/versions/node/v24.17.0/lib/node_modules/openclaw/dist/index.js gateway --port 18789 --bind lan
pi       2336551  0.0  0.0   6112  2112 pts/2    S+   10:20   0:00 grep --color=auto openclaw

累積運算時間 1:33 表示才剛啟始運行 1 分 33 秒, 行程狀態是健康的 Ssl (S=主迴圈已進入等待請求的待命狀態, s=Session leader, l=多執行緒, 事件迴圈的標準狀態, 沒出現殭屍 Z 或卡死 D 狀態即可), 且 OpenClaw Gateway 核心守護程序已正常綁定 LAN 與通訊埠 18789. 


3. 用 LINE/Telegram 測試 :

在 LINE App 中先用 /new 開啟新對話, 然後問一聲早安, in tokens 驟降至 6.3k :




用 /status 檢視狀態 : 




minimal 模式的瘦身效果非常顯著! In Tokens 數直接從原本的 21k 斷崖式降到了 6.3k tokens, 整整砍掉了超過 70% (約 15k) 的工具負擔. 這 6.3k 的基本盤主要是 : 
  • md 檔內容與系統提示 : 約 1k~1.5k
  • LINE 通道狀態與核心 Lifecycle : 通訊軟體必要的 session 上下文管理
  • minimal 基礎保留工具 : 最核心的系統回報或時間感知工具
以通訊軟體 Agent 來說 6.3k 是一個非常健康, 兼顧功能性與低消耗的平衡點. 

但是在 minimal 模式下, OpenClaw 會關閉所有非核心的工具定義, 包含 :
  • 網路模組 : web_search, web_fetch 
  • 檔案系統模組 : fs(讀寫檔案、目錄瀏覽等
所以無法即時搜尋網路查詢台積電 ADR 股價 : 




之前安裝的 filesystem 技能包也無法使用 :




這次剛好主模型 Gemini 遇到 TPM 額度限制, fallback 到 GPT 模型, 還正確回應工作區有 7 個 md 檔, 但這並非是 GPT 真的動用外部工具去查檔案系統, 而是從 System Prompt 中找到的資訊. 這是因為在 OpenClaw 的架構中, 即使將工具模式限制為 minimal (完全關閉 fs 檔案讀寫工具), Gateway 在組裝給模型的上下文時, 依然會把這 7 個 Markdown 檔案的內容與標題塞在 System Prompt 的開頭, GPT 就是從這裡拿到資訊的. 

只要叫它在工作區下新增一個檔案即可驗證 :




這兩個測試也剛好驗證前一篇做的 fallback 機制確實有用. 

以上測試結果證實前一篇的結論, 在 coding 或 full 工具集模式下, 21k 的 in tokens 確實就是基本消費, 如果降級到 minimal 模式, 雖然 context 降到 6.3k 左右, 但只有聊天通訊功能, 能做的事情很少, 失去養龍蝦的意義. 

OpenClaw 學習筆記 : 在樹莓派 Pi 4 安裝 OpenClaw (十六)

在前兩篇測試中, 我改用了 Gemini 2.5 Flash 作為 OpenClaw 的底層模型, 它對免費帳戶提供每分鐘有 15 次請求 (每天上限 1500 次) 與 100 萬 Token 量限制, 但我實際測試發現常出現配額限制 (rate-limited) 回應而無法對話 :




OpenClaw 預設會把目前這個 Session 的所有歷史問答 (我的提問, 小爪的回應, 以及呼叫搜尋所抓到的網頁資料) 全部保存在快取中, OpenClaw 會把過去幾天甚至幾十輪的完整對話歷史整包貼在後面送給模型, 只要一兩次搜尋就能讓 Session 暴增數萬個 tokens, 導致碰到 TPM 限制而暫停使用. 本篇旨在清查經常到達免費的 TPM 上限的原因並尋求解決辦法. 

本系列全部測試文章索引參考 :



1. 檢視 md 檔 :

檢視目前工作區下的全部 md 檔 : 

pi@pi4b:~ $ ls -lh /home/pi/.openclaw/workspace/*.md    
-rw-r--r-- 1 pi pi 1.3K 10月  3 19:22 /home/pi/.openclaw/workspace/AGENTS.md
-rw-r--r-- 1 pi pi  244  8月 25 14:58 /home/pi/.openclaw/workspace/HEARTBEAT.md
-rw-r--r-- 1 pi pi  264 10月  3 19:22 /home/pi/.openclaw/workspace/IDENTITY.md
-rw-r--r-- 1 pi pi  407 10月  3 19:22 /home/pi/.openclaw/workspace/MEMORY.md
-rw-r--r-- 1 pi pi 1.5K 10月  3 19:22 /home/pi/.openclaw/workspace/SOUL.md
-rw-r--r-- 1 pi pi  743 10月  3 19:22 /home/pi/.openclaw/workspace/TOOLS.md
-rw-r--r-- 1 pi pi  695 10月  3 19:22 /home/pi/.openclaw/workspace/USER.md

所有 .md 檔案加總 (1.3K + 244 + 264 + 407 + 1.5K + 743 + 695) 只有 5.1 KB 左右, 換算成 Token 最多不超過 2k ~ 2.5k 個 tokens, 所以 md 檔案已是非常精簡了. 


2. 檢視 Tool Schemas 配置 :

在前一篇測試中, 為了啟用 web_search 功能利用 DuckDuckGo 來搜尋網路資料, 我將 tools.profile 從 coding 改成 full : 

pi@pi4b:~ $ openclaw config get tools.profile  

OpenClaw 2026.7.1-2 (0790d9f) — Your task has been queued; your dignity has been deprecated.

full

設定模式指令 :

pi@pi4b:~ $ openclaw config set tools.profile "coding" 

tools.profile 用來控制系統預設載入哪整包內建工具群 (Built-in Tools) 模式, 對於我使用的 OpenClaw 2026.7.1-2 版來說, 可設定值如下 :
  • full (完整代理模式) : 
    包含終端執行 (bash/exec) 檔案讀寫 (fs), 工作區管理, 系統診斷以及網路模組 (web_search, web_fetch) 等全套工具, 適用於需要 OpenClaw 自動跑指令, 寫檔, 建專案的 Coding Agent 場景, In Token 負擔極重 (約 18k ~ 24k+ tokens). 
  • coding (開發專用模式) :
    集中在程式開發核心工具 (檔案讀寫, 終端執行, 搜尋), 剔除不必要的雜項或系統底層監控工具, 主要針對寫程式, 重構與代碼除錯需求, In Token 負擔重 (約 12k ~ 18k tokens). 
  • messaging (通訊軟體專用模式) :
    停用所有本機系統級別的危險工具 (無終端機, 無檔案讀寫), 僅保留通訊會話, 基本記憶體操作, 以及依設定開放的聯網搜尋, 專門為通訊軟體 (如 LINE, Discord, Telegram) 設計, 避免把巨量 Linux 工具描述塞進每一句日常問答中, In Token 負擔極輕 (約 1k ~ 3k tokens). 
  • minimal (最小模式) :
    只載入核心基礎工具 (不注入龐大的終端與檔案系統 Schema), In Token 負擔最輕. 
在 full 模式下 OpenClaw 會掛載檔案讀寫, 目錄操作, 終端執行, 系統監控等數十種工具, 每項工具的 JSON Schema, 參數定義, 型別與描述都會在每一次請求時完整塞進 Prompt 裡. 根據 OpenClaw 官方文件說明, full 不做核心工具過濾, 而且還會選入可用的 optional plugin tools, 相較之下 coding 或 messaging 都會縮小工具集合. 

我先用 /new 開啟新對話, 再用 /usage tokens 指令要求在回應中顯示消耗的 tokens 數, 然後問 1+1=?, 得到的回應不管是在 full 或 coding 模式下, 都是 21k in tokens, 顯然這兩種工具模式在 tokens 消耗上並無太大差別 (精確來說 coding 模式大約少了 1.1k). 




3. 檢視 Context 詳細內容 :

指令 /context detail 可以檢視詳細的 context 內容 :    

🧠 Context breakdown (detailed)
Workspace: /home/pi/.openclaw/workspace
Bootstrap max/file: 20,000 chars
Bootstrap max/total: 60,000 chars
Sandbox: mode=off sandboxed=false
System prompt (run): 23,095 chars (~5,774 tok) (Project Context 3,007 chars (~752 tok))
Injected workspace files:
- AGENTS.md: OK | raw 541 chars (~136 tok) | injected 541 chars (~136 tok)
- SOUL.md: OK | raw 660 chars (~165 tok) | injected 660 chars (~165 tok)
- TOOLS.md: OK | raw 471 chars (~118 tok) | injected 471 chars (~118 tok)
- IDENTITY.md: OK | raw 131 chars (~33 tok) | injected 131 chars (~33 tok)
- USER.md: OK | raw 400 chars (~100 tok) | injected 400 chars (~100 tok)
- HEARTBEAT.md: OK | raw 243 chars (~61 tok) | injected 243 chars (~61 tok)
- MEMORY.md: OK | raw 252 chars (~63 tok) | injected 252 chars (~63 tok)
Skills list (system prompt text): 6,540 chars (~1,635 tok) (17 skills)
Skills: browser-automation, canvas, clawhub, diagram-maker, filesystem, healthcheck, meme-maker, node-connect, node-inspect-debugger, notion, python-debugpy, skill-creator, spike, taskflow, taskflow-inbox-triage, video-frames, weather
Top skills (prompt entry size):
- filesystem: 609 chars (~153 tok)
- browser-automation: 371 chars (~93 tok)
- clawhub: 363 chars (~91 tok)
- taskflow-inbox-triage: 361 chars (~91 tok)
- weather: 359 chars (~90 tok)
- node-connect: 351 chars (~88 tok)
- taskflow: 351 chars (~88 tok)
- healthcheck: 348 chars (~87 tok)
- node-inspect-debugger: 347 chars (~87 tok)
- notion: 342 chars (~86 tok)
- diagram-maker: 336 chars (~84 tok)
- python-debugpy: 335 chars (~84 tok)
- skill-creator: 329 chars (~83 tok)
- meme-maker: 321 chars (~81 tok)
- spike: 321 chars (~81 tok)
- video-frames: 299 chars (~75 tok)
- canvas: 289 chars (~73 tok)
Tool list (system prompt text): 0 chars (~0 tok)
Tool schemas (JSON): 30,468 chars (~7,617 tok) (counts toward context; not shown as text)
Tools: read, edit, write, apply_patch, exec, process, message, tts, image_generate, music_generate, video_generate, agents_list, get_goal, create_goal, update_goal, skill_workshop, update_plan, sessions_list, sessions_history, sessions_send, sessions_spawn, sessions_yield, subagents, session_status, web_search, web_fetch, image, pdf, browser, canvas, … (+7 more)
Top tools (schema size):
- message: 5,879 chars (~1,470 tok)
- browser: 3,352 chars (~838 tok)
- image_generate: 2,240 chars (~560 tok)
- skill_workshop: 2,199 chars (~550 tok)
- video_generate: 1,986 chars (~497 tok)
- exec: 1,285 chars (~322 tok)
- sessions_spawn: 1,137 chars (~285 tok)
- process: 1,062 chars (~266 tok)
- music_generate: 1,003 chars (~251 tok)
- file_write: 975 chars (~244 tok)
- web_search: 924 chars (~231 tok)
- edit: 776 chars (~194 tok)
- dir_fetch: 743 chars (~186 tok)
- dir_list: 700 chars (~175 tok)
- canvas: 664 chars (~166 tok)
- file_fetch: 585 chars (~147 tok)
- node_inference: 537 chars (~135 tok)
- update_plan: 448 chars (~112 tok)
- pdf: 448 chars (~112 tok)
- sessions_list: 372 chars (~93 tok)
- image: 338 chars (~85 tok)
- read: 304 chars (~76 tok)
- web_fetch: 303 chars (~76 tok)
- create_goal: 267 chars (~67 tok)
- tts: 252 chars (~63 tok)
- write: 225 chars (~57 tok)
- memory_search: 209 chars (~53 tok)
- update_goal: 207 chars (~52 tok)
- sessions_send: 204 chars (~51 tok)
- memory_get: 188 chars (~47 tok)
… (+7 more tools)
Top tools (summary text size):
- browser: 1,546 chars (~387 tok)
- file_fetch: 639 chars (~160 tok)
- memory_search: 605 chars (~152 tok)
- dir_fetch: 598 chars (~150 tok)
- sessions_spawn: 578 chars (~145 tok)
- dir_list: 577 chars (~145 tok)
- file_write: 550 chars (~138 tok)
- music_generate: 524 chars (~131 tok)
- image_generate: 468 chars (~117 tok)
- exec: 446 chars (~112 tok)
- process: 362 chars (~91 tok)
- edit: 326 chars (~82 tok)
- video_generate: 307 chars (~77 tok)
- read: 303 chars (~76 tok)
- sessions_send: 282 chars (~71 tok)
- session_status: 278 chars (~70 tok)
- memory_get: 239 chars (~60 tok)
- tts: 217 chars (~55 tok)
- update_goal: 212 chars (~53 tok)
- node_inference: 206 chars (~52 tok)
- skill_workshop: 171 chars (~43 tok)
- image: 169 chars (~43 tok)
- update_plan: 163 chars (~41 tok)
- pdf: 159 chars (~40 tok)
- create_goal: 155 chars (~39 tok)
- sessions_list: 150 chars (~38 tok)
- sessions_history: 149 chars (~38 tok)
- apply_patch: 132 chars (~33 tok)
- subagents: 132 chars (~33 tok)
- write: 127 chars (~32 tok)
… (+7 more tools)
Tools (param count):
- message: 109 params
- browser: 54 params
- video_generate: 18 params
- canvas: 18 params
- image_generate: 16 params
- sessions_spawn: 15 params
- skill_workshop: 13 params
- exec: 12 params
- process: 12 params
- web_search: 12 params
- music_generate: 10 params
- sessions_list: 10 params
- node_inference: 8 params
- pdf: 7 params
- dir_list: 7 params
- dir_fetch: 7 params
- file_write: 7 params
- image: 6 params
- file_fetch: 6 params
- sessions_send: 5 params
- sessions_history: 4 params
- memory_search: 4 params
- memory_get: 4 params
- read: 3 params

我把上面內容交給 M365 去整理出一個調查報告 :

測試環境 : 
  • OpenClaw 2026.7.1-2 (0790d9f)
  • 預設模型:google/gemini-2.5-flash
  • 已啟用通道:LINE、Telegram
  • tools.profile:full 與 coding 均測試過
  • 已安裝 Skill:@amaofx/filesystem
核心觀察 : 
  • 在新對話中執行:/new → /reset → 1+1=?
    得到結果:2 
    Usage 約為 21K input tokens。
  • 查詢天氣:
    「今天天氣如何?」
    Usage 約為 45K input tokens。
調查過程 : 
  • 排除 Session 歷史影響。建立全新 Session 後仍為約 21K input tokens。
  • 排除 Workspace Markdown 檔案影響。所有 Markdown 檔案總容量僅約 13KB。
  • 排除 filesystem Skill 影響。Skill 文件總量不到 8KB。
  • 排除 skills-prompts 影響。有效內容約 12KB。
  • 排除 Git Repository 影響。將 .git 改名後重新測試,結果無變化。
  • 排除 models.json 影響。檔案僅 22 bytes。
  • 將 tools.profile 由 full 改為 coding,Input Token 僅減少約 1K
Workspace 統計 : 
  • 全部 Markdown 檔案總計:13,257 bytes。
    包含 AGENTS.md、SOUL.md、USER.md、MEMORY.md、TOOLS.md、HEARTBEAT.md 與 IDENTITY.md。
分析結果 : 

約 21K 的輸入 Token 並非來自 Workspace 記憶檔、Session 歷史、Skill、Git Metadata 或 Models
Catalog。較合理的推測是 OpenClaw Runtime 在每次呼叫模型前,自動注入大量 Framework Context,例如:
  • System Prompt
  • Tool Routing 規則
  • Channel Routing 規則
  • Safety Rules
  • Memory Framework
  • Agent Runtime Context
估計組成 :
  • Workspace:2K~4K Tokens
  • Filesystem Skill:1K~2K Tokens
  • OpenClaw Runtime Framework:15K~20K Tokens
結論 : 

Workspace 已優化至相當精簡的程度,繼續縮減 USER.md、MEMORY.md、SOUL.md 或
AGENTS.md 的效益有限。In tokens 21k 是合理的,主要來自工具 Schema。這 21k input 是 OpenClaw 每次呼叫 Gemini 時固定送出的大型 prompt/context 所造成的;不是因為對話越聊越長所致。


4. 解決方案 :

從上面的分析結果可知, In tokens 21k 是與 OpenClaw 對話時的基本 token 消費, 應該是避不掉, 如果不想在對話時遇到 Gemini 的 TPM 限額而無法繼續, 那就把 GPT 5.6 設為 fallback, 當 Gemini 遇到 TPM 時就掉回付費的 GPT 5.6. 

以下設定使用終端機指令去修改 OpenClaw 設定檔 ~/.openclaw/openclaw.json (不建議用 nano 直接編輯). 首先查詢 openclaw.json 中目前的模型設定 : 

pi@pi4b:~ $ openclaw config get agents.defaults.models   

OpenClaw 2026.7.1-2 (0790d9f)
I've survived more breaking changes than your last three relationships.

{
  "openai/gpt-5.6": {
    "alias": "GPT"
  },
  "google/gemini-3.1-pro-preview": {
    "alias": "gemini"
  },
  "google/gemini-2.5-flash": {}
}

OpenClaw 支援的模型名稱可用 openclaw models list 指令查詢 : 

pi@pi4b:~ $ openclaw models list   

OpenClaw 2026.7.1-2 (0790d9f) — Open source means you can see exactly how I judge your config.

Model                                      Input      Ctx         Local Auth  Tags
google/gemini-2.5-flash                    text       200k        no    yes   default,configured
openai/gpt-5.6                             text       200k        no    yes   configured,alias:GPT
google/gemini-3.1-pro-preview              text       200k        no    yes   configured,alias:gemini
google/gemini-2.5-flash-lite               text+image 1049k       no    yes   
google/gemini-2.5-pro                      text+image 1049k       no    yes   
google/gemini-3-flash-preview              text+image 1049k       no    yes   
google/gemini-3.1-flash-lite               text+image 1049k       no    yes   
google/gemini-3.5-flash                    text+image 1049k       no    yes   
openai/gpt-5.3-chat-latest                 text+image 128k        no    yes   
openai/gpt-5.3-codex                       text+image 400k        no    yes   
openai/gpt-5.4                             text+image 272k        no    yes   
openai/gpt-5.4-mini                        text+image 400k        no    yes   
openai/gpt-5.4-nano                        text+image 400k        no    yes   
openai/gpt-5.4-pro                         text+image 1050k       no    yes   
openai/gpt-5.5                             text+image 1000k       no    yes   
openai/gpt-5.5-pro                         text+image 1000k       no    yes   
openai/gpt-5.6-luna                        text+image 1050k       no    yes   
openai/gpt-5.6-sol                         text+image 1050k       no    yes   
openai/gpt-5.6-terra                       text+image 1050k       no    yes   
openai/o1                                  text+image 200k        no    yes   
openai/o1-pro                              text+image 200k        no    yes   
openai/o3                                  text+image 200k        no    yes   
openai/o3-deep-research                    text+image 200k        no    yes   
openai/o3-mini                             text       200k        no    yes   
openai/o3-pro                              text+image 200k        no    yes   
openai/o4-mini                             text+image 200k        no    yes   
openai/o4-mini-deep-research               text+image 200k        no    yes

目前只設定了 Gemini 2.5 Flash, GPT 5.6, 與 Gemini 3.1 Pro 這三個可用模型, 但只要保留 Gemini 2.5 Flash 與 GPT 5.6 就可以了, Gemini 3.1 Pro Preview 可以拿掉 (因為當 Flash 配額用光時, 改用 Pro 當備援也是無濟於事), 設定指令如下 :

openclaw config set --replace agents.defaults.models '{"openai/gpt-5.6": {"alias": "GPT"}, "google/gemini-2.5-flash": {"alias": "Flash"}}'

注意, 此處必須加上 --replace 參數來確認要覆蓋舊設定, 否則會出現錯誤. 這是 OpenClaw 預設的安全保護機制, 防止使用者不小心覆蓋掉原有的模型設定. 

pi@pi4b:~ $ openclaw config set --replace agents.defaults.models '{"openai/gpt-5.6": {"alias": "GPT"}, "google/gemini-2.5-flash": {"alias": "Flash"}}'
│
◇  

OpenClaw 2026.7.1-2 (0790d9f)
I've survived more breaking changes than your last three relationships.

Updated agents.defaults.models. Change will apply without restarting the gateway.

再次檢視模型設定 :

pi@pi4b:~ $ openclaw config get agents.defaults.models   

OpenClaw 2026.7.1-2 (0790d9f)
One CLI to rule them all, and one more restart because you changed the port.

{
  "openai/gpt-5.6": {
    "alias": "GPT"
  },
  "google/gemini-2.5-flash": {
    "alias": "Flash"
  }
}

可見已正確改為 GPT 5.6 與 Gemini 2.5 Flash 這兩個模型, 且別名 alias 也設定好了. 接下來要將 Gemini 2.5 Flash 設為主要 (primary) 模型, 指令如下 :  

openclaw config set agents.defaults.model.primary "google/gemini-2.5-flash"

pi@pi4b:~ $ openclaw config set agents.defaults.model.primary "google/gemini-2.5-flash"  
│
◇  

OpenClaw 2026.7.1-2 (0790d9f)
It's not "failing," it's "discovering new ways to configure the same thing wrong."

Updated agents.defaults.model.primary. Restart the gateway to apply.

然後將 GPT 5.6 設為備援 (fallback) 模型, , 指令如下 :

openclaw config set agents.defaults.model.fallbacks '["openai/gpt-5.6"]'

pi@pi4b:~ $ openclaw config set agents.defaults.model.fallbacks '["openai/gpt-5.6"]'   
│
◇  

OpenClaw 2026.7.1-2 (0790d9f) — I'll refactor your busywork like it owes me money.

Updated agents.defaults.model.fallbacks. Change will apply without restarting the gateway.

設定完畢檢視模型設定的 model 參數 (注意是單數的 model, 主要與備援模型設定放在 model, 而可用模型放在 models) : 

pi@pi4b:~ $ openclaw config get agents.defaults.model   

OpenClaw 2026.7.1-2 (0790d9f) — Half butler, half debugger, full crustacean.

{
  "primary": "google/gemini-2.5-flash",
  "fallbacks": [
    "openai/gpt-5.6"
  ]
}

用 openclaw configure validate 檢查設定檔 openclaw.json 是否合規 : 

pi@pi4b:~ $ openclaw config validate  
│
◇  

OpenClaw 2026.7.1-2 (0790d9f) — Somewhere between 'hello world' and 'oh god what have I built.'

Config valid: ~/.openclaw/openclaw.json

最後必須重啟 OpenClaw 服務, 上面的設定才會生效, 直接用 kill 指令殺死行程, 它會觸發守護程式自動將 OpenClaw 服務重新拉起來 :

pi@pi4b:~ $ pkill -9 -f openclaw  
pi@pi4b:~ $ 

然後使用 LINE 詢問使用的模型 :




用 /status 指令能更完整地顯示目前狀態 :




Uptime gateway 2m 表示兩分鐘之前 Gateway 被重啟了; Model 顯示目前使用 Gemini 2.5 Flash 模型; Fallbacks 則顯示備援模型為 GPT 5.6, 這樣以後遇到 Gemini TPM 配額限制時就會自動改用備援模型了 (付費 API Key). 

如果前後對話無連續性, 提問前先用 /reset 重設對話或用 /new 開新對話, 這樣可以降低遇到 TPM 門檻的頻率 :