feat: add AI学习助手 agent (KG+RAG ideal) and renshenguo feishu bot

- Add AI学习助手 agent creation script with all 39 tools, 3-layer KG+RAG memory
- Add renshenguo (人参果) feishu bot integration (app_service + ws_handler)
- Register renshenguo WS client in main.py startup
- Add RENSHENGUO_APP_ID / RENSHENGUO_APP_SECRET / RENSHENGUO_AGENT_ID config
- Reorganize docs from root into docs/ subdirectories
- Move startup scripts to scripts/startup/
- Various backend optimizations and tool improvements

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
renjianbo
2026-05-06 01:37:13 +08:00
parent f33bc461ff
commit eabf90c496
171 changed files with 4906 additions and 445 deletions

View File

@@ -0,0 +1,195 @@
# (红头)Windows 服务器启动与重启唯一指南
本文是 `D:\aaa\aiagent` 在 Windows 本地开发环境下的**唯一启动/重启文档**。
后续只看这一份即可。
---
## 0. 统一结论(先看)
- 推荐端口:
- 前端:`3001`
- 后端 API`8037`
- Redis`6379`
- `backend/.env` 必须与实际 Redis 端口一致:
- 推荐:`REDIS_URL=redis://localhost:6379/0`
- 任何 `.env` / 依赖 / 工具代码变更后,至少重启:
- API + Celery`restart_backend_celery.ps1`
- 若出现 `timeout of 30000ms exceeded`,优先检查:
1) Redis 是否可连
2) Celery Worker 是否在跑
3) API 与 Worker 是否使用同一 `backend\venv`
---
## 1. 一键启动 / 停止 / 重启
在 PowerShell 中执行(仓库根目录):
```powershell
cd D:\aaa\aiagent
```
### 1.1 一键启动(全套)
```powershell
powershell -ExecutionPolicy Bypass -File .\start_aiagent.ps1
```
默认目标:
- 前端:`http://localhost:3001`
- 后端文档:`http://127.0.0.1:8037/docs`
- Redis`127.0.0.1:6379`
### 1.2 一键停止(全套)
```powershell
powershell -ExecutionPolicy Bypass -File .\stop_aiagent.ps1
```
### 1.3 仅重启后端 + Celery最常用
```powershell
powershell -ExecutionPolicy Bypass -File .\restart_backend_celery.ps1
```
适用场景:改了 `.env`、Python 依赖、内置工具实现、Agent 执行逻辑。
---
## 2. 标准“重启服务器”流程(推荐照抄)
```powershell
cd D:\aaa\aiagent
powershell -ExecutionPolicy Bypass -File .\stop_aiagent.ps1
powershell -ExecutionPolicy Bypass -File .\start_aiagent.ps1
```
完成后立刻验证:
```powershell
netstat -ano | findstr :6379
netstat -ano | findstr :8037
netstat -ano | findstr :3001
curl http://127.0.0.1:8037/health
```
---
## 3. 本次故障复盘(学生作业管理助手超时)
### 3.1 现象
- Agent 对话区报错:`发送失败: timeout of 30000ms exceeded`
- 前端可打开,但执行一直超时。
### 3.2 根因
1. `backend/.env` 配置为:
- `REDIS_URL=redis://localhost:6380/0`
2. 实际 Redis 监听在:
- `6379`
3. 导致 Celery 任务队列链路异常(或 Worker 无法稳定消费Agent 执行超时。
### 3.3 修复
1.`backend/.env` 改为:
- `REDIS_URL=redis://localhost:6379/0`
2. 执行:
- `powershell -ExecutionPolicy Bypass -File .\restart_backend_celery.ps1`
3. 验证:
- `6379/8037/3001` 监听正常
- `/health` 返回 `200`
- Celery worker 进程存在
### 3.4 预防
- 不要混用两套端口约定(`6379``6380`)。
- 每次重启后先做 1 分钟健康检查(端口 + `/health` + 1 条 Agent 测试消息)。
---
## 4. 常见问题与快速处理
### 4.1 执行策略拦截脚本
```powershell
Set-ExecutionPolicy -Scope Process Bypass
```
### 4.2 `start_aiagent.ps1` 报 PowerShell 解析错误
症状:出现 `ParserError`、字符串终止符缺失、`[OK]` 附近报错。
处理:
1. 临时手动启动(见 4.3
2. 将脚本保存为 **UTF-8建议无 BOM/ ASCII 兼容内容**,避免中文引号或异常字符
### 4.3 一键脚本不可用时的手动拉起(应急)
开 3~4 个终端:
1) Redis
```powershell
cd D:\aaa\aiagent\backend\redis
.\redis-server.exe --port 6379
```
2) API
```powershell
cd D:\aaa\aiagent\backend
.\venv\Scripts\Activate.ps1
python -m uvicorn app.main:app --host 0.0.0.0 --port 8037
```
3) Celery
```powershell
cd D:\aaa\aiagent\backend
.\venv\Scripts\Activate.ps1
python -m celery -A app.core.celery_app worker --loglevel=info --pool=threads --concurrency=8
```
4) 前端
```powershell
cd D:\aaa\aiagent\frontend
$env:AIAGENT_API_PROXY='http://127.0.0.1:8037'
pnpm dev --port 3001
```
---
## 5. OCR上传图片识别必查项
`backend/.env` 建议:
```ini
TESSERACT_CMD=C:/Program Files/Tesseract-OCR/tesseract.exe
TESSERACT_TESSDATA_DIR=D:/aaa/aiagent/tessdata
```
自检:
```powershell
cd D:\aaa\aiagent\backend
.\venv\Scripts\python scripts\check_ocr_env.py
```
若新增依赖后仍报 OCR 缺失,重启 Celery。
---
## 6. 访问地址
- 前端:`http://localhost:3001`
- 后端 API`http://127.0.0.1:8037`
- 后端文档:`http://127.0.0.1:8037/docs`
- 健康检查:`http://127.0.0.1:8037/health`
---
## 7. 维护规则(强制)
- 所有 Windows 启动/重启内容只维护本文件。
- 其他旧文档仅保留跳转,不再写重复步骤。
- 修改启动逻辑后,先更新本文件再通知团队。

