教程概述
系列索引: 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?
Modal 提供无服务器 GPU 计算:
- 无需自己管理服务器
- GPU 可即时拉起
- 只按实际计算时间付费
配置步骤
步骤 1:安装 Modal CLI
pip install modal
modal auth
步骤 2:将 Hermes 部署到 Modal
hermes modal deploy
步骤 3:使用 Modal 运行
hermes --backend modal
Modal 架构
flowchart LR
A[本地 CLI] --> B[Modal API]
B --> C[GPU 容器]
C --> D[Hermes 进程]
D --> E[响应结果]
E --> A
style C fill:#fff3e0
Modal 配置
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\"]"
Modal GPU 不可用
原因:额度已耗尽。
解决方案:
hermes --backend modal --gpu-type T4
总结
终端后端提供了部署灵活性:
- Local — 免费、简单,但依赖本机
- Docker — 隔离、可复现
- SSH — 远程、持续在线
- Daytona — 无服务器,空闲自动休眠
- Singularity — HPC 集群与 GPU
- Modal — 无服务器 GPU,按量付费
关键要点
- ✅ 按实际场景选择合适后端
- ✅ Daytona 可显著降低空闲成本
- ✅ Modal 适合突发型 GPU 需求
- ✅ SSH 后端适合部署到 VPS
系列导航:
- ← 上一篇: 教程 6:多模型配置
- → 下一篇: 教程 8:cron 调度 — 自动化与定时报告
- 返回: 系列索引