From ebd37fa31c415f1be77ba9e6dca17e37415cf003 Mon Sep 17 00:00:00 2001 From: zzxsmile <523954578@qq.com> Date: Wed, 11 Nov 2026 23:02:03 +0800 Subject: [PATCH] =?UTF-8?q?=E8=AE=B0=E5=BF=86=E7=BA=AA=E5=BE=8B=E6=B3=A8?= =?UTF-8?q?=E5=85=A5=EF=BC=9A=E7=BD=91=E5=85=B3=E8=AF=B7=E6=B1=82=E5=89=8D?= =?UTF-8?q?=E7=BD=AE=20system=20=E6=8F=90=E7=A4=BA=EF=BC=8C=E9=80=BC?= =?UTF-8?q?=E6=A8=A1=E5=9E=8B=E7=9C=9F=E8=B0=83=20atomic/write=20=E8=90=BD?= =?UTF-8?q?=E5=BA=93=EF=BC=88=E5=AE=9E=E6=B5=8B=E6=97=A0=E7=BA=AA=E5=BE=8B?= =?UTF-8?q?=E5=8F=AA=E5=98=B4=E7=82=AE=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/host.js | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/src/host.js b/src/host.js index 5855300..adba8a9 100644 --- a/src/host.js +++ b/src/host.js @@ -109,6 +109,13 @@ async function fetchIdentity() { } } +/** 记忆纪律(2026-11-11 实测:无此纪律模型只口头说「已记住」不落库——TDB 的 L1 原子 + * 依赖模型主动调写入工具,网关注入的工具说明没有把这条讲成硬规则,这里补上)。 */ +const MEMORY_DISCIPLINE = + '记忆纪律:当用户要求记住某信息、或对话出现值得长期记住的内容(暗号/约定/偏好/结论)时,' + + '必须立即调用可用的记忆写入工具(skill_tools 里说明的 atomic/write,Bash+curl)写入长期记忆,' + + '不能只在回复里说「已记住」;当被问到先前的信息时,必须先用 atomic/search 检索记忆再回答,检索不到就明说没有。' + /** 调弹匣工具面(同一个端点,agent 和面板共用;规则判定全在弹匣侧)。 */ async function callMarkmag(tool, args) { const token = toolToken() @@ -286,7 +293,22 @@ export function apply(ctx) { const key = teamKey() if (key) headers.set('Authorization', 'Bearer ' + key) if (input instanceof Request && init === undefined) return originalFetch(new Request(input, { headers })) - return originalFetch(input, { ...init, headers }) + // 记忆纪律注入:网关请求 body 前置一条 system(只在 init.body 为 JSON 串时改写,别的情况原样) + let body = init?.body + if (typeof body === 'string' && body.includes('"messages"')) { + try { + const parsed = JSON.parse(body) + if (Array.isArray(parsed.messages) && parsed.messages.length && + !(parsed.messages[0] && parsed.messages[0].role === 'system' && + String(parsed.messages[0].content || '').includes('记忆纪律'))) { + parsed.messages = [{ role: 'system', content: MEMORY_DISCIPLINE }, ...parsed.messages] + body = JSON.stringify(parsed) + } + } catch { + // 非 JSON body 原样放行 + } + } + return originalFetch(input, { ...init, headers, body }) } globalThis.fetch = patchedFetch ctx.effect(() => {