词元之母TOK.MOM - 平台充值汇率 1:1 即 1 人民币充值到账 1 美元,支持一个 Key 调用近 600+ 海内外模型,限时特价模型低至 1 折,欢迎上岸!
用户 ↔ 消息平台 ↔ 平台适配器 ↔ Gateway Runner ↔ AIAgentgateway/platforms/base.py 中的 BasePlatformAdapter,并实现以下方法:connect() — 建立连接(WebSocket、长轮询、HTTP 服务器等)(抽象方法)disconnect() — 清理关闭 (抽象方法)send() — 向聊天发送文本消息 (抽象方法)send_typing() — 显示正在输入指示器(可选覆盖)get_chat_info() — 返回聊天元数据(可选覆盖)self.handle_message(event) 转发,基类将其路由到 gateway runner。~/.hermes/plugins/my-platform/
PLUGIN.yaml # Plugin 元数据
adapter.py # 适配器类 + register() 入口点requires_env 和 optional_env 块会自动填充 hermes config UI 条目(参见下方在 hermes config 中暴露环境变量)。config.yaml 中配置平台:__init__ 中读取)。ctx.register_platform() 时,以下集成点将自动处理 — 无需修改核心代码:| 集成点 | 工作方式 |
|---|---|
| Gateway 适配器创建 | 在内置 if/elif 链之前检查注册表 |
| 配置解析 | Platform._missing_() 接受任意平台名称 |
| 已连接平台验证 | 调用注册表中的 validate_config() |
| 用户授权 | 检查 allowed_users_env / allow_all_env |
| 仅环境变量自动启用 | env_enablement_fn 填充 PlatformConfig.extra + home_channel |
| YAML 配置桥接 | apply_yaml_config_fn 将 config.yaml 键转换为环境变量/extras |
| Cron 投递 | cron_deliver_env_var 使 deliver=<name> 生效 |
hermes config UI 条目 | plugin.yaml 中的 requires_env / optional_env 自动填充 |
| send_message 工具 | 通过实时 gateway 适配器路由 |
| Webhook 跨平台投递 | 检查注册表中的已知平台 |
/update 命令访问 | allow_update_command 标志 |
| 频道目录 | Plugin 平台包含在枚举中 |
| 系统 prompt 提示 | platform_hint 注入 LLM 上下文 |
| 消息分块 | max_message_length 用于智能分割 |
| PII 脱敏 | pii_safe 标志 |
hermes status | 显示带 (plugin) 标签的 plugin 平台 |
hermes gateway setup | Plugin 平台出现在设置菜单中 |
hermes tools / hermes skills | Plugin 平台出现在每平台配置中 |
| Token 锁(多配置文件) | 在 connect() 中使用 acquire_scoped_lock() |
| 孤立配置警告 | Plugin 缺失时输出描述性日志 |
~/.hermes/.env 来配置平台,而不是编辑 config.yaml。env_enablement_fn hook 允许你的 plugin 在适配器构建之前读取这些环境变量,使 hermes gateway status、get_connected_platforms() 和 cron 投递无需实例化平台 SDK 即可看到正确状态。config.yaml 键(my_platform.require_mention、my_platform.allowed_channels 等)而非环境变量。apply_yaml_config_fn hook 允许你的 plugin 自行处理这一转换,而无需强制核心 gateway/config.py 了解你平台的 YAML schema。load_gateway_config() 期间,于通用共享键循环(处理 unauthorized_dm_behavior、notice_delivery、reply_prefix、require_mention 等公共键)之后、_apply_env_overrides() 之前调用,因此你的 plugin 只需桥接平台专属键。deliver=my_platform 的 cron 任务路由到已配置的主频道,将 cron_deliver_env_var 设置为持有默认聊天/房间/频道 ID 的环境变量名:deliver=my_platform 任务的主目标时会读取此环境变量,并将该平台视为 _KNOWN_DELIVERY_PLATFORMS 风格检查中的有效 cron 目标。如果你的 env_enablement_fn 填充了 home_channel 字典(见上文),则优先使用该值 — cron_deliver_env_var 是在环境变量填充之前运行的 cron 任务的回退方案。cron_deliver_env_var 使你的平台成为可识别的 deliver= 目标。要在 cron 任务运行于独立进程(即 hermes cron run 与 hermes gateway 分离)时使实际发送成功,需注册 standalone_sender_fn:tools/send_message_tool.py 中内置了直接 REST 辅助函数,使 cron 无需在同一进程中持有 gateway 即可投递。Plugin 平台历史上依赖 _gateway_runner_ref(),该函数在 gateway 进程外返回 None,因此若没有 standalone_sender_fn,cron 端发送会失败并报 No live adapter for platform '<name>'。pconfig 和 chat_id,以及可选的 thread_id、media_files 和 force_document 关键字参数。返回 {"success": True, "message_id": ...} 视为成功投递;返回 {"error": "..."} 会将消息记录到 cron 的 delivery_errors 中。函数内抛出的异常由调度器捕获并报告为 Plugin standalone send failed: <reason>。参考实现位于 plugins/platforms/{irc,teams,google_chat}/adapter.py。