View File

@@ -0,0 +1,7 @@
# 前后端服务器启动和停止(已合并)
本文件已停止维护。
请改看唯一文档:`(红头)Windows服务器启动与重启唯一指南.md`
路径:`D:\aaa\aiagent\(红头)Windows服务器启动与重启唯一指南.md`

View File

@@ -0,0 +1,7 @@
# 启动注意事项(已合并)
本文件已停止维护。
请改看唯一文档:`(红头)Windows服务器启动与重启唯一指南.md`
路径:`D:\aaa\aiagent\(红头)Windows服务器启动与重启唯一指南.md`

View File

@@ -0,0 +1,474 @@
# Windows 启动指南(已合并)
本文件已停止维护,请只看以下唯一文档:
- `D:\aaa\aiagent\(红头)Windows服务器启动与重启唯一指南.md`
说明:历史内容已合并至上方文档,后续不再在本文件更新。
# Windows 启动指南(已合并)
本文件已停止维护。
请改看唯一文档:`(红头)Windows服务器启动与重启唯一指南.md`
路径:`D:\aaa\aiagent\(红头)Windows服务器启动与重启唯一指南.md`
# Windows 本地启动指南
## 前置要求
### 已安装的软件
- ✅ Python 3.12.7(已安装)
- ✅ Node.js 22.13.0(已安装)
- ✅ npm 10.9.2(已安装)
- ✅ pnpm 10.33.0(已安装)
### 需要安装的软件
- ❌ Redis需要安装但可以选择便携版
## 步骤 1安装 Redis选择一种方式
### 选项 A使用 Docker 运行 Redis推荐最简单
如果你不介意使用 Docker 来运行 Redis其他服务仍在本地运行
1. **安装 Docker Desktop**
- 下载地址https://www.docker.com/products/docker-desktop/
- 安装后启动 Docker Desktop
2. **启动 Redis 容器**
```bash
docker run -d --name redis -p 6380:6379 redis:7-alpine
```
3. **验证 Redis 是否运行**
```bash
docker ps
```
应该能看到 Redis 容器正在运行。
### 选项 B使用 Redis 便携版(快速启动,无需安装)
1. **下载 Redis Windows 便携版**
```bash
cd "D:/aaa/aiagent/backend"
curl -L -o redis.zip "https://github.com/microsoftarchive/redis/releases/download/win-3.2.100/Redis-x64-3.2.100.zip"
```
2. **解压 Redis**
```bash
# Windows PowerShell
Expand-Archive -Path redis.zip -DestinationPath redis
# 或使用解压工具解压
```
3. **启动 Redis 服务器**
```bash
cd redis
./redis-server.exe redis.windows.conf
```
Redis 将在端口 6379 启动。
4. **验证 Redis 是否运行**
```bash
./redis-cli.exe ping
```
应该返回:`PONG`
### 选项 C安装 Redis for Windows作为服务
1. **下载 Redis Windows 版本**
- 从 GitHub 下载https://github.com/microsoftarchive/redis/releases
- 下载 `Redis-x64-3.2.100.msi`
2. **安装 Redis**
- 运行安装程序,按照默认设置安装
- 安装完成后Redis 会作为 Windows 服务运行
3. **修改 Redis 端口(可选)**
- 默认 Redis 运行在 6379 端口
- 如果需要使用 6380 端口(与 docker-compose 配置一致),需要修改配置文件
- 配置文件位置:`C:\Program Files\Redis\redis.windows-service.conf`
- 找到 `port 6379` 改为 `port 6380`
- 重启 Redis 服务
### 选项 D使用 WSL 安装 Redis
如果你有 WSLWindows Subsystem for Linux
```bash
# 在 WSL 中运行
sudo apt update
sudo apt install redis-server
sudo service redis-server start
# 需要配置 Redis 允许远程连接
```
## 步骤 2配置后端环境
### 1. 创建虚拟环境并安装依赖
```bash
cd backend
# 创建虚拟环境
python -m venv venv
# 激活虚拟环境
# Windows CMD:
venv\Scripts\activate
# Windows PowerShell:
.\venv\Scripts\Activate.ps1
# Git Bash:
source venv/Scripts/activate
# 安装依赖
pip install -r requirements.txt
```
### 2. 配置环境变量
```bash
# 复制环境变量文件
copy env.example .env
```
编辑 `.env` 文件,确保以下配置正确:
```ini
# 数据库配置已配置为腾讯云MySQL无需修改
DATABASE_URL=mysql+pymysql://root:!Rjb12191@gz-cynosdbmysql-grp-d26pzce5.sql.tencentcdb.com:24936/agent_db?charset=utf8mb4
# Redis配置根据你的Redis安装方式选择
# 如果使用Docker Redis端口6380
REDIS_URL=redis://localhost:6380/0
# 如果使用Windows Redis默认端口6379
# REDIS_URL=redis://localhost:6379/0
# CORS配置
CORS_ORIGINS=http://localhost:3001,http://127.0.0.1:3001,http://localhost:3000,http://127.0.0.1:3000,http://localhost:8038,http://101.43.95.130:8038
# DeepSeek API密钥已有
DEEPSEEK_API_KEY=sk-fdf7cc1c73504e628ec0119b7e11b8cc
DEEPSEEK_BASE_URL=https://api.deepseek.com
```
### 3. 运行数据库迁移
```bash
# 确保虚拟环境已激活
alembic upgrade head
```
### 4. 启动后端服务
```bash
uvicorn app.main:app --host 0.0.0.0 --port 8037 --reload
```
后端服务将在 http://localhost:8037 启动。
### 5. 启动 Celery Worker新终端
```bash
# 在新终端中进入backend目录并激活虚拟环境
cd backend
venv\Scripts\activate
# 启动 Celery Worker
celery -A app.core.celery_app worker --loglevel=info
```
## 步骤 3配置前端环境
### 1. 安装依赖
```bash
cd frontend
pnpm install
```
### 2. 配置 API 地址
编辑 `frontend/vite.config.ts`,确保代理配置正确:
```typescript
export default defineConfig({
server: {
port: 3001,
proxy: {
'/api': {
target: 'http://localhost:8037',
changeOrigin: true,
},
'/ws': {
target: 'ws://localhost:8037',
ws: true,
},
},
},
})
```
### 3. 启动前端服务
```bash
pnpm dev
```
前端服务将在 http://localhost:3001 启动。
注意:访问地址是 http://localhost:3001前端默认使用3001端口。
## 步骤 4验证服务
### 1. 检查服务状态
- **后端API**: http://localhost:8037
- **API文档**: http://localhost:8037/docs
- **前端**: http://localhost:3001
### 2. 测试健康检查
```bash
curl http://localhost:8037/health
```
应该返回:`{"status":"healthy"}`
## 步骤 5创建第一个工作流
1. 访问 http://localhost:3001
2. 注册新用户或使用现有账户登录
3. 点击"创建工作流"进入可视化编辑器
4. 拖拽节点、连接、配置并保存
5. 运行工作流测试
## 常见问题
### 1. Redis 连接失败
**错误信息**
```
redis.exceptions.ConnectionError: Error 10061 connecting to localhost:6380
```
**解决方案**
- 检查 Redis 是否正在运行
- 确认 Redis 端口是否正确
- 检查防火墙是否阻止了 Redis 端口
### 2. 数据库连接失败
**错误信息**
```
pymysql.err.OperationalError: (2003, "Can't connect to MySQL server...")
```
**解决方案**
- 检查网络连接(腾讯云数据库需要互联网访问)
- 确认数据库连接信息正确
- 检查数据库是否允许远程连接
### 3. 前端无法连接后端
**错误信息**
```
Proxy error: Could not proxy request /api/auth/me from localhost:3001 to http://localhost:8037
```
**解决方案**
- 检查后端服务是否正在运行http://localhost:8037
- 检查前端代理配置vite.config.ts
- 检查 CORS 配置(.env 文件中的 CORS_ORIGINS
### 4. Celery 任务不执行
**解决方案**
- 检查 Celery Worker 是否正在运行
- 检查 Redis 连接是否正常
- 查看 Celery Worker 日志
### 5. 端口被占用
**解决方案**
- 检查端口 8037 和 3001 是否被其他程序占用
- 可以修改端口:
- 后端:修改启动命令端口 `--port 8038`
- 前端:修改 `vite.config.ts` 中的 `port`
## 一键启动脚本(推荐)
下面给出一套更稳的 PowerShell 一键启动脚本:
- 自动检查并启动 Redis优先使用 `backend/redis/redis-server.exe`
- 自动拉起后端 API默认 8037若被占用自动切到 8041
- 自动拉起 Celery Worker
- 自动拉起前端(并将前端代理指向实际 API 端口)
### 脚本文件:`start_aiagent.ps1`
> 建议保存到仓库根目录:`D:\aaa\aiagent\start_aiagent.ps1`
```powershell
param(
[int]$ApiPort = 8037,
[int]$FallbackApiPort = 8041,
[int]$FrontendPort = 3001
)
$ErrorActionPreference = "Stop"
$RepoRoot = Split-Path -Parent $MyInvocation.MyCommand.Path
$Backend = Join-Path $RepoRoot "backend"
$Frontend = Join-Path $RepoRoot "frontend"
$RedisDir = Join-Path $Backend "redis"
$RedisExe = Join-Path $RedisDir "redis-server.exe"
$RedisCli = Join-Path $RedisDir "redis-cli.exe"
function Test-PortListening([int]$Port) {
$line = netstat -ano | Select-String ":$Port\s+.*LISTENING" | Select-Object -First 1
return [bool]$line
}
function Ensure-Redis {
if (Test-PortListening 6379) {
Write-Host "[OK] Redis already listening on 6379" -ForegroundColor Green
return
}
if (-not (Test-Path $RedisExe)) {
throw "Redis 可执行文件不存在:$RedisExe"
}
Write-Host "[RUN] Starting Redis on 6379 ..." -ForegroundColor Yellow
Start-Process -FilePath $RedisExe -ArgumentList "--port 6379" -WorkingDirectory $RedisDir | Out-Null
Start-Sleep -Seconds 2
if (-not (Test-PortListening 6379)) {
throw "Redis 启动失败6379 未监听"
}
if (Test-Path $RedisCli) {
& $RedisCli -p 6379 ping | Out-Null
}
Write-Host "[OK] Redis started" -ForegroundColor Green
}
function Resolve-ApiPort {
if (-not (Test-PortListening $ApiPort)) {
return $ApiPort
}
Write-Host "[WARN] Port $ApiPort is occupied, switching to $FallbackApiPort" -ForegroundColor Yellow
if (Test-PortListening $FallbackApiPort) {
throw "端口 $ApiPort 和 $FallbackApiPort 都被占用,请先释放端口"
}
return $FallbackApiPort
}
Write-Host "== AIAgent Windows 一键启动 ==" -ForegroundColor Cyan
Write-Host "Repo: $RepoRoot"
Ensure-Redis
$RealApiPort = Resolve-ApiPort
$ApiBase = "http://127.0.0.1:$RealApiPort"
Write-Host "[RUN] Starting backend API on $RealApiPort ..." -ForegroundColor Yellow
Start-Process powershell -ArgumentList @(
"-NoExit",
"-Command",
"cd '$Backend'; .\venv\Scripts\Activate.ps1; python -m uvicorn app.main:app --host 0.0.0.0 --port $RealApiPort"
)
Write-Host "[RUN] Starting Celery worker ..." -ForegroundColor Yellow
Start-Process powershell -ArgumentList @(
"-NoExit",
"-Command",
"cd '$Backend'; .\venv\Scripts\Activate.ps1; python -m celery -A app.core.celery_app worker --loglevel=info --pool=threads --concurrency=8"
)
Write-Host "[RUN] Starting frontend on $FrontendPort (proxy -> $ApiBase) ..." -ForegroundColor Yellow
Start-Process powershell -ArgumentList @(
"-NoExit",
"-Command",
"`$env:AIAGENT_API_PROXY='$ApiBase'; cd '$Frontend'; pnpm dev --port $FrontendPort"
)
Write-Host ""
Write-Host "[DONE] 启动命令已下发" -ForegroundColor Green
Write-Host "前端: http://localhost:$FrontendPort" -ForegroundColor Cyan
Write-Host "后端: $ApiBase/docs" -ForegroundColor Cyan
Write-Host "Redis: 127.0.0.1:6379" -ForegroundColor Cyan
```
### 运行方式
```powershell
cd D:\aaa\aiagent
powershell -ExecutionPolicy Bypass -File .\start_aiagent.ps1
```
### 可选参数
```powershell
# 指定端口
powershell -ExecutionPolicy Bypass -File .\start_aiagent.ps1 -ApiPort 8037 -FallbackApiPort 8041 -FrontendPort 3001
```
---
## 快速启动脚本(简版)
### Windows CMD 脚本 (`start_all.cmd`)
```batch
@echo off
echo 启动低代码智能体平台...
REM 启动后端服务
start cmd /k "cd /d backend && venv\Scripts\activate && uvicorn app.main:app --host 0.0.0.0 --port 8037 --reload"
REM 启动 Celery Worker
start cmd /k "cd /d backend && venv\Scripts\activate && celery -A app.core.celery_app worker --loglevel=info"
REM 启动前端服务
start cmd /k "cd /d frontend && pnpm dev"
echo 服务启动完成!
echo 前端: http://localhost:3001
echo 后端API: http://localhost:8037/docs
```
### PowerShell 脚本 (`start_all.ps1`)
```powershell
Write-Host "启动低代码智能体平台..." -ForegroundColor Green
# 启动后端服务
Start-Process powershell -ArgumentList "-NoExit", "-Command", "cd backend; .\venv\Scripts\Activate.ps1; uvicorn app.main:app --host 0.0.0.0 --port 8037 --reload"
# 启动 Celery Worker
Start-Process powershell -ArgumentList "-NoExit", "-Command", "cd backend; .\venv\Scripts\Activate.ps1; celery -A app.core.celery_app worker --loglevel=info"
# 启动前端服务
Start-Process powershell -ArgumentList "-NoExit", "-Command", "cd frontend; pnpm dev"
Write-Host "服务启动完成!" -ForegroundColor Green
Write-Host "前端: http://localhost:3001" -ForegroundColor Yellow
Write-Host "后端API: http://localhost:8037/docs" -ForegroundColor Yellow
```
## 停止服务
### 停止所有服务
1.`Ctrl+C` 停止每个终端中的服务
2. 停止 Redis
- Docker Redis: `docker stop redis`
- Windows Redis 服务: 停止 "Redis" 服务
## 生产环境建议
对于生产环境,建议使用:
1. **Docker Compose**:统一管理和部署所有服务
2. **Nginx**:反向代理和负载均衡
3. **Supervisor**:进程管理
4. **数据库备份**:定期备份腾讯云数据库
---
**文档版本**: 1.1
**最后更新**: 2026-04-09
> 注意:本指南针对 Windows 本地开发环境。生产环境部署请参考 [方案-优化版.md](./方案-优化版.md)。

View File

@@ -0,0 +1,74 @@
# Install / uninstall AIAgent auto-start scheduled task
# Usage:
# powershell -ExecutionPolicy Bypass -File .\install_autostart.ps1
# powershell -ExecutionPolicy Bypass -File .\install_autostart.ps1 -Uninstall
param(
[switch]$Uninstall
)
$ErrorActionPreference = "Stop"
$RepoRoot = Split-Path -Parent $MyInvocation.MyCommand.Path
$TaskName = "AIAgent-Startup"
$ScriptPath = Join-Path $RepoRoot "start_aiagent_background.ps1"
if (-not (Test-Path $ScriptPath)) {
Write-Host "ERROR: $ScriptPath not found" -ForegroundColor Red
exit 1
}
if ($Uninstall) {
Write-Host "Uninstalling scheduled task: $TaskName ..." -ForegroundColor Yellow
Unregister-ScheduledTask -TaskName $TaskName -Confirm:$false -ErrorAction SilentlyContinue
Write-Host "[OK] Task '$TaskName' removed" -ForegroundColor Green
exit 0
}
# Remove old task if exists
Unregister-ScheduledTask -TaskName $TaskName -Confirm:$false -ErrorAction SilentlyContinue
# Build action: run background start script
$argString = "-NoProfile -ExecutionPolicy Bypass -WindowStyle Hidden -File `"$ScriptPath`""
$action = New-ScheduledTaskAction -Execute "powershell.exe" -Argument $argString
# Build trigger: 30 seconds after system boot
$trigger = New-ScheduledTaskTrigger -AtStartup -RandomDelay (New-TimeSpan -Seconds 30)
# Build settings
$settings = New-ScheduledTaskSettingsSet `
-AllowStartIfOnBatteries `
-DontStopIfGoingOnBatteries `
-StartWhenAvailable `
-RestartCount 3 `
-RestartInterval (New-TimeSpan -Minutes 1) `
-ExecutionTimeLimit (New-TimeSpan -Minutes 10)
# Run as SYSTEM (no login required)
$principal = New-ScheduledTaskPrincipal -UserId "SYSTEM" -LogonType ServiceAccount -RunLevel Highest
Register-ScheduledTask -TaskName $TaskName `
-Trigger $trigger `
-Action $action `
-Settings $settings `
-Principal $principal `
-Description "AIAgent platform auto-start (Redis + API + Celery + Frontend)" `
-Force
Write-Host ""
Write-Host "==================================================" -ForegroundColor Green
Write-Host "[OK] Auto-start task installed" -ForegroundColor Green
Write-Host "==================================================" -ForegroundColor Green
Write-Host ""
Write-Host "Task name : $TaskName"
Write-Host "Trigger : At system startup (30s delay)"
Write-Host "Run as : SYSTEM (no login required)"
Write-Host "Logs : $RepoRoot\logs\"
Write-Host ""
Write-Host "Manual test (run now):"
Write-Host " Start-ScheduledTask -TaskName '$TaskName'"
Write-Host ""
Write-Host "Uninstall:"
Write-Host " powershell -ExecutionPolicy Bypass -File `"$($MyInvocation.MyCommand.Path)`" -Uninstall"
Write-Host ""
Write-Host "Verify in GUI:"
Write-Host " taskschd.msc -> 任务计划程序库 -> $TaskName"

View File

@@ -0,0 +1,100 @@
# Windows 启动和停止用法(已合并)
本文件已停止维护,请只看以下唯一文档:
- `D:\aaa\aiagent\(红头)Windows服务器启动与重启唯一指南.md`
说明:历史内容已合并至上方文档,后续不再在本文件更新。
# Windows 启动和停止用法(已合并)
本文件已停止维护。
请改看唯一文档:`(红头)Windows服务器启动与重启唯一指南.md`
路径:`D:\aaa\aiagent\(红头)Windows服务器启动与重启唯一指南.md`
# AIAgent Windows 启动和停止用法
## 一键启动
在 PowerShell 中执行:
```powershell
cd D:\aaa\aiagent
powershell -ExecutionPolicy Bypass -File .\start_aiagent.ps1
```
启动后默认访问:
- 前端:`http://localhost:3001`
- 后端文档:`http://127.0.0.1:8037/docs`
- Redis`127.0.0.1:6379`
说明:
-`8037` 被占用,脚本会自动切换到 `8041` 启动后端。
- 前端会自动使用 `AIAGENT_API_PROXY` 指向实际后端端口。
## 启动参数(可选)
```powershell
powershell -ExecutionPolicy Bypass -File .\start_aiagent.ps1 -ApiPort 8037 -FallbackApiPort 8041 -FrontendPort 3001
```
## 一键停止
在 PowerShell 中执行:
```powershell
cd D:\aaa\aiagent
powershell -ExecutionPolicy Bypass -File .\stop_aiagent.ps1
```
会尝试停止以下进程:
- 后端 API`uvicorn app.main:app`
- Celery Worker`celery -A app.core.celery_app worker`
- 前端 dev`vite` / `pnpm dev` / `npm run dev`
- Redis`redis-server`
并检查端口:
- `3001`
- `8037`
- `8041`
- `6379`
## 常见问题
### 1) 执行策略拦截脚本
先执行:
```powershell
Set-ExecutionPolicy -Scope Process Bypass
```
### 2) 发送消息超时30 秒)
优先检查 Redis 和 Worker
```powershell
netstat -ano | findstr :6379
```
确认 Celery Worker 正在运行。
### 3) 8037 端口被占用
先查占用:
```powershell
netstat -ano | findstr :8037
```
再结束对应 PID管理员 PowerShell
```powershell
taskkill /PID <PID> /T /F
```
## 脚本文件位置
- 启动脚本:`D:\aaa\aiagent\start_aiagent.ps1`
- 停止脚本:`D:\aaa\aiagent\stop_aiagent.ps1`

