使用说明
基于代理多智能体系统的实时空域副本
一个多智能体系统,使用OpenSky Network API监控实时航班流量,并通过操作Copilot和个人飞行看门狗提供智能空域监控。
建筑
- n8n:数据获取和存储的工作流编排
- MCP服务器:将航班数据作为特工的工具公开
- CrewAI/LangGraph:配备运维分析师和旅行者支持代理的多代理系统
- Groq有限责任公司API:推理和自然语言生成
- 前端:旅行者和运营视图的简单UI
先决条件
- Python 3.8+
- Node.js和npm(适用于n8n)
- Groq API密钥(自由层)
安装说明
1.安装Python依赖项
pip install -r requirements.txt
2.设置n8n
n8n应该已经与您的工作流一起运行:
- 工作流程1:计划触发器→ HTTP请求→ Code → 写入文件→ Code
- 工作流程2:Webhook→ 读取文件→ Code → 响应Webhook
确保两个工作流都 活跃的 在n8n中。
测试您的webhook:
http://localhost:5678/webhook/latest-data
3.配置环境变量
这 .env 文件应该已经用以下方式创建:
GROQ_API_KEY=your_groq_api_key_here
WEBHOOK_BASE_URL=http://localhost:5678/webhook
FALLBACK_DATA_DIR=C:/Users/hp/Documents
MCP_SERVER_URL=http://localhost:8000
4.启动MCP服务器
在终端中:
python start_mcp_server.py
或者:
python -m mcp_server.server
服务器将于启动 http://localhost:8000
5.测试MCP服务器
健康检查:
curl http://localhost:8000/health
列出可用工具:
curl http://localhost:8000/mcp/tools
获取区域快照:
curl -X POST http://localhost:8000/mcp/tools/flights.list_region_snapshot \
-H "Content-Type: application/json" \
-d '{"region": "data"}'
通过Callsign获取航班:
curl -X POST http://localhost:8000/mcp/tools/flights.get_by_callsign \
-H "Content-Type: application/json" \
-d '{"callsign": "SWR7YT"}'
列出活动警报:
curl -X POST http://localhost:8000/mcp/tools/alerts.list_active \
-H "Content-Type: application/json" \
-d '{}'
项目结构
Agentic-assign-3/
├── config/
│ └── regions.json # Predefined region bounding boxes
├── mcp_server/
│ ├── __init__.py
│ └── server.py # FastAPI MCP server
├── utils/
│ ├── __init__.py
│ └── anomaly_detector.py # Anomaly detection logic
├── agents/
│ ├── __init__.py
│ ├── mcp_tools.py # MCP tools wrapper for agents
│ ├── ops_analyst.py # Operations Analyst Agent
│ ├── traveler_support.py # Traveler Support Agent
│ └── crew.py # CrewAI orchestration
├── frontend/
│ └── app.py # Streamlit frontend
├── main.py # FastAPI agent server
├── start_mcp_server.py # MCP server launcher
├── start_frontend.py # Frontend launcher
├── test_mcp_server.py # MCP server test script
├── requirements.txt
└── README.md
MCP工具
MCP服务器公开了三个工具:
-
flights.list_region_snapshot(地区)
- 返回某个区域的最新快照
- 端点:
POST /mcp/tools/flights.list_region_snapshot
-
flights.get_bycallsign(呼号,地区?)
- 查找给定航班呼号的最新记录
- 端点:
POST /mcp/tools/flights.get_by_callsign
-
alerts.list_active()
- 返回当前标记的异常
- 端点:
POST /mcp/tools/alerts.list_active
异常检测
系统检测到:
- 高空低速:高度>8000米时速度<50米/秒
- 在高空静止:飞行时速度<5 m/s
- 快速下降:垂直速度<-20m/s
- 极端高度/速度:海拔高度>12000米,高速
6.启动代理API服务器
在新终端中:
python main.py
API服务器将于启动 http://localhost:8001
7.启动前端
在新终端中:
streamlit run frontend/app.py
或者:
python start_frontend.py
前端将在您的浏览器中打开 http://localhost:8501
运行完整系统
你需要 4个终端/窗口 同时运行:
-
n8n (已运行)
- Webhook位于:
http://localhost:5678/webhook/latest-data
- Webhook位于:
-
MCP服务器:
python start_mcp_server.py- 正在运行:
http://localhost:8000
- 正在运行:
-
代理API服务器:
python main.py- 正在运行:
http://localhost:8001
- 正在运行:
-
前端:
streamlit run frontend/app.py- 正在运行:
http://localhost:8501
- 正在运行:
系统组件
- ✅ n8n工作流(已完成)
- ✅ MCP服务器(已完成)
- ✅ 代理层(CrewAI)(已完成)
- ✅ 前端用户界面(Streamlit)(已完成)
- ✅ 集成(已完成)
API文档
-
MCP服务器 (端口8000):
- Swagger用户界面:
http://localhost:8000/docs - 重新记录:
http://localhost:8000/redoc
- Swagger用户界面:
-
代理API服务器 (端口8001):
- Swagger用户界面:
http://localhost:8001/docs - 重新记录:
http://localhost:8001/redoc
- Swagger用户界面:
特性
旅行者模式
- 输入航班呼号(例如SWR7YT、THY4KZ)
- 与AI助手讨论您的航班
- 获取实时航班信息
- 问题的自然语言答案
操作模式
- 选择要分析的区域
- 获取操作摘要
- 查看异常警报
- 监控空域状态
代理到代理(A2A)通信
- 旅行者支持代理可以委托给运营分析师代理
- 基于问题类型的自动路由
- 代理之间无缝协作
故障排除
Webhook无法访问
- 确保n8n webhook工作流 活跃的
- 检查webhook URL是否匹配:
http://localhost:5678/webhook/latest-data
MCP服务器找不到数据
- 服务器将首先尝试使用webhook,然后回退到文件
- 检查中的文件路径
FALLBACK_DATA_DIR匹配您的n8n写入位置 - 确保文件路径使用正斜杠:
C:/Users/hp/Documents/
端口冲突
- MCP服务器默认使用端口8000
- 变化
server.py如果需要:uvicorn.run(app, host="0.0.0.0", port=8000)
许可证
该项目是作为代理人工智能任务3的一部分,用于教育目的。