opkit 是面向 AI Agent 运维场景的设备连接中间件,Agent 通过它连接、操作各类设备。它负责:
opkit is a device-connectivity middleware for AI-agent-driven operations: agents connect to and operate all kinds of devices through it. It is responsible for:
- 凭据与会话管理:
- 访问设备的凭据对 Agent 不可见
- 会话生命周期管理(例如 Redfish 如果不及时清理会话可能造成 BMC 卡死)
Credential and session management: device credentials stay invisible to the agent; session lifecycles are managed for it (e.g. an untidy Redfish logout can wedge a BMC).
- 协议包装与适配:
- 对各类协议做基础包装,例如网络设备的 WebUI、SSH 终端等
- 透传协议内容(例如终端字符、HTTP 报文),不对内容进行解析和识别
Protocol wrapping and adaptation: basic wrappers for each protocol — network-device WebUIs, SSH terminals, and so on — passing protocol content through (terminal characters, HTTP messages) without parsing or interpreting it.
flowchart LR
subgraph Agent 侧
MCP[MCP 客户端]
CLI[CLI]
AstrBot[AstrBot Plugin]
end
subgraph opkit
kernel[凭据与会话管理]
proto[协议后端]
kernel <--> proto
end
subgraph 设备
webui[WebUI]
sshd[SSH]
bmc[BMC Redfish]
end
MCP --- kernel
CLI --- kernel
AstrBot --- kernel
proto --> webui
proto --> sshd
proto --> bmc
支持 HTTP 和 stdio,提供如下工具:
Available over HTTP and stdio. The tools:
- 会话管理:
list_devices:列出设备及其支持的协议open_session:打开(或复用)会话,兼作连通性与凭据探针list_sessions:列出当前所有会话close_session:关闭会话
Session management:list_deviceslists devices and their protocols;open_sessionopens (or reuses) a session and doubles as a connectivity/credential probe;list_sessionslists everything currently open;close_sessioncloses one.
- 各类协议:
ssh_exec:SSH exec,单命令执行并返回结构化结果ssh_terminal:SSH 终端的字节流写入与读取(data省略时只读)http:WebUI HTTP 请求redfish:BMC Redfish 请求
Per protocol:ssh_execruns one command over SSH exec and returns a structured result;ssh_terminalwrites and reads an SSH terminal's byte stream (omitdatafor a read-only poll);httpsends WebUI HTTP requests;redfishsends BMC Redfish requests.
-
账户:一份凭据,供各协议使用
Accounts: one credential set, used by any protocol.
accounts: - name: lab-admin username: admin password: plaintext-password # intentional; keep this file out of VCS - name: net-op username: root ssh_private_key: | -----BEGIN OPENSSH PRIVATE KEY-----
-
设备和协议:一个设备可以有多种协议,一个协议就是一种连接方式,不同协议的配置项不同
Devices and protocols: a device may expose several protocols; a protocol is one way in, and each protocol has its own config keys. -
用户名覆盖:协议可设置
username:覆盖账户的用户名,无需为部分用户名不可更改的厂商/协议创建多个凭据相同的账户
Username override: a protocol entry may setusername:to override the account's — no need for duplicate accounts when a vendor fixes the login name.
devices:
# One box, two channels.
- name: node1
redfish:
endpoint: https://10.0.0.3
account: lab-admin
ssh-exec:
endpoint: 10.0.0.3
account: net-op
- name: sw-core
ssh-terminal:
endpoint: 172.25.3.1
port: 22
account: net-op
- name: cpe-ap
http:
endpoint: http://192.168.1.1
auth: tplink # none | tplink | zte-be7200 | mellanox
account: webui-onlyhttp 协议下,不同设备有不同认证方式:
Under the http protocol, different devices authenticate differently:
auth |
Login flow | Username |
|---|---|---|
none |
匿名访问 | — |
tplink |
混淆密码 POST /logon.cgi;g_tid token 注入后续 *.cgi 请求 |
必填 |
zte-be7200 |
password+login token 的 SHA-256 摘要;POST 请求注入 _sessionTOKEN |
必填——设置 username: admin(固件拒绝其他用户名) |
mellanox |
Onyx launch-script 表单登录 | 必填 |
none: anonymous. tplink: scrambled-password POST to /logon.cgi with a g_tid token injected into later *.cgi requests; username required. zte-be7200: SHA-256 digest of password + login token, with _sessionTOKEN injected into POSTs; set username: admin — the firmware rejects other names. mellanox: Onyx launch-script form login; username required.
下表的传输行为均在生产硬件上端到端验证过(会话 open、operations、close):
Transport behavior in this table was verified end to end on production hardware (session open, operations, close):
| Vendor and model | Software | Protocol |
|---|---|---|
| Huawei S1730S-S48T4X-A1 | VRP 5.170 (V200R022C00SPC500) | ssh-terminal |
| Huawei S5720-28P-LI-AC | VRP 5.170 (V200R011C10SPC600) | ssh-terminal |
| Huawei S5720S-52P-LI-AC | VRP 5.170 (V200R011C10SPC600) | ssh-terminal |
| Huawei FutureMatrix S6720S-S24S28X-A | VRP 5.170 (V200R022C00SPC500) | ssh-terminal |
| MikroTik CCR2004-1G-12S+2XS (r3) | RouterOS 7.23.1 stable | ssh-exec |
| OpenWrt and ImmortalWrt devices | Various | ssh-exec |
| TP-Link TL-SG2226 / TL-SG2024D / TL-SE2206 | 2023–2024 WebUIs | http: tplink |
| ZTE 问天 BE7200 Pro+ (ZXSLC SR7410) | V1.0.0.4B8.8000 | http: zte-be7200 |
| Mellanox SN2700 | Onyx 3.7.1134 | http: mellanox + ssh-terminal |
src:源代码docs/device-skills:各类设备的操作经验
srcholds the source;docs/device-skillscollects operating experience for specific devices.
- 写
protocols/<name>.py:协议的 dataclass +parse_config、拥有线上状态的 session 类、提供open / occupied / list_open / close / close_all的 manager。 - 在
opkit.config.PARSERS注册解析器。 - 在
opkit.mcp_server加它的操作工具。
1. Writeprotocols/<name>.py: the protocol dataclass +parse_config, a session class owning its wire state, and a manager providingopen / occupied / list_open / close / close_all. 2. Register the parser inopkit.config.PARSERS. 3. Add its operation tool inopkit.mcp_server.
一些厂商的 WebUI 对 Agent 不友好,直接抓取请求解析往往无法找到正确路径。一般建议 Agent 先使用浏览器操作 WebUI,同时抓取请求,然后形成 Skill。 Some vendors' WebUIs are agent-hostile: sniffing requests up front rarely finds the right endpoints. The working approach is to drive the WebUI in a real browser once while capturing traffic, then distill that into a device skill.
为兼容各类老旧设备,默认采用如下配置:
To stay compatible with aging devices, these defaults apply:
- TLS/SSL
- 证书验证全局关闭
- 启用老版本协议(TLS 1.2 等)
- SSH
- 主机公钥不校验
- 启用弃用的 RSA 套件
TLS/SSL: certificate verification is globally disabled; older protocol versions (TLS 1.2 and such) are enabled. SSH: host keys are not verified; deprecated RSA suites are enabled.
协议内容透传不做脱敏,所以输出中的敏感内容可能仍会被暴露给 Agent,请使用可信的 Agent。
Protocol content is passed through without sanitization, so sensitive material in responses may still reach the agent — use agents you trust.
调用方提交受管 header(cookie/authorization/host/x-auth-token)会被拒绝,因为那会破坏会话处理。
Callers submitting managed headers (cookie/authorization/host/x-auth-token) are rejected, because that would break session handling.