从零搭建 Blog Writer Agent:让 AI 自己写文章、自己部署

上一篇讲了 Kanban + Profile 的概念,这篇直接上实操:7 步从零搭建一个能自动写文章、构建、部署的 AI Agent。全流程 2.5 分钟跑通,每一步都有真实命令和输出。

这是「多 Agent 协作」系列第 2 篇。第 1 篇讲了概念:Kanban + Profile:让你的 AI Agent 自己管博客。这篇是纯实操——每一步都是我刚跑过的真实命令。

先说结论

搭一个会自己写博客的 AI Agent,7 步,2.5 分钟。不是 demo,是真的能写文章、构建验证、部署上线的 Agent。

1
2
你:hermes kanban create "写一篇 Kanban 入门" --assignee blog-writer
AI:自动写文章 → 构建验证 → 完成汇报

整个过程你只需要发一条命令

前置条件

  • 已安装 Hermes Agent(v0.13.0+)
  • 有一个 Hugo/Hexo 等静态博客项目
  • Gateway 正在运行

第 1 步:启用 Kanban Toolset

Kanban 是隐藏 toolset——hermes tools list 里看不到它。需要手动在 config.yaml 里添加:

1
2
3
4
# ~/.hermes/config.yaml
toolsets:
- hermes-cli
- kanban    # ← 加这一行

同时在 config.yaml 底部确认 dispatcher 配置(通常已有):

1
2
3
4
kanban:
  dispatch_in_gateway: true
  dispatch_interval_seconds: 60
  failure_limit: 2

改完重启 gateway:

1
systemctl restart hermes-gateway.service

第 2 步:创建 blog-writer Profile

Profile 就是一个独立的 AI 身份——有自己的配置、人格、工作目录。

1
hermes profile create blog-writer --clone

输出:

1
2
3
Profile 'blog-writer' created at ~/.hermes/profiles/blog-writer
Cloned config, .env, SOUL.md, and skills from default.
Wrapper created: ~/.local/bin/blog-writer

--clone 会复制当前 profile 的 API 密钥、配置、记忆文件,省得重新配置。

第 3 步:写 SOUL.md(定义人格)

SOUL.md 决定了这个 Agent 的行为模式。给 blog-writer 写一个专门的人格:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
cat > ~/.hermes/profiles/blog-writer/SOUL.md << 'EOF'
# Blog Writer Agent

你是博客写作和部署专家。

## 职责
1. 撰写技术博客文章(Markdown + Hugo front matter)
2. 构建验证(hugo --minify)
3. 部署到云存储

## 严格规则
- 日期必须是 RFC3339 格式:2026-05-15T10:00:00+08:00
- categories 和 tags 都要包含主题关键词
- description 必须填写
- **永远不要用 read_file → write_file 修改 Markdown**
- 构建后必须检查页面数
EOF

第 4 步:配置工作目录

让 blog-writer 的默认工作目录指向博客项目:

1
2
3
4
5
6
7
# 编辑 blog-writer 的 config.yaml
# 在 terminal 段添加:
terminal:
  cwd: /root/blog
toolsets:
- hermes-cli
- kanban

这样 worker 被调度时,会自动 cd 到博客目录。

第 5 步:初始化 Kanban 看板

1
hermes kanban init

输出:

1
2
3
4
5
6
Kanban DB initialized at ~/.hermes/kanban.db

Discovered 3 profile(s) on disk:
  blog-writer
  default
  yuan

看板是一张 SQLite 表,所有 profile 共享。验证一下:

1
2
hermes kanban stats     # 0 tasks (空看板)
hermes kanban assignees # blog-writer (idle)

第 6 步:创建第一个写作任务

1
2
3
4
5
6
hermes kanban create \
  --assignee blog-writer \
  --skill hugo-blog \
  --workspace 'dir:/root/blog' \
  --body '写一篇 Kanban 入门文章。要求:RFC3339日期、categories含hermes、构建验证' \
  '测试任务:写一篇 Kanban 入门文章'

