English | 简体中文
WeChat iLink rate-limit heartbeat and automated task recovery for Hermes Agent. Solves the WeChat proactive message quota (限流) problem - iLink allows only 10 messages per 24h per user conversation - by pushing periodic heartbeat messages to keep the channel alive, with dual-cron architecture for zero-token heartbeat pushes and LLM-powered task continuation.
- The Problem
- Features
- Architecture
- File Structure
- Prerequisites
- Docker vs Host: Path Differences
- Installation
- Push Format
- Testing
- FAQ
- Related Projects
- License
WeChat iLink enforces a proactive message quota: 10 messages per 24-hour window per user conversation. When an AI agent sends messages consecutively, it quickly exhausts this quota and the WeChat channel gets rate-limited (限流). Users must manually send "继续" (continue) to reset the quota and resume the conversation.
hermes-wexin-heartbeat solves this with a dual-cron architecture running every 5 minutes:
loop_heartbeat- Pushes a heartbeat message only when there's something to report (pending tasks, retry queue, recent events, or gateway down). Runs inno_agentmode (zero token consumption). Stays silent when idle to conserve the 10-message/24h quota.loop_continuation— Automatically detects the last unfinished task and continues execution without user intervention. Runs inagentmode (LLM reasoning, consumes few tokens).
Users never need to send "continue" - the system recovers on its own.
- Proactive quota: iLink allows max 10 proactive messages per 24h per user conversation; user sending any message resets the quota to 10
- Burst limit: Short-window burst cap of ~5 messages/second per account; exceeding this triggers rate-limiting (限流,
ret=-2) - DM-focused: iLink primarily supports direct messages (私聊); group chat (群聊) support is limited and depends on account type
- Exclusive lock: Only one process can poll iLink
getupdatesat a time - Session expiry: 24h without user interaction expires the session; Hermes auto-reconnects. Note:
ret=-2is ambiguous - it can mean either rate limit OR expiredcontext_token
- Zero-token heartbeat:
no_agentmode checks every 5 minutes, pushes only when there's something to report (silent when idle) - Automatic task recovery: Detects unfinished tasks and resumes them without user intervention
- Retry queue: Failed messages are automatically retried with exponential backoff and cooldown
- Pending task tracking: CLI tool (
pending.py) for enqueue/list/complete/fail task management - Configurable timezone: Display time in any timezone via
TZ_OFFSET_HOURS/TZ_LABELenv vars - Docker & Host support: All paths derive from
HERMES_HOMEenv var, works in both deployment modes - Gateway health check: Gateway status (✓/✗) included in push when there's an alert
- Pure Python stdlib: No external dependencies - runs on any Python 3 installation
┌──────────────────────────────────────────────────────────────┐
│ cron scheduler (every 5 min) │
├──────────────────────┬───────────────────────────────────────┤
│ loop_heartbeat │ loop_continuation │
│ (no_agent, 0 token) │ (agent, consumes few tokens) │
│ │ │
│ 1. Write heartbeat │ 1. Check pending.py list for tasks │
│ 2. Process retry q │ 2. Has tasks -> auto-continue │
│ 3. Read pending state│ 3. Done -> pending.py complete │
│ 4. Push if active │ 4. Failed -> pending.py fail │
│ │ 5. Push to WeChat │
└──────────────────────┴───────────────────────────────────────┘
Why two crons?
| loop_heartbeat | loop_continuation | |
|---|---|---|
| Mode | no_agent (zero tokens) |
agent (LLM reasoning) |
| Function | Push status when active | Auto-continue tasks |
| Always pushes? | No - silent when idle, pushes only on events/tasks/alerts | Only when there are pending tasks |
| When rate-limited | Auto-retries push after 5 min | Auto-continues after 5 min |
hermes-wexin-heartbeat/
├── README.md # English docs (this file)
├── README.zh-CN.md # Chinese docs (简体中文)
├── screenshot/ # Push format screenshot
├── scripts/
│ ├── loop_heartbeat.py # Main heartbeat script (no_agent)
│ ├── loop_continuation.sh # Continuation checker (agent cron)
│ └── pending.py # Pending task management CLI
- Hermes Agent installed with gateway running
- WeChat (微信) channel configured via iLink (
hermes gateway setup→ select Weixin) hermes sendcommand available (used to push messages to WeChat)- Cron scheduler enabled (
hermes cron listreturns normally) WEIXIN_HOME_CHANNELset in~/.hermes/.env(required for proactive message delivery)
Hermes Agent uses different paths depending on deployment mode. This project's scripts default to Docker paths but support both via the HERMES_HOME environment variable.
| Setting | Docker | Host (bare metal) |
|---|---|---|
HERMES_HOME |
/opt/data |
~/.hermes |
| Hermes binary | /opt/hermes/.venv/bin/hermes |
~/.local/bin/hermes |
| Config directory | /opt/data (mounted from host ~/.hermes) |
~/.hermes |
| Audit logs | $HERMES_HOME/audit |
~/.hermes/audit |
| Cron jobs | $HERMES_HOME/cron/ |
~/.hermes/cron/ |
| Pending tasks | $HERMES_HOME/state/pending.jsonl |
~/.hermes/state/pending.jsonl |
| Gateway process | Supervised by s6-overlay in container | systemd service or manual |
Docker deployment (host ~/.hermes → container /opt/data):
docker run -d --name hermes \
-v ~/.hermes:/opt/data \
-p 8642:8642 \
nousresearch/hermes-agent gateway runHost deployment — set HERMES_HOME before running scripts:
export HERMES_HOME="$HOME/.hermes"
export HERMES_SEND_CMD="$HOME/.local/bin/hermes send"# Place scripts into Hermes' scripts directory
cp scripts/loop_heartbeat.py $HERMES_HOME/scripts/cron/
cp scripts/loop_continuation.sh $HERMES_HOME/scripts/cron/
cp scripts/pending.py $HERMES_HOME/scripts/
# Ensure they are executable
chmod +x $HERMES_HOME/scripts/cron/loop_heartbeat.py
chmod +x $HERMES_HOME/scripts/cron/loop_continuation.sh
chmod +x $HERMES_HOME/scripts/pending.pyAll configurable variables are at the top of loop_heartbeat.py and support environment variable overrides:
# Hermes root directory
# Docker: /opt/data | Host: ~/.hermes
HERMES_HOME = os.environ.get("HERMES_HOME", "/opt/data")
# Audit log directory
AUDIT_DIR = os.environ.get("HERMES_AUDIT_DIR") or os.path.join(HERMES_HOME, "audit")
# Retry queue & dead letter (derived from HERMES_HOME)
RETRY_QUEUE_DIR = os.path.join(HERMES_HOME, "cron", "retry_queue")
DEAD_DIR = os.path.join(HERMES_HOME, "cron", "retry_dead_letter")
# Timezone (relative to UTC)
TZ_OFFSET_HOURS = int(os.environ.get("TZ_OFFSET_HOURS", "8")) # Beijing=8, Tokyo=9, UTC=0
TZ_LABEL = os.environ.get("TZ_LABEL", "北京时间")
# hermes send command path
HERMES_SEND_CMD = os.environ.get("HERMES_SEND_CMD", "/opt/hermes/.venv/bin/hermes send")Environment variables reference:
| Variable | Description | Docker default | Host typical |
|---|---|---|---|
HERMES_HOME |
Hermes config root | /opt/data |
~/.hermes |
HERMES_AUDIT_DIR |
Audit log directory | $HERMES_HOME/audit |
~/.hermes/audit |
TZ_OFFSET_HOURS |
Timezone offset from UTC | 8 (Beijing) |
8 (Beijing) |
TZ_LABEL |
Timezone display label | 北京时间 |
北京时间 |
HERMES_SEND_CMD |
hermes send command path |
/opt/hermes/.venv/bin/hermes send |
~/.local/bin/hermes send |
HERMES_SEND_PATH |
Subprocess PATH override | Includes /opt/hermes/.venv/bin |
Includes ~/.local/bin |
hermes cron create \
--name "loop_heartbeat (5min)" \
--schedule "*/5 * * * *" \
--script "cron/loop_heartbeat.py" \
--no-agent \
--deliver origin \
--workdir "$HERMES_HOME"First, ensure cron/loop_continuation.sh is in place (copied in step 1).
hermes cron create \
--name "loop_continuation (5min)" \
--schedule "*/5 * * * *" \
--script "cron/loop_continuation.sh" \
--deliver origin \
--workdir "$HERMES_HOME"Then set the prompt for the continuation cron:
hermes cron update YOUR_JOB_ID \
--prompt "You are the Loop Continuation Agent. Goal: automatically detect and resume interrupted conversations.
Steps:
1. Run \`python3 $HERMES_HOME/scripts/pending.py list\` to check for pending tasks
2. If there are pending tasks, pick the most urgent one and continue executing it
3. If no pending tasks, check the audit logs from the last 5 minutes for unfinished work
4. If unfinished work is found, continue executing it
5. When done, mark it complete with \`python3 $HERMES_HOME/scripts/pending.py complete <id>\`
6. On failure, mark it with \`python3 $HERMES_HOME/scripts/pending.py fail <id> <reason>\`
7. If there are no pending tasks and no unfinished work, return '[SILENT]' (this suppresses message delivery to avoid spam)
Note: This is automatic continuation. Do not ask the user questions, just do it. When there is nothing to do, stay silent - do not push unnecessary messages."# Add a task
python3 $HERMES_HOME/scripts/pending.py enqueue "Configure multimodal model"
# List tasks
python3 $HERMES_HOME/scripts/pending.py list
# Complete a task
python3 $HERMES_HOME/scripts/pending.py complete t-123456
# Mark as failed
python3 $HERMES_HOME/scripts/pending.py fail t-123456 "Invalid API key"
# View status distribution
python3 $HERMES_HOME/scripts/pending.py statusIf there is no pending.jsonl file, the loop heartbeat skips the task section and only pushes retries and events.
When there's something to report, a push is sent in the following format:
⏳ 23:00 北京时间 | 待办 1 · 已完成 3 · 重试 2 · 事件 5
[待办] 配置多模态模型 (1次)
[已完成] 下载视频 (1次)
[已完成] 转 GIF (1次)
[已完成] 写文案 (1次)
... 还有 1 条
Gateway: ✓
Status labels: [待办] · [进行中] · [已完成] · [失败]
Example of an actual push:
Run manually to test:
# Test heartbeat
python3 scripts/loop_heartbeat.py
# Test pending task management
python3 scripts/pending.py statusiLink allows only 10 proactive messages per 24h per user conversation. With a 5-minute cron interval, the quota is exhausted in 50 minutes. To conserve quota, increase the cron interval (e.g., */30 * * * * = every 30 min = 48 pushes/24h, still over quota but allows retry on failure). Alternatively, the user can send any message to reset the quota to 10. You can also increase MIN_RETRY_INTERVAL for the retry queue.
Remove the _process_retry_queue() call, or set RETRY_QUEUE_DIR to an empty directory.
Just delete the pending.jsonl file. The heartbeat will skip the task section.
Manually run python3 scripts/cron/loop_heartbeat.py. Output goes to stdout.
Check if there are pending tasks (pending.py list). If none, continuation has nothing to do. Also verify WEIXIN_HOME_CHANNEL is set in your Hermes .env file — without it, proactive pushes have nowhere to deliver.
No. Heartbeat is no_agent (zero tokens, pure script), continuation is agent (LLM). They run independently.
Set environment variables before running the script or in your Hermes .env:
export TZ_OFFSET_HOURS=9 # Tokyo time
export TZ_LABEL="JST"Both work. Docker is recommended for production (isolated, easy to upgrade, s6 auto-restart). Host installation is simpler for development. See Docker vs Host section for path differences.
- Hermes Agent - The AI agent framework this project extends. Open-source, MIT license, by Nous Research.
- Hermes Agent Docs - Official documentation (EN/zh-Hans)
- Hermes WeChat Integration - WeChat iLink setup guide
- Hermes Cron Docs - Cron scheduler reference
MIT
