🏡 模拟物联网MCP编排器
该项目演示了如何使用 模型上下文协议(MCP) 与LangChain ReAct风格的代理合作。每个设备生态系统都作为自己的MCP服务器运行,代理协调它们之间的工具调用。
✨ 示例用法
从命令行:
uv run main.py "Lock the front door and power on the TV and set the lights to netflix and chill"🔄 代理编排流程
- 解析用户的自然语言请求。
- 从以下选项中选择合适的工具 多个MCP服务器.
- 按顺序调用每个工具(
lock_door,power_on,set_color,set_brightness). - 返回干净、人类可读的结果。
✅ 示例输出
The front door has been locked, the TV is powered on, and the living room lights have been set to a warm white color with a brightness level of 40% for a cozy "Netflix and chill" vibe. Enjoy your time!______________________________________________________________________
📊 多服务器序列图
sequenceDiagram
participant User
participant LangChain_Agent
participant Locks_Server
participant SonyTV_Server
participant Hue_Server
User->>LangChain_Agent: "Lock the front door and power on the TV and set the lights to netflix and chill"
LangChain_Agent->>Locks_Server: lock_door(door="front")
Locks_Server-->>LangChain_Agent: { "status": "ok" }
LangChain_Agent->>SonyTV_Server: power_on()
SonyTV_Server-->>LangChain_Agent: { "status": "ok" }
LangChain_Agent->>Hue_Server: set_color(room="living room", color="warm white")
Hue_Server-->>LangChain_Agent: { "status": "ok" }
LangChain_Agent->>Hue_Server: set_brightness(room="living room", level=40)
Hue_Server-->>LangChain_Agent: { "status": "ok" }
LangChain_Agent-->>User: "The front door has been locked, the TV is powered on, and the living room lights have been set..."