From ffac8c759c2ba8f340a3cba3c03378b992dc28e0 Mon Sep 17 00:00:00 2001 From: kicer Date: Thu, 24 Sep 2026 08:49:57 +0800 Subject: [PATCH] =?UTF-8?q?prompt.txt=E9=BB=98=E8=AE=A4=E7=BB=84=E5=90=88?= =?UTF-8?q?=E6=AE=B5=E6=94=B9=E8=B5=B0effectiveTools():=E6=AD=A4=E5=89=8D?= =?UTF-8?q?=E7=9B=B4=E6=8E=A5concat=E5=85=A8=E9=87=8F,=E6=8A=8A=E5=85=A8?= =?UTF-8?q?=E5=B1=80tools=5Fdeny=E5=B1=8F=E8=94=BD=E7=9A=84lab=E4=B9=9Fdum?= =?UTF-8?q?p=E4=BA=86=E8=BF=9B=E5=8E=BB,=E4=B8=8E=E6=A8=A1=E5=9E=8B?= =?UTF-8?q?=E5=AE=9E=E6=94=B6=E4=B8=8D=E7=AC=A6(=E4=BA=BA=E5=B7=A5?= =?UTF-8?q?=E6=A0=B8=E5=AF=B9=E8=A2=AB=E8=AF=AF=E5=AF=BC);=E7=8E=B0?= =?UTF-8?q?=E4=B8=8Eengine=E6=AF=8F=E8=BD=AE=E5=AE=9E=E9=99=85=E5=8F=91?= =?UTF-8?q?=E9=80=81=E5=90=8C=E6=BA=90,=E6=A0=87=E9=A2=98=E6=B3=A8?= =?UTF-8?q?=E6=98=8E=E8=BF=87=E6=BB=A4=E3=80=81=E6=97=A5=E5=BF=97=E6=94=B9?= =?UTF-8?q?=E8=BF=87=E6=BB=A4=E6=95=B0/=E5=8E=9F=E5=A7=8B=E6=95=B0?= =?UTF-8?q?=E5=8F=8C=E5=80=BC(tools=3D12/13),profile=E6=AE=B5=E5=AF=B9?= =?UTF-8?q?=E7=85=A7=E5=9F=BA=E6=95=B0=E6=94=B9=E7=94=A8=E5=8E=9F=E5=A7=8B?= =?UTF-8?q?=E5=85=A8=E9=87=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/server/server.js | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/app/server/server.js b/app/server/server.js index 72597b5..1359b24 100644 --- a/app/server/server.js +++ b/app/server/server.js @@ -111,27 +111,30 @@ const PORT = process.env.PORT || cfg.port; // 启动成功后把模型实际收到的各部分 dump 到文件方便人工核对(data_root 默认 ./data, // 宿主机对应 /data/prompt.txt,已被 gitignore)。包含: -// 1) 默认组合:system 消息(模板 + 可用技能段落 + 语言指令)+ tools 数组(内置 + MCP); +// 1) 默认组合:system 消息(模板 + 可用技能段落 + 语言指令)+ tools 数组(内置 + MCP 过滤全局 tools_deny); // 2) 每套 model_profiles 一段:按其白名单过滤后的 tools + 自定义 prompt(未配则回落默认模板)。 function dumpPromptBundle() { const file = path.join(cfg.data_root, 'prompt.txt'); const lang = (cfg.agent || {}).language; - const tools = engine.TOOL_DEFINITIONS.concat(mcp.toolDefinitions()); + // 默认组合必须走 effectiveTools()(无 profile 分支 = 全局 deny 过滤),与 engine 每轮实际发送同源: + // 直接 concat 全量会把 lab 这类被 deny 的工具也 dump 进去——模型其实收不到,人工核实时误导。 + const tools = engine.effectiveTools(); + const allCount = engine.TOOL_DEFINITIONS.concat(mcp.toolDefinitions()).length; const parts = [ '# ===== 1. System Prompt(默认组合,system 消息,进程内恒定)=====\n\n' + llm.systemPromptText(lang), - '\n\n# ===== 2. Tools(默认组合 ' + tools.length + ' 个:内置 + MCP,随每次请求的 tools 字段发送)=====\n\n' + JSON.stringify(tools, null, 2), + '\n\n# ===== 2. Tools(默认组合 ' + tools.length + ' 个:内置 + MCP 过滤全局 tools_deny 后,随每次请求的 tools 字段发送)=====\n\n' + JSON.stringify(tools, null, 2), ]; for (const name of Object.keys(cfg.model_profiles || {})) { const pTools = engine.effectiveTools(name); parts.push( '\n\n# ===== profile "' + name + '" =====\n\n' + '# --- system prompt ---\n\n' + llm.systemPromptText(lang, name) + - '\n\n# --- tools(白名单过滤后 ' + pTools.length + ' / 全量 ' + tools.length + ' 个)---\n\n' + JSON.stringify(pTools, null, 2) + '\n\n# --- tools(allow/deny 过滤后 ' + pTools.length + ' / 原始全量 ' + allCount + ' 个)---\n\n' + JSON.stringify(pTools, null, 2) ); } fs.mkdirSync(path.dirname(file), { recursive: true }); fs.writeFileSync(file, parts.join(''), 'utf8'); - log.info('startup', ' prompt_dump=' + file + ' (tools=' + tools.length + + log.info('startup', ' prompt_dump=' + file + ' (tools=' + tools.length + '/' + allCount + ', profiles=' + (Object.keys(cfg.model_profiles || {}).join(',') || '-') + ')'); }