View File

@@ -0,0 +1,10 @@
将修改上传到 git 仓 **rjb_win_dev** 分支:
http://101.43.95.130:3001/admin/aiagent.git
```powershell
cd D:\aaa\aiagent
git push -u origin rjb_win_dev
```
鉴权请使用本机已保存的凭据,或在提示时输入平台账号;**勿在文档中保存明文密码**,也勿将含密码的文件提交到仓库。

View File

@@ -0,0 +1,104 @@
# 🚀 启动说明
## 使用 Docker Compose 启动(推荐)
### 1. 启动所有服务
```bash
docker-compose -f docker-compose.dev.yml up -d
```
### 2. 查看服务状态
```bash
docker-compose ps
```
### 3. 查看日志
```bash
# 查看所有服务日志
docker-compose logs -f
# 查看特定服务日志
docker-compose logs -f backend
docker-compose logs -f frontend
docker-compose logs -f celery
```
### 4. 停止服务
```bash
docker-compose down
```
### 5. 重启服务
```bash
docker-compose restart
```
## 📍 访问地址
- **前端**: http://localhost:8038
- **后端API**: http://localhost:8037
- **API文档**: http://localhost:8037/docs
- **健康检查**: http://localhost:8037/health
## 🔧 配置说明
### 数据库配置
- **数据库类型**: MySQL腾讯云数据库
- **连接地址**: gz-cynosdbmysql-grp-d26pzce5.sql.tencentcdb.com:24936
- **数据库名**: agent_db
- **字符集**: utf8mb4
### 端口配置
- **前端端口**: 8038容器内3000
- **后端端口**: 8037容器内8000
- **Redis端口**: 6379
## ⚠️ 注意事项
1. **数据库连接**: 确保服务器能够访问腾讯云MySQL数据库
2. **首次启动**: 首次启动可能需要一些时间下载镜像和安装依赖
3. **数据库迁移**: 首次运行需要执行数据库迁移(如果需要)
4. **环境变量**: 数据库连接信息已在docker-compose.dev.yml中配置
## 🐛 常见问题
### 1. 容器启动失败
检查:
- Docker 和 Docker Compose 是否正常运行
- 端口是否被占用8038, 8037, 6379
- 磁盘空间是否充足
### 2. 数据库连接失败
检查:
- 网络是否能够访问腾讯云数据库
- 数据库连接信息是否正确
- 数据库是否已创建
### 3. 前端无法访问后端
检查:
- 后端服务是否正常运行
- 前端配置的API URL是否正确
- CORS配置是否正确
### 4. Celery任务不执行
检查:
- Celery Worker容器是否正常运行
- Redis连接是否正常
- 查看Celery日志`docker-compose logs -f celery`
## 📝 下一步
1. 访问 http://localhost:8037/docs 查看API文档
2. 开始开发功能模块
3. 参考 [方案-优化版.md](./方案-优化版.md) 了解详细技术方案

