fix(agent): 图片识别原文直接回显,避免长报告被护栏截断

- 新增 WS format 帧:识别原文只并入会话上下文并分片原样回显,不再经过模型二次改写

- 原方案走 chat 会被咨询提示词压缩成 1-3 句,并被 OutputGuard 的 400 字上限截断

- 补充分片回显测试与 README 协议说明
This commit is contained in:
lik
2026-11-01 12:31:56 +08:00
parent d52ecd6536
commit 47fdb91dbe
4 changed files with 91 additions and 1 deletions
+60
View File
@@ -0,0 +1,60 @@
import { test } from "node:test";
import assert from "node:assert/strict";
import EscortAgent from "../agent/bots/bot-escort/agent.js";
// 一份超过护栏 400 字上限的识别原文:用来确认回显分支不再截断长报告
const IMAGE_TEXT = [
"【图像识别】检验报告|血常规",
"",
"【原文转写】",
"",
"白细胞计数 WBC 6.2 10^9/L 3.5-9.5".repeat(30),
"",
"【说明】本内容为图像文字识别结果,不构成诊断意见。",
].join("\n");
test("图片识别原文完整回显,不经过模型与输出护栏", async () => {
const agent = new EscortAgent();
const chunks = [];
await agent.streamChat(
{ _id: "test-user", profile: {}, location: {} },
[{
type: "format",
ts: "2026-11-01 10:00:00",
content: IMAGE_TEXT,
id: "req_format",
}],
(source, type, content, id) => {
chunks.push({ source, type, content, id });
}
);
// 分片回显,拼接后必须与原文完全一致:长报告不能被字符上限截断
assert.ok(chunks.length > 1);
assert.equal(chunks.map(item => item.content).join(""), IMAGE_TEXT);
assert.deepEqual(new Set(chunks.map(item => item.id)), new Set(["req_format"]));
assert.deepEqual(new Set(chunks.map(item => item.source)), new Set(["main"]));
assert.deepEqual(new Set(chunks.map(item => item.type)), new Set(["ai"]));
// 原文进历史:用户接着问「这项指标什么意思」时模型能看到报告内容
assert.equal(agent.messages.length, 1);
assert.match(agent.messages[0].text, /白细胞计数 WBC 6\.2/);
// 走回显分支时不构建 agent,也就不会产生模型调用
assert.equal(agent.agent, undefined);
});
test("空白识别原文不投递", async () => {
const agent = new EscortAgent();
const chunks = [];
await agent.streamChat(
{ _id: "test-user", profile: {}, location: {} },
[{ type: "format", ts: "2026-11-01 10:00:00", content: " ", id: "req_empty" }],
(source, type, content, id) => {
chunks.push({ source, type, content, id });
}
);
assert.equal(chunks.length, 0);
assert.equal(agent.messages.length, 0);
});