- 一院一 Markdown 档案(data/hospitals),索引与章节自动维护;读取支持 section 与 24k 截断,写入校验日期与单条长度,别名精确冲突时不新建 - 子代理按 allowWrite 分可写/只读工具集与提示词:管理端与陪诊员可写,就诊人端只读(物理移除写入工具) - 新增 scripts/import_hospitals.js 存量导入:压缩医生为一行、默认前 60 位,支持 dry-run、幂等与冲突报告,生成 112 家医院档案 - 管理端图片识别原文沿用原样回显策略,不再经模型二次整理 - npm test 212 项通过(新增知识库 12 项、导入 3 项)
52 lines
1.8 KiB
JavaScript
52 lines
1.8 KiB
JavaScript
import { tool } from "@langchain/core/tools";
|
|
import { z } from "zod";
|
|
import { hospitalKnowledgeStore, MAX_READ_CHARS } from "./store.js";
|
|
|
|
const hospitalKnowledgeReadTool = tool(
|
|
async ({ hospital, section }) => {
|
|
try {
|
|
const result = await hospitalKnowledgeStore.read(hospital, { section });
|
|
if (!result.found) {
|
|
return {
|
|
success: false,
|
|
error: result.error || `医院知识库中没有「${hospital}」的记录`,
|
|
candidates: result.candidates || [],
|
|
};
|
|
}
|
|
if (result.sectionMissing) {
|
|
return {
|
|
success: false,
|
|
error: `「${result.name}」档案中没有「${section}」章节`,
|
|
hospital: result.name,
|
|
sections: result.sections,
|
|
};
|
|
}
|
|
return {
|
|
success: true,
|
|
hospital: result.name,
|
|
aliases: result.aliases,
|
|
city: result.city,
|
|
file: result.file,
|
|
sections: result.sections,
|
|
content: result.content,
|
|
truncated: result.truncated,
|
|
note: result.note || undefined,
|
|
};
|
|
} catch (error) {
|
|
return { success: false, error: error.message };
|
|
}
|
|
},
|
|
{
|
|
name: "hospital_knowledge_read",
|
|
description:
|
|
`读取一家医院的完整知识档案(Markdown 文本)。可用医院正式名称或别名定位;未收录时返回候选医院供确认。`
|
|
+ `档案较长时用 section 只读指定章节;单次返回上限 ${MAX_READ_CHARS} 字符,超限会截断并提示按章节读取。`,
|
|
schema: z.object({
|
|
hospital: z.string().describe("医院名称或别名,例如「北京协和医院」「协和」"),
|
|
section: z.string().optional().describe("只读指定章节,例如「联系电话」「医生与排班」;不传时返回整个档案"),
|
|
}),
|
|
},
|
|
);
|
|
|
|
export { hospitalKnowledgeReadTool };
|