返回

Hermes Agent 教程 7:终端后端 — 本地与云端部署

将 Hermes Agent 部署到本地、Docker、SSH、Daytona、Singularity 或 Modal 后端。本文介绍无服务器持久化、GPU 集群选项和混合部署策略。

教程概述

系列索引: Hermes Agent 教程系列

何时需要读这篇:如果你要管理多个 Hermes 实例、需要 GPU 加速,或想要一种在空闲时几乎不花钱的无服务器部署方式,那么这篇会非常有用。

本文介绍 Hermes Agent 的终端后端,也就是从本地执行到云端无服务器运行的多种部署选项。

你将学到什么

  • ✅ 六种后端选项及其权衡
  • ✅ 本地后端配置
  • ✅ Docker 后端配置
  • ✅ 面向远程服务器的 SSH 后端
  • ✅ Daytona 的无服务器持久化方案
  • ✅ Modal 的 GPU 集群部署方式

后端概览

为什么需要多种后端?

Hermes Agent 可以运行在不同环境中:

flowchart TD
    A[Hermes Agent] --> B[Local]
    A --> C[Docker]
    A --> D[SSH Remote]
    A --> E[Daytona]
    A --> F[Singularity]
    A --> G[Modal Serverless]

    B --> H[你的笔记本]
    C --> I[容器隔离]
    D --> J[远程服务器]
    E --> K[无服务器 VPS]
    F --> L[HPC 集群]
    G --> M[GPU 无服务器]

    style G fill:#e8f5e9
    style M fill:#fff3e0

后端对比

后端 成本 持久化 GPU 适合场景
Local 免费 仅本机 开发
Docker 免费 容器内 可选 隔离运行
SSH VPS 成本 完整 可选 远程控制
Daytona 约 $5/月 VPS 无服务器 常驻可唤醒
Singularity HPC 成本 完整 科研场景
Modal 按量付费 无服务器 GPU 任务

Local 后端

默认后端

Local 后端会直接在你的机器上运行 Hermes:

# 默认行为
hermes

# 显式指定 local
hermes --backend local

配置

backends:
  local:
    shell: bash
    working_dir: /home/user/projects
    timeout: 300  # 秒

局限

  • 只有你登录设备时它才会运行
  • 不提供 GPU 加速
  • 记忆只能本地持久化

Docker 后端

为什么用 Docker?

Docker 可以带来:

  • 与宿主系统隔离
  • 可复现的运行环境
  • 更容易清理

配置步骤

步骤 1:拉取 Hermes Docker 镜像

docker pull nousresearch/hermes-agent:latest

步骤 2:配置 Hermes

hermes config set backends.docker.image "nousresearch/hermes-agent:latest"

步骤 3:用 Docker 运行

hermes --backend docker

Docker 配置

backends:
  docker:
    image: nousresearch/hermes-agent:latest
    volumes:
      - ~/.hermes:/root/.hermes  # 持久化记忆
      - ~/projects:/workspace    # 挂载文件
    gpu: false
    network: host

GPU 支持

为 Docker 开启 GPU:

backends:
  docker:
    gpu: true
    gpu_memory: 8GB

需要配合 NVIDIA Docker runtime。

SSH 后端

为什么用 SSH?

SSH 后端允许 Hermes 运行在远程服务器上:

  • 可持续在线,不依赖笔记本
  • 拥有更多资源,如内存和存储
  • 有机会接入远程 GPU

配置步骤

步骤 1:配置 SSH

hermes config set backends.ssh.host "your-server.com"
hermes config set backends.ssh.user "hermes"
hermes config set backends.ssh.key "~/.ssh/hermes_key"

步骤 2:部署 Hermes 到服务器

# 先在远程服务器上安装 Hermes
ssh [email protected] "curl -fsSL https://raw.githubusercontent.com/NousResearch/hermes-agent/main/scripts/install.sh | bash"

# 再通过 SSH 后端运行
hermes --backend ssh

SSH 配置

backends:
  ssh:
    host: your-server.com
    user: hermes
    key: ~/.ssh/hermes_key
    working_dir: /home/hermes/workspace
    timeout: 600

Daytona 后端

