Files
AIclinicalresearch/docs/03-业务模块/IIT Manager Agent/05-测试文档/IIT Manager Agent V2.8:基于“周报卷叠”的终极记忆架构.md
HaHafeng 0c590854b5 docs(iit): Add IIT Manager Agent V2.9 development plan with multi-agent architecture
Features:
- Add V2.9 enhancements: Cron Skill, User Profiling, Feedback Loop, Multi-Intent Handling
- Create modular development plan documents (database, engines, services, memory, tasks)
- Add V2.5/V2.6/V2.8/V2.9 design documents for architecture evolution
- Add system design white papers and implementation guides

Architecture:
- Dual-Brain Architecture (SOP + ReAct engines)
- Three-layer memory system (Flow Log, Hot Memory, History Book)
- ProfilerService for personalized responses
- SchedulerService with Cron Skill support

Also includes:
- Frontend nginx config updates
- Backend test scripts for WeChat signature
- Database backup files

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-02-05 22:33:26 +08:00

134 lines
5.1 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# **IIT Manager Agent V2.8:基于“周报卷叠”的终极记忆架构**
**版本:** V2.8 (The Chronicle Edition)
**日期:** 2026-02-05
**核心变更:** 采纳“以周报代替向量检索”的建议。利用 LLM 的长窗口能力,通过周期性压缩数据,实现全生命周期的可读记忆。
**适用场景:** 1-3 年周期的临床研究项目。
## **1\. 核心理念:把“大数据”变成“厚书”**
我们不再试图在海量碎片数据中大海捞针Vector Search而是把数据写成一本\*\*“编年史”\*\*。
* **每日**:忠实记录流水账。
* **每周**LLM 阅读本周流水账,写一页“历史书”(周报)。
* **查询时**LLM 直接阅读整本“历史书”。
### **优势分析**
| 维度 | 向量检索 (V2.6/2.7) | 周报卷叠 (V2.8) |
| :---- | :---- | :---- |
| **准确性** | 模糊匹配,容易漏掉关键细节 | **全量阅读**,拥有上帝视角,极准 |
| **可解释性** | 黑盒向量,不知道 AI 看了啥 | **白盒周报**,医生可以随时翻阅、修正周报 |
| **技术难度** | 高 (Embedding, Vector DB) | **低** (Cron Job \+ LLM Summary) |
| **成本** | 检索便宜,但索引维护贵 | 生成周报耗 Token但查询极其高效 |
## **2\. 数据库设计 (Schema)**
### **2.1 新增 iit\_weekly\_reports 表**
model IitWeeklyReport {
id String @id @default(uuid())
projectId String
weekNumber Int // 例如: 202605 (2026年第5周)
startDate DateTime
endDate DateTime
// 核心LLM 生成的高浓缩总结
// 包含入组进度、发生的AE、关键沟通结论
summary String @db.Text
// 结构化数据 (可选,用于画图)
stats Json? // { "enrolled": 5, "queries": 2 }
createdAt DateTime @default(now())
@@unique(\[projectId, weekNumber\])
@@map("iit\_weekly\_reports")
@@schema("iit\_schema")
}
## **3\. 核心流程实现**
### **3.1 写入端:每周一凌晨的“编史官” (Cron Job)**
**SchedulerService.ts:**
// 每周一凌晨 02:00 执行
async generateWeeklyMemory(projectId: string) {
// 1\. 获取上周所有的原始对话 & 操作日志
const logs \= await this.rawLogs.get({
projectId,
from: lastMonday,
to: thisSunday
});
// 2\. 调用 LLM 进行“有损压缩”
const prompt \= \`
你是一个临床项目经理。请阅读上周的项目流水账,生成一份【周报记忆块】。
要求:
1\. 忽略闲聊和无关信息。
2\. 重点记录:入组人数变化、新增不良事件(AE)、主要方案偏离、PI的关键决策。
3\. 格式为 Markdown字数控制在 500 字以内。
流水账数据:
${JSON.stringify(logs)}
\`;
const summary \= await this.llm.chat(prompt);
// 3\. 存入数据库 (成为历史书的一页)
await prisma.iitWeeklyReport.create({
data: { projectId, summary, ... }
});
}
### **3.2 读取端:查询时的“速读” (Context Injection)**
当意图识别发现用户在问“过去”或“趋势”时,直接把**所有周报**读出来。
**ChatService.ts:**
async buildHistoryContext(projectId: string): Promise\<string\> {
// 1\. 取出该项目所有历史周报 (按时间正序)
// 3年也就 150 条Postgres 毫秒级返回
const reports \= await prisma.iitWeeklyReport.findMany({
where: { projectId },
orderBy: { weekNumber: 'asc' },
select: { weekNumber: true, summary: true }
});
// 2\. 拼接成一本“书”
// 格式:
// \[Week 2026-01\]: 入组 2 人,无异常。
// \[Week 2026-02\]: P003 发生 SAE已上报。
const chronicle \= reports.map(r \=\> \`\[Week ${r.weekNumber}\]: ${r.summary}\`).join('\\n');
return \`
\=== 项目编年史 (Project Chronicle) \===
${chronicle}
\====================================
\`;
}
## **4\. 最终开发计划修正 (Phase 5\)**
我们将 Week 5 的任务彻底简化:
| 时间 | 任务 | 说明 |
| :---- | :---- | :---- |
| **Day 24** | **原始日志表** | 确保 iit\_conversation\_history 记录完整。 |
| **Day 25** | **周报表结构** | 创建 iit\_weekly\_reports 表。 |
| **Day 26** | **编史官 Worker** | 写一个 Cron Job每周把 Log 压缩成 Report。 |
| **Day 27** | **记忆注入** | 在回答 QA\_QUERY 类问题时,将历史周报注入 Context。 |
## **5\. 总结:为什么这是终极方案?**
1. **解决了“上下文遗忘”**150 个周报拼接起来,刚好填满 DeepSeek 的上下文窗口。AI 可以看到**完整**的项目生命周期,这是 RAG 切片做不到的。
2. **解决了“幻觉”**:周报是持久化的,医生可以去后台检查某一周的周报写得对不对。如果 AI 瞎写,医生可以手动修正。**修正后的周报就是新的真理。**
3. **极简运维**:不需要维护向量库索引,不需要调优 Embedding 模型。就是简单的 SQL 查询和文本拼接。
**就用这个方案。这是目前为止最完美、最优雅的解决路径。**