View File

@@ -0,0 +1,62 @@
# 数据库初始化说明
## 问题
注册失败的原因是数据库 `agent_db` 不存在。
## 解决方案
### 方法一使用MySQL客户端创建数据库推荐
连接到腾讯云MySQL数据库执行以下SQL
```sql
CREATE DATABASE IF NOT EXISTS agent_db CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
```
### 方法二:使用命令行工具
如果你有MySQL客户端工具可以执行
```bash
mysql -h gz-cynosdbmysql-grp-d26pzce5.sql.tencentcdb.com -P 24936 -u root -p
# 输入密码: !Rjb12191
# 然后执行
CREATE DATABASE IF NOT EXISTS agent_db CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
```
### 方法三使用Python脚本创建
```python
import pymysql
# 连接MySQL不指定数据库
conn = pymysql.connect(
host='gz-cynosdbmysql-grp-d26pzce5.sql.tencentcdb.com',
port=24936,
user='root',
password='!Rjb12191'
)
cursor = conn.cursor()
cursor.execute("CREATE DATABASE IF NOT EXISTS agent_db CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci")
conn.close()
print("数据库创建成功")
```
## 创建表结构
数据库创建后表结构会在首次运行时自动创建通过SQLAlchemy或者你可以手动执行
```bash
# 进入后端容器
docker-compose -f docker-compose.dev.yml exec backend bash
# 运行初始化脚本
python -c "from app.core.database import init_db; init_db(); print('表创建成功')"
```
## 验证
数据库和表创建成功后,重新尝试注册用户即可。

