← 返回
AI智能

Model Switch Notify

模型切换通知。当agent使用的模型发生变化时,第一时间通知当前会话用户。支持心跳检测机制,消息中断时下次会话自动通知。使用 SQLite 存储。
模型切换通知。当agent模型变更时,立即通知当前会话用户。支持心跳检测,消息中断后自动通知。使用SQLite存储。
wljmmx
AI智能 clawhub v1.0.1 2 版本 100000 Key: 无需
★ 0
Stars
📥 546
下载
💾 6
安装
2
版本
#latest

概述

模型切换通知 Skill v3.0

功能概述

自动检测模型切换并通知用户:

  • 记录每个 agent 上次使用的模型(SQLite 存储)
  • 心跳检测:每次会话回复时自动检查
  • 消息中断处理:下次会话第一时间通知
  • 模型变化时推送通知到当前会话

核心特性

1. 心跳检测机制

每次会话回复时执行心跳检测:

  1. 检查是否有待发送通知(上次中断时)
  2. 检查模型是否变化
  3. 更新心跳时间戳

2. 消息中断处理

如果通知发送失败/中断:

  1. 保存待发送通知到数据库
  2. 下次会话第一时间发送
  3. 发送后自动清除

3. SQLite 存储

只使用 SQLite 数据库存储:

  • 路径:~/.openclaw/data/model-switch.db
  • 支持 pending_notify 字段记录中断通知

使用方法

命令行工具

# 心跳检测(每次会话回复时调用)
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
}

参数获取方式

参数来源示例
------------------
agentIdRuntime agent=coder
currentModelRuntime model=ollama/qwen3.5-code
channelInbound Contextqqbot
sessionIdInbound Context chat_idqqbot: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}

集成指南

在 Agent 中集成

每次会话回复前执行:

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 数据库

注意事项

  1. 心跳检测:每次会话回复时调用 check 命令
  2. 中断处理:消息发送失败时调用 interrupt 命令
  3. 存储方式:只使用 SQLite,不再支持 JSON 文件
  4. 跨会话:模型状态和中断通知跨会话持久化

更新日志

  • v3.0.0 (2026-03-16): 移除 JSON 存储,只使用 SQLite;添加心跳检测和中断通知机制
  • v2.0.0 (2026-03-16): 添加 SQLite 支持、详细集成指南
  • v1.0.0 (2026-03-13): 初始版本

版本历史

共 2 个版本

  • v1.0.1 当前
    2026-05-01 17:52 安全 安全
  • v1.0.0
    2026-03-19 16:59 安全 安全

安全检测

腾讯云安全 (Keen)

安全,无风险
查看报告

腾讯云安全 (Sanbu)

安全,无风险
查看报告

🔗 相关推荐

ai-intelligence

self-improving agent

pskoett
捕获经验教训、错误和纠正,以实现持续改进。使用时机:(1)命令或操作意外失败;(2)用户纠正……
★ 4,056 📥 796,389
ai-intelligence

Self-Improving + Proactive Agent

ivangdavila
自我反思+自我批评+自我学习+自组织记忆。智能体评估自身工作、发现错误并持续改进。
★ 1,350 📥 317,745
ai-intelligence

ontology

oswalpalash
类型化知识图谱,用于结构化智能体记忆与可组合技能。支持创建/查询实体(人员、项目、任务、事件、文档)及关联...
★ 709 📥 243,557