自动布局
This commit is contained in:
479
androidExampleDemo/多功能android应用智能体的提示词.md
Normal file
479
androidExampleDemo/多功能android应用智能体的提示词.md
Normal file
@@ -0,0 +1,479 @@
|
||||
# 多功能Android应用智能体 - 提示词文档
|
||||
|
||||
## 📋 项目概述
|
||||
|
||||
创建一个智能Agent,能够帮助开发者快速生成、优化和调试Android应用。该Agent应该能够理解开发需求,提供代码生成、架构建议、性能优化、问题诊断等多方面的支持。
|
||||
|
||||
## 🎯 核心功能需求
|
||||
|
||||
### 1. 需求分析与理解
|
||||
- **输入**: 用户描述的应用需求(自然语言)
|
||||
- **输出**: 结构化的需求分析结果
|
||||
- 应用类型(工具类、社交类、电商类等)
|
||||
- 核心功能模块
|
||||
- 技术栈建议
|
||||
- 复杂度评估
|
||||
- 开发周期估算
|
||||
|
||||
### 2. 架构设计建议
|
||||
- **功能**: 根据需求生成Android应用架构方案
|
||||
- **输出内容**:
|
||||
- 架构模式(MVP、MVVM、MVI等)
|
||||
- 模块划分
|
||||
- 技术选型(框架、库、工具)
|
||||
- 目录结构建议
|
||||
- 依赖管理方案
|
||||
|
||||
### 3. 代码生成
|
||||
- **功能**: 生成Android应用的核心代码
|
||||
- **支持类型**:
|
||||
- Activity/Fragment代码
|
||||
- ViewModel代码
|
||||
- Repository代码
|
||||
- Adapter代码
|
||||
- 网络请求代码(Retrofit)
|
||||
- 数据库代码(Room)
|
||||
- 布局XML文件
|
||||
- 资源文件(strings.xml、colors.xml等)
|
||||
|
||||
### 4. 性能优化建议
|
||||
- **功能**: 分析代码并提供性能优化建议
|
||||
- **优化方向**:
|
||||
- 内存优化
|
||||
- 启动速度优化
|
||||
- 网络请求优化
|
||||
- 图片加载优化
|
||||
- 布局渲染优化
|
||||
- 电量消耗优化
|
||||
|
||||
### 5. 问题诊断与修复
|
||||
- **功能**: 分析错误日志,提供解决方案
|
||||
- **支持场景**:
|
||||
- 崩溃分析(Crash Log)
|
||||
- ANR问题诊断
|
||||
- 内存泄漏检测
|
||||
- 网络请求失败
|
||||
- 权限问题
|
||||
- 兼容性问题
|
||||
|
||||
### 6. 最佳实践建议
|
||||
- **功能**: 提供Android开发最佳实践
|
||||
- **内容**:
|
||||
- 代码规范
|
||||
- 安全建议
|
||||
- 用户体验优化
|
||||
- 测试策略
|
||||
- 发布流程
|
||||
|
||||
## 🔄 工作流设计
|
||||
|
||||
### 工作流结构
|
||||
|
||||
```
|
||||
开始节点 (start)
|
||||
↓
|
||||
需求理解与分析节点 (LLM)
|
||||
↓
|
||||
需求分类节点 (Condition)
|
||||
├─→ [代码生成需求] → 代码生成节点 (LLM/Template)
|
||||
├─→ [架构设计需求] → 架构设计节点 (LLM)
|
||||
├─→ [问题诊断需求] → 问题诊断节点 (LLM)
|
||||
└─→ [性能优化需求] → 性能优化节点 (LLM)
|
||||
↓ ↓ ↓ ↓
|
||||
└─────────────────────────────────────────────────┘
|
||||
↓
|
||||
结果整合节点 (Transform)
|
||||
↓
|
||||
格式化输出节点 (LLM)
|
||||
↓
|
||||
结束节点 (end)
|
||||
```
|
||||
|
||||
### 详细节点配置
|
||||
|
||||
#### 1. 开始节点 (start-1)
|
||||
```json
|
||||
{
|
||||
"id": "start-1",
|
||||
"type": "start",
|
||||
"data": {
|
||||
"label": "开始",
|
||||
"description": "接收用户输入的Android开发需求"
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
#### 2. 需求理解与分析节点 (llm-requirement-analysis)
|
||||
```json
|
||||
{
|
||||
"id": "llm-requirement-analysis",
|
||||
"type": "llm",
|
||||
"data": {
|
||||
"label": "需求理解与分析",
|
||||
"model": "deepseek-chat",
|
||||
"temperature": 0.3,
|
||||
"max_tokens": 2000,
|
||||
"prompt": "你是一个专业的Android开发顾问。请分析用户的需求,提取以下信息:\n1. 应用类型(工具类、社交类、电商类、游戏类等)\n2. 核心功能模块列表\n3. 目标用户群体\n4. 技术复杂度(简单/中等/复杂)\n5. 开发周期估算(周)\n6. 推荐的技术栈\n\n用户需求:{{user_query}}\n\n请以JSON格式输出分析结果:\n{\n \"app_type\": \"应用类型\",\n \"core_modules\": [\"模块1\", \"模块2\", ...],\n \"target_users\": \"目标用户\",\n \"complexity\": \"简单|中等|复杂\",\n \"estimated_weeks\": 数字,\n \"tech_stack\": [\"技术1\", \"技术2\", ...],\n \"summary\": \"需求摘要\"\n}"
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
#### 3. 需求分类节点 (condition-classify)
|
||||
```json
|
||||
{
|
||||
"id": "condition-classify",
|
||||
"type": "condition",
|
||||
"data": {
|
||||
"label": "需求分类",
|
||||
"condition": "{{input.complexity}}",
|
||||
"branches": [
|
||||
{
|
||||
"value": "代码生成",
|
||||
"condition": "包含'生成'、'创建'、'写代码'等关键词"
|
||||
},
|
||||
{
|
||||
"value": "架构设计",
|
||||
"condition": "包含'架构'、'设计'、'结构'等关键词"
|
||||
},
|
||||
{
|
||||
"value": "问题诊断",
|
||||
"condition": "包含'错误'、'崩溃'、'问题'、'bug'等关键词"
|
||||
},
|
||||
{
|
||||
"value": "性能优化",
|
||||
"condition": "包含'优化'、'性能'、'速度'、'卡顿'等关键词"
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
#### 4. 代码生成节点 (llm-code-generation)
|
||||
```json
|
||||
{
|
||||
"id": "llm-code-generation",
|
||||
"type": "llm",
|
||||
"data": {
|
||||
"label": "代码生成",
|
||||
"model": "deepseek-chat",
|
||||
"temperature": 0.2,
|
||||
"max_tokens": 4000,
|
||||
"prompt": "你是一个专业的Android开发工程师。根据以下需求分析,生成完整的Android代码。\n\n需求分析:{{input}}\n\n请生成以下内容:\n1. Java/Kotlin代码(包含必要的注释)\n2. 布局XML文件\n3. 资源文件配置\n4. 依赖配置(build.gradle)\n5. 使用说明\n\n代码要求:\n- 遵循Android开发最佳实践\n- 使用现代Android架构(推荐MVVM)\n- 包含错误处理\n- 代码注释清晰\n- 支持Android API 24+\n\n请以Markdown格式输出,包含代码块。"
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
#### 5. 架构设计节点 (llm-architecture)
|
||||
```json
|
||||
{
|
||||
"id": "llm-architecture",
|
||||
"type": "llm",
|
||||
"data": {
|
||||
"label": "架构设计",
|
||||
"model": "deepseek-chat",
|
||||
"temperature": 0.3,
|
||||
"max_tokens": 3000,
|
||||
"prompt": "你是一个Android架构师。根据需求分析,设计一个合理的Android应用架构。\n\n需求分析:{{input}}\n\n请提供:\n1. 架构模式选择(MVP/MVVM/MVI)及理由\n2. 模块划分方案\n3. 技术栈选型(框架、库、工具)\n4. 目录结构设计\n5. 数据流设计\n6. 依赖关系图\n7. 扩展性考虑\n\n请以Markdown格式输出,包含架构图和说明。"
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
#### 6. 问题诊断节点 (llm-diagnosis)
|
||||
```json
|
||||
{
|
||||
"id": "llm-diagnosis",
|
||||
"type": "llm",
|
||||
"data": {
|
||||
"label": "问题诊断",
|
||||
"model": "deepseek-chat",
|
||||
"temperature": 0.2,
|
||||
"max_tokens": 3000,
|
||||
"prompt": "你是一个Android问题诊断专家。分析用户提供的错误信息,提供诊断和解决方案。\n\n错误信息:{{user_query}}\n\n请提供:\n1. 问题类型(崩溃/ANR/内存泄漏/网络错误等)\n2. 根本原因分析\n3. 解决方案(步骤清晰)\n4. 修复代码示例\n5. 预防措施\n6. 相关文档链接\n\n请以Markdown格式输出。"
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
#### 7. 性能优化节点 (llm-optimization)
|
||||
```json
|
||||
{
|
||||
"id": "llm-optimization",
|
||||
"type": "llm",
|
||||
"data": {
|
||||
"label": "性能优化",
|
||||
"model": "deepseek-chat",
|
||||
"temperature": 0.3,
|
||||
"max_tokens": 3000,
|
||||
"prompt": "你是一个Android性能优化专家。根据用户描述的性能问题,提供优化方案。\n\n性能问题:{{user_query}}\n需求分析:{{input}}\n\n请提供:\n1. 性能瓶颈分析\n2. 优化方案(按优先级排序)\n3. 具体优化代码\n4. 优化前后对比\n5. 性能测试建议\n6. 监控指标\n\n请以Markdown格式输出。"
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
#### 8. 结果整合节点 (transform-integration)
|
||||
```json
|
||||
{
|
||||
"id": "transform-integration",
|
||||
"type": "transform",
|
||||
"data": {
|
||||
"label": "结果整合",
|
||||
"mode": "merge",
|
||||
"mapping": {
|
||||
"requirement_analysis": "{{input}}",
|
||||
"solution": "{{code_generation|architecture|diagnosis|optimization}}",
|
||||
"timestamp": "{{$timestamp}}",
|
||||
"agent_type": "Android开发助手"
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
#### 9. 格式化输出节点 (llm-format)
|
||||
```json
|
||||
{
|
||||
"id": "llm-format",
|
||||
"type": "llm",
|
||||
"data": {
|
||||
"label": "格式化输出",
|
||||
"model": "deepseek-chat",
|
||||
"temperature": 0.1,
|
||||
"max_tokens": 4000,
|
||||
"prompt": "请将以下Android开发方案整理成专业的Markdown文档格式。\n\n方案内容:{{input}}\n\n文档结构:\n1. 需求分析摘要\n2. 解决方案\n3. 代码示例\n4. 实施步骤\n5. 注意事项\n6. 参考资料\n\n请确保格式清晰、代码高亮正确、结构完整。"
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
#### 10. 结束节点 (end-1)
|
||||
```json
|
||||
{
|
||||
"id": "end-1",
|
||||
"type": "end",
|
||||
"data": {
|
||||
"label": "结束",
|
||||
"description": "返回最终结果"
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
## 📝 使用示例
|
||||
|
||||
### 示例1:生成登录功能代码
|
||||
|
||||
**用户输入**:
|
||||
```
|
||||
帮我生成一个Android登录功能的代码,包括:
|
||||
1. 登录Activity
|
||||
2. 登录ViewModel
|
||||
3. 网络请求(使用Retrofit)
|
||||
4. 登录布局XML
|
||||
```
|
||||
|
||||
**Agent处理流程**:
|
||||
1. 需求理解 → 识别为"代码生成"需求
|
||||
2. 代码生成节点 → 生成完整登录功能代码
|
||||
3. 结果整合 → 整合需求分析和代码
|
||||
4. 格式化输出 → 生成Markdown文档
|
||||
|
||||
**输出内容**:
|
||||
- 需求分析摘要
|
||||
- MainActivity.java(登录Activity)
|
||||
- LoginViewModel.java
|
||||
- ApiService.java(Retrofit接口)
|
||||
- activity_login.xml(布局文件)
|
||||
- 使用说明
|
||||
|
||||
### 示例2:架构设计咨询
|
||||
|
||||
**用户输入**:
|
||||
```
|
||||
我想开发一个电商类Android应用,包含商品浏览、购物车、订单管理等功能。
|
||||
请帮我设计应用架构。
|
||||
```
|
||||
|
||||
**Agent处理流程**:
|
||||
1. 需求理解 → 分析电商应用需求
|
||||
2. 需求分类 → 识别为"架构设计"需求
|
||||
3. 架构设计节点 → 生成架构方案
|
||||
4. 结果整合 → 整合需求分析和架构设计
|
||||
5. 格式化输出 → 生成架构设计文档
|
||||
|
||||
**输出内容**:
|
||||
- 需求分析(应用类型、核心模块、复杂度)
|
||||
- 架构模式选择(推荐MVVM)
|
||||
- 模块划分(商品模块、购物车模块、订单模块等)
|
||||
- 技术栈选型(Retrofit、Room、Glide等)
|
||||
- 目录结构
|
||||
- 数据流设计图
|
||||
|
||||
### 示例3:问题诊断
|
||||
|
||||
**用户输入**:
|
||||
```
|
||||
我的应用在启动时崩溃了,错误信息:
|
||||
java.lang.RuntimeException: Unable to start activity ComponentInfo{...}:
|
||||
android.view.InflateException: Binary XML file line #15: Error inflating class android.support.v7.widget.Toolbar
|
||||
```
|
||||
|
||||
**Agent处理流程**:
|
||||
1. 需求理解 → 识别为"问题诊断"需求
|
||||
2. 问题诊断节点 → 分析崩溃原因
|
||||
3. 结果整合 → 整合诊断结果
|
||||
4. 格式化输出 → 生成问题诊断报告
|
||||
|
||||
**输出内容**:
|
||||
- 问题类型:XML布局解析错误
|
||||
- 根本原因:Toolbar类导入错误或主题配置问题
|
||||
- 解决方案:
|
||||
1. 检查依赖配置
|
||||
2. 修改Toolbar导入
|
||||
3. 检查主题配置
|
||||
- 修复代码示例
|
||||
- 预防措施
|
||||
|
||||
### 示例4:性能优化
|
||||
|
||||
**用户输入**:
|
||||
```
|
||||
我的应用列表页面滚动时很卡顿,特别是加载图片时。
|
||||
请帮我优化性能。
|
||||
```
|
||||
|
||||
**Agent处理流程**:
|
||||
1. 需求理解 → 识别为"性能优化"需求
|
||||
2. 性能优化节点 → 分析性能瓶颈
|
||||
3. 结果整合 → 整合优化方案
|
||||
4. 格式化输出 → 生成优化指南
|
||||
|
||||
**输出内容**:
|
||||
- 性能瓶颈分析(图片加载、列表渲染)
|
||||
- 优化方案:
|
||||
1. 使用Glide/Picasso进行图片加载和缓存
|
||||
2. RecyclerView优化(ViewHolder复用、分页加载)
|
||||
3. 异步加载图片
|
||||
- 优化代码示例
|
||||
- 性能测试建议
|
||||
|
||||
## 🛠️ 技术实现要点
|
||||
|
||||
### 1. Prompt设计原则
|
||||
- **明确角色定位**:始终强调Agent是"专业的Android开发顾问/工程师"
|
||||
- **结构化输出**:要求以JSON或Markdown格式输出
|
||||
- **上下文传递**:确保前一个节点的输出能正确传递给下一个节点
|
||||
- **错误处理**:在Prompt中包含错误处理要求
|
||||
|
||||
### 2. 条件判断逻辑
|
||||
- 使用关键词匹配识别需求类型
|
||||
- 支持多种需求类型的组合
|
||||
- 提供默认分支处理未知需求
|
||||
|
||||
### 3. 代码生成质量
|
||||
- 要求遵循Android开发最佳实践
|
||||
- 包含必要的注释和文档
|
||||
- 支持现代Android架构(MVVM推荐)
|
||||
- 考虑兼容性(API 24+)
|
||||
|
||||
### 4. 输出格式统一
|
||||
- 使用Markdown格式
|
||||
- 代码块使用正确的语言标识(java、kotlin、xml等)
|
||||
- 包含目录结构
|
||||
- 提供使用说明
|
||||
|
||||
## 📊 测试用例
|
||||
|
||||
### 测试用例1:简单代码生成
|
||||
```
|
||||
输入:生成一个显示"Hello World"的Activity
|
||||
预期:生成MainActivity.java和activity_main.xml
|
||||
```
|
||||
|
||||
### 测试用例2:复杂架构设计
|
||||
```
|
||||
输入:设计一个支持多用户的社交类应用架构
|
||||
预期:包含用户模块、社交模块、消息模块等的架构设计
|
||||
```
|
||||
|
||||
### 测试用例3:问题诊断
|
||||
```
|
||||
输入:应用在Android 12上崩溃,错误是权限被拒绝
|
||||
预期:提供Android 12权限变更说明和解决方案
|
||||
```
|
||||
|
||||
### 测试用例4:性能优化
|
||||
```
|
||||
输入:应用启动时间超过5秒,如何优化?
|
||||
预期:提供启动优化方案(懒加载、异步初始化等)
|
||||
```
|
||||
|
||||
## 🚀 部署与使用
|
||||
|
||||
### 1. 创建Agent
|
||||
1. 登录Agent管理平台
|
||||
2. 点击"创建Agent"
|
||||
3. 输入Agent名称:"Android应用开发助手"
|
||||
4. 描述:"帮助开发者快速生成、优化和调试Android应用"
|
||||
|
||||
### 2. 配置工作流
|
||||
1. 在工作流设计器中添加上述所有节点
|
||||
2. 按照工作流结构连接节点
|
||||
3. 配置每个节点的参数(参考节点配置部分)
|
||||
4. 验证工作流逻辑
|
||||
|
||||
### 3. 测试Agent
|
||||
1. 保存工作流
|
||||
2. 部署Agent(状态改为"已发布")
|
||||
3. 使用测试工具或前端界面测试
|
||||
4. 根据测试结果调整Prompt和节点配置
|
||||
|
||||
### 4. 优化建议
|
||||
- **Prompt优化**:根据实际输出结果调整Prompt,使其更精确
|
||||
- **温度参数**:代码生成使用较低温度(0.2),创意设计使用较高温度(0.7)
|
||||
- **Token限制**:根据输出长度需求调整max_tokens
|
||||
- **分支优化**:根据常见需求类型优化条件判断逻辑
|
||||
|
||||
## 📚 扩展功能建议
|
||||
|
||||
### 1. 代码审查功能
|
||||
- 添加代码审查节点
|
||||
- 分析代码质量、安全性、性能
|
||||
- 提供改进建议
|
||||
|
||||
### 2. 测试用例生成
|
||||
- 根据功能代码自动生成单元测试
|
||||
- 生成UI测试用例
|
||||
- 提供测试覆盖率建议
|
||||
|
||||
### 3. 依赖管理
|
||||
- 分析项目依赖
|
||||
- 检测过时依赖
|
||||
- 推荐替代方案
|
||||
- 生成依赖更新计划
|
||||
|
||||
### 4. 多语言支持
|
||||
- 支持Kotlin代码生成
|
||||
- 支持Flutter、React Native等跨平台框架建议
|
||||
|
||||
### 5. 版本适配
|
||||
- 提供Android版本兼容性建议
|
||||
- 检测API废弃警告
|
||||
- 提供迁移方案
|
||||
|
||||
## ⚠️ 注意事项
|
||||
|
||||
1. **代码安全性**:生成的代码需要人工审查,特别是涉及用户数据和安全的部分
|
||||
2. **最佳实践**:Agent提供的建议应该结合项目实际情况,不能盲目采用
|
||||
3. **版本兼容性**:确保生成的代码支持目标Android版本
|
||||
4. **性能考虑**:代码生成时应该考虑性能影响
|
||||
5. **法律合规**:确保生成的代码符合相关法律法规要求
|
||||
|
||||
## 🔗 相关资源
|
||||
|
||||
- [Android开发官方文档](https://developer.android.com/)
|
||||
- [Android架构指南](https://developer.android.com/topic/architecture)
|
||||
- [Material Design指南](https://material.io/design)
|
||||
- [Android性能优化](https://developer.android.com/topic/performance)
|
||||
|
||||
---
|
||||
|
||||
**最后更新**:2026-01-20
|
||||
|
||||
**版本**:v1.0
|
||||
|
||||
**作者**:Android开发智能体团队
|
||||
394
backend/scripts/generate_android_agent.py
Executable file
394
backend/scripts/generate_android_agent.py
Executable file
@@ -0,0 +1,394 @@
|
||||
#!/usr/bin/env python3
|
||||
"""
|
||||
生成Android应用开发助手Agent
|
||||
这是一个专门用于Android应用开发的Agent,能够帮助开发者快速生成、优化和调试Android应用
|
||||
"""
|
||||
import sys
|
||||
import os
|
||||
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
|
||||
|
||||
from sqlalchemy.orm import Session
|
||||
from app.core.database import SessionLocal
|
||||
from app.models.agent import Agent
|
||||
from app.models.user import User
|
||||
from datetime import datetime
|
||||
import uuid
|
||||
|
||||
|
||||
def generate_android_agent(db: Session, username: str = "admin"):
|
||||
"""生成Android应用开发助手Agent"""
|
||||
print("=" * 60)
|
||||
print("生成Android应用开发助手Agent")
|
||||
print("=" * 60)
|
||||
print()
|
||||
|
||||
# 查找用户
|
||||
user = db.query(User).filter(User.username == username).first()
|
||||
if not user:
|
||||
print(f"❌ 未找到用户 '{username}',请先创建该用户")
|
||||
return
|
||||
print(f"✅ 找到用户: {user.username} (ID: {user.id})")
|
||||
print()
|
||||
|
||||
# 生成Android应用开发助手工作流配置
|
||||
# 工作流结构:
|
||||
# 开始 -> 需求分析 -> 需求分类 -> [代码生成|架构设计|问题诊断|性能优化] -> 结果整合 -> 格式化输出 -> 结束
|
||||
|
||||
nodes = []
|
||||
edges = []
|
||||
|
||||
# 1. 开始节点
|
||||
start_node = {
|
||||
"id": "start-1",
|
||||
"type": "start",
|
||||
"position": {"x": 50, "y": 400},
|
||||
"data": {
|
||||
"label": "开始",
|
||||
"output_format": "json"
|
||||
}
|
||||
}
|
||||
nodes.append(start_node)
|
||||
|
||||
# 2. 需求理解与分析节点(LLM节点)
|
||||
requirement_analysis_node = {
|
||||
"id": "llm-requirement-analysis",
|
||||
"type": "llm",
|
||||
"position": {"x": 250, "y": 400},
|
||||
"data": {
|
||||
"label": "需求理解与分析",
|
||||
"provider": "deepseek",
|
||||
"model": "deepseek-chat",
|
||||
"temperature": "0.3",
|
||||
"max_tokens": "2000",
|
||||
"prompt": """你是一个专业的Android开发顾问。请分析用户的需求,提取以下信息:
|
||||
|
||||
用户需求:{{query}}
|
||||
|
||||
请以JSON格式输出分析结果:
|
||||
{
|
||||
"app_type": "应用类型(工具类、社交类、电商类、游戏类等)",
|
||||
"core_modules": ["模块1", "模块2", ...],
|
||||
"target_users": "目标用户群体",
|
||||
"complexity": "简单|中等|复杂",
|
||||
"estimated_weeks": 数字,
|
||||
"tech_stack": ["技术1", "技术2", ...],
|
||||
"summary": "需求摘要"
|
||||
}
|
||||
|
||||
请确保输出是有效的JSON格式。"""
|
||||
}
|
||||
}
|
||||
nodes.append(requirement_analysis_node)
|
||||
edges.append({
|
||||
"id": "e1",
|
||||
"source": "start-1",
|
||||
"target": "llm-requirement-analysis"
|
||||
})
|
||||
|
||||
# 3. 数据准备节点(Transform节点)- 用于传递数据
|
||||
data_prepare_node = {
|
||||
"id": "transform-prepare",
|
||||
"type": "transform",
|
||||
"position": {"x": 450, "y": 400},
|
||||
"data": {
|
||||
"label": "准备数据",
|
||||
"mode": "merge",
|
||||
"mapping": {
|
||||
"requirement_analysis": "{{output}}",
|
||||
"user_query": "{{query}}"
|
||||
}
|
||||
}
|
||||
}
|
||||
nodes.append(data_prepare_node)
|
||||
edges.append({
|
||||
"id": "e2",
|
||||
"source": "llm-requirement-analysis",
|
||||
"target": "transform-prepare"
|
||||
})
|
||||
|
||||
# 4. 需求分类节点(条件节点)
|
||||
classify_condition = {
|
||||
"id": "condition-classify",
|
||||
"type": "condition",
|
||||
"position": {"x": 650, "y": 400},
|
||||
"data": {
|
||||
"label": "需求分类",
|
||||
"condition": "{user_query} contains '生成' or {user_query} contains '创建' or {user_query} contains '写代码' or {user_query} contains '代码'"
|
||||
}
|
||||
}
|
||||
nodes.append(classify_condition)
|
||||
edges.append({
|
||||
"id": "e3",
|
||||
"source": "transform-prepare",
|
||||
"target": "condition-classify"
|
||||
})
|
||||
|
||||
# 5. 代码生成节点(LLM节点)- true分支
|
||||
code_generation_node = {
|
||||
"id": "llm-code-generation",
|
||||
"type": "llm",
|
||||
"position": {"x": 850, "y": 300},
|
||||
"data": {
|
||||
"label": "代码生成",
|
||||
"provider": "deepseek",
|
||||
"model": "deepseek-chat",
|
||||
"temperature": "0.2",
|
||||
"max_tokens": "4000",
|
||||
"prompt": """你是一个专业的Android开发工程师。根据以下需求分析,生成完整的Android代码。
|
||||
|
||||
用户原始需求:{{user_query}}
|
||||
需求分析结果:{{requirement_analysis}}
|
||||
|
||||
请生成以下内容:
|
||||
1. Java/Kotlin代码(包含必要的注释)
|
||||
2. 布局XML文件
|
||||
3. 资源文件配置(如需要)
|
||||
4. 依赖配置(build.gradle,如需要)
|
||||
5. 使用说明
|
||||
|
||||
代码要求:
|
||||
- 遵循Android开发最佳实践
|
||||
- 使用现代Android架构(推荐MVVM)
|
||||
- 包含错误处理
|
||||
- 代码注释清晰
|
||||
- 支持Android API 24+
|
||||
|
||||
请以Markdown格式输出,包含代码块,使用正确的语言标识(java、kotlin、xml等)。"""
|
||||
}
|
||||
}
|
||||
nodes.append(code_generation_node)
|
||||
edges.append({
|
||||
"id": "e4-true",
|
||||
"source": "condition-classify",
|
||||
"target": "llm-code-generation",
|
||||
"sourceHandle": "true"
|
||||
})
|
||||
|
||||
# 6. 架构设计节点(LLM节点)- false分支(当不是代码生成时)
|
||||
architecture_node = {
|
||||
"id": "llm-architecture",
|
||||
"type": "llm",
|
||||
"position": {"x": 850, "y": 500},
|
||||
"data": {
|
||||
"label": "架构设计/问题诊断/性能优化",
|
||||
"provider": "deepseek",
|
||||
"model": "deepseek-chat",
|
||||
"temperature": "0.3",
|
||||
"max_tokens": "3000",
|
||||
"prompt": """你是一个Android开发专家。根据用户需求,提供专业的开发建议。
|
||||
|
||||
用户原始需求:{{user_query}}
|
||||
需求分析结果:{{requirement_analysis}}
|
||||
|
||||
请根据需求类型提供相应的帮助:
|
||||
|
||||
**如果是架构设计需求**,请提供:
|
||||
1. 架构模式选择(MVP/MVVM/MVI)及理由
|
||||
2. 模块划分方案
|
||||
3. 技术栈选型(框架、库、工具)
|
||||
4. 目录结构设计
|
||||
5. 数据流设计
|
||||
6. 扩展性考虑
|
||||
|
||||
**如果是问题诊断需求**(包含错误、崩溃、问题、bug等关键词),请提供:
|
||||
1. 问题类型(崩溃/ANR/内存泄漏/网络错误等)
|
||||
2. 根本原因分析
|
||||
3. 解决方案(步骤清晰)
|
||||
4. 修复代码示例
|
||||
5. 预防措施
|
||||
|
||||
**如果是性能优化需求**(包含优化、性能、速度、卡顿等关键词),请提供:
|
||||
1. 性能瓶颈分析
|
||||
2. 优化方案(按优先级排序)
|
||||
3. 具体优化代码
|
||||
4. 优化前后对比
|
||||
5. 性能测试建议
|
||||
|
||||
请以Markdown格式输出,确保内容专业、清晰、实用。"""
|
||||
}
|
||||
}
|
||||
nodes.append(architecture_node)
|
||||
edges.append({
|
||||
"id": "e4-false",
|
||||
"source": "condition-classify",
|
||||
"target": "llm-architecture",
|
||||
"sourceHandle": "false"
|
||||
})
|
||||
|
||||
# 7. 结果整合节点(Transform节点)
|
||||
integration_node = {
|
||||
"id": "transform-integration",
|
||||
"type": "transform",
|
||||
"position": {"x": 1050, "y": 400},
|
||||
"data": {
|
||||
"label": "结果整合",
|
||||
"mode": "merge",
|
||||
"mapping": {
|
||||
"requirement_analysis": "{{requirement_analysis}}",
|
||||
"user_query": "{{user_query}}",
|
||||
"solution": "{{output}}",
|
||||
"agent_type": "Android应用开发助手",
|
||||
"timestamp": "{{$timestamp}}"
|
||||
}
|
||||
}
|
||||
}
|
||||
nodes.append(integration_node)
|
||||
|
||||
# 连接代码生成节点到整合节点
|
||||
edges.append({
|
||||
"id": "e5-code",
|
||||
"source": "llm-code-generation",
|
||||
"target": "transform-integration"
|
||||
})
|
||||
|
||||
# 连接架构设计节点到整合节点
|
||||
edges.append({
|
||||
"id": "e5-arch",
|
||||
"source": "llm-architecture",
|
||||
"target": "transform-integration"
|
||||
})
|
||||
|
||||
# 8. 格式化输出节点(LLM节点)
|
||||
format_node = {
|
||||
"id": "llm-format",
|
||||
"type": "llm",
|
||||
"position": {"x": 1250, "y": 400},
|
||||
"data": {
|
||||
"label": "格式化输出",
|
||||
"provider": "deepseek",
|
||||
"model": "deepseek-chat",
|
||||
"temperature": "0.1",
|
||||
"max_tokens": "4000",
|
||||
"prompt": """请将以下Android开发方案整理成专业的Markdown文档格式。
|
||||
|
||||
方案内容:{{input}}
|
||||
|
||||
文档结构:
|
||||
1. **需求分析摘要**
|
||||
- 应用类型
|
||||
- 核心模块
|
||||
- 技术复杂度
|
||||
- 开发周期估算
|
||||
|
||||
2. **解决方案**
|
||||
- 详细说明
|
||||
- 代码示例(如有)
|
||||
- 架构设计(如有)
|
||||
|
||||
3. **实施步骤**
|
||||
- 步骤清晰的实施指南
|
||||
|
||||
4. **注意事项**
|
||||
- 重要提醒
|
||||
- 常见问题
|
||||
|
||||
5. **参考资料**
|
||||
- 相关文档链接
|
||||
|
||||
请确保格式清晰、代码高亮正确、结构完整。如果输入中已经包含格式良好的内容,请保持原有格式并适当优化。"""
|
||||
}
|
||||
}
|
||||
nodes.append(format_node)
|
||||
edges.append({
|
||||
"id": "e6",
|
||||
"source": "transform-integration",
|
||||
"target": "llm-format"
|
||||
})
|
||||
|
||||
# 9. 结束节点
|
||||
end_node = {
|
||||
"id": "end-1",
|
||||
"type": "end",
|
||||
"position": {"x": 1450, "y": 400},
|
||||
"data": {
|
||||
"label": "结束",
|
||||
"description": "返回最终结果"
|
||||
}
|
||||
}
|
||||
nodes.append(end_node)
|
||||
edges.append({
|
||||
"id": "e7",
|
||||
"source": "llm-format",
|
||||
"target": "end-1"
|
||||
})
|
||||
|
||||
# 创建或更新Agent
|
||||
workflow_config = {
|
||||
"nodes": nodes,
|
||||
"edges": edges
|
||||
}
|
||||
|
||||
agent = db.query(Agent).filter(
|
||||
Agent.name == "Android应用开发助手",
|
||||
Agent.user_id == user.id
|
||||
).first()
|
||||
|
||||
if agent:
|
||||
agent.workflow_config = workflow_config
|
||||
agent.description = "帮助开发者快速生成、优化和调试Android应用。支持代码生成、架构设计、问题诊断、性能优化等功能。"
|
||||
agent.updated_at = datetime.now()
|
||||
agent.status = "published" # 设置为已发布状态,可直接使用
|
||||
print("⚠️ Agent 'Android应用开发助手' 已存在,将更新它...")
|
||||
else:
|
||||
agent = Agent(
|
||||
id=str(uuid.uuid4()),
|
||||
name="Android应用开发助手",
|
||||
description="帮助开发者快速生成、优化和调试Android应用。支持代码生成、架构设计、问题诊断、性能优化等功能。",
|
||||
workflow_config=workflow_config,
|
||||
status="published", # 直接设置为已发布状态,可立即使用
|
||||
user_id=user.id,
|
||||
version=1
|
||||
)
|
||||
db.add(agent)
|
||||
|
||||
try:
|
||||
db.commit()
|
||||
db.refresh(agent)
|
||||
print()
|
||||
print("✅ Agent创建/更新成功!")
|
||||
print()
|
||||
print(f"📋 Agent信息:")
|
||||
print(f" - ID: {agent.id}")
|
||||
print(f" - 名称: {agent.name}")
|
||||
print(f" - 状态: {agent.status} (已发布,可直接使用)")
|
||||
print(f" - 版本: {agent.version}")
|
||||
print(f" - 节点数: {len(nodes)}")
|
||||
print(f" - 连接数: {len(edges)}")
|
||||
print()
|
||||
print("🎯 功能特性:")
|
||||
print(" ✅ 需求分析与理解")
|
||||
print(" ✅ 代码生成(Activity、ViewModel、Repository等)")
|
||||
print(" ✅ 架构设计建议(MVP/MVVM/MVI)")
|
||||
print(" ✅ 问题诊断与修复")
|
||||
print(" ✅ 性能优化建议")
|
||||
print(" ✅ 格式化输出")
|
||||
print()
|
||||
print("💡 使用提示:")
|
||||
print(" 1. 在Agent管理页面找到 'Android应用开发助手'")
|
||||
print(" 2. 点击 '使用' 按钮开始使用")
|
||||
print(" 3. 输入你的Android开发需求,例如:")
|
||||
print(" - '帮我生成一个登录功能的代码'")
|
||||
print(" - '设计一个电商应用的架构'")
|
||||
print(" - '我的应用崩溃了,错误信息是...'")
|
||||
print(" - '如何优化列表页面的滚动性能?'")
|
||||
print()
|
||||
return agent
|
||||
except Exception as e:
|
||||
db.rollback()
|
||||
print(f"❌ 创建Agent失败: {str(e)}")
|
||||
import traceback
|
||||
traceback.print_exc()
|
||||
return None
|
||||
|
||||
|
||||
def main():
|
||||
"""主函数"""
|
||||
db = SessionLocal()
|
||||
try:
|
||||
generate_android_agent(db, username="admin")
|
||||
finally:
|
||||
db.close()
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
626
backend/scripts/generate_batch_agents.py
Executable file
626
backend/scripts/generate_batch_agents.py
Executable file
@@ -0,0 +1,626 @@
|
||||
#!/usr/bin/env python3
|
||||
"""
|
||||
批量生成多个Agent
|
||||
生成一批不同类型的Agent,展示各种工作流模式
|
||||
"""
|
||||
import sys
|
||||
import os
|
||||
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
|
||||
|
||||
from sqlalchemy.orm import Session
|
||||
from app.core.database import SessionLocal
|
||||
from app.models.agent import Agent
|
||||
from app.models.user import User
|
||||
from datetime import datetime
|
||||
import uuid
|
||||
|
||||
|
||||
def generate_text_summary_agent(db: Session, user: User):
|
||||
"""生成文本摘要Agent"""
|
||||
nodes = []
|
||||
edges = []
|
||||
|
||||
start_node = {
|
||||
"id": "start-1",
|
||||
"type": "start",
|
||||
"position": {"x": 50, "y": 300},
|
||||
"data": {"label": "开始", "output_format": "json"}
|
||||
}
|
||||
nodes.append(start_node)
|
||||
|
||||
summary_node = {
|
||||
"id": "llm-summary",
|
||||
"type": "llm",
|
||||
"position": {"x": 250, "y": 300},
|
||||
"data": {
|
||||
"label": "文本摘要",
|
||||
"provider": "deepseek",
|
||||
"model": "deepseek-chat",
|
||||
"temperature": "0.3",
|
||||
"max_tokens": "2000",
|
||||
"prompt": """你是一个专业的文本摘要专家。请对以下文本进行摘要。
|
||||
|
||||
文本内容:{{query}}
|
||||
|
||||
请生成:
|
||||
1. 核心要点(3-5条)
|
||||
2. 简要摘要(100-200字)
|
||||
3. 关键词(5-10个)
|
||||
|
||||
请以Markdown格式输出。"""
|
||||
}
|
||||
}
|
||||
nodes.append(summary_node)
|
||||
|
||||
end_node = {
|
||||
"id": "end-1",
|
||||
"type": "end",
|
||||
"position": {"x": 450, "y": 300},
|
||||
"data": {"label": "结束"}
|
||||
}
|
||||
nodes.append(end_node)
|
||||
|
||||
edges.append({"id": "e1", "source": "start-1", "target": "llm-summary", "sourceHandle": "right", "targetHandle": "left"})
|
||||
edges.append({"id": "e2", "source": "llm-summary", "target": "end-1", "sourceHandle": "right", "targetHandle": "left"})
|
||||
|
||||
return {
|
||||
"name": "文本摘要Agent",
|
||||
"description": "智能文本摘要工具,能够提取文本核心要点、生成简要摘要和关键词。",
|
||||
"workflow_config": {"nodes": nodes, "edges": edges}
|
||||
}
|
||||
|
||||
|
||||
def generate_code_review_agent(db: Session, user: User):
|
||||
"""生成代码审查Agent"""
|
||||
nodes = []
|
||||
edges = []
|
||||
|
||||
start_node = {
|
||||
"id": "start-1",
|
||||
"type": "start",
|
||||
"position": {"x": 50, "y": 300},
|
||||
"data": {"label": "开始", "output_format": "json"}
|
||||
}
|
||||
nodes.append(start_node)
|
||||
|
||||
analysis_node = {
|
||||
"id": "llm-analysis",
|
||||
"type": "llm",
|
||||
"position": {"x": 250, "y": 300},
|
||||
"data": {
|
||||
"label": "代码分析",
|
||||
"provider": "deepseek",
|
||||
"model": "deepseek-chat",
|
||||
"temperature": "0.2",
|
||||
"max_tokens": "3000",
|
||||
"prompt": """你是一个资深的代码审查专家。请审查以下代码。
|
||||
|
||||
代码:{{query}}
|
||||
|
||||
请检查:
|
||||
1. 代码规范(命名、格式、注释)
|
||||
2. 潜在bug和错误
|
||||
3. 性能问题
|
||||
4. 安全性问题
|
||||
5. 最佳实践建议
|
||||
|
||||
请以Markdown格式输出,包含问题列表和改进建议。"""
|
||||
}
|
||||
}
|
||||
nodes.append(analysis_node)
|
||||
|
||||
end_node = {
|
||||
"id": "end-1",
|
||||
"type": "end",
|
||||
"position": {"x": 450, "y": 300},
|
||||
"data": {"label": "结束"}
|
||||
}
|
||||
nodes.append(end_node)
|
||||
|
||||
edges.append({"id": "e1", "source": "start-1", "target": "llm-analysis", "sourceHandle": "right", "targetHandle": "left"})
|
||||
edges.append({"id": "e2", "source": "llm-analysis", "target": "end-1", "sourceHandle": "right", "targetHandle": "left"})
|
||||
|
||||
return {
|
||||
"name": "代码审查Agent",
|
||||
"description": "专业的代码审查工具,能够检查代码规范、潜在bug、性能问题和安全性。",
|
||||
"workflow_config": {"nodes": nodes, "edges": edges}
|
||||
}
|
||||
|
||||
|
||||
def generate_translation_agent(db: Session, user: User):
|
||||
"""生成翻译Agent"""
|
||||
nodes = []
|
||||
edges = []
|
||||
|
||||
start_node = {
|
||||
"id": "start-1",
|
||||
"type": "start",
|
||||
"position": {"x": 50, "y": 300},
|
||||
"data": {"label": "开始", "output_format": "json"}
|
||||
}
|
||||
nodes.append(start_node)
|
||||
|
||||
detect_node = {
|
||||
"id": "llm-detect",
|
||||
"type": "llm",
|
||||
"position": {"x": 250, "y": 300},
|
||||
"data": {
|
||||
"label": "语言检测",
|
||||
"provider": "deepseek",
|
||||
"model": "deepseek-chat",
|
||||
"temperature": "0.1",
|
||||
"max_tokens": "500",
|
||||
"prompt": """请检测以下文本的语言类型。
|
||||
|
||||
文本:{{query}}
|
||||
|
||||
请输出JSON格式:
|
||||
{
|
||||
"language": "检测到的语言(中文/英文/日文等)",
|
||||
"confidence": "置信度(高/中/低)"
|
||||
}"""
|
||||
}
|
||||
}
|
||||
nodes.append(detect_node)
|
||||
|
||||
translate_node = {
|
||||
"id": "llm-translate",
|
||||
"type": "llm",
|
||||
"position": {"x": 450, "y": 300},
|
||||
"data": {
|
||||
"label": "翻译",
|
||||
"provider": "deepseek",
|
||||
"model": "deepseek-chat",
|
||||
"temperature": "0.3",
|
||||
"max_tokens": "2000",
|
||||
"prompt": """你是一个专业的翻译专家。请翻译以下文本。
|
||||
|
||||
原文:{{query}}
|
||||
语言信息:{{output}}
|
||||
|
||||
请提供:
|
||||
1. 翻译结果
|
||||
2. 翻译说明(如有特殊处理)
|
||||
|
||||
请以Markdown格式输出。"""
|
||||
}
|
||||
}
|
||||
nodes.append(translate_node)
|
||||
|
||||
end_node = {
|
||||
"id": "end-1",
|
||||
"type": "end",
|
||||
"position": {"x": 650, "y": 300},
|
||||
"data": {"label": "结束"}
|
||||
}
|
||||
nodes.append(end_node)
|
||||
|
||||
edges.append({"id": "e1", "source": "start-1", "target": "llm-detect", "sourceHandle": "right", "targetHandle": "left"})
|
||||
edges.append({"id": "e2", "source": "llm-detect", "target": "llm-translate", "sourceHandle": "right", "targetHandle": "left"})
|
||||
edges.append({"id": "e3", "source": "llm-translate", "target": "end-1", "sourceHandle": "right", "targetHandle": "left"})
|
||||
|
||||
return {
|
||||
"name": "智能翻译Agent",
|
||||
"description": "多语言翻译工具,支持语言自动检测和高质量翻译。",
|
||||
"workflow_config": {"nodes": nodes, "edges": edges}
|
||||
}
|
||||
|
||||
|
||||
def generate_qa_agent(db: Session, user: User):
|
||||
"""生成问答助手Agent"""
|
||||
nodes = []
|
||||
edges = []
|
||||
|
||||
start_node = {
|
||||
"id": "start-1",
|
||||
"type": "start",
|
||||
"position": {"x": 50, "y": 300},
|
||||
"data": {"label": "开始", "output_format": "json"}
|
||||
}
|
||||
nodes.append(start_node)
|
||||
|
||||
understand_node = {
|
||||
"id": "llm-understand",
|
||||
"type": "llm",
|
||||
"position": {"x": 250, "y": 300},
|
||||
"data": {
|
||||
"label": "问题理解",
|
||||
"provider": "deepseek",
|
||||
"model": "deepseek-chat",
|
||||
"temperature": "0.3",
|
||||
"max_tokens": "1000",
|
||||
"prompt": """请分析用户的问题,提取关键信息。
|
||||
|
||||
用户问题:{{query}}
|
||||
|
||||
请输出JSON格式:
|
||||
{
|
||||
"question_type": "问题类型(技术/生活/学习等)",
|
||||
"keywords": ["关键词1", "关键词2"],
|
||||
"intent": "用户意图"
|
||||
}"""
|
||||
}
|
||||
}
|
||||
nodes.append(understand_node)
|
||||
|
||||
answer_node = {
|
||||
"id": "llm-answer",
|
||||
"type": "llm",
|
||||
"position": {"x": 450, "y": 300},
|
||||
"data": {
|
||||
"label": "生成答案",
|
||||
"provider": "deepseek",
|
||||
"model": "deepseek-chat",
|
||||
"temperature": "0.7",
|
||||
"max_tokens": "2000",
|
||||
"prompt": """你是一个知识渊博的助手。请回答用户的问题。
|
||||
|
||||
用户问题:{{query}}
|
||||
问题分析:{{output}}
|
||||
|
||||
请提供:
|
||||
1. 直接答案
|
||||
2. 详细解释
|
||||
3. 相关建议
|
||||
|
||||
请以Markdown格式输出,确保答案准确、清晰、有用。"""
|
||||
}
|
||||
}
|
||||
nodes.append(answer_node)
|
||||
|
||||
end_node = {
|
||||
"id": "end-1",
|
||||
"type": "end",
|
||||
"position": {"x": 650, "y": 300},
|
||||
"data": {"label": "结束"}
|
||||
}
|
||||
nodes.append(end_node)
|
||||
|
||||
edges.append({"id": "e1", "source": "start-1", "target": "llm-understand", "sourceHandle": "right", "targetHandle": "left"})
|
||||
edges.append({"id": "e2", "source": "llm-understand", "target": "llm-answer", "sourceHandle": "right", "targetHandle": "left"})
|
||||
edges.append({"id": "e3", "source": "llm-answer", "target": "end-1", "sourceHandle": "right", "targetHandle": "left"})
|
||||
|
||||
return {
|
||||
"name": "智能问答助手",
|
||||
"description": "智能问答系统,能够理解问题意图并提供详细准确的答案。",
|
||||
"workflow_config": {"nodes": nodes, "edges": edges}
|
||||
}
|
||||
|
||||
|
||||
def generate_document_agent(db: Session, user: User):
|
||||
"""生成文档生成Agent"""
|
||||
nodes = []
|
||||
edges = []
|
||||
|
||||
start_node = {
|
||||
"id": "start-1",
|
||||
"type": "start",
|
||||
"position": {"x": 50, "y": 300},
|
||||
"data": {"label": "开始", "output_format": "json"}
|
||||
}
|
||||
nodes.append(start_node)
|
||||
|
||||
plan_node = {
|
||||
"id": "llm-plan",
|
||||
"type": "llm",
|
||||
"position": {"x": 250, "y": 300},
|
||||
"data": {
|
||||
"label": "文档规划",
|
||||
"provider": "deepseek",
|
||||
"model": "deepseek-chat",
|
||||
"temperature": "0.3",
|
||||
"max_tokens": "1500",
|
||||
"prompt": """请根据用户需求规划文档结构。
|
||||
|
||||
用户需求:{{query}}
|
||||
|
||||
请输出JSON格式的文档大纲:
|
||||
{
|
||||
"title": "文档标题",
|
||||
"sections": [
|
||||
{"name": "章节1", "content": "内容描述"},
|
||||
{"name": "章节2", "content": "内容描述"}
|
||||
]
|
||||
}"""
|
||||
}
|
||||
}
|
||||
nodes.append(plan_node)
|
||||
|
||||
generate_node = {
|
||||
"id": "llm-generate",
|
||||
"type": "llm",
|
||||
"position": {"x": 450, "y": 300},
|
||||
"data": {
|
||||
"label": "生成文档",
|
||||
"provider": "deepseek",
|
||||
"model": "deepseek-chat",
|
||||
"temperature": "0.5",
|
||||
"max_tokens": "4000",
|
||||
"prompt": """请根据文档规划生成完整的文档内容。
|
||||
|
||||
用户需求:{{query}}
|
||||
文档规划:{{output}}
|
||||
|
||||
请生成结构完整、内容详实的Markdown文档。"""
|
||||
}
|
||||
}
|
||||
nodes.append(generate_node)
|
||||
|
||||
end_node = {
|
||||
"id": "end-1",
|
||||
"type": "end",
|
||||
"position": {"x": 650, "y": 300},
|
||||
"data": {"label": "结束"}
|
||||
}
|
||||
nodes.append(end_node)
|
||||
|
||||
edges.append({"id": "e1", "source": "start-1", "target": "llm-plan", "sourceHandle": "right", "targetHandle": "left"})
|
||||
edges.append({"id": "e2", "source": "llm-plan", "target": "llm-generate", "sourceHandle": "right", "targetHandle": "left"})
|
||||
edges.append({"id": "e3", "source": "llm-generate", "target": "end-1", "sourceHandle": "right", "targetHandle": "left"})
|
||||
|
||||
return {
|
||||
"name": "文档生成Agent",
|
||||
"description": "智能文档生成工具,能够根据需求规划文档结构并生成完整内容。",
|
||||
"workflow_config": {"nodes": nodes, "edges": edges}
|
||||
}
|
||||
|
||||
|
||||
def generate_data_analysis_agent(db: Session, user: User):
|
||||
"""生成数据分析Agent"""
|
||||
nodes = []
|
||||
edges = []
|
||||
|
||||
start_node = {
|
||||
"id": "start-1",
|
||||
"type": "start",
|
||||
"position": {"x": 50, "y": 300},
|
||||
"data": {"label": "开始", "output_format": "json"}
|
||||
}
|
||||
nodes.append(start_node)
|
||||
|
||||
parse_node = {
|
||||
"id": "llm-parse",
|
||||
"type": "llm",
|
||||
"position": {"x": 250, "y": 300},
|
||||
"data": {
|
||||
"label": "数据解析",
|
||||
"provider": "deepseek",
|
||||
"model": "deepseek-chat",
|
||||
"temperature": "0.2",
|
||||
"max_tokens": "2000",
|
||||
"prompt": """请解析用户提供的数据。
|
||||
|
||||
数据内容:{{query}}
|
||||
|
||||
请输出JSON格式:
|
||||
{
|
||||
"data_type": "数据类型(表格/列表/文本等)",
|
||||
"structure": "数据结构描述",
|
||||
"key_fields": ["字段1", "字段2"]
|
||||
}"""
|
||||
}
|
||||
}
|
||||
nodes.append(parse_node)
|
||||
|
||||
analysis_node = {
|
||||
"id": "llm-analysis",
|
||||
"type": "llm",
|
||||
"position": {"x": 450, "y": 300},
|
||||
"data": {
|
||||
"label": "数据分析",
|
||||
"provider": "deepseek",
|
||||
"model": "deepseek-chat",
|
||||
"temperature": "0.3",
|
||||
"max_tokens": "3000",
|
||||
"prompt": """请对数据进行深入分析。
|
||||
|
||||
原始数据:{{query}}
|
||||
数据解析:{{output}}
|
||||
|
||||
请提供:
|
||||
1. 数据概览
|
||||
2. 关键指标
|
||||
3. 趋势分析
|
||||
4. 洞察建议
|
||||
|
||||
请以Markdown格式输出,包含数据表格和图表描述。"""
|
||||
}
|
||||
}
|
||||
nodes.append(analysis_node)
|
||||
|
||||
end_node = {
|
||||
"id": "end-1",
|
||||
"type": "end",
|
||||
"position": {"x": 650, "y": 300},
|
||||
"data": {"label": "结束"}
|
||||
}
|
||||
nodes.append(end_node)
|
||||
|
||||
edges.append({"id": "e1", "source": "start-1", "target": "llm-parse", "sourceHandle": "right", "targetHandle": "left"})
|
||||
edges.append({"id": "e2", "source": "llm-parse", "target": "llm-analysis", "sourceHandle": "right", "targetHandle": "left"})
|
||||
edges.append({"id": "e3", "source": "llm-analysis", "target": "end-1", "sourceHandle": "right", "targetHandle": "left"})
|
||||
|
||||
return {
|
||||
"name": "数据分析Agent",
|
||||
"description": "智能数据分析工具,能够解析数据、提取关键指标并提供深度洞察。",
|
||||
"workflow_config": {"nodes": nodes, "edges": edges}
|
||||
}
|
||||
|
||||
|
||||
def generate_creative_writing_agent(db: Session, user: User):
|
||||
"""生成创意写作Agent"""
|
||||
nodes = []
|
||||
edges = []
|
||||
|
||||
start_node = {
|
||||
"id": "start-1",
|
||||
"type": "start",
|
||||
"position": {"x": 50, "y": 300},
|
||||
"data": {"label": "开始", "output_format": "json"}
|
||||
}
|
||||
nodes.append(start_node)
|
||||
|
||||
brainstorm_node = {
|
||||
"id": "llm-brainstorm",
|
||||
"type": "llm",
|
||||
"position": {"x": 250, "y": 300},
|
||||
"data": {
|
||||
"label": "头脑风暴",
|
||||
"provider": "deepseek",
|
||||
"model": "deepseek-chat",
|
||||
"temperature": "0.8",
|
||||
"max_tokens": "1500",
|
||||
"prompt": """你是一个创意写作专家。请根据用户需求进行头脑风暴。
|
||||
|
||||
用户需求:{{query}}
|
||||
|
||||
请提供:
|
||||
1. 创意主题(3-5个)
|
||||
2. 故事大纲
|
||||
3. 角色设定
|
||||
4. 写作风格建议
|
||||
|
||||
请以Markdown格式输出。"""
|
||||
}
|
||||
}
|
||||
nodes.append(brainstorm_node)
|
||||
|
||||
write_node = {
|
||||
"id": "llm-write",
|
||||
"type": "llm",
|
||||
"position": {"x": 450, "y": 300},
|
||||
"data": {
|
||||
"label": "创作内容",
|
||||
"provider": "deepseek",
|
||||
"model": "deepseek-chat",
|
||||
"temperature": "0.9",
|
||||
"max_tokens": "4000",
|
||||
"prompt": """请根据创意方案进行创作。
|
||||
|
||||
用户需求:{{query}}
|
||||
创意方案:{{output}}
|
||||
|
||||
请创作一篇完整的作品(文章、故事、诗歌等),确保内容生动、有趣、有创意。"""
|
||||
}
|
||||
}
|
||||
nodes.append(write_node)
|
||||
|
||||
end_node = {
|
||||
"id": "end-1",
|
||||
"type": "end",
|
||||
"position": {"x": 650, "y": 300},
|
||||
"data": {"label": "结束"}
|
||||
}
|
||||
nodes.append(end_node)
|
||||
|
||||
edges.append({"id": "e1", "source": "start-1", "target": "llm-brainstorm", "sourceHandle": "right", "targetHandle": "left"})
|
||||
edges.append({"id": "e2", "source": "llm-brainstorm", "target": "llm-write", "sourceHandle": "right", "targetHandle": "left"})
|
||||
edges.append({"id": "e3", "source": "llm-write", "target": "end-1", "sourceHandle": "right", "targetHandle": "left"})
|
||||
|
||||
return {
|
||||
"name": "创意写作Agent",
|
||||
"description": "创意写作助手,能够进行头脑风暴并创作各种类型的创意内容。",
|
||||
"workflow_config": {"nodes": nodes, "edges": edges}
|
||||
}
|
||||
|
||||
|
||||
def generate_batch_agents(db: Session, username: str = "admin"):
|
||||
"""批量生成Agent"""
|
||||
print("=" * 60)
|
||||
print("批量生成Agent")
|
||||
print("=" * 60)
|
||||
print()
|
||||
|
||||
# 查找用户
|
||||
user = db.query(User).filter(User.username == username).first()
|
||||
if not user:
|
||||
print(f"❌ 未找到用户 '{username}',请先创建该用户")
|
||||
return
|
||||
print(f"✅ 找到用户: {user.username} (ID: {user.id})")
|
||||
print()
|
||||
|
||||
# 定义要生成的Agent列表
|
||||
agent_generators = [
|
||||
generate_text_summary_agent,
|
||||
generate_code_review_agent,
|
||||
generate_translation_agent,
|
||||
generate_qa_agent,
|
||||
generate_document_agent,
|
||||
generate_data_analysis_agent,
|
||||
generate_creative_writing_agent,
|
||||
]
|
||||
|
||||
created_count = 0
|
||||
updated_count = 0
|
||||
failed_count = 0
|
||||
|
||||
for generator in agent_generators:
|
||||
try:
|
||||
agent_data = generator(db, user)
|
||||
agent_name = agent_data["name"]
|
||||
|
||||
# 检查Agent是否已存在
|
||||
existing_agent = db.query(Agent).filter(
|
||||
Agent.name == agent_name,
|
||||
Agent.user_id == user.id
|
||||
).first()
|
||||
|
||||
if existing_agent:
|
||||
existing_agent.workflow_config = agent_data["workflow_config"]
|
||||
existing_agent.description = agent_data["description"]
|
||||
existing_agent.updated_at = datetime.now()
|
||||
existing_agent.status = "published"
|
||||
updated_count += 1
|
||||
print(f"⚠️ 更新Agent: {agent_name}")
|
||||
else:
|
||||
agent = Agent(
|
||||
id=str(uuid.uuid4()),
|
||||
name=agent_name,
|
||||
description=agent_data["description"],
|
||||
workflow_config=agent_data["workflow_config"],
|
||||
status="published",
|
||||
user_id=user.id,
|
||||
version=1
|
||||
)
|
||||
db.add(agent)
|
||||
created_count += 1
|
||||
print(f"✅ 创建Agent: {agent_name}")
|
||||
except Exception as e:
|
||||
failed_count += 1
|
||||
print(f"❌ 生成Agent失败: {generator.__name__} - {str(e)}")
|
||||
import traceback
|
||||
traceback.print_exc()
|
||||
|
||||
try:
|
||||
db.commit()
|
||||
print()
|
||||
print("=" * 60)
|
||||
print("✅ 批量生成完成!")
|
||||
print("=" * 60)
|
||||
print(f" - 新建: {created_count} 个")
|
||||
print(f" - 更新: {updated_count} 个")
|
||||
print(f" - 失败: {failed_count} 个")
|
||||
print()
|
||||
print("📋 生成的Agent列表:")
|
||||
for generator in agent_generators:
|
||||
agent_data = generator(db, user)
|
||||
print(f" • {agent_data['name']}")
|
||||
print()
|
||||
except Exception as e:
|
||||
db.rollback()
|
||||
print(f"❌ 提交失败: {str(e)}")
|
||||
import traceback
|
||||
traceback.print_exc()
|
||||
|
||||
|
||||
def main():
|
||||
"""主函数"""
|
||||
db = SessionLocal()
|
||||
try:
|
||||
generate_batch_agents(db, username="admin")
|
||||
finally:
|
||||
db.close()
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
233
backend/scripts/generate_test_agent.py
Executable file
233
backend/scripts/generate_test_agent.py
Executable file
@@ -0,0 +1,233 @@
|
||||
#!/usr/bin/env python3
|
||||
"""
|
||||
生成测试Agent - 演示左右连接
|
||||
这是一个测试Agent,用于演示节点左右连接的功能
|
||||
"""
|
||||
import sys
|
||||
import os
|
||||
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
|
||||
|
||||
from sqlalchemy.orm import Session
|
||||
from app.core.database import SessionLocal
|
||||
from app.models.agent import Agent
|
||||
from app.models.user import User
|
||||
from datetime import datetime
|
||||
import uuid
|
||||
|
||||
|
||||
def generate_test_agent(db: Session, username: str = "admin"):
|
||||
"""生成测试Agent(左右连接)"""
|
||||
print("=" * 60)
|
||||
print("生成测试Agent(左右连接演示)")
|
||||
print("=" * 60)
|
||||
print()
|
||||
|
||||
# 查找用户
|
||||
user = db.query(User).filter(User.username == username).first()
|
||||
if not user:
|
||||
print(f"❌ 未找到用户 '{username}',请先创建该用户")
|
||||
return
|
||||
print(f"✅ 找到用户: {user.username} (ID: {user.id})")
|
||||
print()
|
||||
|
||||
# 生成测试工作流配置
|
||||
# 工作流结构(横向排列,使用左右连接):
|
||||
# 开始 → 处理1 → 处理2 → 处理3 → 结束
|
||||
|
||||
nodes = []
|
||||
edges = []
|
||||
|
||||
# 节点横向排列,Y坐标相同,X坐标递增
|
||||
base_y = 300
|
||||
x_spacing = 250
|
||||
|
||||
# 1. 开始节点
|
||||
start_node = {
|
||||
"id": "start-1",
|
||||
"type": "start",
|
||||
"position": {"x": 50, "y": base_y},
|
||||
"data": {
|
||||
"label": "开始",
|
||||
"output_format": "json"
|
||||
}
|
||||
}
|
||||
nodes.append(start_node)
|
||||
|
||||
# 2. 处理节点1(LLM)
|
||||
process1_node = {
|
||||
"id": "llm-process1",
|
||||
"type": "llm",
|
||||
"position": {"x": 50 + x_spacing, "y": base_y},
|
||||
"data": {
|
||||
"label": "处理1",
|
||||
"provider": "deepseek",
|
||||
"model": "deepseek-chat",
|
||||
"temperature": "0.3",
|
||||
"max_tokens": "1000",
|
||||
"prompt": """你是一个测试助手。请简单处理用户输入。
|
||||
|
||||
用户输入:{{query}}
|
||||
|
||||
请输出:已处理用户输入:"{{query}}"
|
||||
"""
|
||||
}
|
||||
}
|
||||
nodes.append(process1_node)
|
||||
|
||||
# 3. 处理节点2(Transform)
|
||||
process2_node = {
|
||||
"id": "transform-process2",
|
||||
"type": "transform",
|
||||
"position": {"x": 50 + x_spacing * 2, "y": base_y},
|
||||
"data": {
|
||||
"label": "处理2",
|
||||
"mode": "merge",
|
||||
"mapping": {
|
||||
"original_input": "{{query}}",
|
||||
"processed_result": "{{output}}"
|
||||
}
|
||||
}
|
||||
}
|
||||
nodes.append(process2_node)
|
||||
|
||||
# 4. 处理节点3(LLM)
|
||||
process3_node = {
|
||||
"id": "llm-process3",
|
||||
"type": "llm",
|
||||
"position": {"x": 50 + x_spacing * 3, "y": base_y},
|
||||
"data": {
|
||||
"label": "处理3",
|
||||
"provider": "deepseek",
|
||||
"model": "deepseek-chat",
|
||||
"temperature": "0.3",
|
||||
"max_tokens": "1000",
|
||||
"prompt": """请对处理结果进行总结。
|
||||
|
||||
原始输入:{{original_input}}
|
||||
处理结果:{{processed_result}}
|
||||
|
||||
请输出一个简洁的总结。"""
|
||||
}
|
||||
}
|
||||
nodes.append(process3_node)
|
||||
|
||||
# 5. 结束节点
|
||||
end_node = {
|
||||
"id": "end-1",
|
||||
"type": "end",
|
||||
"position": {"x": 50 + x_spacing * 4, "y": base_y},
|
||||
"data": {
|
||||
"label": "结束",
|
||||
"description": "返回最终结果"
|
||||
}
|
||||
}
|
||||
nodes.append(end_node)
|
||||
|
||||
# 创建连接(使用左右连接)
|
||||
# 注意:使用 sourceHandle='right' 和 targetHandle='left' 来指定左右连接
|
||||
edges.append({
|
||||
"id": "e1",
|
||||
"source": "start-1",
|
||||
"target": "llm-process1",
|
||||
"sourceHandle": "right", # 从开始节点的右侧连接
|
||||
"targetHandle": "left" # 连接到处理1节点的左侧
|
||||
})
|
||||
|
||||
edges.append({
|
||||
"id": "e2",
|
||||
"source": "llm-process1",
|
||||
"target": "transform-process2",
|
||||
"sourceHandle": "right", # 从处理1节点的右侧连接
|
||||
"targetHandle": "left" # 连接到处理2节点的左侧
|
||||
})
|
||||
|
||||
edges.append({
|
||||
"id": "e3",
|
||||
"source": "transform-process2",
|
||||
"target": "llm-process3",
|
||||
"sourceHandle": "right", # 从处理2节点的右侧连接
|
||||
"targetHandle": "left" # 连接到处理3节点的左侧
|
||||
})
|
||||
|
||||
edges.append({
|
||||
"id": "e4",
|
||||
"source": "llm-process3",
|
||||
"target": "end-1",
|
||||
"sourceHandle": "right", # 从处理3节点的右侧连接
|
||||
"targetHandle": "left" # 连接到结束节点的左侧
|
||||
})
|
||||
|
||||
# 创建或更新Agent
|
||||
workflow_config = {
|
||||
"nodes": nodes,
|
||||
"edges": edges
|
||||
}
|
||||
|
||||
agent = db.query(Agent).filter(
|
||||
Agent.name == "测试Agent(左右连接)",
|
||||
Agent.user_id == user.id
|
||||
).first()
|
||||
|
||||
if agent:
|
||||
agent.workflow_config = workflow_config
|
||||
agent.description = "测试Agent,演示节点左右连接功能。工作流横向排列,使用左右连接点。"
|
||||
agent.updated_at = datetime.now()
|
||||
agent.status = "published"
|
||||
print("⚠️ Agent '测试Agent(左右连接)' 已存在,将更新它...")
|
||||
else:
|
||||
agent = Agent(
|
||||
id=str(uuid.uuid4()),
|
||||
name="测试Agent(左右连接)",
|
||||
description="测试Agent,演示节点左右连接功能。工作流横向排列,使用左右连接点。",
|
||||
workflow_config=workflow_config,
|
||||
status="published",
|
||||
user_id=user.id,
|
||||
version=1
|
||||
)
|
||||
db.add(agent)
|
||||
|
||||
try:
|
||||
db.commit()
|
||||
db.refresh(agent)
|
||||
print()
|
||||
print("✅ Agent创建/更新成功!")
|
||||
print()
|
||||
print(f"📋 Agent信息:")
|
||||
print(f" - ID: {agent.id}")
|
||||
print(f" - 名称: {agent.name}")
|
||||
print(f" - 状态: {agent.status} (已发布,可直接使用)")
|
||||
print(f" - 版本: {agent.version}")
|
||||
print(f" - 节点数: {len(nodes)}")
|
||||
print(f" - 连接数: {len(edges)}")
|
||||
print()
|
||||
print("🎯 工作流特点:")
|
||||
print(" ✅ 节点横向排列")
|
||||
print(" ✅ 使用左右连接点(sourceHandle='right', targetHandle='left')")
|
||||
print(" ✅ 工作流:开始 → 处理1 → 处理2 → 处理3 → 结束")
|
||||
print()
|
||||
print("💡 使用提示:")
|
||||
print(" 1. 在Agent管理页面找到 '测试Agent(左右连接)'")
|
||||
print(" 2. 点击 '使用' 按钮开始使用")
|
||||
print(" 3. 输入任意文本进行测试")
|
||||
print(" 4. 在工作流设计器中查看左右连接的视觉效果")
|
||||
print()
|
||||
return agent
|
||||
except Exception as e:
|
||||
db.rollback()
|
||||
print(f"❌ 创建Agent失败: {str(e)}")
|
||||
import traceback
|
||||
traceback.print_exc()
|
||||
return None
|
||||
|
||||
|
||||
def main():
|
||||
"""主函数"""
|
||||
db = SessionLocal()
|
||||
try:
|
||||
generate_test_agent(db, username="admin")
|
||||
finally:
|
||||
db.close()
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
@@ -20,6 +20,55 @@
|
||||
<el-icon><DocumentCopy /></el-icon>
|
||||
粘贴节点 (Ctrl+V)
|
||||
</el-button>
|
||||
<el-divider direction="vertical" />
|
||||
<!-- 节点对齐功能 -->
|
||||
<el-dropdown @command="handleAlignNodes" trigger="click">
|
||||
<el-button>
|
||||
<el-icon><Rank /></el-icon>
|
||||
对齐
|
||||
<el-icon class="el-icon--right"><ArrowDown /></el-icon>
|
||||
</el-button>
|
||||
<template #dropdown>
|
||||
<el-dropdown-menu>
|
||||
<el-dropdown-item command="left">
|
||||
<el-icon><Sort style="transform: rotate(90deg)" /></el-icon>
|
||||
左对齐
|
||||
</el-dropdown-item>
|
||||
<el-dropdown-item command="right">
|
||||
<el-icon><Sort style="transform: rotate(-90deg)" /></el-icon>
|
||||
右对齐
|
||||
</el-dropdown-item>
|
||||
<el-dropdown-item command="top">
|
||||
<el-icon><Sort /></el-icon>
|
||||
上对齐
|
||||
</el-dropdown-item>
|
||||
<el-dropdown-item command="bottom">
|
||||
<el-icon><Sort style="transform: rotate(180deg)" /></el-icon>
|
||||
下对齐
|
||||
</el-dropdown-item>
|
||||
<el-dropdown-item command="center-h">
|
||||
<el-icon><Grid /></el-icon>
|
||||
水平居中
|
||||
</el-dropdown-item>
|
||||
<el-dropdown-item command="center-v">
|
||||
<el-icon><Grid style="transform: rotate(90deg)" /></el-icon>
|
||||
垂直居中
|
||||
</el-dropdown-item>
|
||||
<el-dropdown-item command="distribute-h" divided>
|
||||
<el-icon><Operation /></el-icon>
|
||||
水平分布
|
||||
</el-dropdown-item>
|
||||
<el-dropdown-item command="distribute-v">
|
||||
<el-icon><Operation style="transform: rotate(90deg)" /></el-icon>
|
||||
垂直分布
|
||||
</el-dropdown-item>
|
||||
</el-dropdown-menu>
|
||||
</template>
|
||||
</el-dropdown>
|
||||
<el-button @click="handleAutoLayout" title="自动布局 (Ctrl+L)">
|
||||
<el-icon><Operation /></el-icon>
|
||||
自动布局
|
||||
</el-button>
|
||||
<div class="toolbar-spacer"></div>
|
||||
<div class="zoom-controls">
|
||||
<el-button size="small" @click="zoomIn" title="放大 (Ctrl +)">
|
||||
@@ -1255,7 +1304,7 @@ import { Controls } from '@vue-flow/controls'
|
||||
import { MiniMap } from '@vue-flow/minimap'
|
||||
import type { Node, Edge, NodeClickEvent, EdgeClickEvent, Connection, Viewport } from '@vue-flow/core'
|
||||
import { ElMessage, ElMessageBox } from 'element-plus'
|
||||
import { Check, Warning, ZoomIn, ZoomOut, FullScreen, DocumentCopy, User, VideoPlay, InfoFilled, WarningFilled } from '@element-plus/icons-vue'
|
||||
import { Check, Warning, ZoomIn, ZoomOut, FullScreen, DocumentCopy, User, VideoPlay, InfoFilled, WarningFilled, Rank, ArrowDown, Sort, Grid, Operation } from '@element-plus/icons-vue'
|
||||
import { useWorkflowStore } from '@/stores/workflow'
|
||||
import api from '@/api'
|
||||
import type { WorkflowNode, WorkflowEdge } from '@/types'
|
||||
@@ -2253,6 +2302,11 @@ const handleKeyDown = (event: KeyboardEvent) => {
|
||||
event.preventDefault()
|
||||
zoomOut()
|
||||
}
|
||||
// Ctrl+L 自动布局
|
||||
if (event.ctrlKey && event.key === 'l') {
|
||||
event.preventDefault()
|
||||
handleAutoLayout()
|
||||
}
|
||||
}
|
||||
|
||||
// 删除节点(优化版)
|
||||
@@ -2454,6 +2508,292 @@ const handleClear = () => {
|
||||
ElMessage.success('画布已清空')
|
||||
}
|
||||
|
||||
// 节点对齐功能
|
||||
const handleAlignNodes = (command: string) => {
|
||||
// 获取选中的节点(支持多选)
|
||||
const selectedNodes = nodes.value.filter(node => node.selected)
|
||||
|
||||
if (selectedNodes.length < 2) {
|
||||
ElMessage.warning('请至少选择2个节点进行对齐')
|
||||
return
|
||||
}
|
||||
|
||||
// 计算对齐基准值
|
||||
let baseValue: number
|
||||
// 默认节点尺寸(根据节点类型可能有不同)
|
||||
const defaultNodeWidth = 150
|
||||
const defaultNodeHeight = 50
|
||||
|
||||
const positions = selectedNodes.map(node => {
|
||||
// 尝试从DOM获取实际尺寸,如果获取不到则使用默认值
|
||||
let width = defaultNodeWidth
|
||||
let height = defaultNodeHeight
|
||||
|
||||
// 可以通过vueFlowInstance获取节点尺寸
|
||||
try {
|
||||
const nodeElement = document.querySelector(`[data-id="${node.id}"]`)
|
||||
if (nodeElement) {
|
||||
const rect = nodeElement.getBoundingClientRect()
|
||||
width = rect.width || defaultNodeWidth
|
||||
height = rect.height || defaultNodeHeight
|
||||
}
|
||||
} catch (e) {
|
||||
// 如果获取失败,使用默认值
|
||||
}
|
||||
|
||||
return {
|
||||
id: node.id,
|
||||
x: node.position.x,
|
||||
y: node.position.y,
|
||||
width,
|
||||
height
|
||||
}
|
||||
})
|
||||
|
||||
switch (command) {
|
||||
case 'left':
|
||||
// 左对齐:以最左边的节点为基准
|
||||
baseValue = Math.min(...positions.map(p => p.x))
|
||||
positions.forEach(pos => {
|
||||
updateNode(pos.id, { position: { x: baseValue, y: pos.y } })
|
||||
})
|
||||
ElMessage.success('节点已左对齐')
|
||||
break
|
||||
|
||||
case 'right':
|
||||
// 右对齐:以最右边的节点为基准
|
||||
baseValue = Math.max(...positions.map(p => p.x + p.width))
|
||||
positions.forEach(pos => {
|
||||
updateNode(pos.id, { position: { x: baseValue - pos.width, y: pos.y } })
|
||||
})
|
||||
ElMessage.success('节点已右对齐')
|
||||
break
|
||||
|
||||
case 'top':
|
||||
// 上对齐:以最上边的节点为基准
|
||||
baseValue = Math.min(...positions.map(p => p.y))
|
||||
positions.forEach(pos => {
|
||||
updateNode(pos.id, { position: { x: pos.x, y: baseValue } })
|
||||
})
|
||||
ElMessage.success('节点已上对齐')
|
||||
break
|
||||
|
||||
case 'bottom':
|
||||
// 下对齐:以最下边的节点为基准
|
||||
baseValue = Math.max(...positions.map(p => p.y + p.height))
|
||||
positions.forEach(pos => {
|
||||
updateNode(pos.id, { position: { x: pos.x, y: baseValue - pos.height } })
|
||||
})
|
||||
ElMessage.success('节点已下对齐')
|
||||
break
|
||||
|
||||
case 'center-h':
|
||||
// 水平居中:以所有节点的中心点为基准
|
||||
const minX = Math.min(...positions.map(p => p.x))
|
||||
const maxX = Math.max(...positions.map(p => p.x + p.width))
|
||||
const centerX = (minX + maxX) / 2
|
||||
positions.forEach(pos => {
|
||||
updateNode(pos.id, { position: { x: centerX - pos.width / 2, y: pos.y } })
|
||||
})
|
||||
ElMessage.success('节点已水平居中')
|
||||
break
|
||||
|
||||
case 'center-v':
|
||||
// 垂直居中:以所有节点的中心点为基准
|
||||
const minY = Math.min(...positions.map(p => p.y))
|
||||
const maxY = Math.max(...positions.map(p => p.y + p.height))
|
||||
const centerY = (minY + maxY) / 2
|
||||
positions.forEach(pos => {
|
||||
updateNode(pos.id, { position: { x: pos.x, y: centerY - pos.height / 2 } })
|
||||
})
|
||||
ElMessage.success('节点已垂直居中')
|
||||
break
|
||||
|
||||
case 'distribute-h':
|
||||
// 水平分布:均匀分布节点
|
||||
const sortedByX = [...positions].sort((a, b) => a.x - b.x)
|
||||
const totalWidth = sortedByX[sortedByX.length - 1].x + sortedByX[sortedByX.length - 1].width - sortedByX[0].x
|
||||
const spacing = totalWidth / (sortedByX.length - 1)
|
||||
let currentX = sortedByX[0].x
|
||||
sortedByX.forEach((pos, index) => {
|
||||
if (index > 0) {
|
||||
currentX = sortedByX[index - 1].x + sortedByX[index - 1].width + spacing - pos.width
|
||||
}
|
||||
updateNode(pos.id, { position: { x: currentX, y: pos.y } })
|
||||
})
|
||||
ElMessage.success('节点已水平分布')
|
||||
break
|
||||
|
||||
case 'distribute-v':
|
||||
// 垂直分布:均匀分布节点
|
||||
const sortedByY = [...positions].sort((a, b) => a.y - b.y)
|
||||
const totalHeight = sortedByY[sortedByY.length - 1].y + sortedByY[sortedByY.length - 1].height - sortedByY[0].y
|
||||
const vSpacing = totalHeight / (sortedByY.length - 1)
|
||||
let currentY = sortedByY[0].y
|
||||
sortedByY.forEach((pos, index) => {
|
||||
if (index > 0) {
|
||||
currentY = sortedByY[index - 1].y + sortedByY[index - 1].height + vSpacing - pos.height
|
||||
}
|
||||
updateNode(pos.id, { position: { x: pos.x, y: currentY } })
|
||||
})
|
||||
ElMessage.success('节点已垂直分布')
|
||||
break
|
||||
}
|
||||
|
||||
// 标记有变更
|
||||
hasChanges.value = true
|
||||
}
|
||||
|
||||
// 自动布局功能(基于DAG的层次布局算法)
|
||||
const handleAutoLayout = async () => {
|
||||
if (nodes.value.length === 0) {
|
||||
ElMessage.warning('画布中没有节点')
|
||||
return
|
||||
}
|
||||
|
||||
// 找到开始节点
|
||||
const startNode = nodes.value.find(n => n.type === 'start')
|
||||
if (!startNode) {
|
||||
ElMessage.warning('未找到开始节点,无法进行自动布局')
|
||||
return
|
||||
}
|
||||
|
||||
// 构建邻接表(有向图)
|
||||
const graph: Record<string, string[]> = {}
|
||||
const inDegree: Record<string, number> = {}
|
||||
|
||||
// 初始化
|
||||
nodes.value.forEach(node => {
|
||||
graph[node.id] = []
|
||||
inDegree[node.id] = 0
|
||||
})
|
||||
|
||||
// 构建图
|
||||
edges.value.forEach(edge => {
|
||||
if (graph[edge.source] && !graph[edge.source].includes(edge.target)) {
|
||||
graph[edge.source].push(edge.target)
|
||||
inDegree[edge.target] = (inDegree[edge.target] || 0) + 1
|
||||
}
|
||||
})
|
||||
|
||||
// 拓扑排序,将节点分层
|
||||
const layers: string[][] = []
|
||||
const visited = new Set<string>()
|
||||
const queue: string[] = []
|
||||
|
||||
// 找到所有入度为0的节点(开始节点)
|
||||
Object.keys(inDegree).forEach(nodeId => {
|
||||
if (inDegree[nodeId] === 0) {
|
||||
queue.push(nodeId)
|
||||
}
|
||||
})
|
||||
|
||||
// 如果没有入度为0的节点,使用开始节点
|
||||
if (queue.length === 0 && startNode) {
|
||||
queue.push(startNode.id)
|
||||
}
|
||||
|
||||
// 分层遍历
|
||||
while (queue.length > 0) {
|
||||
const layer: string[] = []
|
||||
const layerSize = queue.length
|
||||
|
||||
for (let i = 0; i < layerSize; i++) {
|
||||
const nodeId = queue.shift()!
|
||||
if (visited.has(nodeId)) continue
|
||||
|
||||
visited.add(nodeId)
|
||||
layer.push(nodeId)
|
||||
|
||||
// 处理该节点的所有出边
|
||||
const neighbors = graph[nodeId] || []
|
||||
neighbors.forEach(neighborId => {
|
||||
inDegree[neighborId] = (inDegree[neighborId] || 0) - 1
|
||||
if (inDegree[neighborId] === 0 && !visited.has(neighborId)) {
|
||||
queue.push(neighborId)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
if (layer.length > 0) {
|
||||
layers.push(layer)
|
||||
}
|
||||
}
|
||||
|
||||
// 处理未访问的节点(可能是孤立节点)
|
||||
nodes.value.forEach(node => {
|
||||
if (!visited.has(node.id)) {
|
||||
if (layers.length === 0) {
|
||||
layers.push([node.id])
|
||||
} else {
|
||||
layers[layers.length - 1].push(node.id)
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
// 布局参数
|
||||
const nodeWidth = 200
|
||||
const nodeHeight = 80
|
||||
const horizontalSpacing = 280 // 水平间距(增大间距,避免节点重叠)
|
||||
const verticalSpacing = 180 // 垂直间距(增大间距,使布局更清晰)
|
||||
const startX = 100
|
||||
const startY = 100
|
||||
|
||||
// 计算每层的布局(水平居中)
|
||||
layers.forEach((layer, layerIndex) => {
|
||||
const layerY = startY + layerIndex * verticalSpacing
|
||||
const layerWidth = (layer.length - 1) * horizontalSpacing
|
||||
const layerStartX = startX - layerWidth / 2
|
||||
|
||||
layer.forEach((nodeId, nodeIndex) => {
|
||||
const nodeX = layerStartX + nodeIndex * horizontalSpacing
|
||||
updateNode(nodeId, {
|
||||
position: { x: nodeX, y: layerY }
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
// 自动调整视口,使所有节点可见
|
||||
await nextTick()
|
||||
setTimeout(() => {
|
||||
try {
|
||||
const allNodes = nodes.value
|
||||
if (allNodes.length > 0) {
|
||||
const minX = Math.min(...allNodes.map(n => n.position.x))
|
||||
const maxX = Math.max(...allNodes.map(n => n.position.x + nodeWidth))
|
||||
const minY = Math.min(...allNodes.map(n => n.position.y))
|
||||
const maxY = Math.max(...allNodes.map(n => n.position.y + nodeHeight))
|
||||
|
||||
const centerX = (minX + maxX) / 2
|
||||
const centerY = (minY + maxY) / 2
|
||||
const width = maxX - minX
|
||||
const height = maxY - minY
|
||||
|
||||
// 计算合适的缩放比例
|
||||
const viewport = getViewport()
|
||||
if (viewport) {
|
||||
const scale = Math.min(
|
||||
(viewport.zoom * 800) / width,
|
||||
(viewport.zoom * 600) / height,
|
||||
1.2 // 最大缩放不超过1.2
|
||||
)
|
||||
|
||||
setViewport({
|
||||
x: -centerX * scale + 400,
|
||||
y: -centerY * scale + 300,
|
||||
zoom: scale
|
||||
}, { duration: 300 })
|
||||
}
|
||||
}
|
||||
} catch (e) {
|
||||
console.warn('自动调整视口失败:', e)
|
||||
}
|
||||
}, 100)
|
||||
|
||||
ElMessage.success(`自动布局完成,共 ${layers.length} 层,${nodes.value.length} 个节点`)
|
||||
hasChanges.value = true
|
||||
}
|
||||
|
||||
// 测试动画 - 依次执行所有节点,展示完整的工作流动画效果
|
||||
const handleTestAnimation = () => {
|
||||
// 清除之前的测试状态
|
||||
|
||||
1385
创建Agent经验.md
Normal file
1385
创建Agent经验.md
Normal file
File diff suppressed because it is too large
Load Diff
186
创建Agent经验总结.md
Normal file
186
创建Agent经验总结.md
Normal file
@@ -0,0 +1,186 @@
|
||||
# 创建Agent经验总结(实战版)
|
||||
|
||||
> 基于本仓库实际落地的 **Android应用开发助手**(已发布可用)沉淀:从“想法→工作流→落库→发布→验证→避坑”一套流程。
|
||||
|
||||
## 1. 目标与验收标准
|
||||
|
||||
- **目标**:在 Agent 管理页面出现一个“可运行/可使用”的 Agent,并且能通过 `/api/v1/executions` 正常触发执行并拿到结果。
|
||||
- **关键验收**:
|
||||
- **状态**:Agent 为 `published` 或 `running`(否则普通用户无法执行)
|
||||
- **工作流**:`workflow_config` 必须包含合法的 `nodes` / `edges`,能从 `start` 走到 `end`
|
||||
- **数据链路**:LLM prompt 能正确拿到用户输入(一般是 `{{query}}` / `{{user_query}}`)
|
||||
|
||||
## 2. 两种创建方式:UI vs 脚本
|
||||
|
||||
### 2.1 UI 创建(适合调试)
|
||||
|
||||
- 优点:所见即所得、方便调整 prompt/连线/节点参数
|
||||
- 缺点:重复劳动多,不利于批量/版本化
|
||||
|
||||
### 2.2 脚本创建(推荐用于“生成一批可运行Agent/一键复现”)
|
||||
|
||||
- 典型做法:写一个 `backend/scripts/generate_xxx_agent.py`,直接用 SQLAlchemy 创建或更新 Agent。
|
||||
- 本仓库示例:
|
||||
- `backend/scripts/generate_android_agent.py`(Android应用开发助手)
|
||||
- `backend/scripts/generate_content_agent.py`(内容生成助手)
|
||||
|
||||
## 3. Agent 能不能“运行”,最关键的规则
|
||||
|
||||
### 3.1 Agent 状态与执行权限
|
||||
|
||||
后端创建执行时会做状态校验:**非 owner 执行必须是 `published/running`**。
|
||||
|
||||
对应代码(要点:状态不对会 403):
|
||||
|
||||
```103:104:backend/app/api/executions.py
|
||||
if agent.status not in ["published", "running"] and agent.user_id != current_user.id:
|
||||
raise HTTPException(status_code=403, detail="Agent未发布或无权执行")
|
||||
```
|
||||
|
||||
**经验**:
|
||||
- 如果你希望“创建出来立刻可用”,脚本里就直接写 `status="published"`。
|
||||
- 如果你希望“先草稿”,脚本里写 `draft`,但要用 owner 测试或再部署发布。
|
||||
|
||||
### 3.2 workflow_config 的最低要求
|
||||
|
||||
- 必须包含:
|
||||
- `nodes`: 节点数组
|
||||
- `edges`: 连线数组
|
||||
- 且能通过校验(创建接口会校验):
|
||||
- 参考:`backend/app/api/agents.py` 中 `create_agent` 会调用 `validate_workflow(...)`
|
||||
|
||||
**经验**:
|
||||
- 最小可运行工作流:`start -> llm -> end`
|
||||
- 复杂工作流建议:`start -> 分析(llm) -> 分流(condition) -> 子分支(llm/transform) -> 汇总(transform) -> 输出优化(llm) -> end`
|
||||
|
||||
## 4. 数据流转与 Prompt 设计(决定“是否答非所问”)
|
||||
|
||||
### 4.1 输入字段命名建议
|
||||
|
||||
本平台执行 Agent 时,常见输入会放在:
|
||||
- `query`
|
||||
- `USER_INPUT`
|
||||
|
||||
Android 示例项目也是这样发起的:
|
||||
- `query = 用户输入`
|
||||
- `USER_INPUT = 用户输入`
|
||||
|
||||
**经验**:
|
||||
- prompt 里优先用 `{{query}}`(平台链路更稳定)
|
||||
- 如果你做了 transform 映射,可统一成 `user_query` 再用 `{{user_query}}`
|
||||
|
||||
### 4.2 先分析、再生成:降低跑偏
|
||||
|
||||
常见稳定结构:
|
||||
- 第 1 个 LLM:**需求抽取/结构化**(JSON 输出)
|
||||
- 后续 LLM:拿着“结构化需求 + 原始需求”做生成/诊断/优化
|
||||
|
||||
这样可以显著减少“答非所问”,也便于条件分支与 transform 做数据拼接。
|
||||
|
||||
## 5. 条件分支的关键坑:`sourceHandle`
|
||||
|
||||
条件节点“走哪个分支”,靠 edge 的 `sourceHandle` 来区分(例如 `true` / `false`)。
|
||||
|
||||
对应引擎逻辑(要点:**只保留 sourceHandle == branch 的边**):
|
||||
|
||||
```1936:1961:backend/app/services/workflow_engine.py
|
||||
if node.get('type') == 'condition':
|
||||
branch = result.get('branch', 'false')
|
||||
# 只保留:不是从条件节点出发的边,或 从条件节点出发且sourceHandle匹配分支的边
|
||||
edges_to_remove = []
|
||||
edges_to_keep = []
|
||||
for edge in active_edges:
|
||||
if edge['source'] == next_node_id:
|
||||
edge_handle = edge.get('sourceHandle')
|
||||
if edge_handle == branch:
|
||||
edges_to_keep.append(edge)
|
||||
else:
|
||||
edges_to_remove.append(edge)
|
||||
else:
|
||||
edges_to_keep.append(edge)
|
||||
active_edges = edges_to_keep
|
||||
```
|
||||
|
||||
**经验**:
|
||||
- 条件节点的出边必须带 `sourceHandle`,而且值要与引擎产出的 `branch` 完全一致(常用:`true`/`false`)
|
||||
- 否则会出现:
|
||||
- 分支全跑 / 分支全不跑 / 走错分支
|
||||
|
||||
## 6. 用脚本创建“可运行Agent”的推荐模板
|
||||
|
||||
核心点:
|
||||
- 查用户(owner)
|
||||
- 构造 `nodes/edges`
|
||||
- 若同名存在则更新,否则创建
|
||||
- 设置 `status="published"`
|
||||
|
||||
本仓库可直接复用(已验证创建成功):
|
||||
- `backend/scripts/generate_android_agent.py`
|
||||
|
||||
运行方式:
|
||||
|
||||
```bash
|
||||
cd /home/renjianbo/aiagent
|
||||
python3 backend/scripts/generate_android_agent.py
|
||||
```
|
||||
|
||||
运行后会输出 Agent ID、节点数、边数,且状态为 `published`。
|
||||
|
||||
## 7. 如何验证 Agent “真的可运行”
|
||||
|
||||
### 7.1 前端验证
|
||||
|
||||
- 进入 **Agent管理**
|
||||
- 找到 Agent(例如:Android应用开发助手)
|
||||
- 状态为 **已发布/运行中**
|
||||
- 点击 **使用**,输入一句话触发执行
|
||||
|
||||
### 7.2 API 验证(推荐可自动化)
|
||||
|
||||
1) 登录获取 token(form-urlencoded)
|
||||
2) 发起执行:
|
||||
|
||||
```json
|
||||
POST /api/v1/executions
|
||||
{
|
||||
"agent_id": "你的agent_id",
|
||||
"input_data": {
|
||||
"query": "帮我生成一个登录页",
|
||||
"USER_INPUT": "帮我生成一个登录页"
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
3) 轮询状态:
|
||||
- `GET /api/v1/executions/{execution_id}/status`
|
||||
4) 获取结果:
|
||||
- `GET /api/v1/executions/{execution_id}`
|
||||
|
||||
## 8. 常见问题与排查清单
|
||||
|
||||
- **Agent 列表里看到了,但点“使用”无权限/403**
|
||||
- 检查 `status` 是否为 `published/running`
|
||||
- 是否为 owner 在测试草稿
|
||||
|
||||
- **LLM 输出跑偏/答非所问**
|
||||
- 是否把用户输入稳定透传到了 `{{query}}`
|
||||
- 是否先做“需求结构化”再生成
|
||||
- prompt 是否过泛、缺少输出格式约束
|
||||
|
||||
- **条件节点后续分支乱跑**
|
||||
- 检查条件节点出边是否有 `sourceHandle=true/false`
|
||||
- 检查引擎分支值是否与 sourceHandle 对齐
|
||||
|
||||
- **输出结构混乱**
|
||||
- 建议末端增加 `llm-format` 做统一 Markdown 格式化
|
||||
- end 节点尽量只输出最终 `output` 字段(不要拼接用户 query)
|
||||
|
||||
## 9. 本次落地成果(可复用资产)
|
||||
|
||||
- **可运行 Agent**:Android应用开发助手(脚本创建,状态 `published`)
|
||||
- **生成脚本**:`backend/scripts/generate_android_agent.py`
|
||||
- **Prompt 方案文档**:`androidExampleDemo/多功能android应用智能体的提示词.md`
|
||||
|
||||
---
|
||||
|
||||
最后更新:2026-01-20
|
||||
185
开发进度.md
185
开发进度.md
@@ -127,24 +127,118 @@
|
||||
- [x] 错误处理优化 ✅
|
||||
- [x] 前端组件优化和样式完善 ✅
|
||||
|
||||
## 📝 下一步计划
|
||||
## 📝 下一步计划(待开发功能)
|
||||
|
||||
1. **集成OpenAI模型**
|
||||
- 在LLM节点中实现真实的OpenAI API调用
|
||||
- 支持模型选择和参数配置
|
||||
### 第八阶段:监控和告警前端界面(中优先级)
|
||||
|
||||
2. **实现WebSocket实时推送**
|
||||
- 执行状态实时更新
|
||||
- 执行进度显示
|
||||
#### 后端状态 ✅
|
||||
- [x] 告警规则API(CRUD、启用/禁用)✅
|
||||
- [x] 告警服务(检查告警、触发告警)✅
|
||||
- [x] 告警日志API ✅
|
||||
|
||||
3. **完善可视化编辑器**
|
||||
- 优化节点样式
|
||||
- 实现连线验证
|
||||
- 添加节点删除和编辑功能
|
||||
#### 前端待开发
|
||||
- [ ] 系统监控面板
|
||||
- [ ] 系统资源监控(CPU、内存、磁盘)
|
||||
- [ ] 执行统计图表(成功率、执行时间、错误率)
|
||||
- [ ] 实时执行状态看板
|
||||
- [ ] 告警规则管理页面
|
||||
- [ ] 告警规则列表
|
||||
- [ ] 告警规则创建/编辑表单
|
||||
- [ ] 告警规则启用/禁用
|
||||
- [ ] 告警日志页面
|
||||
- [ ] 告警历史列表
|
||||
- [ ] 告警详情查看
|
||||
- [ ] 告警通知配置(邮件、Webhook等)
|
||||
|
||||
4. **执行结果展示**
|
||||
- 执行历史页面
|
||||
- 执行结果详情展示
|
||||
### 第九阶段:用户体验优化(中优先级)
|
||||
|
||||
- [ ] 工作流编辑器优化
|
||||
- [ ] 节点连接线样式优化(已完成左右连接支持)
|
||||
- [ ] 节点对齐和自动布局
|
||||
- [ ] 工作流模板快速应用
|
||||
- [ ] 节点搜索和筛选
|
||||
- [ ] Agent使用体验优化
|
||||
- [ ] Agent快速测试功能
|
||||
- [ ] Agent使用统计和分析
|
||||
- [ ] Agent性能监控
|
||||
- [ ] 移动端适配
|
||||
- [ ] 响应式布局优化
|
||||
- [ ] 移动端工作流查看(只读)
|
||||
- [ ] 移动端执行状态查看
|
||||
|
||||
### 第十阶段:高级功能(低优先级,按需开发)
|
||||
|
||||
#### 多租户支持
|
||||
- [ ] 租户模型和API
|
||||
- [ ] 租户隔离(数据隔离、资源隔离)
|
||||
- [ ] 租户管理界面
|
||||
- [ ] 资源配额管理
|
||||
|
||||
#### 插件系统
|
||||
- [ ] 插件注册机制
|
||||
- [ ] 自定义节点插件开发框架
|
||||
- [ ] 插件市场(插件上传、下载、评分)
|
||||
- [ ] 插件版本管理
|
||||
|
||||
#### 性能优化
|
||||
- [ ] 工作流执行性能优化(并发执行、缓存)
|
||||
- [ ] 前端性能优化(懒加载、虚拟滚动)
|
||||
- [ ] 数据库查询优化(索引、查询优化)
|
||||
- [ ] API响应时间优化
|
||||
|
||||
### 第十一阶段:部署和运维(生产环境准备)
|
||||
|
||||
#### 生产环境配置
|
||||
- [ ] 生产环境Docker配置优化
|
||||
- [ ] Docker Compose生产配置
|
||||
- [ ] 多环境配置管理(dev/staging/prod)
|
||||
- [ ] 配置文件加密
|
||||
- [ ] Kubernetes部署配置
|
||||
- [ ] K8s部署清单(Deployment、Service、Ingress)
|
||||
- [ ] 水平扩展配置
|
||||
- [ ] 健康检查和就绪探针
|
||||
- [ ] 环境变量管理
|
||||
- [ ] 敏感信息管理(密钥管理)
|
||||
- [ ] 配置中心集成
|
||||
|
||||
#### 监控和日志
|
||||
- [ ] Prometheus指标收集
|
||||
- [ ] 业务指标(执行数、成功率、耗时)
|
||||
- [ ] 系统指标(CPU、内存、网络)
|
||||
- [ ] Grafana仪表板
|
||||
- [ ] 系统监控仪表板
|
||||
- [ ] 业务监控仪表板
|
||||
- [ ] 日志聚合
|
||||
- [ ] ELK Stack集成
|
||||
- [ ] 日志查询和分析
|
||||
- [ ] 错误追踪
|
||||
- [ ] Sentry集成
|
||||
- [ ] 错误告警和通知
|
||||
|
||||
#### CI/CD
|
||||
- [ ] GitHub Actions配置
|
||||
- [ ] 自动化测试流程
|
||||
- [ ] 自动化构建流程
|
||||
- [ ] 自动化部署流程
|
||||
- [ ] 代码质量检查
|
||||
- [ ] Linter配置(ESLint、Pylint)
|
||||
- [ ] 代码覆盖率检查
|
||||
- [ ] 安全扫描
|
||||
|
||||
### 第十二阶段:文档和测试完善
|
||||
|
||||
- [ ] 用户文档
|
||||
- [ ] 用户使用手册
|
||||
- [ ] 视频教程
|
||||
- [ ] 常见问题FAQ
|
||||
- [ ] 开发者文档
|
||||
- [ ] API文档完善
|
||||
- [ ] 架构设计文档
|
||||
- [ ] 插件开发指南
|
||||
- [ ] 测试覆盖
|
||||
- [ ] 单元测试覆盖率提升(目标80%+)
|
||||
- [ ] 集成测试完善
|
||||
- [ ] E2E测试(Playwright/Cypress)
|
||||
|
||||
## 🎯 当前状态
|
||||
|
||||
@@ -156,8 +250,16 @@
|
||||
|
||||
## 📊 完成度
|
||||
|
||||
- **第一阶段MVP**: 约 100% ✅
|
||||
- **整体项目**: 约 90-95%
|
||||
- **第一阶段MVP**: 100% ✅
|
||||
- **第二阶段核心功能**: 100% ✅
|
||||
- **第三阶段核心功能**: 100% ✅
|
||||
- **第四-七阶段功能**: 100% ✅
|
||||
- **整体项目**: 约 85-90%
|
||||
- 核心功能:100% ✅
|
||||
- 监控告警前端:0% ⚠️
|
||||
- 用户体验优化:60% 🚧
|
||||
- 高级功能(多租户、插件):0% ⚠️
|
||||
- 部署运维:30% 🚧
|
||||
|
||||
## ✅ 最新测试结果
|
||||
|
||||
@@ -176,6 +278,55 @@
|
||||
4. **可视化编辑器** - 拖拽节点、连线、配置面板
|
||||
5. **异步任务处理** - Celery集成,支持长时间运行的任务
|
||||
|
||||
## 🎯 当前优先级建议
|
||||
|
||||
### 高优先级(建议优先开发)
|
||||
|
||||
1. **监控和告警前端界面** ⭐⭐⭐
|
||||
- 系统监控面板
|
||||
- 告警规则管理页面
|
||||
- 告警日志查看
|
||||
- **预计工作量**: 1-2周
|
||||
|
||||
2. **用户体验优化** ⭐⭐
|
||||
- 工作流编辑器优化(节点对齐、自动布局)
|
||||
- Agent使用体验优化
|
||||
- **预计工作量**: 1-2周
|
||||
|
||||
### 中优先级(按需开发)
|
||||
|
||||
3. **性能优化** ⭐⭐
|
||||
- 工作流执行性能优化
|
||||
- 前端性能优化
|
||||
- **预计工作量**: 1-2周
|
||||
|
||||
4. **生产环境部署配置** ⭐⭐
|
||||
- Docker/K8s配置
|
||||
- 监控和日志集成
|
||||
- **预计工作量**: 2-3周
|
||||
|
||||
### 低优先级(长期规划)
|
||||
|
||||
5. **多租户支持** ⭐
|
||||
- 适用于SaaS场景
|
||||
- **预计工作量**: 3-4周
|
||||
|
||||
6. **插件系统** ⭐
|
||||
- 扩展性增强
|
||||
- **预计工作量**: 4-6周
|
||||
|
||||
## 📈 近期开发建议
|
||||
|
||||
**接下来1-2个月的重点**:
|
||||
1. 完成监控和告警前端界面(让系统可观测)
|
||||
2. 优化用户体验(提升使用体验)
|
||||
3. 完善生产环境部署配置(准备上线)
|
||||
|
||||
**长期规划**(3-6个月):
|
||||
1. 多租户支持(如需要SaaS模式)
|
||||
2. 插件系统(增强扩展性)
|
||||
3. 性能优化(支持更大规模)
|
||||
|
||||
---
|
||||
|
||||
**最后更新**: 2024年
|
||||
**最后更新**: 2026-01-20
|
||||
|
||||
Reference in New Issue
Block a user