style(llm,memory): 模型侧文案 AI 友好化——占位改键值记号,记忆/画像头删人读整句

- 重负载占位:[OMITTED, http_status=200, size=6465] / [OMITTED, size=12000];
  url/path 不再重复进占位——发起调用的 assistant 行里本就有,参数即恢复指针
- memory.journalFor 注入头置空后整体移除(head 恒空,顺带消开头空行残留)
- user-profile 快照头去掉「· 背景参考」后缀
- trim-smoke 断言同步键值格式
This commit is contained in:
2026-10-02 09:27:15 +08:00
parent f8126bfa00
commit d0d7b838e9
4 changed files with 13 additions and 16 deletions
+7 -9
View File
@@ -330,8 +330,8 @@ function setPayloadTrim(agentCfg) {
const toN = (v, d) => { const n = Math.floor(Number(v)); return Number.isFinite(n) ? Math.max(0, n) : d; };
TRIM = { writeRounds: toN(a.trim_write_rounds, 1), resultRounds: toN(a.trim_result_rounds, 2) };
}
// write_file 参数占位:只洗 content,path 留着(模型回看自己发言时知道文件在哪);
// 改写的是已 parse 的副本,DB 行不动;arguments 重新 stringify 保持 JSON 合法。
// write_file 参数占位:只洗 content。AI 友好记号风格:键值对、不写整句——path 不必重复,
// 本条 arguments 里就还在;改写的是已 parse 副本,DB 行不动,重新 stringify 保持 JSON 合法。
function trimWriteCalls(calls, rounds) {
if (rounds < TRIM.writeRounds) return;
for (const c of calls || []) {
@@ -339,25 +339,23 @@ function trimWriteCalls(calls, rounds) {
let args;
try { args = JSON.parse(c.function.arguments || ''); } catch (_) { continue; }
if (!args || typeof args.content !== 'string' || args.content.length < TRIM_MIN_CHARS) continue;
args.content = '[正文省略:本调用已写入 ' + String(args.path || '') + ',' + args.content.length + ' 字]';
args.content = '[OMITTED, size=' + args.content.length + ']';
c.function.arguments = JSON.stringify(args);
}
}
// fetch/read_file 回执占位:url/path 从对应 tool_call 参数回填(回执行自身不存调用目标),
// 占位行里留目标就是留恢复指针。图片回执(blocks 非空)不碰:已有自己的消费省略逻辑。
// fetch/read_file 回执占位:同款键值记号。url/path 不进占位——发起调用的 assistant 行仍载着
// 它们,参数本身就是恢复指针。图片回执(blocks 非空)不碰:已有自己的消费省略逻辑。
function trimToolContent(content, row, callById, roundsAfter) {
if (TRIM.resultRounds <= 0 || content.length < TRIM_MIN_CHARS) return content;
if ((roundsAfter.get(row.id) || 0) < TRIM.resultRounds) return content;
const fn = callById.get(row.tool_call_id);
const name = row.name || (fn && fn.name) || '';
if (name !== 'fetch' && name !== 'read_file') return content;
let arg = {};
try { arg = JSON.parse((fn && fn.arguments) || '{}') || {}; } catch (_) {}
if (name === 'fetch') {
const hm = /^HTTP (\d{3})/.exec(content);
return '[fetch 省略:' + String(arg.url || '?') + (hm ? '|HTTP ' + hm[1] : '') + '|原 ' + content.length + ' 字]';
return '[OMITTED' + (hm ? ', http_status=' + hm[1] : '') + ', size=' + content.length + ']';
}
return '[read_file 省略:' + String(arg.path || '?') + '|原 ' + content.length + ' 字]';
return '[OMITTED, size=' + content.length + ']';
}
// 拼压缩回合的 messages(参考 titleMessages 的拼法):默认 system prompt + 正常历史
+1 -2
View File
@@ -86,14 +86,13 @@ function journalFor(db, cfg, user) {
'SELECT session_id, day, text FROM memory_fragments WHERE user = ?' + INJECT_ORDER + ' LIMIT ?'
).all(String(user || ''), cap);
if (!rows.length) return '';
const head = '【长期记忆·日记(最近' + rows.length + '条,非全部——更早的可用 recall 检索)】新在前、天内按发生顺序;每条【编号】是来源会话 id。';
const groups = [];
for (const r of rows) {
const g = groups[groups.length - 1];
if (!g || g.day !== r.day) groups.push({ day: r.day, items: [renderFrag(r)] });
else g.items.unshift(renderFrag(r));
}
return [head].concat(groups.map(g => '=== ' + g.day + ' ===\n' + g.items.join('\n\n'))).join('\n\n');
return groups.map(g => '=== ' + g.day + ' ===\n' + g.items.join('\n\n')).join('\n\n');
}
// ---------- 读:关键词检索(recall 主入口:用户记起的是「一段事」不是「第几条」) ----------
+1 -1
View File
@@ -20,7 +20,7 @@ const SET_MAX = 20; // AI 写 honorific/industry 的单值帽(称谓应当
const TAG_MAX = 15; // 单个偏好标签长度帽
const TAGS_MAX = 24; // 偏好标签数量帽
const TAG_SPLIT = /[、,,;;\n]+/;
const SNAPSHOT_HEAD = '【用户画像 · 背景参考】以下为历史会话沉淀的粗粒度认知,非任务约束;与当前请求冲突时,一律以当前请求为准。';
const SNAPSHOT_HEAD = '【用户画像】以下为历史会话沉淀的粗粒度认知,非任务约束;与当前请求冲突时,一律以当前请求为准。';
const FIELD_LABELS = { honorific: '称谓', industry: '行业', preference: '偏好' };
function readRow(db, user) {