fix(agent): 放宽出诊清单输出与历史工具结果保留长度

输出上限支持按端配置并放宽到 escort 3000 / admin 5000;医院与网页类工具结果入历史保留 3000 字,数据库类维持 300 字,避免出诊信息被截断或追问时丢失。
This commit is contained in:
lik
2026-11-19 19:47:58 +08:00
parent b08a4b8e1b
commit 59022dc5dd
7 changed files with 86 additions and 12 deletions
+12 -3
View File
@@ -1,7 +1,7 @@
import { test } from "node:test";
import assert from "node:assert/strict";
import { OutputGuard, OUTPUT_MAX_CHARS } from "../agent/infra/guard.js";
import { OutputGuard, OUTPUT_MAX_CHARS, resolveOutputMaxChars } from "../agent/infra/guard.js";
// 按服务端聚合方式跑完一整条流,返回最终下发给客户端的文本
function runStream(chunks, options) {
@@ -58,6 +58,15 @@ test("没有句末可切时按上限硬切", () => {
});
test("两类 agent 的默认上限符合预期", () => {
assert.equal(OUTPUT_MAX_CHARS.escort, 400);
assert.equal(OUTPUT_MAX_CHARS.admin, 1800);
assert.equal(OUTPUT_MAX_CHARS.escort, 3000);
assert.equal(OUTPUT_MAX_CHARS.admin, 5000);
});
test("输出上限支持数字与按端配置,非法值回落到默认", () => {
assert.equal(resolveOutputMaxChars({ escort: 1200, admin: 2400 }, "escort", 3000), 1200);
assert.equal(resolveOutputMaxChars({ escort: 1200, admin: 2400 }, "admin", 5000), 2400);
assert.equal(resolveOutputMaxChars(2000, "admin", 5000), 2000);
assert.equal(resolveOutputMaxChars(undefined, "escort", 3000), 3000);
assert.equal(resolveOutputMaxChars({ escort: 0 }, "escort", 3000), 3000);
assert.equal(resolveOutputMaxChars({ admin: "bad" }, "admin", 5000), 5000);
});
+24
View File
@@ -13,6 +13,11 @@ import {
applyBaiduAuthorization,
buildRequestUrl,
} from "../agent/infra/tools/web/http_get.js";
import {
appendToolMessage,
TOOL_RESULT_MAX_CHARS,
LARGE_TOOL_RESULT_MAX_CHARS,
} from "../agent/infra/history.js";
test("订单状态机只允许正向流转", () => {
assert.equal(canTransition("pending", "confirmed"), true);
@@ -162,3 +167,22 @@ test("状态机表覆盖全部订单状态", () => {
["cancelled", "none", "requested"]
);
});
test("历史中医院/网页结果保留更长开头,数据库结果维持短截断", () => {
// 2000 字:数据库类仍截到 300,医院/网页类完整保留(原上限 300 会丢失出诊清单后半段)
const medium = "医".repeat(2000);
const dbStored = appendToolMessage([], { name: "escort_record_query", content: medium });
assert.equal(dbStored.content.slice(0, TOOL_RESULT_MAX_CHARS), medium.slice(0, TOOL_RESULT_MAX_CHARS));
assert.ok(dbStored.content.includes("已截断"));
for (const name of ["hospital_knowledge_read", "web_fetch"]) {
const stored = appendToolMessage([], { name, content: medium });
assert.equal(stored.content, medium);
}
// 超长内容:医院/网页类截到 3000,而不是 300
const long = "医".repeat(5000);
const largeStored = appendToolMessage([], { name: "hospital_knowledge_read", content: long });
assert.equal(largeStored.content.slice(0, LARGE_TOOL_RESULT_MAX_CHARS), long.slice(0, LARGE_TOOL_RESULT_MAX_CHARS));
assert.ok(largeStored.content.includes("已截断"));
});