输出:

1
Created t_9dd47956  (ready, assignee=blog-writer)

关键参数解释:

参数作用
--assignee blog-writer指定谁来做
--skill hugo-blog给 worker 注入博客相关知识
--workspace dir:/root/blog工作目录(不是临时 scratch)
--body '...'任务的详细要求

第 7 步:等 2 分钟,验收

Dispatcher 每 60 秒轮询一次 ready 任务。大约 70 秒后:

1
2
hermes kanban stats
# blog-writer  running=1  ← 正在执行

再等 82 秒:

1
2
3
4
hermes kanban show t_9dd47956
# status: done
# summary: 完成测试文章「Hermes Kanban 快速入门」,186页构建通过
# Run #1: completed @blog-writer 82s

文章已经写好了。 看看产出:

1
2
3
4
5
6
7
8
---
title: "Hermes Kanban 快速入门"
date: 2026-05-15T17:00:00+08:00
categories: ["hermes"]
tags: ["hermes", "kanban", "agent"]
---
## 什么是 Kanban?
Hermes Kanban 是内置的任务调度系统...

front matter 格式正确,日期 RFC3339,构建验证通过。全流程从创建到完成 2 分 22 秒

背后发生了什么

整个调度流程:

1
2
3
4
5
6
7
8
9
你发命令 → kanban create(SQLite 写入一条 ready 任务)
    ↓ 60s
Gateway dispatcher 轮询 → 发现 ready 任务 → claim
spawn 子进程:hermes -p blog-writer --skills kanban-worker --skills hugo-blog chat -q "work kanban task t_9dd47956"
    ↓ 82s
blog-writer 读任务 → 写文章 → hugo 构建 → kanban_complete
任务状态 → done,你收到通知

几个关键设计:

  • Dispatcher 嵌在 Gateway 里,不需要给 blog-writer 单独跑 gateway
  • Worker 是独立子进程hermes -p blog-writer 启动,完成后自行退出
  • --skills 自动注入,每个 worker 都会加载 kanban-worker skill(行为规范)
  • Claim TTL = 15 分钟,超时自动 reclaim,不会永远卡住

我踩过的 4 个坑

坑 1:hermes 不在 PATH 中

Dispatcher spawn worker 时执行 hermes -p blog-writer ...,如果 hermes 不在 PATH 里,直接失败。

1
2
3
4
5
# 检查
which hermes  # 如果为空,需要手动链接

# 修复
ln -sf ~/.hermes/hermes-agent/venv/bin/hermes /usr/local/bin/hermes

坑 2:blog-writer 不需要独立 gateway

一开始我以为每个 profile 都得跑自己的 gateway。错了。Dispatcher 运行在主 gateway 里,通过 hermes -p blog-writer spawn 子进程。子进程不需要消息平台,不需要 gateway。

如果你给 blog-writer 启动了 gateway,会和主 gateway 冲突(weixin token 被占)。

坑 3:kanban toolset 是隐藏的

hermes tools list 不显示 kanban。它是条件注册的——只有 config.yaml 的 toolsets 列表里有 kanban 才会激活。很多教程会遗漏这一步。

坑 4:workspace 默认是 scratch

如果不指定 --workspace,默认用 scratch(临时目录,任务完成后会被清理)。博客项目要用 dir:/root/blog,否则写完文章就被删了。

时间线回顾

时刻事件
17:07:00kanban create → 任务 ready
17:07:10Dispatcher claim + spawn worker
17:08:32Worker 完成,kanban_complete
总耗时1 分 32 秒(从创建到完成)

下一步

这是系列第 2 篇。接下来的内容:

  • 第 3 篇:多任务编排——让多个 Agent 同时写多篇文章,Pipeline + Fan-out 实战
  • 第 4 篇:踩坑全记录——格式陷阱、模型选择、成本控制、调试技巧

关注 varkm,一起学习,一起成长