技能三件套:description按实现补全返回/超时/校验契约,与system prompt冲突消除;Available Skills注入改仅列名字省token(list_skills职责调整为描述/兜底查询);runSkill加input_args类型守卫

This commit is contained in:
2026-09-22 22:43:45 +08:00
parent 290527d2b7
commit 0527270aa5
5 changed files with 17 additions and 11 deletions
+1 -1
View File
@@ -38,7 +38,7 @@ For out-of-scope requests: state the limit in one or two sentences, don't over-a
## Skills
- Prefer skills when they match. The Available Skills list below is current — call them directly, no need for `list_skills`.
- Prefer skills when they match. The Available Skills list shows names only; check parameters with `get_skill_info`, then `run_skill`. `list_skills` gives one-line descriptions when you need to choose.
- Use `get_skill_info` for parameters, then `run_skill` to execute.
- Skills run in the server's managed Python env; you cannot install packages for them at runtime. If `run_skill` fails for a missing package or system tool, tell the user it needs a server-side change.
+1 -1
View File
@@ -50,7 +50,7 @@ You are a file / data / information processing assistant. The environment expose
## Skill Usage
- Prefer using available skills when they match the task.
- The "Available Skills" list below shows the currently installed skills; use it directly without calling `list_skills` first. If the list is empty or seems stale (e.g. a listed skill does not exist), call `list_skills` to check live.
- The "Available Skills" list below shows installed skill names only. Pick a skill by name, call `get_skill_info` for its parameters, then `run_skill`. Call `list_skills` for one-line descriptions (e.g. to choose among several skills) or to confirm a stale/empty list.
- Use `get_skill_info` to understand a skill's parameters, then `run_skill` to execute it.
- Only if no skill matches, proceed with other tools or write your own solution.
- The listed skills are prepared and ready at server startup; do not try to install dependencies for a skill yourself.
+3 -3
View File
@@ -187,7 +187,7 @@
"type": "function",
"function": {
"name": "list_skills",
"description": "Lists all available skills from the skill root directory, returning each skill's name and brief description.\n\nSkills are self-contained directories with a SKILL.md description and an executable entry point (run.py or run.sh). Use this tool to refresh or confirm the current list of available skills, then use get_skill_info for details or run_skill to execute.",
"description": "Lists all installed skills with a one-line description each, read live from the skill root directory.\n\nThe system prompt's Available Skills section shows skill names only; use this tool when you need descriptions to choose among them or to confirm what is installed. An empty skill set returns an empty list — that is not an error.",
"parameters": {
"type": "object",
"required": [],
@@ -199,7 +199,7 @@
"type": "function",
"function": {
"name": "get_skill_info",
"description": "Returns the full content of the SKILL.md file for a given skill, including its purpose, parameters (input_schema), and usage instructions.",
"description": "Returns the full raw SKILL.md of a skill (front matter included): purpose, input_schema (the parameters run_skill accepts), and usage notes. Since the system prompt lists skill names only, call this before running a skill you have not used in this conversation. If the skill does not exist, an error is returned.",
"parameters": {
"type": "object",
"required": ["skill_name"],
@@ -216,7 +216,7 @@
"type": "function",
"function": {
"name": "run_skill",
"description": "Executes a specified skill with the provided input arguments. The skill's entry script receives a JSON string as the only command-line argument.\n\n- Required parameters are validated against the skill's input_schema.\n- Default timeout is 120 seconds.\n- Relative paths in arguments are resolved against the session working directory; you may pass relative or absolute paths.",
"description": "Executes a skill with the given input arguments, validated against the skill's input_schema (a validation error names the missing fields). The entry script receives a JSON string as its only CLI argument, so input_args must be a JSON object.\n\n- Returns the skill's combined stdout+stderr as plain text after it exits; exit 0 with no output yields '(无输出)'. A non-zero exit raises an error containing the output and [exit code: N].\n- Direct output files via arguments: relative paths in arguments are resolved against the session working directory; do not rely on the skill's cwd.\n- Default timeout 120 seconds: the process group is killed and the error includes partial output collected so far (a timeout is not a skill failure).",
"parameters": {
"type": "object",
"required": ["skill_name", "input_args"],
+10 -5
View File
@@ -70,14 +70,15 @@ async function listSkills(ctx) {
}
// ---------- system prompt 注入:可用技能列表 ----------
// 把技能列表格式化成 “## Available Skills” 段落(每行一个技能:名称 + 描述,描述内换行压成空格)。
// 把技能列表格式化成 “## Available Skills” 段落(仅名字,每行一个,省 token;
// 描述查 list_skills,参数查 get_skill_info)。
// 由 llm.setSkillListText 拼入 system prompt:启动时快照(server.js)与技能变更后
// (routes/skills.js 的创建/重命名/删除/文件变更)调用,让模型直接感知已有技能,
// 省掉先 list_skills 探索的往返;list_skills 仍保留作实时兑底查询。
// (routes/skills.js 的创建/重命名/删除/文件变更)调用,让模型直接感知已装技能,
// 省掉先 list_skills 探索的往返;list_skills 保留作实时描述/兼容性查询。
function formatSkillListForPrompt(list) {
if (!list || !list.length) return '';
const lines = list.map(s => '- ' + s.name + ': ' + String(s.description).replace(/\s*\n\s*/g, ' '));
return '## Available Skills\nSkills installed on this server (call directly via run_skill; no need to call list_skills first):\n' + lines.join('\n');
const lines = list.map(s => '- ' + s.name);
return '## Available Skills\nInstalled skills (names only). To use one: `get_skill_info` for its parameters, then `run_skill` to execute. Call `list_skills` for one-line descriptions when choosing among skills.\n' + lines.join('\n');
}
// ---------- 3.2 get_skill_info ----------
@@ -192,6 +193,10 @@ function runEntry(ctx, entry, args, cwd, timeoutMs) {
// ---------- 3.3 run_skill ----------
async function runSkill(ctx, skillName, inputArgs) {
// 非对象参数会在 absolutizeArgs 的 Object.entries 里静默错位成垃圾键值(如字符串→索引对象),显式拦下。
if (inputArgs != null && (typeof inputArgs !== 'object' || Array.isArray(inputArgs))) {
throw new SkillExecutionError('input_args 必须是对象(键值参数),收到:' + JSON.stringify(inputArgs).slice(0, 80), 1);
}
const dir = skillDir(ctx, skillName);
if (!fs.existsSync(dir)) throw new SkillNotFoundError('技能不存在:' + skillName);