model_profiles.tools_allow 语义修正:空数组 [] = 零工具(纯文本组合)
此前复用 MCP 的 normToolNames 约定(空数组视作未配置),导致 tools_allow: [] 的 profile 反而全量发工具。现只认「没写/非数组 = 不过滤」;[] 为有效配置 = 一个都不发 (callModel 对空数组不发 tools 字段)。与 MCP tools_allow 的约定有意分叉,文档同步。
This commit is contained in:
@@ -46,9 +46,11 @@ platforms:
|
||||
# 模型 profile(可选):预定义多套「prompt + tools 白名单」组合,platforms 里的模型用
|
||||
# profile: <名字> 引用,同 id 模型跨平台复用时免重复配置。动机:默认发给模型的
|
||||
# 内置工具 schema + system prompt 合计 ~20KB 字符(约 6K token),对特别小的模型会撑爆上下文。
|
||||
# - tools_allow:白名单(字符串数组),只保留名单内的工具发给模型;内置名 + MCP 最终名
|
||||
# (含冲突时加的 服务名__ 前缀,与 data/prompt.txt dump 一致可对)。不配 = 全量发。
|
||||
# 只影响模型「看得到什么」:名单外但真实存在的工具若被调用,后端照常执行,不拦不误杀。
|
||||
// - tools_allow:白名单(字符串数组),只保留名单内的工具发给模型;内置名 + MCP 最终名
|
||||
// (含冲突时加的 服务名__ 前缀,与 data/prompt.txt dump 一致可对)。不配 = 全量发;
|
||||
// 空数组 [] = 一个都不发(纯文本模式,给弱到不会调工具的小模型;与 MCP 的 tools_allow
|
||||
// 「空名单视作未配」约定有意不同)。只影响模型「看得到什么」:名单外但真实存在的工具若被调用,
|
||||
// 后端照常执行,不拦不误杀。
|
||||
# - system_prompt_file:自定义 system prompt 文件,相对 server/templates/(也接受绝对路径),
|
||||
# 配置加载时一次性读入常驻内存;设了就完全接管(不拼技能列表段,只保留末尾语言指令)。
|
||||
# 文件缺失/为空直接校验报错。两者至少配一个;引用不存在的 profile 名同样直接报错。
|
||||
|
||||
@@ -20,9 +20,10 @@ function normToolNames(v) {
|
||||
const TEMPLATES_DIR = path.join(__dirname, 'templates');
|
||||
|
||||
// model_profiles 归一化:顶层 map {名称: {tools_allow?, system_prompt_file?}},
|
||||
// 供 platforms[].models[].profile 引用(同 id 模型跨平台复用时免重复配置)。
|
||||
// - tools_allow 复用 MCP 名单约定(normToolNames):只按最终发给模型的工具名匹配
|
||||
// (内置名 + MCP 名,含冲突时加的 server__ 前缀);非数组/空数组 = 未配置不过滤。
|
||||
// 供 platforms[].models[].profile 引用(同 id 模型跳平台复用时免重复配置)。
|
||||
// - tools_allow 只按最终发给模型的工具名匹配(内置名 + MCP 名,含冲突时加的 server__ 前缀)。
|
||||
// 语义与 MCP 的 tools_allow(空数组=未配)有意不同:这里空数组 [] 是有效配置 = 一个工具都不发
|
||||
// (纯文本模式,给弱到不会调工具的小模型用);只有「没写/非数组」才是「不过滤、发全量」。
|
||||
// - system_prompt_file:相对 templates/(也接受绝对路径),配置加载时一次性读入常驻内存,
|
||||
// 运行期切换零 IO;缺失/读不到/内容为空直接报校验错——拦在保存/重启预检,不留到运行期降级。
|
||||
// - 两样都没配 = 不起任何作用,报错误防误配空壳。
|
||||
@@ -35,7 +36,10 @@ function normalizeModelProfiles(rawProfiles) {
|
||||
if (!p || typeof p !== 'object' || Array.isArray(p)) {
|
||||
throw new Error('model_profiles.' + key + ' 必须是对象 {tools_allow, system_prompt_file}');
|
||||
}
|
||||
const tools_allow = normToolNames(p.tools_allow);
|
||||
// 不用 normToolNames:那会把空数组吐成 undefined(丢抑「[] = 零工具」语义);这里只归一字符串项。
|
||||
const tools_allow = Array.isArray(p.tools_allow)
|
||||
? p.tools_allow.map(x => String(x).trim()).filter(Boolean)
|
||||
: undefined;
|
||||
const file = String(p.system_prompt_file || '').trim();
|
||||
let prompt = '';
|
||||
if (file) {
|
||||
|
||||
@@ -252,13 +252,14 @@ function resolveProfileName(session, run) {
|
||||
}
|
||||
|
||||
// 本轮工具定义集:内置 + MCP 全量;profile 配了 tools_allow 则按最终名过滤
|
||||
// (与发给模型的 tools 字段/prompt.txt dump 同源可对)。只影响模型「看得到什么」:
|
||||
// (与发给模型的 tools 字段/prompt.txt dump 同源可对)。空数组 = 零工具(纯文本组合,
|
||||
// callModel 对空数组不发 tools 字段);未配 = 全量。只影响模型「看得到什么」:
|
||||
// 名单外但真实存在的工具若被调用,executor 照常执行(HANDLERS 全表分发),不拦不误杀。
|
||||
function effectiveTools(profileName) {
|
||||
const all = TOOL_DEFINITIONS.concat(mcp.toolDefinitions());
|
||||
const prof = profileName && cfg.model_profiles && cfg.model_profiles[profileName];
|
||||
const allow = prof && prof.tools_allow;
|
||||
if (!allow) return all;
|
||||
if (!Array.isArray(allow)) return all;
|
||||
const set = new Set(allow);
|
||||
return all.filter(t => t && t.function && set.has(t.function.name));
|
||||
}
|
||||
|
||||
@@ -335,7 +335,7 @@ stateDiagram-v2
|
||||
- 加载:`loadConfig(AGENT_CONFIG)` 读文件 → `parseAndValidate`。
|
||||
- 兼容:旧版 `models[]`(扁平)自动迁移到 `platforms[]` 层级;旧版 `web_search.*` 迁移到 `mcp_servers[]`(log.info 提示)。
|
||||
- 规范化:`normalizePlatforms` 校验 `name/url/type`,key 层 `concurrency`,model 层 `{id, display_name, vision, enable, extra_params, thinking_params, profile}`;同平台内 model id 必须唯一(内部唯一键 = 平台名/模型id);`profile` 引用不存在的名字直接报错。
|
||||
- `model_profiles`(顶层,`normalizeModelProfiles`):多套可复用的 prompt+tools 组合,每项 `{tools_allow?, system_prompt_file?}`,两者至少配一个。`tools_allow` 复用 `normToolNames` 约定(非数组/空数组 = 未配),按**最终发给模型的工具名**匹配(含 MCP 的 `服务名__` 前缀,与 prompt.txt dump 同源可对);`system_prompt_file` 相对 `server/templates/`(compose 已 bind-mount ./app/server,宿主直接可改),**配置加载时一次性读入常驻内存**,缺失/为空报错拦在保存/重启预检。运行期切换(前端传参)零 IO、不碰本配置。
|
||||
- `model_profiles`(顶层,`normalizeModelProfiles`):多套可复用的 prompt+tools 组合,每项 `{tools_allow?, system_prompt_file?}`,两者至少配一个。`tools_allow` 按**最终发给模型的工具名**匹配(内置 + MCP,含 `服务名__` 前缀,与 prompt.txt dump 同源可对);未配 = 全量,**空数组 `[]` = 零工具(纯文本组合)**——与 MCP 的 `tools_allow`(空名单视作未配)有意不同。`system_prompt_file` 相对 `server/templates/`(compose 已 bind-mount ./app/server,宿主直接可改),**配置加载时一次性读入常驻内存**,缺失/为空报错拦在保存/重启预检。运行期切换(前端传参)零 IO、不碰本配置。
|
||||
- 默认值(`DEFAULTS`):port=8090、log_level=info、terminal default 30s/10K、agent temperature=1.0、max_tool_iterations=20、max_retries=2、model_hold 3min/30min/10s、上传 1.5MB 阈值/2000px/0.85。
|
||||
- 读写:`readConfigText` / `writeConfigText`(先校验后写,无原子 rename,因 bind mount 上 rename 会 EBUSY);`applyEditsToText` 用 `YAML.Document` 保留注释。
|
||||
- `getConfig` 是浅引用,路由层拿到的就是运行中实例,**改完 in-memory 不影响**(要重启)。
|
||||
|
||||
Reference in New Issue
Block a user