Skip to content
Back to search

multi-agent

A multi-agent travel assistant system built using the **Agent2Agent (A2A)** protocol and **MCP (Model Context Protocol)**

Safety scan

A static text scan, not a guarantee. Select the badge to see what was scanned and every finding.

Checked today
Badge for your README
findsafeskills safety rating

Markdown

[![findsafeskills safety rating](/api/listings/phoenix-zhou--multi-agent/badge.svg)](/listings/phoenix-zhou--multi-agent)

HTML

<a href="/listings/phoenix-zhou--multi-agent"><img src="/api/listings/phoenix-zhou--multi-agent/badge.svg" alt="findsafeskills safety rating" /></a>

Install

i

What was scanned

The files the safety scan read, as written by the repository's author and shown as plain text. Lines with a finding are marked.

README.md · README · 225 lines

View this file on GitHub (read at the repository's current version: the scan did not record which commit it read)

  1. # 🤖 基于 A2A 协议的旅行智能助手
  2. 一个采用 **Agent2Agent (A2A)** 协议 + **MCP (Model Context Protocol)** 构建的多智能体旅行助手系统。系统通过总控中心进行意图识别与路由,由多个专业 Agent 协作完成**天气查询、票务查询、票务预定、景点推荐**等服务,支持 CLI 与 Streamlit Web 两种交互方式。
  3. ## ✨ 功能特性
  4. - 🧭 **智能意图识别**:基于大语言模型(LLM)对用户输入进行意图识别,支持多意图组合(如"明天天气怎么样?顺便查一下去西安的机票")
  5. - 🌤️ **天气查询**:基于真实天气数据,支持自然语言查询(城市 + 日期/相对时间词)
  6. - 🚄 **票务查询**:火车票 / 机票 / 演唱会门票查询,支持票价、余票、车次等信息
  7. - 🎫 **票务预定**:Agent 之间协作完成预定流程(先查余票 → 再执行预定)
  8. - 🏞️ **景点推荐**:直接由 LLM 生成个性化的景点推荐(AIGC)
  9. - 🔄 **多轮对话**:支持上下文记忆,自动对残缺查询进行改写补全
  10. - 🧩 **A2A 协议**:Agent 之间通过标准 A2A 协议通信,自带 AgentCard 名片与技能声明
  11. - 🛠️ **MCP 标准化**:数据访问能力以 MCP 工具形式暴露,与 Agent 解耦
  12. - 💬 **双交互界面**:CLI 命令行版 + Streamlit Web 聊天界面
  13. ## 🏗️ 系统架构
  14. ```
  15. ┌─────────────────────────────────────────────────────────────┐
  16. │ 总控中心 (Orchestrator) │
  17. │ app.py (Streamlit Web) / main.py (CLI) │
  18. │ - 意图识别 (Intent Agent, LLM) │
  19. │ - 查询改写 (Query Rewriting) │
  20. │ - 结果总结 (Summarization, LLM) │
  21. └──────────────┬──────────────────────┬───────────────────────┘
  22. │ A2A 协议 │ A2A 协议
  23. ▼ ▼
  24. ┌───────────────────────┐ ┌───────────────────────────┐
  25. │ A2A Agent 层 │ │ │
  26. │ WeatherQueryAssistant│ │ TicketOrderAssistant │
  27. │ (端口 5005) │ │ (端口 5007) │
  28. │ TicketQueryAssistant │ │ └─ 调用 TicketQuery... │
  29. │ (端口 5006) │ │ (Agent 间协作) │
  30. └───────┬───────────┬───┘ └───────────┬───────────────┘
  31. │ MCP │ MCP │ MCP
  32. ▼ ▼ ▼
  33. ┌─────────────┐ ┌────────────┐ ┌───────────────┐
  34. │ MCP Server 层│ │ │ │ │
  35. │WeatherTools │ │TicketTools │ │ OrderTools │
  36. │ (端口 8002) │ │(端口 8001) │ │ (端口 8003) │
  37. │query_weather│ │query_tickets│ │order_train/ │
  38. │ │ │ │ │order_flight/ │
  39. │ │ │ │ │order_concert │
  40. └──────┬──────┘ └──────┬─────┘ └──────┬────────┘
  41. │ │ │
  42. ▼ ▼ ▼
  43. ┌────────────────────────────────────┐
  44. │ MySQL 数据库 travel_rag │
  45. │ weather_data / train_tickets / │
  46. │ flight_tickets / concert_tickets │
  47. └────────────────────────────────────┘
  48. ```
  49. ### 处理流程
  50. ```
  51. 用户输入 → 意图识别(LLM) → 路由到对应 Agent
  52. ├─ out_of_scope / 追问 → 直接回复
  53. ├─ attraction → LLM 直接生成景点推荐
  54. └─ weather/flight/train/concert/order
  55. → A2A Agent 生成 SQL (LLM)
  56. → 调用 MCP 工具查询数据库
  57. → 返回结果 → 总控中心 LLM 总结 → 用户
  58. ```
  59. ### 端口规划
  60. | 服务 | 组件 | 端口 |
  61. |------|------|------|
  62. | A2A Agent | WeatherQueryAssistant(天气查询) | 5005 |
  63. | A2A Agent | TicketQueryAssistant(票务查询) | 5006 |
  64. | A2A Agent | TicketOrderAssistant(票务预定) | 5007 |
  65. | MCP Server | WeatherTools(天气工具) | 8002 |
  66. | MCP Server | TicketTools(票务工具) | 8001 |
  67. | MCP Server | OrderTools(预定工具) | 8003 |
  68. | Web UI | Streamlit 应用 | 8501(默认) |
  69. ## 📁 目录结构
  70. ```
  71. multi-agent/
  72. ├── app.py # Streamlit Web 入口(总控中心)
  73. ├── main.py # CLI 命令行入口(总控中心)
  74. ├── main_prompts.py # 提示词模板(意图识别/结果总结/景点推荐)
  75. ├── config.py # 全局配置(LLM / 数据库 / 意图映射)
  76. ├── create_logger.py # 日志配置
  77. │
  78. ├── a2a_server/ # A2A 协议 Agent 服务层
  79. │ ├── weather_server.py # 天气查询 Agent(端口 5005)
  80. │ ├── ticket_server.py # 票务查询 Agent(端口 5006)
  81. │ └── order_server.py # 票务预定 Agent(端口 5007)
  82. │
  83. ├── mcp_server/ # MCP Server 数据服务层
  84. │ ├── mcp_weather_server.py # 天气 MCP(端口 8002)
  85. │ ├── mcp_ticket_server.py # 票务 MCP(端口 8001)
  86. │ └── mcp_order_server.py # 预定 MCP(端口 8003)
  87. │
  88. ├── query_data/
  89. │ └── query_ticket.py # 票务数据库查询服务
  90. │
  91. ├── utils/
  92. │ ├── format.py # JSON 日期/Decimal 序列化工具
  93. │ └── spider_weather.py # 和风天气数据爬虫(定时更新天气库)
  94. │
  95. ├── sql/
  96. │ ├── sql_data.sql # 建库建表 DDL
  97. │ └── insert2.sql # 票务示例数据
  98. │
  99. └── test/ # 各服务测试脚本
  100. ├── test_weather_mcp_server.py
  101. ├── test_ticket_mcp_server.py
  102. ├── test_order_mcp_server.py
  103. ├── test_weather_agent_server.py
  104. ├── test_ticket_agent_server.py
  105. └── test_order_agent_server.py
  106. ```
  107. ## 🛠️ 技术栈
  108. - **Agent 协议**:[A2A](https://github.com/a2aproject/A2A)(`python_a2a`)
  109. - **工具协议**:[MCP](https://modelcontextprotocol.io)(`mcp` / FastMCP / `langchain-mcp-adapters`)
  110. - **大语言模型**:LangChain(`langchain-openai`),通过 SiliconFlow 接入 Qwen2.5-72B-Instruct(可替换任意 OpenAI 兼容接口)
  111. - **Web 界面**:Streamlit
  112. - **数据库**:MySQL(`mysql-connector-python`)
  113. - **数据源**:和风天气 API(30 天预报)
  114. ## 🚀 快速开始
  115. ### 1. 环境准备
  116. ```bash
  117. # Python 3.9+
  118. pip install streamlit langchain langchain-openai python-a2a mcp
  119. pip install langchain-mcp-adapters mysql-connector-python requests schedule pytz
  120. ```
  121. ### 2. 初始化数据库
  122. ```bash
  123. # 执行建库建表脚本
  124. mysql -u root -p < sql/sql_data.sql
  125. # 导入票务示例数据
  126. mysql -u root -p travel_rag < sql/insert2.sql
  127. ```
  128. > 如需导入真实天气数据,运行 `python utils/spider_weather.py`(需配置和风天气 API Key)。
  129. ### 3. 修改配置
  130. 编辑 `config.py`,配置你的 LLM 与数据库信息:
  131. ```python
  132. # 大模型配置
  133. self.base_url = 'https://api.siliconflow.cn/v1'
  134. self.api_key = 'sk-xxx' # 替换为你的 API Key
  135. self.model_name = 'Qwen/Qwen2.5-72B-Instruct'
  136. # 数据库配置
  137. self.host = 'localhost'
  138. self.user = 'root'
  139. self.password = '123456'
  140. self.database = 'travel_rag'
  141. ```
  142. ### 4. 启动服务(按顺序)
  143. ```bash
  144. # ① 启动 MCP Server(数据层)
  145. python mcp_server/mcp_weather_server.py # 端口 8002
  146. python mcp_server/mcp_ticket_server.py # 端口 8001
  147. python mcp_server/mcp_order_server.py # 端口 8003
  148. # ② 启动 A2A Agent(智能体层)
  149. python a2a_server/weather_server.py # 端口 5005
  150. python a2a_server/ticket_server.py # 端口 5006
  151. python a2a_server/order_server.py # 端口 5007
  152. # ③ 启动总控中心(二选一)
  153. python main.py # CLI 交互版
  154. streamlit run app.py # Web 聊天版
  155. ```
  156. ## 💬 使用示例
  157. ```
  158. > 成都明天天气怎么样
  159. > 帮我查一下明天成都到西安的高铁票
  160. > 7月15号从成都到西安的机票还有吗
  161. > 帮我订一张明天成都到西安的二等座火车票
  162. > 去西安有什么好玩的景点推荐
  163. > 明天天气怎么样 + 顺便看看去广州的机票 # 多意图组合
  164. ```
  165. CLI 版输入 `cards` 可查看所有 Agent 的卡片信息(技能/描述/地址),输入 `quit` 退出。
  166. ## 🔑 核心设计说明
  167. 1. **意图识别与查询改写**(`main_prompts.py`):总控中心将用户输入收敛为 `weather / flight / train / concert / order / attraction / out_of_scope` 等固定意图;结合对话历史将残缺查询(如"那明天呢?")改写为完整明确的句子,使下游 Agent 无需关心上下文。
  168. 2. **SQL 生成 Agent**(`a2a_server/`):下游 Agent 通过 LLM 将自然语言转换为 SQL,并将数据库 Schema 作为提示词上下文。信息不足时返回 `input_required` 追问用户,无关提问则拒绝回答。
  169. 3. **Agent 间协作**(`order_server.py`):票务预定 Agent 先调用票务查询 Agent 确认余票,再将余票信息拼接后交由 MCP 预定工具执行,体现了多 Agent 协作流程。
  170. 4. **MCP 解耦**:数据库访问统一封装为 MCP 工具(`query_weather` / `query_tickets` / `order_train` 等),Agent 通过 HTTP 流式调用,数据层与智能体层彻底解耦,便于扩展。
  171. ## 🧪 测试
  172. `test/` 目录下提供了各 MCP Server 与 A2A Agent 的独立测试脚本,启动对应服务后即可运行:
  173. ```bash
  174. python test/test_weather_mcp_server.py
  175. python test/test_weather_agent_server.py
  176. python test/test_ticket_mcp_server.py
  177. python test/test_ticket_agent_server.py
  178. python test/test_order_mcp_server.py
  179. python test/test_order_agent_server.py
  180. ```
  181. ## 📄 License
  182. MIT
  183. ## 对应的博客:[]

Ratings and comments

Sign in to rate this skill.

Sign in

Free to use. If it’s helped, pass it on.