基于 LangGraph 工作流框架的智能旅行规划系统。
trip-planner/
├── frontend/ # Vue3 前端
├── backend/ # FastAPI + LangGraph 后端
└── README.md # 本文件
- Node.js: >= 18.x
- Python: >= 3.9
- 包管理器: npm 或 yarn
cd backend# Windows
python -m venv venv
venv\Scripts\activate
# macOS/Linux
python -m venv venv
source venv/bin/activatepip install -r requirements.txt复制示例配置文件并修改为你的API密钥:
cp .env.example .env编辑 .env 文件,填入你的API密钥:
# LLM配置(GLM-4)
LLM_API_KEY="your_glm_api_key_here"
LLM_MODEL_ID="glm-4"
LLM_BASE_URL="https://open.bigmodel.cn/api/paas/v4"
# 高德地图API
AMAP_API_KEY="your_amap_key_here"获取 API Key:
python run.py服务启动后:
- 🌐 API 地址: http://localhost:8000
- 📖 接口文档: http://localhost:8000/docs
- 🔍 健康检查: http://localhost:8000/health
# 测试 LangGraph 模块
python verify_langgraph.py
# 运行测试
python tests/langgraph_graph/test_state.py
python tests/langgraph_graph/test_graph.py
# 直接启动(不通过run.py)
uvicorn app.api.main:app --reload --host 0.0.0.0 --port 8000cd frontendnpm install
# 或
yarn installnpm run dev
# 或
yarn dev前端默认地址: http://localhost:5173
npm run build
# 或
yarn buildPOST /api/trip/plan-v2
生成旅行计划(LangGraph 版本)。
请求体:
{
"city": "北京",
"travel_days": 3,
"start_date": "2024-06-01",
"end_date": "2024-06-03",
"preferences": ["美食", "历史文化"],
"accommodation": "舒适型",
"transportation": "飞机",
"free_text_input": ""
}响应:
{
"success": true,
"message": "生成成功(LangGraph)",
"data": {
"city": "北京",
"days": [...],
"weather_info": [...],
"budget": {...}
}
}GET /api/trip/health-v2
{
"status": "healthy",
"framework": "LangGraph",
"version": "0.0.48"
}backend/app/langgraph_graph/
├── state.py # 状态定义(TypedDict)
├── graph.py # 工作流图构建
├── nodes/ # 工作节点
│ ├── attraction_node.py # 景点搜索
│ ├── guide_node.py # 攻略检索(RAG)
│ ├── hotel_node.py # 酒店搜索
│ ├── weather_node.py # 天气查询
│ └── planner_node.py # LLM 规划
└── tools/ # 工具定义
└── map_tools.py # 地图工具
backend/app/services/
├── amap_service.py # 高德地图 API
├── llm_service_langchain.py # LangChain LLM
├── rag/ # RAG 相关
└── unsplash_service.py # 图片搜索
Q: 导入错误 No module named 'app'
# 确保在 backend 目录运行
cd backend
python run.pyQ: 环境变量未加载
# 检查 .env 文件是否存在
ls -la .env
# 手动设置(Windows PowerShell)
$env:AMAP_API_KEY="your_key"
$env:LLM_API_KEY="your_key"Q: LangGraph 模块导入失败
# 验证安装
python verify_langgraph.py
# 重新安装
pip install langgraph>=0.0.48 langchain>=0.1.2Q: 端口被占用
# 更换端口
npm run dev -- --port 3000Q: API 请求失败
检查 frontend/src/services/api.ts 中的 BASE_URL 配置:
const BASE_URL = 'http://localhost:8000/api' // 确保后端地址正确| 文档 | 说明 |
|---|---|
| backend/CLEANUP_REPORT.md | 迁移报告(CrewAI → LangGraph) |
| backend/docs/langgraph_tutorial/RESOURCES.md | 学习资源汇总 |
| backend/tests/README.md | 测试说明 |
- 框架: FastAPI
- 工作流: LangGraph v0.0.48
- LLM: LangChain + GLM-4 (OpenAI 兼容)
- 地图: 高德地图 API
- 框架: Vue 3 + TypeScript
- 构建: Vite
- UI: Ant Design Vue
- 路由: Vue Router
MIT License
祝你使用愉快! 🌍