View File

@@ -0,0 +1,11 @@
# 数据库配置 - 腾讯云数据库
DATABASE_URL=mysql+pymysql://root:!Rjb12191@gz-cynosdbmysql-grp-d26pzce5.sql.tencentcdb.com:24936/agent_db?charset=utf8mb4
# 3. 访问服务
# 前端: http://localhost:8038
# 后端: http://localhost:8037
# API文档: http://localhost:8037/docs

View File

@@ -0,0 +1,132 @@
# 防火墙配置说明
## 问题确认
**已确认是防火墙问题**
- 本地访问 `localhost:8037` ✅ 正常
- 公网访问 `101.43.95.130:8037` ❌ 连接被拒绝
## 解决方案
### 方法1使用脚本自动配置推荐
```bash
# 运行开放端口脚本
sudo bash /home/renjianbo/aiagent/开放端口脚本.sh
```
### 方法2手动配置
#### 如果使用 firewalld (CentOS/RHEL 7+)
```bash
# 开放端口
sudo firewall-cmd --permanent --add-port=8037/tcp
sudo firewall-cmd --permanent --add-port=8038/tcp
# 重新加载配置
sudo firewall-cmd --reload
# 验证
sudo firewall-cmd --list-ports
```
#### 如果使用 ufw (Ubuntu/Debian)
```bash
# 开放端口
sudo ufw allow 8037/tcp
sudo ufw allow 8038/tcp
# 验证
sudo ufw status
```
#### 如果使用 iptables
```bash
# 开放端口
sudo iptables -I INPUT -p tcp --dport 8037 -j ACCEPT
sudo iptables -I INPUT -p tcp --dport 8038 -j ACCEPT
# 保存规则(根据系统不同)
# CentOS/RHEL:
sudo service iptables save
# Debian/Ubuntu:
sudo iptables-save | sudo tee /etc/iptables/rules.v4
```
### 方法3云服务器安全组配置重要
如果使用云服务器腾讯云、阿里云、AWS等**必须在云控制台配置安全组规则**
#### 腾讯云
1. 登录腾讯云控制台
2. 进入「云服务器」->「安全组」
3. 找到对应的安全组,点击「修改规则」
4. 添加入站规则:
- 类型:自定义
- 协议端口TCP:8037
- 来源0.0.0.0/0或指定IP
- 策略:允许
5. 同样添加 8038 端口
#### 阿里云
1. 登录阿里云控制台
2. 进入「ECS」->「网络与安全」->「安全组」
3. 配置规则 -> 入方向 -> 添加安全组规则
4. 端口范围8037/8037授权对象0.0.0.0/0
## 验证
配置完成后,测试:
```bash
# 从服务器本地测试
curl http://localhost:8037/health
# 从公网测试(需要从其他机器或使用在线工具)
curl http://101.43.95.130:8037/health
```
应该返回:`{"status":"healthy"}`
## 检查当前端口监听状态
```bash
# 检查端口是否监听
netstat -tlnp | grep 8037
# 或
ss -tlnp | grep 8037
# 应该看到:
# tcp 0 0 0.0.0.0:8037 ... LISTEN
```
## 常见问题
### Q: 配置了防火墙,但还是无法访问?
A: 检查以下几点:
1. **云服务器安全组**:必须同时配置云控制台的安全组
2. **端口映射**:确认 Docker 端口映射正确(`8037:8000`
3. **服务状态**:确认后端服务正在运行
4. **IP地址**确认公网IP地址正确
### Q: 如何确认是防火墙问题?
A: 从服务器本地测试:
```bash
# 本地访问正常
curl http://localhost:8037/health
# 公网访问被拒绝
curl http://101.43.95.130:8037/health
# 返回: Connection refused
```
---
**状态**: ⚠️ 需要配置防火墙
**下一步**: 运行开放端口脚本或手动配置防火墙规则