Install
openclaw skills install model-switch-notify模型切换通知。当agent使用的模型发生变化时,第一时间通知当前会话用户。支持心跳检测机制,消息中断时下次会话自动通知。使用 SQLite 存储。
openclaw skills install model-switch-notify自动检测模型切换并通知用户:
每次会话回复时执行心跳检测:
如果通知发送失败/中断:
只使用 SQLite 数据库存储:
~/.openclaw/data/model-switch.db# 心跳检测(每次会话回复时调用)
python3 check_model.py check \
--agent "coder" \
--current-model "ollama/qwen3.5-code" \
--channel "qqbot" \
--session "qqbot:c2c:xxx"
# 更新心跳
python3 check_model.py heartbeat \
--agent "coder" \
--current-model "ollama/qwen3.5-code"
# 设置中断通知
python3 check_model.py interrupt \
--agent "coder" \
--model "ollama/qwen3.5-code" \
--message "老板,模型已切换,当前使用:ollama/qwen3.5-code"
# 获取当前状态
python3 check_model.py get --agent "coder"
# 列出所有 agent
python3 check_model.py list
# 重置状态
python3 check_model.py reset --agent "coder"
{
"changed": true,
"previousModel": "ollama/glm-5:cloud",
"currentModel": "ollama/qwen3.5-code",
"shouldNotify": true,
"notifyMessage": "老板,模型已切换,当前使用:ollama/qwen3.5-code",
"firstTime": false,
"pendingNotify": false,
"pendingMessage": null
}
| 参数 | 来源 | 示例 |
|---|---|---|
| agentId | Runtime agent= | coder |
| currentModel | Runtime model= | ollama/qwen3.5-code |
| channel | Inbound Context | qqbot |
| sessionId | Inbound Context chat_id | qqbot:c2c:xxx |
CREATE TABLE model_states (
agent_id TEXT PRIMARY KEY,
last_model TEXT NOT NULL,
last_notify TIMESTAMP,
last_heartbeat TIMESTAMP,
channel TEXT,
session TEXT,
pending_notify INTEGER DEFAULT 0,
pending_message TEXT,
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);
用户消息到达
↓
解析 Runtime 获取 currentModel
↓
调用 check_model.py check
↓
检查 pending_notify(上次中断?)
↓
检查模型是否变化
↓
如果 shouldNotify=true → 返回通知消息
↓
Agent 在回复中附加通知
↓
正常回复用户
发送通知失败/中断
↓
调用 check_model.py interrupt
↓
保存 pending_notify=1, pending_message
↓
下次会话开始
↓
check 检测到 pending_notify
↓
返回 pending_message 作为通知
↓
发送后清除 pending_notify
当前使用模型:{currentModel}
老板,模型已切换,当前使用:{currentModel}
[上次未发送] 老板,模型已切换,当前使用:{currentModel}
每次会话回复前执行:
import subprocess
import json
def check_model_switch(agent_id, current_model, channel, session):
result = subprocess.run([
"python3",
"~/.openclaw/skills/model-switch-notify/scripts/check_model.py",
"check",
"--agent", agent_id,
"--current-model", current_model,
"--channel", channel,
"--session", session
], capture_output=True, text=True)
return json.loads(result.stdout)
# 在回复前检查
result = check_model_switch("coder", "ollama/qwen3.5-code", "qqbot", "qqbot:c2c:xxx")
if result["shouldNotify"]:
notify_msg = result["notifyMessage"]
# 在回复中附加通知
~/.openclaw/skills/model-switch-notify/
├── SKILL.md # 本文档
├── README.md # 使用说明
└── scripts/
└── check_model.py # 检查脚本(SQLite 存储)
~/.openclaw/data/
└── model-switch.db # SQLite 数据库
check 命令interrupt 命令