什么是 Daytona?

Daytona 提供无服务器开发环境

  • 空闲时自动休眠
  • 需要时快速唤醒
  • 两次会话之间几乎不花钱

配置步骤

步骤 1:安装 Daytona CLI

curl -fsSL https://raw.githubusercontent.com/daytonaio/daytona/main/install.sh | bash

步骤 2:配置 Hermes

hermes config set backends.daytona.workspace "hermes-main"

步骤 3:使用 Daytona 运行

hermes --backend daytona

Daytona 工作流

sequenceDiagram
    participant U as 用户
    participant H as Hermes CLI
    participant D as Daytona
    participant W as Workspace

    U->>H: hermes --backend daytona
    H->>D: 唤醒 workspace
    D->>W: 恢复环境
    W->>H: 准备就绪
    H->>U: Hermes 可用

    Note over D,W: 空闲时成本接近 0

    U->>H: /exit
    H->>D: 休眠 workspace
    D->>W: 挂起
    W->>D: 状态已保存

    style D fill:#fff3e0

成本模型

状态 成本
活跃 VPS 费率(通常约 $5/月)
空闲 接近于零
休眠

Singularity 后端

什么是 Singularity?

Singularity 是 HPC 集群常用的容器格式,科研机构里很常见。

配置步骤

步骤 1:构建 Singularity 镜像

singularity build hermes.sif hermes.def

定义文件示例:

Bootstrap: docker
From: nousresearch/hermes-agent:latest

%files
    ~/.hermes /root/.hermes

%environment
    export HERMES_HOME=/root/.hermes

步骤 2:配置

hermes config set backends.singularity.image "hermes.sif"

步骤 3:运行

hermes --backend singularity

GPU 集群使用

backends:
  singularity:
    image: hermes.sif
    gpu: true
    gpu_count: 4
    bind:
      - ~/.hermes:/root/.hermes

什么是 Modal?

Modal 提供无服务器 GPU 计算

  • 无需自己管理服务器
  • GPU 可即时拉起
  • 只按实际计算时间付费

配置步骤

步骤 1:安装 Modal CLI

pip install modal
modal auth

步骤 2:将 Hermes 部署到 Modal

hermes modal deploy

步骤 3:使用 Modal 运行

hermes --backend modal
flowchart LR
    A[本地 CLI] --> B[Modal API]
    B --> C[GPU 容器]
    C --> D[Hermes 进程]
    D --> E[响应结果]
    E --> A

    style C fill:#fff3e0
backends:
  modal:
    gpu: A100
    memory: 16GB
    timeout: 600
    image: nousresearch/hermes-modal:latest

成本优化

Modal 按 GPU 秒级用量计费,可以这样优化:

# 快速模式(不用 GPU)
hermes --backend modal --no-gpu

# 只在需要时请求 GPU
hermes --backend modal --gpu-demand

后端选择指南

使用场景 推荐后端 原因
个人开发 Local 免费、简单
隔离测试 Docker 环境干净
团队共享 Agent SSH + VPS 持续在线
低成本常驻 Daytona 空闲自动休眠
科研 GPU 任务 Singularity 可接入 HPC 集群
突发 GPU 需求 Modal 无服务器、按量计费

常见问题排查

后端连接失败

原因:SSH key 配置错误,或服务器不可达。

解决方案

hermes doctor --backend ssh

Docker volume 没挂载成功

原因:路径不匹配。

解决方案

hermes config set backends.docker.volumes "[\"~/.hermes:/root/.hermes\"]"

原因:额度已耗尽。

解决方案

hermes --backend modal --gpu-type T4

总结

终端后端提供了部署灵活性

  1. Local — 免费、简单,但依赖本机
  2. Docker — 隔离、可复现
  3. SSH — 远程、持续在线
  4. Daytona — 无服务器,空闲自动休眠
  5. Singularity — HPC 集群与 GPU
  6. Modal — 无服务器 GPU,按量付费

关键要点

  • ✅ 按实际场景选择合适后端
  • ✅ Daytona 可显著降低空闲成本
  • ✅ Modal 适合突发型 GPU 需求
  • ✅ SSH 后端适合部署到 VPS

系列导航: