llm: 工具回执夹图改批次后 user 合并投递 + 同回合去重护栏(线上死循环复盘)
多模态上游兼容性事故:tool 角色消息带 image_url 块是非标准形态,大量 OpenAI 兼容上游整批忽略或只认批次最后一张——模型看不到图、却见回执写着 「已回传」,加上旧催读文案「如需重读请再次 read_file」火上浇油,模型一轮轮 重读同一批图烧 token 死循环。改为: - llm.js buildMessages:未消费的 tool 回执图不塞回执内(回执降级纯文本), image_ref 现签外链后统一并入该批回执之后的一条 user 消息(user 角色各家 通吃);每张图前配一行「[图片 N,对应回执] <回执首行>」标签,模型可对号; 旧库 data: URL 块原样并入;签不到降级文字占位。顺序天然满足 assistant→ tool 紧邻配对约束(合并消息落在整段历史尾部)。 - 两处催读文案(已省略/外链不可用)改为「请告知用户、勿反复重读同一文件」。 - engine.js runLoopInner 死循环护栏:run.imgDelivered 按图 rel 去重,同回合 再读同图只回文字提示不再签新图;run 随回合销毁,新回合自动重置,正常 追问重看不受影响。 - definitions.json read_file 描述同步新形态(图在批次回执后的独立 user 消息到达;同回合重读不再带像素,勿重试)。 - ARCHITECTURE.md §5.1 图片约定、§14 陷阱 7 改写,记录本次复盘。 验证:容器内构造 history 直调 buildMessages 六场景单测全过(合并/标签/ 现签/签失败占位/已消费省略/同批多图序号/旧 data: 透传/user 行原位现签); JSON 与 node --check 通过;restart agent-core 启动干净、微信对账正常。
This commit is contained in:
+15
-2
@@ -689,8 +689,9 @@ async function runLoopInner(sessionId, run) {
|
||||
}
|
||||
}
|
||||
// 工具可返回 {text, image_rel}(read_file 读图且模型支持 vision,压缩产物在 .imgcache/):
|
||||
// 落库时以 image_ref 内容块拼进 tool 消息(哨兵 JSON,见 llm.js encodeBlocks),
|
||||
// buildMessages 发请求前现签成公网外链的 image_url 块;前端工具卡走带 cookie 的下载路由渲染。
|
||||
// 落库时以 image_ref 内容块拼进 tool 消息(哨兵 JSON,见 llm.js encodeBlocks);
|
||||
// buildMessages 发请求前把未消费的图现签成公网外链 image_url 块,并入该批回执之后的
|
||||
// 一条 user 消息发送(tool 角色带图非标准形态,上游支持度差);前端工具卡走带 cookie 的下载路由渲染。
|
||||
let outText;
|
||||
let imageRel = null;
|
||||
if (output && typeof output === 'object' && output.image_rel) {
|
||||
@@ -700,6 +701,18 @@ async function runLoopInner(sessionId, run) {
|
||||
outText = String(output == null ? '' : output);
|
||||
}
|
||||
if (run.cancelled && !isError) outText = (outText ? outText + '\n' : '') + '(用户已终止任务)';
|
||||
// 死循环护栏:同一回合内同一张图只投递一次——若上游没认图,模型会一轮轮重读同一文件、
|
||||
// 每轮都签新图烧 token;同回合再读同图只回文字提示,不再携带图片(run 随回合结束销毁,
|
||||
// 新回合/新用户消息自动重置额度,正常追问重看不受影响)。
|
||||
if (imageRel) {
|
||||
if (!run.imgDelivered) run.imgDelivered = new Set();
|
||||
if (run.imgDelivered.has(imageRel)) {
|
||||
outText += '\n[该图片本回合已投递过,不再重复携带;若你未看到它,请直接告知用户,勿反复重读同一文件]';
|
||||
imageRel = null;
|
||||
} else {
|
||||
run.imgDelivered.add(imageRel);
|
||||
}
|
||||
}
|
||||
log.debug('tool', sessionId + ' ' + tc.function.name + (isError ? ' 失败: ' : ' 完成: ') + outText);
|
||||
const toolContent = imageRel
|
||||
? encodeBlocks([
|
||||
|
||||
Reference in New Issue
Block a user