Hotdry.
ai-systems

使用 Hermes 模型部署本地 Hermes Agent:可靠工具调用与离线自治任务

利用 Hermes Agent 和 Hermes-3 模型栈,实现本地离线 LLM agent 的工具调用、函数执行与自治任务,提供 vLLM 参数、沙箱配置与监控清单。

在 AI agent 领域,本地部署可靠的工具调用系统是关键需求,尤其需要离线运行时。Hermes Agent 结合 NousResearch 的 Hermes 模型(如 Hermes-3-Llama-3.1-8B),提供卓越的函数调用准确率和沙箱执行能力,支持终端命令、文件操作等多工具链路,实现自主任务处理。

Hermes 模型系列专为工具调用优化,在 vLLM 环境下表现突出。“Hermes-3-Llama-3.1-8B 等模型在工具调用基准中准确率领先,支持 JSON 结构化输出和多步规划。”[1] Hermes Agent 则内置终端沙箱(docker/ssh)、持久内存和技能系统,确保 agent 在本地硬件上安全高效运行,无需云服务。

部署步骤与核心参数

  1. 准备环境
    确保 NVIDIA GPU(至少 8GB VRAM for 8B 模型 4bit),安装 CUDA 12+。

    pip install vllm flash-attn --index-url https://download.pytorch.org/whl/cu121
    
  2. 启动本地 Hermes 模型服务器
    使用 vLLM 部署 Hermes-3-Llama-3.1-8B,启用工具调用解析器。关键参数:

    • --tool-call-parser hermes:专用 Hermes 格式解析,避免 JSON 幻觉。
    • --enable-auto-tool-choice:自动工具选择,减少手动干预。
    • --quantization awqgptq:4bit 量化,平衡速度与准确(推荐 Q4_K_M,VRAM ~6-8GB)。
    • --max-model-len 8192:上下文长度适中,避免 OOM。
      示例命令:
    vllm serve NousResearch/Hermes-3-Llama-3.1-8B \
      --host 0.0.0.0 --port 8000 \
      --tool-call-parser hermes \
      --enable-auto-tool-choice \
      --quantization gptq \
      --dtype bfloat16 \
      --gpu-memory-utilization 0.9
    

    服务器启动后,提供 OpenAI 兼容 API(http://localhost:8000/v1)。

  3. 安装 Hermes Agent
    一键安装,支持 Python 3.11+。

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

    安装后,目录 ~/.hermes/ 存储配置。

  4. 配置 Agent 连接本地模型与沙箱
    编辑 ~/.hermes/config.yaml.env

    # .env
    OPENAI_BASE_URL=http://localhost:8000/v1
    OPENAI_API_KEY=dummy  # 本地无需真实 key
    
    # config.yaml
    model: NousResearch/Hermes-3-Llama-3.1-8B
    terminal:
      backend: docker  # 推荐沙箱,隔离 agent 执行
      docker_image: python:3.11-slim
      container_cpu: 2
      container_memory: 4096  # MB
      timeout: 300  # 命令超时秒
    memory:
      enabled: true
      memory_char_limit: 2200
    agent:
      reasoning_effort: high  # 增强多步工具链推理
      max_iterations: 50  # 防止无限循环
    compression:
      enabled: true
      threshold: 0.85
    

    “Hermes Agent 支持 docker/ssh 等后端,确保工具执行不访问主机敏感文件。”[2]
    验证:hermes config check && hermes doctor

工具调用与自治任务实践

可靠工具调用参数

  • 工具集:--toolsets "terminal,file,web"(本地 web 需可选 API key)。
  • 示例交互:
    hermes --toolsets "terminal" chat -q "在沙箱中运行 'pip list' 并总结输出"
    
    Agent 会生成工具调用:terminal(command="pip list", pty=true),解析 JSON args,确保结构化。Hermes 模型准确率高,罕见参数遗漏。

函数执行清单

函数 参数示例 用途
terminal command="ls -la", background=true, timeout=60 后台进程管理
process action="wait", pid=123 监控子进程
file path="~/data.txt", action="read" 文件 I/O
execute_code script="from hermes_tools import ...; print(summary)" 复杂逻辑脚本

自治任务配置

  • 持久内存:MEMORY.md 记录环境事实,USER.md 用户偏好。
  • 技能系统:/skills install k8s,agent 自学工作流存为 SKILL.md。
  • Cron 调度:hermes gateway install,然后 /cron add "0 9 * * *\" 每日市场报告到终端"
    Gateway 作为服务运行:hermes gateway start

监控与回滚

  • 日志:~/.hermes/logs/,监控工具调用失败率。
  • 阈值:若工具准确率 <95%,调高 reasoning_effort: xhigh 或换 70B 模型。
  • 回滚:hermes config set terminal.backend local,测试后切 docker。
  • 性能指标:tokens/s >20(8B 4bit),迭代 <10 / 任务。

此栈适用于开发 / 生产离线 agent,8B 模型单 RTX 4070 即可流畅。扩展时,可并行子 agent(delegation.max_iterations=25)处理多任务。

资料来源

[1] vLLM 工具调用文档:https://docs.vllm.ai/en/latest/features/tool_calling/
[2] Hermes Agent GitHub:https://github.com/NousResearch/hermes-agent
Hermes-3 模型:https://huggingface.co/NousResearch/Hermes-3-Llama-3.1-8B

查看归档