知识引擎/Hermes 知识引擎/Plugins(插件)

原文链接:Plugins sidebar position: 11 sidebar label: "Plugins" title: "Plugins" description: "Extend Hermes with custom tools, hooks, and integrations via the plugi

> 原文链接:Plugins


sidebar_position: 11 sidebar_label: "Plugins" title: "Plugins" description: "Extend Hermes with custom tools, hooks, and integrations via the plugin system"

Plugins(插件)

Hermes 拥有插件系统,用于添加自定义工具、钩子和集成,无需修改核心代码。

构建 Hermes 插件 — 分步指南,附带完整可运行的示例。

快速概览

将一个目录放入 ~/.hermes/plugins/,包含 plugin.yaml 和 Python 代码:

~/.hermes/plugins/my-plugin/
├── plugin.yaml      # 清单文件
├── __init__.py      # register() — 将 schema 连接到处理器
├── schemas.py       # 工具 schema(LLM 看到的内容)
└── tools.py         # 工具处理器(被调用时运行的代码)

启动 Hermes — 你的工具会与内置工具一起出现。模型可以立即调用它们。

最小可运行示例

以下是一个完整的插件,添加了 hello_world 工具,并通过钩子记录每次工具调用。

~/.hermes/plugins/hello-world/plugin.yaml

name: hello-world
version: "1.0"
description: 一个最小示例插件

~/.hermes/plugins/hello-world/__init__.py

"""最小 Hermes 插件 — 注册一个工具和一个钩子。"""


def register(ctx):
    # --- 工具: hello_world ---
    schema = {
        "name": "hello_world",
        "description": "返回给定名称的友好问候。",
        "parameters": {
            "type": "object",
            "properties": {
                "name": {
                    "type": "string",
                    "description": "要问候的名称",
                }
            },
            "required": ["name"],
        },
    }

    def handle_hello(params):
        name = params.get("name", "World")
        return f"Hello, {name}! 👋  (from the hello-world plugin)"

    ctx.register_tool("hello_world", schema, handle_hello)

    # --- 钩子: 记录每次工具调用 ---
    def on_tool_call(tool_name, params, result):
        print(f"[hello-world] tool called: {tool_name}")

    ctx.register_hook("post_tool_call", on_tool_call)

将两个文件放入 ~/.hermes/plugins/hello-world/,重启 Hermes,模型即可立即调用 hello_world。钩子会在每次工具调用后打印一行日志。

项目本地插件位于 ./.hermes/plugins/ 下,默认禁用。仅在受信任的仓库中启用,方法是在启动 Hermes 前设置 HERMES_ENABLE_PROJECT_PLUGINS=true

插件能做什么

能力方式
添加工具ctx.register_tool(name, schema, handler)
添加钩子ctx.register_hook("post_tool_call", callback)
添加斜杠命令ctx.register_command(name, handler, description) — 在 CLI 和 Gateway 会话中添加 /name
添加 CLI 命令ctx.register_cli_command(name, help, setup_fn, handler_fn) — 添加 hermes <plugin> <subcommand>
注入消息ctx.inject_message(content, role="user") — 参见注入消息
携带数据文件Path(__file__).parent / "data" / "file.yaml"
打包技能ctx.register_skill(name, path) — 命名空间为 plugin:skill,通过 skill_view("plugin:skill") 加载
环境变量门控plugin.yaml 中的 requires_env: [API_KEY] — 在 hermes plugins install 期间提示
通过 pip 分发[project.entry-points."hermes_agent.plugins"]

插件发现

