1. 项目简介
这是一个面向机房运维场景的智能监控 Agent Demo,基于 LangChain + LangGraph 构建,用代码状态机(StateGraph)的方式编排多智能体的对话流程。它模拟了运维工作中最典型的三大场景:
- 设备台账配置:对机房设备进行增、删、改、查操作
- 告警确认:查询告警并以 Human-in-the-loop 交互方式完成告警确认
- 性能数据查询:按时间维度查看设备 CPU、内存、流量等性能指标
整个系统支持对话式交互,既可接入 DeepSeek 大模型进行自然语言理解,也可以在无大模型环境下自动降级为确定性模式,保证开箱即用。
2. 核心特性
- 多 Agent 协作:采用 Router + 设备 Agent + 告警 Agent + 性能 Agent 的分工结构,各司其职
- 零 Token 路由:路由决策由纯 Python 函数完成,不消耗 LLM Token
- Human-in-the-loop:告警确认环节通过 interrupt() 暂停图执行,等待用户选择后再恢复
- 断点续跑:基于 MemorySaver 检查点实现对话状态持久化,中断后可无缝恢复
- 双模式自动降级:配置 DEEPSEEK_API_KEY 时使用大模型;未配置时自动切换到确定性模式(关键词匹配),无需 API Key 也能完整运行
- 模拟数据:所有工具均返回模拟数据,无需真实后端即可体验完整流程
3. 架构设计
3.1 多 Agent 职责
| Router | 意图识别,路由分发(零 Token 纯 Python) | — |
| Device Agent | 设备台账增删改查 | list_devices, get_device, add_device, update_device, delete_device |
| Alarm Agent | 告警查询 + 交互式确认 | list_alarms, get_alarm, confirm_alarm, get_alarm_statistics |
| Performance Agent | 性能指标时序查询 | list_metrics, get_device_performance, get_performance_summary |
| Greeting Response | 兜底应答与帮助信息 | — |
3.2 整体流程
#mermaid-svg-th5jKoLKbjMG9qwX{font-family:\”trebuchet ms\”,verdana,arial,sans-serif;font-size:16px;fill:#333;}@keyframes edge-animation-frame{from{stroke-dashoffset:0;}}@keyframes dash{to{stroke-dashoffset:0;}}#mermaid-svg-th5jKoLKbjMG9qwX .edge-animation-slow{stroke-dasharray:9,5!important;stroke-dashoffset:900;animation:dash 50s linear infinite;stroke-linecap:round;}#mermaid-svg-th5jKoLKbjMG9qwX .edge-animation-fast{stroke-dasharray:9,5!important;stroke-dashoffset:900;animation:dash 20s linear infinite;stroke-linecap:round;}#mermaid-svg-th5jKoLKbjMG9qwX .error-icon{fill:#552222;}#mermaid-svg-th5jKoLKbjMG9qwX .error-text{fill:#552222;stroke:#552222;}#mermaid-svg-th5jKoLKbjMG9qwX .edge-thickness-normal{stroke-width:1px;}#mermaid-svg-th5jKoLKbjMG9qwX .edge-thickness-thick{stroke-width:3.5px;}#mermaid-svg-th5jKoLKbjMG9qwX .edge-pattern-solid{stroke-dasharray:0;}#mermaid-svg-th5jKoLKbjMG9qwX .edge-thickness-invisible{stroke-width:0;fill:none;}#mermaid-svg-th5jKoLKbjMG9qwX .edge-pattern-dashed{stroke-dasharray:3;}#mermaid-svg-th5jKoLKbjMG9qwX .edge-pattern-dotted{stroke-dasharray:2;}#mermaid-svg-th5jKoLKbjMG9qwX .marker{fill:#333333;stroke:#333333;}#mermaid-svg-th5jKoLKbjMG9qwX .marker.cross{stroke:#333333;}#mermaid-svg-th5jKoLKbjMG9qwX svg{font-family:\”trebuchet ms\”,verdana,arial,sans-serif;font-size:16px;}#mermaid-svg-th5jKoLKbjMG9qwX p{margin:0;}#mermaid-svg-th5jKoLKbjMG9qwX .label{font-family:\”trebuchet ms\”,verdana,arial,sans-serif;color:#333;}#mermaid-svg-th5jKoLKbjMG9qwX .cluster-label text{fill:#333;}#mermaid-svg-th5jKoLKbjMG9qwX .cluster-label span{color:#333;}#mermaid-svg-th5jKoLKbjMG9qwX .cluster-label span p{background-color:transparent;}#mermaid-svg-th5jKoLKbjMG9qwX .label text,#mermaid-svg-th5jKoLKbjMG9qwX span{fill:#333;color:#333;}#mermaid-svg-th5jKoLKbjMG9qwX .node rect,#mermaid-svg-th5jKoLKbjMG9qwX .node circle,#mermaid-svg-th5jKoLKbjMG9qwX .node ellipse,#mermaid-svg-th5jKoLKbjMG9qwX .node polygon,#mermaid-svg-th5jKoLKbjMG9qwX .node path{fill:#ECECFF;stroke:#9370DB;stroke-width:1px;}#mermaid-svg-th5jKoLKbjMG9qwX .rough-node .label text,#mermaid-svg-th5jKoLKbjMG9qwX .node .label text,#mermaid-svg-th5jKoLKbjMG9qwX .image-shape .label,#mermaid-svg-th5jKoLKbjMG9qwX .icon-shape .label{text-anchor:middle;}#mermaid-svg-th5jKoLKbjMG9qwX .node .katex path{fill:#000;stroke:#000;stroke-width:1px;}#mermaid-svg-th5jKoLKbjMG9qwX .rough-node .label,#mermaid-svg-th5jKoLKbjMG9qwX .node .label,#mermaid-svg-th5jKoLKbjMG9qwX .image-shape .label,#mermaid-svg-th5jKoLKbjMG9qwX .icon-shape .label{text-align:center;}#mermaid-svg-th5jKoLKbjMG9qwX .node.clickable{cursor:pointer;}#mermaid-svg-th5jKoLKbjMG9qwX .root .anchor path{fill:#333333!important;stroke-width:0;stroke:#333333;}#mermaid-svg-th5jKoLKbjMG9qwX .arrowheadPath{fill:#333333;}#mermaid-svg-th5jKoLKbjMG9qwX .edgePath .path{stroke:#333333;stroke-width:2.0px;}#mermaid-svg-th5jKoLKbjMG9qwX .flowchart-link{stroke:#333333;fill:none;}#mermaid-svg-th5jKoLKbjMG9qwX .edgeLabel{background-color:rgba(232,232,232, 0.8);text-align:center;}#mermaid-svg-th5jKoLKbjMG9qwX .edgeLabel p{background-color:rgba(232,232,232, 0.8);}#mermaid-svg-th5jKoLKbjMG9qwX .edgeLabel rect{opacity:0.5;background-color:rgba(232,232,232, 0.8);fill:rgba(232,232,232, 0.8);}#mermaid-svg-th5jKoLKbjMG9qwX .labelBkg{background-color:rgba(232, 232, 232, 0.5);}#mermaid-svg-th5jKoLKbjMG9qwX .cluster rect{fill:#ffffde;stroke:#aaaa33;stroke-width:1px;}#mermaid-svg-th5jKoLKbjMG9qwX .cluster text{fill:#333;}#mermaid-svg-th5jKoLKbjMG9qwX .cluster span{color:#333;}#mermaid-svg-th5jKoLKbjMG9qwX div.mermaidTooltip{position:absolute;text-align:center;max-width:200px;padding:2px;font-family:\”trebuchet ms\”,verdana,arial,sans-serif;font-size:12px;background:hsl(80, 100%, 96.2745098039%);border:1px solid #aaaa33;border-radius:2px;pointer-events:none;z-index:100;}#mermaid-svg-th5jKoLKbjMG9qwX .flowchartTitleText{text-anchor:middle;font-size:18px;fill:#333;}#mermaid-svg-th5jKoLKbjMG9qwX rect.text{fill:none;stroke-width:0;}#mermaid-svg-th5jKoLKbjMG9qwX .icon-shape,#mermaid-svg-th5jKoLKbjMG9qwX .image-shape{background-color:rgba(232,232,232, 0.8);text-align:center;}#mermaid-svg-th5jKoLKbjMG9qwX .icon-shape p,#mermaid-svg-th5jKoLKbjMG9qwX .image-shape p{background-color:rgba(232,232,232, 0.8);padding:2px;}#mermaid-svg-th5jKoLKbjMG9qwX .icon-shape .label rect,#mermaid-svg-th5jKoLKbjMG9qwX .image-shape .label rect{opacity:0.5;background-color:rgba(232,232,232, 0.8);fill:rgba(232,232,232, 0.8);}#mermaid-svg-th5jKoLKbjMG9qwX .label-icon{display:inline-block;height:1em;overflow:visible;vertical-align:-0.125em;}#mermaid-svg-th5jKoLKbjMG9qwX .node .label-icon path{fill:currentColor;stroke:revert;stroke-width:revert;}#mermaid-svg-th5jKoLKbjMG9qwX :root{–mermaid-font-family:\”trebuchet ms\”,verdana,arial,sans-serif;}
设备台账
告警管理
性能查询
问候/其他




