注册表
管理桌面代理会话池的Python FastAPI服务。它启动、运行状况检查和池代理+MCP进程对,公开了一个用于获取和释放会话的简单HTTP API。通过PyInstaller打包为独立的Windows可执行文件。
______________________________________________________________________
项目结构
registry/
├── main.py # FastAPI app — session acquire/release/status endpoints
├── session_manager.py # AgentPool and SessionManager — core pool logic
├── models.py # Session dataclass and enums
├── config.yaml # Server config (rdsh mode)
├── config.local.yaml # Local dev config (local mode)
└── dist/
└── registry/ # PyInstaller output
├── registry.exe
├── config.yaml
└── config.local.yaml______________________________________________________________________
端点
GET /session/acquire?agent_type=desktop
从温水池获取可用会话。返回会话详细信息,包括 agent_url.
答复:
{
"slot": 1,
"agent_type": "desktop",
"agent_port": 8001,
"mcp_port": 5001,
"type": "warm",
"status": "busy",
"agent_url": "http://192.168.0.135:8001",
"mcp_url": "http://192.168.0.135:5001"
}POST /session/release/{agent_port}?agent_type=desktop
将会话释放回池中。暖会已标记为可用;动态会话被取消。
GET /session/status
返回所有代理类型的所有会话的当前状态。
______________________________________________________________________
会话模式
local
直接通过以下方式启动代理和MCP subprocess.Popen 在当前桌面上。用于本地开发和测试。
rdsh
通过以下方式在隔离的Windows RDSH用户会话中启动代理和MCP SessionLauncher.exe。每个插槽在专用用户下运行(agent_user_1, agent_user_2等等),因此自动化是完全隔离的。
______________________________________________________________________
配置
config.yaml (服务器--rdsh模式)
agent_types:
desktop:
session_mode: "rdsh"
warm_sessions: 3
max_sessions: 10
agent_script: "C:/agents/desktop_agent/desktop_agent.exe"
mcp_binary: "C:/agents/GoogleSearchMcp/GoogleSearchMcp.exe"
session_launcher: "C:/agents/SessionLauncher/SessionLauncher.exe"
session_users:
- "agent_user_1"
- "agent_user_2"
- "agent_user_3"
agent_base_port: 8000
mcp_base_port: 5000
host: "192.168.0.135"
health_check_interval_seconds: 30
health_check_timeout_seconds: 5
startup_timeout_seconds: 30config.local.yaml (本地开发--本地模式)
agent_types:
desktop:
session_mode: "local"
warm_sessions: 1
max_sessions: 3
agent_script: "D:/VisualStudioCodeWrkSpce/LLMs/demo-desktop-agent/dist/desktop_agent/desktop_agent.exe"
mcp_binary: "D:/VisualStudioWrkSpce/2022/demo-mcp/GoogleSearchMcp/publish/GoogleSearchMcp.exe"
session_launcher: ""
session_users: []
agent_base_port: 8000
mcp_base_port: 5000
host: "localhost"
health_check_interval_seconds: 30
health_check_timeout_seconds: 5
startup_timeout_seconds: 30______________________________________________________________________
构建
cd D:\VisualStudioCodeWrkSpce\LLMs\registry
.venv\Scripts\pyinstaller --onedir --name registry main.py ^
--hidden-import session_manager ^
--hidden-import models ^
--add-binary "C:\Users\PreetPragyan\AppData\Local\Programs\Python\Python312\python312.dll;_internal"输出: dist\registry\registry.exe
cd D:\\VisualStudioCodeWrkSpce\\LLMs\\registry .venv\\Scripts\\pyinstaller--onedir--名称注册表main.py--隐藏导入会话管理器--隐藏导入模型--添加二进制文件“C:\\Users\\PreeTRagyan\\AppData\\Local\\Programs\\Python\\Python312\\Python312.dll;\_internal”
跑
本地测试
cd D:\VisualStudioCodeWrkSpce\LLMs\registry\dist\registry
# Copy config first
copy ..\..\config.local.yaml .
.\registry.exe --config config.local.yaml在服务器上
cd C:\agents\registry
.\registry.exe负载 config.yaml 默认情况下,来自同一目录。
______________________________________________________________________
部署到服务器
- 复制
dist\registry\内容到C:\agents\registry\ - 复制
config.yaml到C:\agents\registry\ - 停止现有进程:
Get-Process registry, desktop_agent, GoogleSearchMcp | Stop-Process -Force- 重新启动:
.\registry.exe______________________________________________________________________
港口参考
| 组件 | 本地端口 | 服务器端口 |
|---|---|---|
| 注册表 | 9000 | 9000 |
| 桌面代理插槽1-3 | 8001-8003 | 8001-8003 |
| MCP工具槽1-3 | 5001-5003 | 5001-5003 |
______________________________________________________________________
健康检查流程
注册表轮询每个代理的 /health 每30秒结束一次。死会话会自动重新启动。
