SmartBizTripFlow.svg 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. <svg xmlns="http://www.w3.org/2000/svg" width="1560" height="1300" viewBox="0 0 1560 1300" font-family="Microsoft YaHei, Noto Sans CJK SC, sans-serif">
  2. <defs>
  3. <marker id="arr" markerWidth="10" markerHeight="10" refX="8" refY="4" orient="auto">
  4. <path d="M0 0L8 4L0 8Z" fill="#666"/>
  5. </marker>
  6. </defs>
  7. <style>
  8. .title{font-size:26px;font-weight:700;fill:#111}
  9. .sub{font-size:14px;fill:#666}
  10. .layer{font-size:14px;font-weight:700;fill:#777}
  11. .bt{font-size:15px;font-weight:700;fill:#222}
  12. .bb{font-size:12px;fill:#555}
  13. .note{font-size:11px;fill:#888}
  14. .lbl{font-size:12px;fill:#666}
  15. .box{fill:#fff;stroke:#888;stroke-width:1.5}
  16. .band{fill:#f7f7f7;stroke:#ddd;stroke-width:1}
  17. .flow{fill:none;stroke:#666;stroke-width:1.6;marker-end:url(#arr)}
  18. .hflow{fill:none;stroke:#666;stroke-width:1.4;marker-end:url(#arr)}
  19. .link{fill:none;stroke:#999;stroke-width:1.4;marker-start:url(#arr);marker-end:url(#arr)}
  20. </style>
  21. <text x="780" y="44" text-anchor="middle" class="title">SmartBizTrip 整体架构图</text>
  22. <text x="780" y="70" text-anchor="middle" class="sub">六层结构 + 主助手五步处理流程;端口 / 文件名 / 工具名均对照代码核实</text>
  23. <!-- 分层背景带 -->
  24. <rect x="40" y="88" width="1480" height="100" rx="6" class="band"/>
  25. <text x="56" y="112" class="layer">① 客户端层</text>
  26. <rect x="40" y="228" width="1480" height="100" rx="6" class="band"/>
  27. <text x="56" y="252" class="layer">② API 服务层</text>
  28. <rect x="40" y="370" width="1480" height="250" rx="6" class="band"/>
  29. <text x="56" y="394" class="layer">③ 主助手 · 协调层</text>
  30. <rect x="40" y="680" width="1480" height="170" rx="6" class="band"/>
  31. <text x="56" y="704" class="layer">④ A2A 子助手层</text>
  32. <rect x="40" y="890" width="1480" height="170" rx="6" class="band"/>
  33. <text x="56" y="914" class="layer">⑤ MCP 工具层</text>
  34. <rect x="40" y="1100" width="1480" height="140" rx="6" class="band"/>
  35. <text x="56" y="1124" class="layer">⑥ 数据层</text>
  36. <!-- ① 客户端 -->
  37. <rect x="180" y="126" width="560" height="54" rx="4" class="box"/>
  38. <text x="204" y="148" class="bt">网页客户端 — static/index.html</text>
  39. <text x="204" y="170" class="bb">聊天界面 · 代理卡片 · 记忆面板(SSE 逐段渲染)</text>
  40. <rect x="820" y="126" width="560" height="54" rx="4" class="box"/>
  41. <text x="844" y="148" class="bt">命令行客户端 — 课件示例/classroom_main.py</text>
  42. <text x="844" y="170" class="bb">逐轮输入问题,控制台打印回复</text>
  43. <!-- ② API -->
  44. <rect x="330" y="266" width="900" height="54" rx="4" class="box"/>
  45. <text x="354" y="288" class="bt">api_server.py — FastAPI · 127.0.0.1:8080</text>
  46. <text x="354" y="310" class="bb">POST /api/chat/stream(SSE 流式,网页默认) · POST /api/chat · GET /api/agents · /api/memory 系列</text>
  47. <!-- ③ 主助手五步流程 -->
  48. <rect x="45" y="408" width="270" height="92" rx="4" class="box"/>
  49. <text x="65" y="432" class="bt">① 记忆写入</text>
  50. <text x="65" y="456" class="bb">add_message("user")</text>
  51. <text x="65" y="478" class="bb">带偏好 · 历史 · 任务上下文</text>
  52. <rect x="345" y="408" width="270" height="92" rx="4" class="box"/>
  53. <text x="365" y="432" class="bt">② 意图识别 intent_agent</text>
  54. <text x="365" y="456" class="bb">LLM → JSON</text>
  55. <text x="365" y="478" class="bb">意图 / 改写查询 / 追问</text>
  56. <rect x="645" y="408" width="270" height="92" rx="4" class="box"/>
  57. <text x="665" y="432" class="bt">③ 追问 · 范围外?</text>
  58. <text x="665" y="456" class="bb">是 → 直接返回追问,本轮结束</text>
  59. <text x="665" y="478" class="bb">否 → 继续路由</text>
  60. <rect x="945" y="408" width="270" height="92" rx="4" class="box"/>
  61. <text x="965" y="432" class="bt">④ 路由与执行</text>
  62. <text x="965" y="456" class="bb">简单:逐意图直接执行</text>
  63. <text x="965" y="478" class="bb">复杂:规划 → ReAct(依赖分批 · 批内并行)</text>
  64. <rect x="1245" y="408" width="270" height="92" rx="4" class="box"/>
  65. <text x="1265" y="432" class="bt">⑤ 汇总输出</text>
  66. <text x="1265" y="456" class="bb">summarize 整理 · 流式分片</text>
  67. <text x="1265" y="478" class="bb">多步才调汇总模型 · 存记忆</text>
  68. <path d="M315 454 H345" class="hflow"/>
  69. <path d="M615 454 H645" class="hflow"/>
  70. <path d="M915 454 H945" class="hflow"/>
  71. <path d="M1215 454 H1245" class="hflow"/>
  72. <rect x="45" y="544" width="1470" height="58" rx="4" class="box"/>
  73. <text x="69" y="566" class="bt">memory.py — ConversationMemory(记忆模块)</text>
  74. <text x="69" y="588" class="bb">短期对话(10 条) · 用户偏好 · 任务上下文 · 查询实体/历史 | 启动时从 MySQL 记忆表恢复,变更时写回;派发子助手前记录查询历史</text>
  75. <path d="M180 500 V544" class="link"/>
  76. <path d="M1380 500 V544" class="link"/>
  77. <!-- ④ A2A -->
  78. <rect x="40" y="718" width="450" height="96" rx="4" class="box"/>
  79. <text x="64" y="742" class="bt">天气子助手 · :5005</text>
  80. <text x="64" y="766" class="bb">a2a_server/weather_server.py</text>
  81. <text x="64" y="786" class="bb">WeatherQueryAssistant · AgentCard</text>
  82. <text x="64" y="806" class="bb">工具调用 Agent · 缺参数则追问</text>
  83. <rect x="555" y="718" width="450" height="96" rx="4" class="box"/>
  84. <text x="579" y="742" class="bt">票务子助手 · :5006</text>
  85. <text x="579" y="766" class="bb">a2a_server/ticket_server.py</text>
  86. <text x="579" y="786" class="bb">TicketServer(TicketAssistant)</text>
  87. <text x="579" y="806" class="bb">高铁 / 航班 / 会展:查询 + 模拟预订</text>
  88. <rect x="1070" y="718" width="450" height="96" rx="4" class="box"/>
  89. <text x="1094" y="742" class="bt">差旅子助手 · :5007</text>
  90. <text x="1094" y="766" class="bb">a2a_server/trip_server.py</text>
  91. <text x="1094" y="786" class="bb">TripAssistant</text>
  92. <text x="1094" y="806" class="bb">商务用车 / 保险 / 会务套餐</text>
  93. <!-- ⑤ MCP -->
  94. <rect x="40" y="928" width="450" height="96" rx="4" class="box"/>
  95. <text x="64" y="952" class="bt">天气 MCP · :8002</text>
  96. <text x="64" y="976" class="bb">mcp_server/mcp_weather_server.py</text>
  97. <text x="64" y="996" class="bb">query_weather</text>
  98. <text x="64" y="1016" class="bb">双数据源:MySQL / 和风API 直查</text>
  99. <rect x="555" y="928" width="450" height="96" rx="4" class="box"/>
  100. <text x="579" y="952" class="bt">票务 MCP · :8001</text>
  101. <text x="579" y="976" class="bb">mcp_server/mcp_ticket_server.py</text>
  102. <text x="579" y="996" class="bb">query / order:train · flight · event</text>
  103. <text x="579" y="1016" class="bb">参数化 SQL 查询</text>
  104. <rect x="1070" y="928" width="450" height="96" rx="4" class="box"/>
  105. <text x="1094" y="952" class="bt">差旅 MCP · :8003</text>
  106. <text x="1094" y="976" class="bb">mcp_server/mcp_trip_server.py</text>
  107. <text x="1094" y="996" class="bb">query / order:用车 · 保险 · 会务套餐</text>
  108. <text x="1094" y="1016" class="bb">会务套餐走 Milvus 语义检索</text>
  109. <!-- ⑥ 数据层 -->
  110. <rect x="40" y="1138" width="760" height="80" rx="4" class="box"/>
  111. <text x="64" y="1162" class="bt">MySQL · :3306 · biztrip_rag</text>
  112. <text x="64" y="1184" class="bb">业务表:train / flight / event_tickets · weather_data · car_rentals · insurances</text>
  113. <text x="64" y="1206" class="bb">记忆表:user_profiles · query_history · short_term_messages(weather_data ← 爬虫定时采集)</text>
  114. <rect x="1080" y="1138" width="440" height="80" rx="4" class="box"/>
  115. <text x="1104" y="1162" class="bt">Milvus 向量库 · :19530</text>
  116. <text x="1104" y="1184" class="bb">会务套餐集合 · text-embedding-v3 · COSINE</text>
  117. <text x="1104" y="1206" class="bb">初始化:sql/init_meeting_package_rag.py</text>
  118. <!-- 层间连线 -->
  119. <path d="M460 180 V266" class="flow"/>
  120. <path d="M1100 180 V266" class="flow"/>
  121. <text x="475" y="212" class="lbl">POST /api/chat/stream(SSE)</text>
  122. <path d="M780 320 V360 H200 V408" class="flow"/>
  123. <text x="795" y="350" class="lbl">chat_stream / chat</text>
  124. <path d="M265 620 V718" class="flow"/>
  125. <path d="M780 620 V718" class="flow"/>
  126. <path d="M1295 620 V718" class="flow"/>
  127. <text x="300" y="640" class="lbl">A2A 协议:Task → status / artifacts</text>
  128. <text x="300" y="658" class="lbl">意图映射:weather→天气助手 | train / flight / event / order→票务助手</text>
  129. <text x="300" y="676" class="lbl">car_rental / meeting_package / insurance / trip_order→差旅助手 | city_service→主助手直连</text>
  130. <path d="M265 814 V928" class="flow"/>
  131. <path d="M780 814 V928" class="flow"/>
  132. <path d="M1295 814 V928" class="flow"/>
  133. <text x="300" y="872" class="lbl">MCP 工具调用(to_langchain_tool)</text>
  134. <path d="M265 1024 V1138" class="flow"/>
  135. <path d="M780 1024 V1138" class="flow"/>
  136. <path d="M1295 1024 V1138" class="flow"/>
  137. <text x="300" y="1082" class="lbl">参数化 SQL / 向量检索(会务套餐 RAG)</text>
  138. <text x="40" y="1268" class="note">要点:MCP 为参数化工具(%s 防注入,LLM 只提参数不写 SQL);预订均为模拟演示;天气数据由 utils/spider_weather.py 定时从和风API采集入库;启动顺序:MCP(8001-8003) → A2A(5005-5007) → api_server(8080)。</text>
  139. </svg>