基于 RAGFlow + 多 Agent 工作流的专业文档生成平台实现
OpenSpec 是一个企业级专业长文档生成平台,基于 RAG(检索增强生成)+ Multi-Agent 工作流,解决建筑设计、医疗、招投标等领域的长文档自动生成问题。
- 🔗 GitHub:github.com/zhuzhaoyun/…
- 🚀 在线 Demo:archspec.aizzyun.com/
- 📺 B 站视频:www.bilibili.com/video/BV1Do…
技术架构
┌─────────────────────────────────────────────────────────────┐
│ 前端层 (React) │
│ 项目配置 / 章节编辑 / 导出预览 │
└──────────────────────┬──────────────────────────────────────┘
│
┌──────────────────────▼──────────────────────────────────────┐
│ AI Agent 层 (Python) │
│ ┌──────────────┐ ┌──────────────┐ ┌──────────────┐ │
│ │ Researcher │──│ Writer │──│ Auditor │ │
│ │ Agent │ │ Agent │ │ Agent │ │
│ └──────────────┘ └──────────────┘ └──────────────┘ │
└──────────────────────┬──────────────────────────────────────┘
│
┌──────────────────────▼──────────────────────────────────────┐
│ RAG 知识库层 │
│ RAGFlow + 向量数据库 (Infinity) │
│ 国家规范 / 行业标准 / 历史案例 / 模板库 │
└─────────────────────────────────────────────────────────────┘
核心实现
1. RAG 检索流程
# apps/agent/agents/researcher.py
async def retrieve_context(query: str, project_type: str) -> List[Document]:
"""
基于项目类型检索相关知识
"""
# 构建过滤条件
filters = {
"doc_type": ["standard", "template", "case"],
"industry": project_type,
"status": "active"
}
# 多路召回:关键词 + 向量 + 结构化查询
results = await ragflow.search(
query=query,
filters=filters,
top_k=10,
rerank=True # 使用重排序模型提升准确性
)
return results
2. Multi-Agent 工作流
# apps/agent/workflow/document_generation.py
from langgraph import StateGraph, END
class DocumentState(TypedDict):
project_info: dict
outline: List[Chapter]
current_chapter: int
chapters_content: Dict[str, str]
review_comments: List[Comment]
# 定义工作流
workflow = StateGraph(DocumentState)
# 添加节点
workflow.add_node("research", research_agent) # 检索资料
workflow.add_node("write", writer_agent) # 生成内容
workflow.add_node("audit", auditor_agent) # 审核内容
workflow.add_node("revise", revise_agent) # 修改完善
# 定义边
workflow.add_edge("research", "write")
workflow.add_edge("write", "audit")
workflow.add_conditional_edges(
"audit",
lambda state: "revise" if state["review_comments"] else END,
{"revise": "revise", END: END}
)
workflow.add_edge("revise", "audit")
# 编译执行
app = workflow.compile()
3. 提示词工程
使用 Langfuse 进行提示词版本管理:
# prompts/chapter_generation.yaml
system: |
你是一位资深的{industry}领域技术文档撰写专家。
你的任务是根据提供的参考资料,撰写符合行业规范的技术文档章节。
要求:
1. 严格基于参考资料,不得编造规范条文
2. 使用专业术语,符合行业标准表达
3. 结构清晰,层次分明
4. 技术参数必须准确
user: |
项目信息:{project_info}
章节要求:{chapter_requirement}
参考资料:
{retrieved_context}
请生成该章节内容:
4. 前端实时协作编辑
// apps/web/components/ChapterEditor.tsx
import { useWebSocket } from '@/hooks/useWebSocket';
import { DiffEditor } from '@monaco-editor/react';
export function ChapterEditor({ chapterId }: { chapterId: string }) {
const { content, updateContent, aiSuggestion } = useChapter(chapterId);
const { isGenerating } = useGenerationStatus();
return (
<div className="chapter-editor">
<DiffEditor
original={content}
modified={aiSuggestion}
onAccept={updateContent}
onReject={() => {}}
/>
{isGenerating && <GenerationProgress />}
</div>
);
}
快速开始
环境要求
| 组件 | 版本 |
|---|---|
| Docker | >= 20.10 |
| Docker Compose | >= 2.0 |
| Node.js | >= 18 (开发前端) |
| Python | >= 3.10 (开发 Agent) |
| Java | >= 17 (开发后端) |
本地开发
# 1. 克隆仓库
git clone https://github.com/zhuzhaoyun/OpenSpec.git
cd OpenSpec
# 2. 配置环境
cp deploy/docker/.env.example deploy/docker/.env
# 编辑 .env,配置以下必填项:
# - RAGFLOW_API_KEY
# - RAGFLOW_BASE_URL
# - DASHSCOPE_API_KEY (或其他 LLM API Key)
# 3. 启动服务
cd deploy/docker
docker compose up -d
# 4. 访问
open http://localhost
单独开发某个模块
前端开发:
cd apps/web
npm install
npm run dev
# http://localhost:5173
Agent 开发:
cd apps/agent
pip install -r requirements.txt
uvicorn app:app --reload --port 5000
后端开发:
cd apps/backend
mvn spring-boot:run
项目结构
OpenSpec/
├── apps/
│ ├── web/ # React + TypeScript 前端
│ ├── agent/ # Python AI Agent 服务
│ └── backend/ # Java Spring Boot 后端
├── deploy/
│ └── docker/ # Docker Compose 部署配置
├── docs/ # 文档
├── prompts/ # Langfuse 管理的提示词
└── README.md
适用场景
| 行业 | 典型文档 | 核心痛点 |
|---|---|---|
| 建筑设计 | 施工图设计说明、可研报告 | 规范引用多、格式严格 |
| 汽车维修 | 维修手册、故障诊断报告 | 知识分散、更新频繁 |
| 医疗 | 临床试验报告、诊疗指南 | 合规性强、逻辑严谨 |
| 招投标 | 技术标书、招标文件 | 模板化高、重复劳动 |
Roadmap
- 基础 RAG 检索
- Multi-Agent 工作流
- 人机协作编辑
- PDF/Markdown 导出
- AutoCAD 插件(企业版)
- 更多行业模板
- 团队协作功能
- 多语言支持
参与贡献
我们欢迎各种形式的贡献:
- 🐛 提交 Bug 或功能建议
- 💻 提交 PR 改进代码
- 📖 完善文档和教程
- 🌐 翻译多语言版本
- 💡 分享使用场景和反馈
GitHub:github.com/zhuzhaoyun/…
有问题欢迎提 Issue 或联系:dlutyaol@qq.com
OpenSpec 是我的第一个开源项目,欢迎 Star ⭐ 支持!