模型切换通知。当agent使用的模型发生变化时,第一时间通知当前会话用户。支持心跳检测机制,消息中断时下次会话自动通知。使用 SQLite 存储。
自动检测模型切换并通知用户:
每次会话回复时执行心跳检测:
如果通知发送失败/中断:
只使用 SQLite 数据库存储:
bash
json
{
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 |
sql
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,
updatedat TIMESTAMP DEFAULT CURRENTTIMESTAMP
);
用户消息到达
↓
解析 Runtime 获取 currentModel
↓
调用 check_model.py check
↓
检查 pending_notify(上次中断?)
↓
检查模型是否变化
↓
如果 shouldNotify=true → 返回通知消息
↓
Agent 在回复中附加通知
↓
正常回复用户
发送通知失败/中断
↓
调用 check_model.py interrupt
↓
保存 pendingnotify=1, pendingmessage
↓
下次会话开始
↓
check 检测到 pending_notify
↓
返回 pending_message 作为通知
↓
发送后清除 pending_notify
当前使用模型:{currentModel}
老板,模型已切换,当前使用:{currentModel}
[上次未发送] 老板,模型已切换,当前使用:{currentModel}
每次会话回复前执行:
python
import subprocess
import json
def checkmodelswitch(agentid, currentmodel, 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)
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 数据库
该技能支持在以下平台通过对话安装:
帮我安装 SkillHub 和 model-switch-notify-1776105845 技能
设置 SkillHub 为我的优先技能安装源,然后帮我安装 model-switch-notify-1776105845 技能
skillhub install model-switch-notify-1776105845
文件大小: 7.56 KB | 发布时间: 2026-4-15 13:27