feat(iit): Complete CRA Agent V3.0 P1 - ChatOrchestrator with LLM Function Calling

P1 Architecture: Lightweight ReAct (Function Calling loop, max 3 rounds)

Core changes:
- Add ToolDefinition/ToolCall types to LLM adapters (DeepSeek + CloseAI + Claude)
- Replace 6 old tools with 4 semantic tools: read_report, look_up_data, check_quality, search_knowledge
- Create ChatOrchestrator (~160 lines) replacing ChatService (1,442 lines)
- Wire WechatCallbackController to ChatOrchestrator, deprecate ChatService
- Fix nullable content (string | null) across 12+ LLM consumer files

E2E test results: 8/8 scenarios passed (100%)
- QC report query, critical issues, patient data, trend, on-demand QC
- Knowledge base search, project overview, data modification refusal

Net code reduction: ~1,100 lines
Tested: E2E P1 chat test 8/8 passed with DeepSeek API

Made-with: Cursor
This commit is contained in:
2026-02-26 14:27:09 +08:00
parent 203846968c
commit 7c3cc12b2e
32 changed files with 903 additions and 337 deletions

View File

@@ -3,8 +3,9 @@
> **文档版本:** v3.0
> **创建日期:** 2026-01-01
> **维护者:** IIT Manager开发团队
> **最后更新:** 2026-02-25 **CRA Agent V3.0 开发计划定稿**
> **最后更新:** 2026-02-26 **CRA Agent V3.0 P0 + P1 开发完成**
> **重大里程碑:**
> - **2026-02-26CRA Agent V3.0 P0+P1 全部完成!** 自驱动质控流水线 + ChatOrchestrator + LLM Function Calling + E2E 54/54 通过
> - **2026-02-25CRA Agent V3.0 开发计划定稿**(替代 CRA 定位 + 报告驱动架构 + 4 语义化工具 + 统一驾驶舱)
> - ✅ 2026-02-08事件级质控架构 V3.1 完成record+event 独立质控 + 规则动态过滤 + 报告去重)
> - ✅ 2026-02-08质控驾驶舱 UI 开发完成(驾驶舱页面 + 热力图 + 详情抽屉)
@@ -51,24 +52,47 @@ CRA Agent 是一个**替代 CRA 岗位的自主 AI Agent**,而非辅助 CRA
- AI能力DeepSeek/Qwen + 自研 RAGpgvector+ LLM Tool Use
### 当前状态
- **开发阶段****V3.0 开发计划已定稿,准备进入 P0 开发**
- **已完成的基础设施**(可复用
- HardRuleEngine (478行) + SoftRuleEngine (488行) + SkillRunner (756行)
- RedcapAdapter (1363行) + QcReportService (980行) + ToolsService (731行)
- 时质控 Webhook + 质控驾驶舱 UI + 18 张数据库表
- 企业微信推送 + REDCap 生产环境
- **待重构**ChatService (1442行关键词路由) → ChatOrchestrator + 4 Tool Use
- **代码规模**:后端 ~15,000+ 行 / 61 个文件 / 18 张表iit_schema
- **开发阶段****V3.0 P0 + P1 已完成E2E 测试 54/54 通过**
- **P0 已完成**(自驱动质控流水线
- 变量清单导入 + 可视化
- 规则配置增强4 类规则 + AI 辅助建议)
- 时质控 + 报告生成 + eQuery 闭环 + 重大事件归档
- 统一质控驾驶舱(健康分 + 趋势图 + 风险热力图)+ AI Stream Timeline
- **P1 已完成**(对话层 Tool Use 改造):
- LLM Adapter 原生 Function CallingDeepSeek / GPT-5 / Claude-4.5
- 4 语义化工具:`read_report` / `look_up_data` / `check_quality` / `search_knowledge`
- ChatOrchestrator 轻量 ReActmax 3 轮 Function Calling loop
- ChatService (1,442行) 已废弃,替换为 ChatOrchestrator (~160行)
- **待开发**P1-2 对话体验优化 / P2 可选功能
- **代码规模**:后端 ~14,000+ 行(净减 ~1,100 行)/ 20 张表iit_schema
#### ✅ 已完成功能(基础设施)
- ✅ 数据库Schema创建iit_schema9个表 = 原5个 + 新增4个质控表
- ✅ Prisma Schema编写扩展至 ~350 行类型定义)
- ✅ 数据库Schema创建iit_schema20个表 = 原5个 + 4质控表 + 2新增(equery/critical_events) + 9其他
- ✅ Prisma Schema编写扩展至 ~400 行类型定义)
- ✅ 企业微信应用注册和配置
-**REDCap 生产环境部署完成**ECS + RDS + HTTPS
-**REDCap实时集成完成**DET + REST API
-**企业微信推送服务完成**WechatService
-**端到端测试通过**REDCap → Node.js → 企业微信)
-**AI对话集成完成**ChatService + SessionMemory
-~~AI对话集成完成ChatService + SessionMemory~~ → 已替换为 ChatOrchestrator
#### ✅ 已完成功能P0 自驱动质控流水线 - 2026-02-26
-**变量清单导入**REDCap Data Dictionary → iit_field_metadata
-**规则配置增强**4 类规则 + AI 辅助建议 + 变量关联)
-**定时质控调度**pg-boss cron + DailyQcOrchestrator
-**eQuery 闭环**open → responded → ai_reviewing → resolved/reopened
-**重大事件归档**SAE + 方案偏离自动归档 iit_critical_events
-**统一驾驶舱**(健康分 + 趋势图 + 风险热力图 + 核心指标卡片)
-**AI Stream Timeline**Agent 工作时间线可视化)
-**P0 E2E 测试 46/46 通过**
#### ✅ 已完成功能P1 对话层 Tool Use 改造 - 2026-02-26
-**LLM Adapter Function Calling**types.ts + DeepSeekAdapter + CloseAIAdapter
-**4 语义化工具**read_report / look_up_data / check_quality / search_knowledge
-**ChatOrchestrator**(轻量 ReActmax 3 轮 Function Calling loop~160 行)
-**ChatService 废弃**1,442 行 → ChatService.deprecated.ts
-**WechatCallbackController 接线**(入口切换为 ChatOrchestrator
-**P1 E2E 测试 8/8 通过**8 个真实对话场景 + DeepSeek API
#### ✅ 已完成功能(实时质控系统 - 2026-02-07
-**质控数据库表**iit_qc_logs + iit_record_summary + iit_qc_project_stats + iit_field_metadata