← 返回
未分类 中文

Auto Skill Trigger

Auto Skill Trigger - Match skills to tasks using keyword scoring
自动技能触发 - 使用关键词评分匹配技能与任务
hanxiao-bot
未分类 clawhub v1.0.0 1 版本 100000 Key: 无需
★ 0
Stars
📥 419
下载
💾 1
安装
1
版本
#latest

概述

Auto Skill Trigger - Automatic Skill Matching

Overview

Automatically match relevant skills to the current task using keyword/pattern scoring. Pre-filters the list before the LLM decides which to load.

How It Works

  1. When a message arrives, score each skill's description against the message
  2. Only include high-scoring skills in the prompt
  3. The LLM makes the final decision from a relevant subset

Scoring Algorithm

Simple TF-IDF-like keyword overlap:

api.registerHook("before_prompt_build", async ({ event, ctx }) => {
  const msg = event.messages?.[0]?.content || "";
  const keywords = extractKeywords(msg);
  
  // Get all skills and their descriptions
  const skills = await getAllSkills();
  const scored = skills.map(skill => ({
    skill,
    score: keywordOverlap(keywords, skill.description)
  })).filter(s => s.score > 0.3); // threshold
  
  // Sort by score and take top 5
  scored.sort((a, b) => b.score - a.score);
  const topSkills = scored.slice(0, 5);
  
  // Return instruction to prioritize matched skills
  if (topSkills.length > 0) {
    return {
      prompt: `\n\n## Skill Hint\nFocus on: ${topSkills.map(s => s.skill.name).join(", ")}\n`
    };
  }
  return {};
});

Keyword Extraction

function extractKeywords(text) {
  // Extract meaningful words/n-grams
  const words = text.toLowerCase()
    .split(/\W+/)
    .filter(w => w.length > 2)
    .filter(w => !STOP_WORDS.has(w));
  return new Set(words);
}

function keywordOverlap(keywords, description) {
  const descWords = extractKeywords(description);
  let matches = 0;
  for (const kw of keywords) {
    if (descWords.has(kw)) matches++;
  }
  return matches / keywords.size;
}

Configuration

{
  "agents": {
    "defaults": {
      "autoSkillTrigger": {
        "enabled": true,
        "maxSkills": 5,
        "threshold": 0.3,
        "stopWords": ["the", "a", "an", "is", "are", "and"]
      }
    }
  }
}

Patterns That Match

Message PatternMatched Skills
-------------------------------
"帮我查 GitHub issue"github
"天气怎么样"weather
"写个 Python 脚本"coding
"搜一下最近的新闻"search

Limitations

  • Pattern-based matching is imperfect
  • Complex tasks may need multiple skills
  • LLM still has final say via SKILL.md scanning
  • Update threshold based on results

版本历史

共 1 个版本

  • v1.0.0 当前
    2026-05-03 09:02 安全 安全

安全检测

腾讯云安全 (Keen)

安全,无风险
查看报告

腾讯云安全 (Sanbu)

安全,无风险
查看报告

🔗 相关推荐

OpenClaw Hook Examples

hanxiao-bot
为 OpenClaw 提供示例钩子,用于拦截、修改、阻止工具调用,切换模型,记录操作以及处理子代理事件。
★ 0 📥 429

Compact Summary

hanxiao-bot
在刷新或压缩时生成结构化、简洁的内存摘要,涵盖会话统计、工具、用户请求、任务、文件、进度和时间等信息。
★ 0 📥 402

Error Recovery

hanxiao-bot
错误恢复 - 优雅处理失败的策略
★ 0 📥 500