跳到主要内容

Hermes Agent + MLflow AI Gateway

通过将 Hermes 的自定义 OpenAI 兼容提供程序指向您的网关端点,可以将 Hermes Agent 接入 MLflow AI Gateway。这为您提供了集中的模型路由、使用情况跟踪和治理功能,同时 Hermes 可以继续运行其自身的代理循环、工具和会话。

MLflow AI Gateway usage tracking for a Hermes endpoint, showing token usage, tokens per request, cost breakdown, and cost over time

设置

前提条件

  • 一个 MLflow 跟踪环境。如果您需要设置环境,请参阅连接您的环境指南。
  • 已安装 Hermes Agent

第 1 步:创建网关端点

导航至 https://:5000/#/gateway 下的 AI Gateway 选项卡,并点击 Create Endpoint(创建端点)。

  • Provider(提供程序):选择您的上游提供程序,例如 OpenAI
  • Model(模型):选择您希望 Hermes 使用的上游模型,例如 gpt-5.5
  • API Key(API 密钥):设置您的上游提供程序 API 密钥,或者如果您已有密钥,则可以直接复用。
  • Endpoint name(端点名称):选择一个名称,例如 my-hermes-endpoint

第 2 步:将 Hermes 指向网关

运行 Hermes 的交互式模型设置向导

bash
hermes setup model
text
┌─────────────────────────────────────────────────────────┐
│ ⚕ Hermes Agent Setup Wizard │
├─────────────────────────────────────────────────────────┤
│ Let's configure your Hermes Agent installation. │
│ Press Ctrl+C at any time to exit. │
└─────────────────────────────────────────────────────────┘

...

Select provider:
Select by number, Enter to confirm.

(●) 1. Nous Portal (Nous Research subscription)
(○) 2. OpenRouter (100+ models, pay-per-use)
(○) 3. LM Studio (local desktop app with built-in model server)
...
(○) 36. Custom endpoint (enter URL manually)
(○) 37. Configure auxiliary models...
(○) 38. Leave unchanged

Choice [default 1]: 36

出现提示时,选择选项 36: Custom endpoint (enter URL manually)(自定义端点 - 手动输入 URL),并填入指向您网关端点的值。

text
# Step 1: Specify the API base URL
API base URL [e.g. https://api.example.com/v1]: https://:5000/gateway/mlflow/v1

# Step 2: Leave the API key blank (managed by the gateway)
API key [optional]:

# Step 3: Specify the gateway endpoint name as the model name
Model name (e.g. gpt-4, llama-3-70b): my-hermes-endpoint

# Leave other values as default

hermes setup model 会自动将设置配置写入 ~/.hermes/config.yaml

提示

Hermes 的 custom 提供程序需要标准且兼容 OpenAI 的 /v1 API。MLflow AI Gateway 正是在 /gateway/mlflow/v1 处提供了该接口。

替代方案:直接编辑 ~/.hermes/config.yaml

如果您不想使用向导,等效配置如下:

yaml
model:
default: "my-hermes-endpoint"
provider: "custom"
base_url: "https://:5000/gateway/mlflow/v1"
# api_key: "your-gateway-api-key"

第 3 步:运行 Hermes Agent

启动一个交互式 Hermes 会话

bash
hermes

Hermes 会通过 my-hermes-endpoint 将其底层模型调用路由至网关。

替代方案:通过网关路由 Hermes API 服务器

如果您以 API 服务器模式运行 Hermes,相同的配置也适用。请在 ~/.hermes/.env 中启用服务器。

bash
API_SERVER_ENABLED=true

然后启动它并发送测试请求:

bash
hermes gateway run
bash
python - <<'PY'
from openai import OpenAI

client = OpenAI(base_url="https://:8642/v1", api_key="not-required")
response = client.chat.completions.create(
model="hermes-agent",
messages=[{"role": "user", "content": "Say hello in one sentence."}],
)
print(response.choices[0].message.content)
PY

您可以获得什么

每一个通过网关路由的 Hermes 模型请求都会被 MLflow 捕获。打开 Usage(使用情况)页面并查看 MLflow UI 中的 Logs(日志)选项卡,即可审查每次请求的输入、输出、Token 使用量和延迟。

您还可以为流经端点的每一个 Hermes 请求应用防护栏(Guardrails)——例如 PII 检测或安全过滤——而无需修改 Hermes 本身。

Create Guardrail dialog in the MLflow AI Gateway with Safety, PII Detection, and Custom Guardrail options

有关通过网关路由 Hermes 后可获得的功能,请参阅以下指南:

追踪 Hermes 端到端执行过程

通过网关路由 Hermes 可以捕获每一个模型请求,但它无法显示完整的代理循环,包括工具调用、多轮推理或会话元数据。

若要捕获这些信息,请遵循追踪 Hermes Agent指南进行完整设置。

Hermes Agent tool-calling trace in the MLflow UI