Files
AIclinicalresearch/docs/03-业务模块/IIT Manager Agent/00-系统设计/IIT Manager Agent V2.6 智能化升级方案:双脑架构.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

167 lines
7.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.6 智能化升级方案:双脑架构**
**背景:** 响应产品经理关于“系统不够智能、交互僵硬”的反馈。
**核心目标:** 在保留 V2.5 **SOP 严谨性**(左脑)的基础上,引入 **ReAct 灵活性**(右脑),打造“懂人话”的智能助手。
**适用对象:** 2人高效开发团队
## **1\. 核心理念:为什么我们需要“两个大脑”?**
我们之前的架构V2.5)构建了一个完美的\*\*“左脑”**(逻辑、规则、流程),现在我们需要补上**“右脑”\*\*(直觉、推理、对话)。
| 维度 | 左脑 (SOP 状态机) \- V2.5 | 右脑 (ReAct Agent) \- V2.6 新增 |
| :---- | :---- | :---- |
| **擅长** | 执行标准流程、合规检查、填报表 | 处理模糊提问、多步查询、综合分析 |
| **典型指令** | "对 P001 进行入排质控" | "帮我查下最近那个发烧的病人是谁?" |
| **思维方式** | **线性执行** (Step 1 \-\> Step 2\) | **循环推理** (思考 \-\> 查库 \-\> 发现不够 \-\> 再查) |
| **安全性** | 极高 (写操作必须走这里) | **只读 (Read-Only)**,严禁直接修改数据 |
| **用户评价** | "靠谱但死板" | "聪明但不可控" |
**解决方案:**
我们不是要推翻 V2.5,而是要在它旁边挂载一个 **ReAct Agent**,并通过一个智能的 **意图路由器 (Router)** 来决定用哪个脑子。
## **2\. 架构升级:双脑路由模型 (The Dual-Brain Architecture)**
我们在 ChatService 中引入一个由 LLM 驱动的**意图识别层**。
graph TD
User\[用户输入: "那个发烧的病人..."\] \--\> Router\[🧠 意图路由层 (LLM)\]
Router \--\>|意图: 模糊查询/分析| ReAct\[🎨 右脑: ReAct Agent\]
Router \--\>|意图: 标准作业/写操作| SOP\[📐 左脑: SOP Engine\]
Router \--\>|意图: 信息缺失| AskBack\[❓ 追问机制\]
subgraph "共享工具池 (ToolsService)"
T1\[read\_clinical\_data\]
T2\[search\_protocol\]
T3\[get\_project\_stats\]
end
ReAct \--\>|调用 (只读)| T1
ReAct \--\>|调用 (只读)| T2
SOP \--\>|调用 (读写)| T1
SOP \--\>|调用 (读写)| T3
## **3\. 关键组件实现 (Phase 5\)**
### **3.1 智能意图路由 (The Router)**
不要用正则表达式,直接用 LLM 判断用户想干什么。
// backend/src/modules/iit-manager/services/IntentService.ts
export class IntentService {
async detect(message: string, history: any\[\]): Promise\<IntentResult\> {
const prompt \= \`
你是一个临床研究助手的"分诊台"。请分析用户输入,返回 JSON。
用户输入: "${message}"
分类标准:
1\. QC\_TASK: 明确的质控、检查、录入指令(如"检查P001")。
2\. QA\_QUERY: 模糊的查询、分析、统计问题(如"查下那个发烧的...")。
3\. UNCLEAR: 指代不清,缺少关键信息(如"他怎么样了?")。
返回格式: { "type": "QC\_TASK" | "QA\_QUERY" | "UNCLEAR", "reason": "...", "missing\_info": "..." }
\`;
const result \= await this.llm.chat(prompt);
return JSON.parse(result);
}
}
### **3.2 右脑ReAct Agent (The Smart Loop)**
PM 提到的 ReAct 是对的。我们需要一个循环,让 AI 自己决定调什么工具,调几次。
**核心逻辑:**
1. **思考**:用户问“最近入组的女性患者平均年龄”,我需要先查最近入组名单,再查她们的年龄,最后计算。
2. **行动**:调用 read\_clinical\_data(filter="recent")。
3. **观察**:拿到 5 个患者数据。
4. **思考**:数据有了,我自己算一下平均值。
5. **回答**35.5岁。
// backend/src/modules/iit-manager/engines/ReActEngine.ts
export class ReActEngine {
constructor(private tools: ToolsService) {}
async run(query: string, context: any) {
let messages \= \[
{ role: 'system', content: \`你是一个智能助手。你可以使用工具回答问题。请使用 ReAct 模式思考。\` },
{ role: 'user', content: query }
\];
// 最多思考 5 轮,防止死循环费钱
for (let i \= 0; i \< 5; i++) {
const response \= await this.llm.chat(messages, { tools: this.tools.getDefinitions() });
// 1\. AI 决定结束
if (\!response.hasToolCall) return response.content;
// 2\. AI 决定调工具
const toolResult \= await this.tools.execute(response.toolName, response.args);
// 3\. 把结果喂回去
messages.push({ role: 'tool', content: JSON.stringify(toolResult) });
}
}
}
### **3.3 追问机制 (Clarification)**
这是解决“像个傻子”的关键。如果意图识别是 UNCLEAR不要报错要追问。
* **User**: "他怎么样了?"
* **Old Agent**: "未找到指令。" (傻子)
* **New Agent**: "请问您指的是哪位患者?是刚刚讨论的 P001 吗?" (智能)
**实现**
在 ChatService 中,如果 IntentService 返回 UNCLEAR直接把 missing\_info 包装成反问句返回给用户。
## **4\. 融合后的开发计划更新 (Merge into V2.5)**
我们将 PM 的建议整合进开发计划,作为 **Week 4+ 的核心任务**
### **Phase 5智能化增强 (Smart Layer) \- 新增**
| 时间 | 任务 | 说明 |
| :---- | :---- | :---- |
| **Day 22** | **意图识别路由** | 实现 IntentService替代 Keyword 匹配。 |
| **Day 23** | **ReAct 引擎实现** | 实现多轮思考循环,对接 ToolsService复用现有工具。 |
| **Day 24** | **上下文记忆增强** | 升级 SessionMemory支持由近及远的对话历史回溯。 |
| **Day 25** | **主动追问 UI** | 前端支持“建议气泡”Suggestion Chips方便用户点击回复追问。 |
## **5\. 风险控制:给 ReAct 戴上镣铐**
为了防止 PM 担心的“太灵活导致不可控”,我们需要加两条铁律:
1. **右脑ReAct只读不写**
* ReAct Agent 只能调用 read\_\* 和 search\_\* 类工具。
* 如果它想修改数据(如 update\_record必须引导用户“看来你需要修改数据这属于质控流程请确认是否启动【修改 SOP】
* **原因**:避免 AI 在聊天中随口把临床数据改了,这是合规红线。
2. **幻觉熔断**
* ReAct 循环中,如果连续 2 次调用工具报错,强制终止并转人工。
* 避免 AI 在那里自言自语浪费 Token。
## **6\. 结论**
**你是对的PM 也是对的。**
* **V2.5 (SOP)** 是我们的**骨架**,保证我们站得稳(合规、准确)。
* **PM 建议 (ReAct)** 是我们的**血肉**,让我们看起来像个人(灵活、智能)。
**最终策略:**
继续执行 V2.5 的前 3 周计划(那是基础)。
**Week 4**,原本计划做“视觉识别”,现在建议**替换为“智能化增强ReAct \+ 意图路由)”**。
* 理由:视觉识别是锦上添花,而“不被当成傻子”是用户留存的关键。
**行动:** 请批准将“视觉识别”延后,优先开发“双脑路由”模块。