profile 工具取代 handoff 提取链路:AI 沟通中增量维护画像(list/set/add/remove,顿号标签 + 15字/24个/300字帽 + 整批原子 + 停用拒写);删 runExtraction/profileMessages/profile-prompt.txt 一次性提取(会覆写工具成果);advising 放行 profile;preference 扩容 300,设置页文案同步

This commit is contained in:
2026-09-28 06:52:50 +08:00
parent b1f331f240
commit d1e97ba9f9
10 changed files with 159 additions and 116 deletions
+17
View File
@@ -181,6 +181,23 @@
}
}
},
{
"type": "function",
"function": {
"name": "profile",
"description": "Maintain the current user's profile — stable facts that persist across conversations and get injected into the context of NEW sessions (the current session's injected copy is frozen). Ops: list (read the live profile), set (honorific or industry, single short value), add (append preference tags), remove (delete exact preference tags). Rules: only record what the user has clearly stated or asked to be remembered (form of address, domain, stable output/work preferences); never guess personality, never store one-time task parameters; brief tags beat essays. Preference is a 、-separated tag list (each tag ≤15 chars, ≤24 tags, ≤300 chars total; overflow is rejected — consolidate or remove first). When unsure what is already recorded, op=list returns live state — trust it over memory.",
"parameters": {
"type": "object",
"required": ["op"],
"properties": {
"op": { "type": "string", "enum": ["list", "set", "add", "remove"], "description": "list = read live profile; set = single-value honorific/industry; add/remove = preference tags." },
"honorific": { "type": "string", "description": "op=set: how to address the user (≤20 chars, e.g. 王工). Pass empty string to clear. Exactly one of honorific/industry per call." },
"industry": { "type": "string", "description": "op=set: the user's industry/domain (≤20 chars, e.g. 金融). Pass empty string to clear." },
"tags": { "type": "array", "items": { "type": "string" }, "description": "op=add/remove: preference tag list, e.g. [\"偏好简洁回复\", \"图表中文标注\"]. Matching is exact text." }
}
}
}
},
{
"type": "function",
"function": {
+35
View File
@@ -10,6 +10,7 @@ const Database = require('better-sqlite3'); // db 工具:会话目录下的 da
const rexec = require('../remote-exec');
const publicFiles = require('../public-files');
const scheduler = require('../scheduler'); // 只依赖 log/cron-parser,不成环(engine→executor→scheduler 单向)
const profile = require('../user-profile'); // profile 工具的数据面(仅 llm/log 依赖,无环)
// lab 的 help 伪工具要读全量定义:与 engine 同路径 require → node 缓存同一对象,单一事实源。
const BUILTIN_TOOL_DEFS = require('./definitions.json');
@@ -803,6 +804,39 @@ function toolScheduleTask(ctx, args) {
}
}
// profile:用户画像增量维护(op 分派同 schedule 风格)。user 取自会话行,AI 不可指定他人;
// 条件必填/帽子校验全在 user-profile.js(抛错由引擎包成 is_error 回执),停用拒写不拒读。
function toolProfile(ctx, args) {
const op = String(args.op || '').trim().toLowerCase();
const s = ctx.db.prepare('SELECT user FROM sessions WHERE id = ?').get(ctx.sessionId);
if (!s) throw new Error('会话不存在');
const user = s.user;
switch (op) {
case 'list': {
const p = profile.getProfile(ctx.db, user);
const lines = [
'称谓:' + (p.honorific || '(未记录)'),
'行业:' + (p.industry || '(未记录)'),
'偏好:' + (p.preference || '(未记录)'),
];
if (!p.enabled) lines.push('(该用户已停用画像注入;set/add/remove 会被拒绝)');
lines.push('本会话已注入的快照不会因写入而变;新会话自动携带最新画像。');
return lines.join('\n');
}
case 'set': {
const keys = ['honorific', 'industry'].filter(k => typeof args[k] === 'string');
if (keys.length !== 1) throw new Error('op=set 需要 honorific 或 industry 恰一个字符串参数(偏好标签用 add/remove)');
return profile.setProfileField(ctx.db, user, keys[0], args[keys[0]]);
}
case 'add':
return profile.addProfileTags(ctx.db, user, args.tags);
case 'remove':
return profile.removeProfileTags(ctx.db, user, args.tags);
default:
throw new Error('未知的 op:"' + op + '"。可用:list / set(honorific|industry) / add(tags) / remove(tags)');
}
}
// db:会话本地 SQLite(taskDir/data.db,随会话目录隔离,首次使用自动建库建文件)。
// 连接策略:每次调用 open→用→close,不缓存句柄(会话删目录后不留脏连接);
// 单进程 + better-sqlite3 同步 API,同进程内不存在交叠。busy_timeout 兼容
@@ -1160,6 +1194,7 @@ const HANDLERS = {
terminal: toolTerminal,
fetch: toolFetch,
schedule: toolScheduleTask,
profile: toolProfile,
db: toolDb,
skill: toolSkill,
lab: toolLab,