Files
api_health/agent/bots/bot-escort/task.js
T
lik 50e7e7b0c7 feat(agent): 接入本人数据查询工具,补齐会话清理、历史裁剪与输出护栏
- bot-escort 注入 health_profile / employee / employee_review 查询,均绑定登录用户,只返回本人数据

- bot-escort 移除 hospital-info 子代理:机构信息属公共数据,改走 web 检索

- bot-escort-admin 补 employee / employee_review 管理端查询

- clear 指令单独回执,避免客户端只等到 end 帧无法区分是否已清空

- 温度与历史上限改为可配置(bot 临时对象由 task.js 传入),默认咨询端 0.3、管理端 0

- 用户资料指纹变化时重建 agent,避免继续用旧姓名/手机号/地址作答

- 流式输出接 guard 护栏,tool 结果入历史前截断
2026-11-01 11:42:40 +08:00

47 lines
1.2 KiB
JavaScript

import EscortAgent from "./agent.js";
class ChatTask {
constructor(options = {}) {
this.options = {
modelProvider: options.modelProvider || "deepseek",
apiKey: options.apiKey,
baseURL: options.baseURL,
modelName: options.modelName,
temperature: options.temperature ?? 0.3,
maxIterations: options.maxIterations || 10,
};
this.agents = new Map();
this.maxAgents = options.maxAgents || 100;
}
async streamChat(userInfo, message, callback) {
const userId = userInfo?._id;
let agent = this.agents.get(userId);
if (agent) {
// LRU:重新插入以更新使用顺序
this.agents.delete(userId);
} else {
agent = new EscortAgent({
temperature: this.options.temperature,
maxHistoryChars: this.options.maxHistoryChars,
});
}
this.agents.set(userId, agent);
// 超出上限时淘汰最久未使用的 Agent,避免内存泄漏
if (this.agents.size > this.maxAgents) {
const oldest = this.agents.keys().next().value;
this.agents.delete(oldest);
}
return agent.streamChat(userInfo, [message], callback);
}
}
const chatTask = new ChatTask();
export { ChatTask, chatTask };
export default chatTask;