Sprint 1-3 Completed (Backend + Frontend): Backend (Sprint 1-2): - Implement 5-layer Agent framework (Query->Planner->Executor->Tools->Reflection) - Create agent_schema with 6 tables (agent_definitions, stages, prompts, sessions, traces, reflexion_rules) - Create protocol_schema with 2 tables (protocol_contexts, protocol_generations) - Implement Protocol Agent core services (Orchestrator, ContextService, PromptBuilder) - Integrate LLM service adapter (DeepSeek/Qwen/GPT-5/Claude) - 6 API endpoints with full authentication - 10/10 API tests passed Frontend (Sprint 3): - Add Protocol Agent entry in AgentHub (indigo theme card) - Implement ProtocolAgentPage with 3-column layout - Collapsible sidebar (Gemini style, 48px <-> 280px) - StatePanel with 5 stage cards (scientific_question, pico, study_design, sample_size, endpoints) - ChatArea with sync button and action cards integration - 100% prototype design restoration (608 lines CSS) - Detailed endpoints structure: baseline, exposure, outcomes, confounders Features: - 5-stage dialogue flow for research protocol design - Conversation-driven interaction with sync-to-protocol button - Real-time context state management - One-click protocol generation button (UI ready, backend pending) Database: - agent_schema: 6 tables for reusable Agent framework - protocol_schema: 2 tables for Protocol Agent - Seed data: 1 agent + 5 stages + 9 prompts + 4 reflexion rules Code Stats: - Backend: 13 files, 4338 lines - Frontend: 14 files, 2071 lines - Total: 27 files, 6409 lines Status: MVP core functionality completed, pending frontend-backend integration testing Next: Sprint 4 - One-click protocol generation + Word export
184 lines
8.2 KiB
Markdown
184 lines
8.2 KiB
Markdown
# Protocol Agent 开发计划总览
|
||
|
||
> 版本:v1.0
|
||
> 创建日期:2026-01-24
|
||
> 状态:待开发
|
||
|
||
---
|
||
|
||
## 一、项目背景
|
||
|
||
Protocol Agent(研究方案制定助手)是AIA模块的第13个智能体入口,旨在通过多轮对话引导用户完成临床研究方案的核心要素制定。
|
||
|
||
### 1.1 核心价值
|
||
|
||
- **统一入口**:整合样本量计算、PICO提取等7个工具的能力
|
||
- **长期记忆**:ProtocolContext持久化存储研究方案要素
|
||
- **专业引导**:基于临床研究方法学的思维链引导
|
||
- **平台基础**:为后续统计分析Agent、数据清洗Agent等提供可复用框架
|
||
|
||
### 1.2 设计哲学
|
||
|
||
```
|
||
Code as Skeleton, Data as Brain
|
||
代码是骨架(确定性流程),数据是大脑(灵活配置)
|
||
```
|
||
|
||
---
|
||
|
||
## 二、决策确认记录
|
||
|
||
| 决策项 | 选择 | 说明 |
|
||
|--------|------|------|
|
||
| **入口方式** | B - 第13个入口 | Protocol Agent作为独立入口,12个现有智能体保留 |
|
||
| **状态流转** | **对话驱动** | 用户在对话中说"继续"或点击"同步"按钮,自然推进阶段 |
|
||
| **数据同步** | **内嵌同步按钮** | AI整理好数据后,在回复中显示"同步到方案"按钮 |
|
||
| **Action Card** | B - 规则触发 | 基于阶段和条件规则触发,非LLM决定 |
|
||
| **Reflexion** | B - Prompt-based | 使用Prompt模板进行质量检查(P2优先级) |
|
||
| **MVP范围** | 渐进式演进 | Phase 1聚焦核心流程,后续迭代增强 |
|
||
| **阶段数量** | **5个阶段** | 科学问题→PICO→研究设计→样本量→观察指标 |
|
||
| **完成功能** | **一键生成** | 5阶段完成后,支持一键生成研究方案并下载Word |
|
||
|
||
---
|
||
|
||
## 三、文档索引
|
||
|
||
本开发计划包含以下文档:
|
||
|
||
| 序号 | 文档名称 | 内容说明 |
|
||
|------|----------|----------|
|
||
| 00 | 开发计划总览.md | 本文档,项目概述与决策记录 |
|
||
| 01 | 架构设计.md | 五层Agent架构、组件职责、执行流程 |
|
||
| 02 | 数据库设计.md | 完整Prisma Schema定义 |
|
||
| 03 | 代码结构设计.md | 目录结构、核心接口、类型定义 |
|
||
| 04 | 分阶段实施计划.md | Sprint划分、任务列表、里程碑 |
|
||
|
||
---
|
||
|
||
## 四、核心架构概览
|
||
|
||
### 4.1 核心交互模式:对话驱动
|
||
|
||
```
|
||
┌─────────────────────────────────────────────────────────────────────────┐
|
||
│ 对话驱动交互模式 │
|
||
├─────────────────────────────────────────────────────────────────────────┤
|
||
│ │
|
||
│ 【用户与AI对话】 │
|
||
│ ↓ │
|
||
│ 【AI收集信息,整理数据】 │
|
||
│ ↓ │
|
||
│ 【AI回复中显示 "✅ 同步到方案" 按钮】 │
|
||
│ ↓ │
|
||
│ 【用户点击同步】→ 数据写入Context → State Panel更新 │
|
||
│ ↓ │
|
||
│ 【AI询问:继续下一阶段吗?】 │
|
||
│ ↓ │
|
||
│ 【用户说"继续"】→ AI识别意图 → 自动进入下一阶段 │
|
||
│ │
|
||
└─────────────────────────────────────────────────────────────────────────┘
|
||
```
|
||
|
||
### 4.2 五层架构
|
||
|
||
```
|
||
┌─────────────────────────────────────────────────────────┐
|
||
│ 1. Query Layer 意图识别、实体提取、上下文消歧 │
|
||
├─────────────────────────────────────────────────────────┤
|
||
│ 2. Planner Layer 状态机、策略选择、任务分解 │
|
||
├─────────────────────────────────────────────────────────┤
|
||
│ 3. Executor Layer LLM调用、工具调用、响应构建 │
|
||
├─────────────────────────────────────────────────────────┤
|
||
│ 4. Tools Layer 内部工具、外部工具、RAG、Deep Link │
|
||
├─────────────────────────────────────────────────────────┤
|
||
│ 5. Reflection Layer 质量检查、一致性校验、恢复处理 │
|
||
└─────────────────────────────────────────────────────────┘
|
||
```
|
||
|
||
### 4.3 三层职责划分
|
||
|
||
| 层次 | 职责 | 实现方式 |
|
||
|------|------|----------|
|
||
| **代码层** | 状态流转、数据存储、API调用、错误处理 | TypeScript代码 |
|
||
| **Prompt层** | 意图识别、对话生成、信息提取、质量检查 | Prompt模板 + LLM |
|
||
| **工具层** | Deep Link、外部API、知识库检索 | 工具注册 + 调用 |
|
||
|
||
---
|
||
|
||
## 五、阶段规划
|
||
|
||
### Phase 1:MVP完整功能(4周)
|
||
|
||
**目标**:完成Agent框架 + 5阶段对话 + 一键生成研究方案
|
||
|
||
- ✅ 通用Agent框架搭建
|
||
- ✅ 5个核心阶段(科学问题→PICO→研究设计→样本量→观察指标)
|
||
- ✅ 对话驱动 + 同步按钮交互模式
|
||
- ✅ ProtocolContext持久化
|
||
- ✅ State Panel前端展示
|
||
- ✅ **一键生成研究方案**
|
||
- ✅ **Word文档导出**
|
||
|
||
### Phase 2:知识增强(3周)
|
||
|
||
**目标**:集成专家知识库,提升专业深度
|
||
|
||
- 🔲 EKB知识库建设
|
||
- 🔲 RAG检索集成
|
||
- 🔲 Function Calling工具调用
|
||
- 🔲 高级Reflexion质量检查
|
||
|
||
### Phase 3:平台化(2周)
|
||
|
||
**目标**:配置化、可观测性、多Agent支持
|
||
|
||
- 🔲 后台配置管理界面
|
||
- 🔲 Prompt在线调试
|
||
- 🔲 完整Trace分析
|
||
- 🔲 统计分析Agent接入准备
|
||
|
||
---
|
||
|
||
## 六、技术栈
|
||
|
||
| 类别 | 技术选型 | 说明 |
|
||
|------|----------|------|
|
||
| **后端框架** | Fastify v4 + TypeScript | 现有架构 |
|
||
| **数据库** | PostgreSQL 15 + Prisma 6 | 现有架构 |
|
||
| **LLM** | DeepSeek-V3 (主) / GPT-4 (备) | 通过LLM Gateway |
|
||
| **前端框架** | React 19 + Ant Design 6 | 现有架构 |
|
||
| **状态管理** | Zustand | 轻量级状态管理 |
|
||
|
||
---
|
||
|
||
## 七、风险与缓解
|
||
|
||
| 风险 | 影响 | 缓解措施 |
|
||
|------|------|----------|
|
||
| LLM幻觉 | 生成不准确的医学信息 | Reflexion检查 + 知识库约束 |
|
||
| 上下文丢失 | 长对话信息遗忘 | ProtocolContext持久化 + 摘要策略 |
|
||
| 提取不准确 | Context数据错误 | 置信度标记 + 用户确认 |
|
||
| Prompt调优耗时 | 延迟交付 | 预留充足调优时间 |
|
||
|
||
---
|
||
|
||
## 八、成功标准
|
||
|
||
### Phase 1 交付标准
|
||
|
||
1. **功能完整性**:用户可完成5阶段研究方案要素制定
|
||
2. **数据准确性**:Context提取准确率 > 85%
|
||
3. **用户体验**:单阶段平均对话轮数 < 5轮
|
||
4. **系统稳定性**:API响应成功率 > 99%
|
||
|
||
---
|
||
|
||
## 九、相关文档
|
||
|
||
- [Protocol Agent PRD v1.0](../00-系统设计/Protocol_Agent_PRD_v1.0.md)
|
||
- [MVP简化指南](../00-系统设计/Protocol_Agent_Development_Simplification_Guide.md)
|
||
- [架构设计V3](../02-技术设计/Protocol_Agent_Architecture_Design_V3.md)
|
||
- [技术实现V3](../02-技术设计/Protocol_Agent_Technical_Implementation_V3.md)
|
||
- [后端配置设计](../02-技术设计/Protocol_Agent_Backend_Config_Design.md)
|
||
|