来源路径用例
用户~/.hermes/plugins/个人插件
项目.hermes/plugins/项目特定插件(需要 HERMES_ENABLE_PROJECT_PLUGINS=true
piphermes_agent.plugins entry_points分发包

可用钩子

插件可以为以下生命周期事件注册回调。完整详情、回调签名和示例请参见 事件钩子页面

钩子触发时机
pre_tool_call任何工具执行之前
post_tool_call任何工具返回之后
pre_llm_call每轮一次,LLM 循环之前 — 可返回 {"context": "..."}向用户消息注入上下文
post_llm_call每轮一次,LLM 循环之后(仅成功轮次)
on_session_start新会话创建(仅首轮)
on_session_end每次 run_conversation 调用结束时 + CLI 退出处理器

插件类型

Hermes 有三种插件:

类型功能选择方式位置
通用插件添加工具、钩子、斜杠命令、CLI 命令多选(启用/禁用)~/.hermes/plugins/
记忆 Provider替换或增强内置记忆单选(一个激活)plugins/memory/
上下文引擎替换内置上下文压缩器单选(一个激活)plugins/context_engine/

记忆 Provider 和上下文引擎是 Provider 插件 — 每种类型同时只能激活一个。通用插件可以任意组合启用。

管理插件

hermes plugins                  # 统一交互式 UI
hermes plugins list             # 表格视图,显示启用/禁用状态
hermes plugins install user/repo  # 从 Git 安装
hermes plugins update my-plugin   # 拉取最新版本
hermes plugins remove my-plugin   # 卸载
hermes plugins enable my-plugin   # 重新启用已禁用的插件
hermes plugins disable my-plugin  # 禁用但不移除

交互式 UI

不带参数运行 hermes plugins 会打开一个复合交互式界面:

Plugins
  ↑↓ 导航  SPACE 切换  ENTER 配置/确认  ESC 完成

  General Plugins
 → [✓] my-tool-plugin — 自定义搜索工具
   [ ] webhook-notifier — 事件钩子

  Provider Plugins
     Memory Provider          ▸ honcho
     Context Engine           ▸ compressor
  • General Plugins 区域 — 复选框,用 SPACE 切换
  • Provider Plugins 区域 — 显示当前选择。按 ENTER 进入单选选择器,选择一个活跃 Provider。

Provider 插件选择保存到 config.yaml

memory:
  provider: "honcho"      # 空字符串 = 仅内置

context:
  engine: "compressor"    # 默认内置压缩器

禁用通用插件

禁用的插件保持安装但加载时会被跳过。禁用列表存储在 config.yamlplugins.disabled 中:

plugins:
  disabled:
    - my-noisy-plugin

在运行中的会话中,/plugins 显示当前加载的插件。

注入消息

插件可以使用 ctx.inject_message() 向活动对话注入消息:

ctx.inject_message("新数据从 webhook 到达", role="user")

签名: ctx.inject_message(content: str, role: str = "user") -> bool

工作原理:

  • 如果 Agent 空闲(等待用户输入),消息会排队作为下一个输入并开始新轮次。
  • 如果 Agent 正在运行(活跃处理中),消息会中断当前操作 — 效果等同于用户输入新消息并按回车。
  • 对于非 "user" 角色,内容会添加 [role] 前缀(如 [system] ...)。
  • 如果消息成功排队返回 True,如果没有 CLI 引用可用(例如在 Gateway 模式下)则返回 False

这使得远程控制查看器、消息桥接或 Webhook 接收器等插件能够将消息从外部来源注入对话。

:::note 注意 inject_message 仅在 CLI 模式下可用。在 Gateway 模式下,没有 CLI 引用,该方法返回 False。 :::

完整指南请参见 构建插件指南,了解处理器契约、Schema 格式、钩子行为、错误处理和常见错误。

Continue Exploring

继续探索

这不是课程式的上一篇下一篇,而是从当前节点向外继续漫游。

教程与指南

构建 Hermes 插件

本指南将从头开始引导你构建一个完整的 Hermes 插件。完成后你将拥有一个包含多个工具、生命周期钩子、数据文件和捆绑技能的完整插件。 一个 计算器 插件,包含两个工具: calculate — 计算数学表达式(2 16、sqrt(144)、pi 5 2) unit convert — 单位转换(100 F → 37.

核心功能

Event Hooks(事件钩子)

原文链接:Event Hooks sidebar position: 6 title: "Event Hooks" description: "Run custom code at key lifecycle points — log activity, send alerts, post to webhooks"

核心功能

工具与工具集 (Tools & Toolsets)

Tools are functions that extend the agent's capabilities. They're organized into logical toolsets that can be enabled or disabled per platform.

核心功能

记忆系统 (Memory System)

Hermes Agent has bounded, curated memory that persists across sessions. This lets it remember your preferences, your projects, your environment, and things it h

核心功能

技能系统 (Skill System)

技能是 Hermes 的可复用知识模块。每个技能都是一个 Markdown 文件,在激活时注入到 Agent 的上下文中——为其提供持久的工作流、领域知识和行为指南,而无需将这些内容塞入系统提示中。 技能是可热插拔的:你可以在会话中途安装、创建、编辑和切换技能。它们在 CLI、消息平台和 Gateway 后台任务中均可

核心功能

MCP 集成 (MCP Integration)

MCP 让 Hermes Agent 连接到外部工具服务器,使 Agent 能够使用 Hermes 本身之外的工具——GitHub、数据库、文件系统、浏览器栈、内部 API 等。 如果你曾想让 Hermes 使用一个已经存在于其他地方的工具,MCP 通常是最简洁的方式。 - 无需先编写原生 Hermes 工具即可访问外

Core Features

核心功能

Hermes 的能力核心:工具、记忆、技能、委派、自动化、语音、插件与浏览器控制。

31 篇文档30 个节点

当前节点

Plugins(插件)

同主题继续探索

工具与工具集 (Tools & Toolsets)

Tools are functions that extend the agent's capabilities. They're organized into logical toolsets that can be enabled or disabled per platform.

记忆系统 (Memory System)

Hermes Agent has bounded, curated memory that persists across sessions. This lets it remember your preferences, your projects, your environment, and things it h

技能系统 (Skill System)

技能是 Hermes 的可复用知识模块。每个技能都是一个 Markdown 文件,在激活时注入到 Agent 的上下文中——为其提供持久的工作流、领域知识和行为指南,而无需将这些内容塞入系统提示中。 技能是可热插拔的:你可以在会话中途安装、创建、编辑和切换技能。它们在 CLI、消息平台和 Gateway 后台任务中均可

MCP 集成 (MCP Integration)

MCP 让 Hermes Agent 连接到外部工具服务器,使 Agent 能够使用 Hermes 本身之外的工具——GitHub、数据库、文件系统、浏览器栈、内部 API 等。 如果你曾想让 Hermes 使用一个已经存在于其他地方的工具,MCP 通常是最简洁的方式。 - 无需先编写原生 Hermes 工具即可访问外

ACP 编辑器集成 (ACP Editor Integration)

Hermes Agent 可以作为 ACP 服务器运行,让 ACP 兼容的编辑器通过 stdio 与 Hermes 通信,并渲染: - 聊天消息 - 工具活动 - 文件差异 - 终端命令 - 审批提示 - 流式思考 / 响应片段 当你希望 Hermes 像编辑器原生的编程 Agent 一样工作,而不是独立的 CLI 或

API 服务器 (API Server)

The API server exposes hermes-agent as an OpenAI-compatible HTTP endpoint. Any frontend that speaks the OpenAI format — Open WebUI, LobeChat, LibreChat, NextCha

相关节点

构建 Hermes 插件

本指南将从头开始引导你构建一个完整的 Hermes 插件。完成后你将拥有一个包含多个工具、生命周期钩子、数据文件和捆绑技能的完整插件。 一个 计算器 插件,包含两个工具: calculate — 计算数学表达式(2 16、sqrt(144)、pi 5 2) unit convert — 单位转换(100 F → 37.

Event Hooks(事件钩子)

原文链接:Event Hooks sidebar position: 6 title: "Event Hooks" description: "Run custom code at key lifecycle points — log activity, send alerts, post to webhooks"

工具与工具集 (Tools & Toolsets)

Tools are functions that extend the agent's capabilities. They're organized into logical toolsets that can be enabled or disabled per platform.

记忆系统 (Memory System)

Hermes Agent has bounded, curated memory that persists across sessions. This lets it remember your preferences, your projects, your environment, and things it h

技能系统 (Skill System)

技能是 Hermes 的可复用知识模块。每个技能都是一个 Markdown 文件,在激活时注入到 Agent 的上下文中——为其提供持久的工作流、领域知识和行为指南,而无需将这些内容塞入系统提示中。 技能是可热插拔的:你可以在会话中途安装、创建、编辑和切换技能。它们在 CLI、消息平台和 Gateway 后台任务中均可

MCP 集成 (MCP Integration)

MCP 让 Hermes Agent 连接到外部工具服务器,使 Agent 能够使用 Hermes 本身之外的工具——GitHub、数据库、文件系统、浏览器栈、内部 API 等。 如果你曾想让 Hermes 使用一个已经存在于其他地方的工具,MCP 通常是最简洁的方式。 - 无需先编写原生 Hermes 工具即可访问外