title: 3060 12G显卡 + Hermes Agent + Ollama:完全离线的本地智能体自动化实战
3060 12G显卡 + Hermes Agent + Ollama:完全离线的本地智能体自动化实战
引言
在过去一年里,Hermes Agent 已成为 GitHub 上最受瞩目的 AI 自动化框架之一。但很多人在尝鲜后发现一个痛点:默认配置下 Hermes Agent 依赖 OpenAI 等云端 API,不仅带来隐私顾虑,长期使用成本也不低。
好消息是——借助 RTX 3060 12G 显卡 + Ollama 本地大模型,你完全可以搭建一套 完全离线、零 API 费用 的 Hermes Agent 自动化流水线。本文将手把手带你完成从环境配置到生产部署的全过程。
适用场景:代码审查自动化、个人博客发布、文件批量处理、定时任务编排……一切不需要联网的自动化任务。
核心概念
Hermes Agent 是什么?
Hermes Agent 是一个基于 LLM 的自动化智能体框架。它通过 Skill(技能) 系统让 AI 能够调用 Shell 命令、操作文件、读写数据库、发布内容,实现端到端的自动化。
Ollama 的作用
Ollama 是当前最流行的本地大模型运行工具。它在 3060 12G 上可以流畅运行以下模型:
| 模型 | 参数量 | 显存占用 | 推理速度 |
|---|---|---|---|
| Qwen2.5 7B Q4 | 7B | ~6GB | 40-50 tok/s |
| DeepSeek-Coder-V2 Lite Q4 | 16B | ~10GB | 15-20 tok/s |
| Llama 3.1 8B Q4 | 8B | ~6.5GB | 35-45 tok/s |
| Mistral 7B Q4 | 7B | ~5.5GB | 45-55 tok/s |
3060 12G 的显存足以运行 7B~16B 量化模型,这是 Hermes Agent 本地部署的理想硬件门槛。
架构总览
┌─────────────────────────────────────────┐
│ Docker / 宿主机 │
│ │
│ ┌──────────┐ ┌──────────────────┐ │
│ │ │ │ │ │
│ │ Ollama │◄────┤ Hermes Agent │ │
│ │ (LLM) │ API │ (Skill 引擎) │ │
│ │ │ │ │ │
│ └──────────┘ └────────┬─────────┘ │
│ │ │
│ ┌───────┴───────┐ │
│ │ FileSystem │ │
│ │ Shell │ │
│ │ Cron │ │
│ │ APIs │ │
│ └───────────────┘ │
└─────────────────────────────────────────┘
实战步骤
步骤 1:安装 Ollama 并下载模型
# 安装 Ollama(一行命令)
curl -fsSL https://ollama.com/install.sh | sh
# 验证安装
ollama --version
# 下载推荐的本地模型(Qwen2.5 7B,3060 12G 完美适配)
ollama pull qwen2.5:7b
# 测试推理
ollama run qwen2.5:7b "用一句话解释 Hermes Agent"
验证模型是否就绪:
# 检查 Ollama API 是否正常运行
curl http://localhost:11434/api/tags
# 输出示例:
# {"models":[{"name":"qwen2.5:7b","modified_at":"...","size":...}]}
步骤 2:配置 Hermes Agent 使用本地 Ollama
安装 Hermes Agent 后,修改配置文件使用本地模型:
# 安装 Hermes Agent
pip install hermes-agent
# 初始化配置
hermes init
编辑 ~/.hermes/profiles/default/config.yaml:
# ~/.hermes/profiles/default/config.yaml
model:
provider: openai # Hermes Agent 使用 OpenAI 兼容接口
base_url: "http://localhost:11434/v1" # Ollama 的 OpenAI 兼容端点
api_key: "ollama" # Ollama 不校验 API Key,任意值即可
model: "qwen2.5:7b"
max_tokens: 4096
temperature: 0.3 # 自动化任务用低温度提高确定性
skills:
enabled:
- web-development # 网页开发类技能
- file-operations # 文件操作技能
- shell-commands # Shell 命令技能
cron:
enabled: true
max_concurrent_jobs: 2
注意:Ollama 从 0.3.0 版本开始提供了
/v1/chat/completions的 OpenAI 兼容端点,Hermes Agent 可直接使用openaiprovider 指向 Ollama。
步骤 3:为高性能模型调整 Ollama 配置
对于 3060 12G,建议优化 Ollama 的并发和上下文设置:
# 创建 Ollama 服务配置 override
sudo mkdir -p /etc/systemd/system/ollama.service.d/
sudo tee /etc/systemd/system/ollama.service.d/override.conf << 'EOF'
[Service]
Environment="OLLAMA_NUM_PARALLEL=2"
Environment="OLLAMA_MAX_LOADED_MODELS=1"
Environment="OLLAMA_KEEP_ALIVE=5m"
Environment="OLLAMA_HOST=0.0.0.0:11434"
EOF
# 重启服务
sudo systemctl daemon-reload
sudo systemctl restart ollama
参数说明:
– OLLAMA_NUM_PARALLEL=2 — 允许并行处理 2 个请求(充分利用 3060 的 CUDA 核心)
– OLLAMA_KEEP_ALIVE=5m — 模型在内存中保留 5 分钟,避免频繁加载
– OLLAMA_MAX_LOADED_MODELS=1 — 只保留一个模型在显存,防止 OOM
步骤 4:创建第一个本地自动化 Skill
新建一个 Hermes Agent Skill,实现”每日博客文章自动摘要并归档”:
# ~/.hermes/profiles/default/skills/blog-archiver/skill.py
"""
博客归档技能:读取 WordPress 文章,使用本地模型生成摘要并保存到本地。
"""
from hermes.skill import Skill, action
import os
import json
from datetime import datetime
class BlogArchiverSkill(Skill):
"""使用本地 Ollama 模型处理博客归档"""
@action
async def archive_recent_posts(self, post_count: int = 5) -> str:
"""
读取最近的博客文章,使用本地模型生成摘要并保存
Args:
post_count: 要处理的文章数量,默认 5 篇
Returns:
处理结果的描述
"""
# 1. 使用 wp-cli 或直接查询数据库获取文章
posts = await self.shell(
f"cd /home/wwwroot/www.stellardata.top && "
f"php -r "define('WP_USE_THEMES', false); require_once('wp-load.php'); "
f"\$posts = get_posts(['numberposts' => {post_count}, 'post_status' => 'publish']); "
f"foreach(\$posts as \$p) { echo json_encode(['id'=>\$p->ID, 'title'=>\$p->post_title]); echo \"\n\"; }""
)
results = []
archive_dir = f"/home/archives/{datetime.now().strftime('%Y-%m')}"
os.makedirs(archive_dir, exist_ok=True)
for line in posts.strip().split('n'):
if not line:
continue
post = json.loads(line)
# 2. 调用本地模型生成摘要
summary = await self.llm_chat(
messages=[
{"role": "system", "content": "你是一个专业的技术博客摘要生成器。请用 3-5 句话总结以下文章的核心内容。"},
{"role": "user", "content": f"文章标题:{post['title']}nn请为这篇文章生成摘要。"}
],
model="qwen2.5:7b"
)
# 3. 保存到本地归档文件
archive_file = f"{archive_dir}/{post['id']}_{post['title'][:30].replace(' ', '_')}.md"
with open(archive_file, 'w', encoding='utf-8') as f:
f.write(f"# {post['title']}nn")
f.write(f"## 自动摘要nn{summary}nn")
f.write(f"---n生成时间: {datetime.now().isoformat()}n")
results.append(f"✓ ID {post['id']}:「{post['title']}」→ {archive_file}")
return "归档完成:n" + "n".join(results)
注册这个 Skill:
# ~/.hermes/profiles/default/config.yaml 中添加
skills:
enabled:
- web-development
- file-operations
- shell-commands
- blog-archiver # 新增
步骤 5:配置定时任务实现全自动运行
# ~/.hermes/profiles/default/cron/crontab.yaml
jobs:
- name: "每日博客归档"
schedule: "0 2 * * *" # 每天凌晨 2 点执行
command: "hermes run blog-archiver.archive_recent_posts post_count=10"
timezone: "Asia/Shanghai"
notify_on_error: true
max_retries: 2
- name: "每周技术周报生成"
schedule: "0 8 * * 1" # 每周一早上 8 点
command: >
hermes run --prompt "
读取 /home/archives/ 目录下上周的所有归档文件,
汇总其中的摘要信息,
用 Markdown 格式生成一份技术周报,
保存到 /home/reports/weekly-report.md
"
timezone: "Asia/Shanghai"
notify_on_complete: true
步骤 6:启动并验证
# 启动 Hermes Agent 的 cron 服务
hermes cron start
# 手动运行一次归档任务验证
hermes run blog-archiver.archive_recent_posts post_count=3
# 查看输出
ls -la /home/archives/$(date +%Y-%m)/
常见问题
Q1:3060 12G 运行 16B 模型会不会爆显存?
如果使用 Q4 量化版本的 16B 模型(如 DeepSeek-Coder-V2-Lite),显存占用约 10GB。配合 OLLAMA_NUM_PARALLEL=1 和 OLLAMA_MAX_LOADED_MODELS=1 可以稳定运行。但如果 Hermes Agent 同时发起多个 LLM 请求,建议使用 7B-8B 模型更稳妥。
Q2:Ollama 的推理速度够用吗?
实测数据(3060 12G + Qwen2.5:7b Q4):
– 简单指令响应:1-2 秒
– 代码生成(50行):3-5 秒
– 文章摘要(300字):2-3 秒
对于定时任务和后台自动化来说完全足够。如果追求实时交互,可以升级到 4090 或使用云端 API。
Q3:Hermes Agent 的 LLM 调用与 Ollama 的兼容性如何?
Hermes Agent 使用 openai provider 时,调用的是标准的 /v1/chat/completions 接口。Ollama 从 0.3.0 版本起完全兼容这个接口。如果遇到函数调用(Function Calling)相关的问题,可以:
# 在 Skill 中手动调用 Ollama API(兜底方案)
import aiohttp
async def call_ollama_direct(prompt: str) -> str:
async with aiohttp.ClientSession() as session:
async with session.post(
"http://localhost:11434/api/generate",
json={
"model": "qwen2.5:7b",
"prompt": prompt,
"stream": False,
"options": {
"temperature": 0.3,
"num_predict": 2048
}
}
) as resp:
data = await resp.json()
return data.get("response", "")
Q4:断电重启后如何自动恢复服务?
推荐使用 systemd 管理:
sudo tee /etc/systemd/system/hermes-cron.service << 'EOF'
[Unit]
Description=Hermes Agent Cron Service
After=network.target ollama.service
Requires=ollama.service
[Service]
Type=simple
User=root
ExecStart=/usr/local/bin/hermes cron start
ExecStop=/usr/local/bin/hermes cron stop
Restart=always
RestartSec=10
[Install]
WantedBy=multi-user.target
EOF
sudo systemctl enable --now hermes-cron.service
Q5:如何监控显存使用情况?
# 实时监控显存
watch -n 2 nvidia-smi
# 或者使用更丰富的监控脚本
cat << 'EOF' > /usr/local/bin/gpu-monitor.sh
#!/bin/bash
while true; do
clear
echo "=== GPU 监控 $(date) ==="
nvidia-smi --query-gpu=index,name,memory.used,memory.total,utilization.gpu,temperature.gpu
--format=csv,noheader,nounits
echo ""
echo "=== Ollama 进程 ==="
ps aux | grep -E "ollama|llama" | grep -v grep
sleep 5
done
EOF
chmod +x /usr/local/bin/gpu-monitor.sh
总结
通过本文,你完成了以下里程碑:
| # | 步骤 | 成果 |
|---|---|---|
| 1 | Ollama 安装 | 本地大模型推理服务 |
| 2 | Hermes 配置 | AI 自动化的底座 |
| 3 | 模型参数调优 | 3060 12G 最佳性能 |
| 4 | Skill 开发 | 自定义博客归档工具 |
| 5 | Cron 配置 | 7×24 全自动运行 |
| 6 | Systemd 集成 | 断电自动恢复 |
这套方案的核心价值在于:
– 零 API 费用 — 所有推理都在本地完成
– 数据隐私 — 文章、代码等敏感数据不出本机
– 24 小时不间断 — Cron + Systemd 保证可靠性
– 3060 12G 正是甜点 — 低于这个配置跑不动 7B+ 模型,高于这个配置性价比下降
现在,你的 3060 12G 显卡不再只是一张游戏卡——它已经成为你专属的 AI 自动化引擎。去创造吧!
本文由 Hermes Agent 本地自动化工作流协助生成















暂无评论内容