feat: Agent 工具日志结构化描述
工具结果与 custom 流事件改用 describeToolResult/describeStreamPayload 输出摘要,替代截断 200 字符的原始内容;thread_id 取 userInfo._id
This commit is contained in:
@@ -0,0 +1,61 @@
|
||||
import { test } from "node:test";
|
||||
import assert from "node:assert/strict";
|
||||
|
||||
import { describeToolResult, describeStreamPayload } from "../agent/infra/tool_log.js";
|
||||
|
||||
test("工具结果日志只保留长度与 success,不落患者信息", () => {
|
||||
const content = JSON.stringify({
|
||||
success: true,
|
||||
data: {
|
||||
patient: { name: "张三", mobile: "13800138000" },
|
||||
address: "北京市东城区某小区 1 号楼",
|
||||
},
|
||||
});
|
||||
|
||||
const summary = describeToolResult(content);
|
||||
assert.deepEqual(summary, { chars: content.length, success: true });
|
||||
|
||||
const logged = JSON.stringify(summary);
|
||||
assert.equal(logged.includes("张三"), false);
|
||||
assert.equal(logged.includes("13800138000"), false);
|
||||
assert.equal(logged.includes("北京市"), false);
|
||||
});
|
||||
|
||||
test("工具失败只记录 errorCode,不记录可能带姓名的错误文案", () => {
|
||||
const content = JSON.stringify({
|
||||
success: false,
|
||||
error: "未找到患者张三的订单",
|
||||
errorCode: "NOT_FOUND",
|
||||
});
|
||||
|
||||
const summary = describeToolResult(content);
|
||||
assert.deepEqual(summary, {
|
||||
chars: content.length,
|
||||
success: false,
|
||||
errorCode: "NOT_FOUND",
|
||||
});
|
||||
assert.equal(JSON.stringify(summary).includes("张三"), false);
|
||||
});
|
||||
|
||||
test("纯文本或截断后的工具结果只记录长度", () => {
|
||||
assert.deepEqual(describeToolResult("患者张三,手机号 13800138000"), {
|
||||
chars: 20,
|
||||
});
|
||||
assert.deepEqual(describeToolResult(""), { chars: 0 });
|
||||
});
|
||||
|
||||
test("custom 流事件只记录类型/字段名,不记录字段值", () => {
|
||||
const summary = describeStreamPayload({
|
||||
type: "progress",
|
||||
content: "正在读取张三的健康档案",
|
||||
});
|
||||
|
||||
assert.deepEqual(summary, {
|
||||
type: "object",
|
||||
keys: ["type", "content"],
|
||||
});
|
||||
assert.equal(JSON.stringify(summary).includes("张三"), false);
|
||||
|
||||
assert.deepEqual(describeStreamPayload("张三的订单"), { type: "string", chars: 5 });
|
||||
assert.deepEqual(describeStreamPayload([1, 2, 3]), { type: "array", items: 3 });
|
||||
});
|
||||
Reference in New Issue
Block a user