GCP实战:使用GCE、Hermes Agent和Telegram构建持久化AI助手

发布: (2026年5月2日 GMT+8 20:01)
4 分钟阅读
原文: Dev.to

I’m ready to translate the article for you, but it looks like the body of the post isn’t included in your message—only the source line is present. Could you please paste the full text (or the sections you’d like translated) after the source line? I’ll keep the source link unchanged and translate the rest into Simplified Chinese while preserving all formatting, markdown, code blocks, and URLs.

介绍

在解决了 LINE Bot 的 Vertex AI 迁移问题后,我开始思考 AI 助手是否可以 更主动 并具备 长期记忆。于是我转向了 NousResearch 的开源 Hermes Agent
与普通聊天机器人不同,Hermes 被设计为一种“会呼吸的操作系统”:它能够执行 shell 命令、编写 Python 脚本、管理长期记忆,并通过各种网关(Telegram、Discord)保持联系。

为了让它实现 24/7 不间断运行,我将其部署在 Google Compute Engine (GCE) 上。本指南记录了从零开始的部署过程以及在配置最新的 Gemini 2.5 Flash 模型时遇到的坑。

前置条件

参数描述
PROJECT_ID您的 Google Cloud 项目 ID
LOCATIONglobal
GOOGLE_API_KEY来自 Google AI Studio 的 API 密钥
机器类型e2-medium(推荐用于工具使用)
操作系统镜像Ubuntu 22.04 LTS

创建虚拟机

gcloud compute instances create hermes-agent-vm \
    --project=YOUR_PROJECT_ID \
    --zone=us-central1-a \
    --machine-type=e2-medium \
    --image-family=ubuntu-2204-lts \
    --image-project=ubuntu-os-cloud \
    --boot-disk-size=30GB \
    --metadata=startup-script='#!/bin/bash
        apt-get update
        apt-get install -y git curl python3-pip python3-venv nodejs npm
    '

安装 Hermes Agent

SSH 登录实例

gcloud compute ssh hermes-agent-vm --zone=us-central1-a

运行一键安装脚本

curl -fsSL https://raw.githubusercontent.com/NousResearch/hermes-agent/main/scripts/install.sh | bash
source ~/.bashrc

配置 Hermes

模型配置

创建(或编辑)~/.hermes/config.yaml,并明确指定 Gemini 2.5 Flash 模型,不带 google/ 前缀,例如:

provider:
  name: gemini
  model: gemini-2.5-flash
  # auxiliary models (titles, summarization, etc.)
  auxiliary:
    title: gemini-2.5-flash
    summary: gemini-2.5-flash

API 密钥

~/.hermes/.env 中存储 API 密钥以及任何所需的环境变量:

GOOGLE_API_KEY=YOUR_GOOGLE_API_KEY

设置 Systemd 持久化

/etc/systemd/system/hermes.service 创建一个 Systemd 服务文件:

[Unit]
Description=Hermes Agent Gateway
After=network.target

[Service]
Type=simple
User=root
Environment=HOME=/root
Environment=PYTHONUNBUFFERED=1
ExecStartPre=/usr/bin/pkill -9 -f hermes || true
ExecStart=/usr/local/lib/hermes-agent/venv/bin/hermes gateway run
Restart=always
RestartSec=10

[Install]
WantedBy=multi-user.target

启用并启动服务:

sudo systemctl daemon-reload
sudo systemctl enable hermes
sudo systemctl restart hermes

常见问题排查

症状原因解决方案
Agent reads messages but does not replyConfigured model identifier gemini-3-flash-preview (deprecated)Change all model references to gemini-2.5-flash in config.yaml or patch auxiliary_client.py
“404 Model Not Found” errorsUsing the google/ prefix (e.g., google/gemini-2.5-flash)Use the short name gemini-2.5-flash
“Gateway already running (PID …)” on service startA previous Hermes process is still aliveThe ExecStartPre line in the Systemd unit kills any stray process before starting a new one
Logs show errors from auxiliary functions (title generation, etc.)Default auxiliary model identifiers are outdatedExplicitly set auxiliary models in config.yaml as shown above

结论

通过上述步骤,专用的 Hermes Agent 能在 GCE 上稳定运行,并随时可通过 Telegram 访问。它可以获取信息、执行脚本,并在云 VM 上维护长期记忆。

关键要点

  • 模型标识符变化迅速;请始终根据官方文档或 MCP 工具核实准确的名称。
  • 使用短模型名称(gemini-2.5-flash)可避免路由错误。
  • Systemd 确保代理在 SSH 断开后仍能存活,并在故障时自动重启。

如果您想要一个 24 小时在线的 AI 数字双胞胎,请按照本标准作业程序(SOP)设置您自己的持久 Hermes Agent。

0 浏览
Back to Blog

相关文章

阅读更多 »