system prompt 注入可用技能列表,免去模型先 list_skills 探索
- tools/skills.js 新增 formatSkillListForPrompt:技能列表格式化为 “## Available Skills” 段落(名称 + 描述,每行一个) - llm.js 新增 setSkillListText:技能段落拼在模板之后、语言指令之前; 列表变化时失效 systemPromptText 缓存。仅技能增删/描述变化时更新, 否则进程内恒定,不破坏上游前缀缓存 - server.js 启动时对技能根目录做快照并注入,启动日志输出技能名 - routes/skills.js 六个变更入口(创建/重命名/删除/文件写/文件删/上传) 成功后 fire-and-forget 刷新列表:UI 增删改技能无需重启即生效; list_skills 保留作实时兜底 - system-prompt.txt Skill Usage 措辞更新:直接信任系统 prompt 中的 技能列表,列表缺失或疑似过期时才调 list_skills
This commit is contained in:
+14
-3
@@ -16,11 +16,22 @@ function buildSystemPrompt() {
|
||||
// 同一进程内恒定,不破坏前缀缓存;改配置需重启生效。
|
||||
// system prompt 每次请求都随 messages 发出,拼接结果按语言缓存,不重复分配大字符串。
|
||||
let _promptTextCache = null; // { lang, text }
|
||||
|
||||
// “可用技能”段落(skills.formatSkillListForPrompt):启动时快照(server.js)与技能变更后
|
||||
// (routes/skills.js)经 setSkillListText 更新,拼在模板之后、语言指令之前。
|
||||
// 与语言指令同一约定:仅技能增删/描述变化时更新,否则进程内恒定,不破坏前缀缓存。
|
||||
let SKILL_LIST_TEXT = '';
|
||||
function setSkillListText(text) {
|
||||
SKILL_LIST_TEXT = text || '';
|
||||
_promptTextCache = null; // 列表变化后拼接结果需重建
|
||||
}
|
||||
|
||||
function systemPromptText(language) {
|
||||
const t = String(language || '').trim();
|
||||
if (_promptTextCache && _promptTextCache.lang === t) return _promptTextCache.text;
|
||||
const text = !t ? SYSTEM_PROMPT_TEMPLATE : SYSTEM_PROMPT_TEMPLATE +
|
||||
'\n\n## Reply Language\n' +
|
||||
let text = SYSTEM_PROMPT_TEMPLATE;
|
||||
if (SKILL_LIST_TEXT) text += '\n\n' + SKILL_LIST_TEXT;
|
||||
if (t) text += '\n\n## Reply Language\n' +
|
||||
'- ALWAYS respond to the user in ' + t + '. Tool descriptions, tool outputs and errors are usually in English — ' +
|
||||
'never let them switch your reply language. Tool names, parameters, code, file paths and shell commands stay as-is; ' +
|
||||
'every sentence addressed to the user MUST be in ' + t + '.';
|
||||
@@ -307,4 +318,4 @@ async function callModel(cfg, modelId, messages, tools, options) {
|
||||
return { content, reasoning, tool_calls: Array.from(toolCalls.values()), finish_reason: finishReason, usage, aborted, sseFrames };
|
||||
}
|
||||
|
||||
module.exports = { callModel, buildMessages, buildSystemPrompt, systemPromptText, encodeBlocks, decodeBlocks };
|
||||
module.exports = { callModel, buildMessages, buildSystemPrompt, systemPromptText, setSkillListText, encodeBlocks, decodeBlocks };
|
||||
|
||||
Reference in New Issue
Block a user