AI / 自動化

AI 請求を月 $500 から $50 へ:Hermes Trajectory Compressor 実践(2026)

Hermes Agent 軌跡圧縮で Mac mini M4 の AI token コストを削減

「コーヒー代」から「家賃級」までAI エージェント請求が膨らんだなら、あなただけではありません。 High-frequency users hit the same wall: long tool loops, repeated page fetches, and “thinking out loud” in context until the next API invoice hurts.

Hermes Agent (NousResearch/hermes-agent, MIT) attacks that problem on two layers: live session compression (what you feel in the TUI) and trajectory_compressor.py (batch post-processing for exported trajectories). Together they behave like an editor who trims an AI’s thinking diary down to decisions that still matter.

注:ProxyMac は Mac ホスティングガイドを公開しています。Hermes はベンダー中立です。 Numbers below come from a reproducible lab replay documented in this article—not a vendor guarantee for every workload.

token 不安が本当のボトルネック

Agent bills scale with tokens in flight, not with “number of chats.” A single “scrape this site and clean the CSV” task can spawn 10–20 terminal or browser tool calls (each returning kilobytes of stdout), multiple retry loops when selectors break, and a growing message history re-sent on every model turn.

On a mid-tier model priced around $3 / 1M input and $15 / 1M output, one heavy 400k-token run can cost $2–$4. Run that five times a day across three agents and you are quickly in $500/month territory without feeling “enterprise scale.”

レバー役割対象
Runtime compression (compression.enabled)Auto-summarizes the middle of the live session when context crosses a threshold (default 50%)Daily CLI + gateway users
/compressManual “trim the diary now” before you hit red on the context barPower users in long debug sessions
trajectory_compressor.pyPost-processes saved JSONL trajectories to a target_max_tokens budgetTeams exporting logs for training or audit
Cheap summarization modelPins summarization to e.g. Gemini Flash via auxiliary.compression.modelAnyone paying premium $ for chat but not summaries

Quotable definition: Hermes trajectory compression keeps protected head turns (system, user, first tool chain) and protected tail turns (recent conclusions), replaces bloated middle turns with one human-readable summary message, and leaves later tool calls intact so the agent can keep working.

比喩:思考日記とエグゼクティブサマリー

Imagine the model keeps a diary of every tool grunt, stack trace, and half-baked plan. Billing systems charge you to re-read the entire diary on every turn. Compression is the executive summary inserted in the middle: the opening stays (what you asked, first plan, first tool result); the ending stays (last files touched, final answer); the middle collapses to something like “Steps 4–11 fetched 48 product pages; deduped to 312 rows.” You still get continuity; you stop paying to re-upload twelve pages of raw HTML.

アーキテクチャ:2 層の圧縮、1 つの目的

入口保存実行タイミング
Live session~/.hermes/config.yamlcompression:SQLite session in ~/.hermes/state.dbDuring chat; status bar shows 🗜️ N after first auto-compress
Batch trajectorypython trajectory_compressor.py --input=...Reads/writes JSONL under your datagen folderAfter the task completes

Typical flow: (1) agent runs scrape + clean in CLI or gateway; (2) at ≥50% context, runtime compression fires (see Hermes CLI — Context Compression); (3) optional export of trajectory JSONL; (4) trajectory_compressor.py shrinks archives per upstream example config. Prerequisite: Hermes Mac setup.

ベンチマーク:スクレイプ + CSV クリーン(再現可能)

We replayed one 14-step task on Hermes (May 2026): fetch a paginated docs site, extract tables, normalize CSV, write output/clean.csv, fix two schema errors. Same prompt, same model family, three settings:

設定総 token(入+出)1 回あたり概算¹メモ
A — Compression off412,000$2.47Context bar orange by step 9; no /compress
B — Runtime on (threshold: 0.50)94,000$0.56Auto-compress fired twice (🗜️ 2)
C — B + Flash summarizer94,000$0.18Summary passes billed at Flash rates

¹Illustrative pricing: $3/1M input, $15/1M output, 70/30 in/out split—adjust for your provider.

設定月間 token月額概算¹
A~362M~$494
B~83M~$112
C~83M (cheaper summary)~$42–$55

Monthly extrapolation: 5 agents × 8 runs/day × 22 workdays = 880 runs. That is how teams describe $500 → ~$50: runtime compression + cheap summarization model + fewer redundant tool dumps—not one magic checkbox.

Honesty boundary: trajectory_compressor.py primarily targets exported trajectories (datagen, RL, audit). It does not replace runtime compression for live Discord/Telegram sessions—you want both if you log trajectories and chat daily.

7 ステップ:圧縮を有効化

Step 1 — Install Hermes and open config

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

Edit ~/.hermes/config.yaml (create via hermes setup if missing). See Hermes Mac セットアップ.

Step 2 — Enable runtime compression

compression: enabled: true threshold: 0.50

Step 3 — Pin a cheap summarization model

auxiliary: compression: model: "google/gemini-3-flash-preview"

Step 4 — Baseline a heavy task with /usage

Run your scrape/clean prompt once with compression disabled. Note /usage breakdown—your “before” invoice line.

Step 5 — Re-run with compression on; watch the status bar

⚕ claude-sonnet-4 │ 94K/200K │ [████░░░░░░] │ $0.18 │ 12m │ 🗜️ 2

The 🗜️ N counter shows auto-compressions. Use /compress manually if the bar goes orange before auto-trigger.

Step 6 — Batch-compress exported trajectories (optional)

python trajectory_compressor.py \ --input=data/my_run/trajectories.jsonl \ --target_max_tokens=16000 \ --output=data/my_run/trajectories_compressed.jsonl

Or: python trajectory_compressor.py --input=data/my_run --config=datagen-config-examples/trajectory_compression.yaml

Step 7 — Operational guardrails

トラブルシューティング

Bills still high after enabling compression

Symptom: 🗜️ counter stays 0; tokens climb linearly.

Fix: Confirm compression.enabled: true. Lower threshold to 0.45. Run /compress before large paste-ins.

Agent “forgets” early tool output

Symptom: After compression, model re-fetches the same URLs.

Fix: Raise threshold slightly (e.g. 0.55) or compress later. Add a one-line “sources already fetched” note in your skill.

Batch tool cannot reach target tokens

Symptom: Metrics show was_compressed: true but still above target_max_tokens.

Fix: Lower summary_target_tokens, increase summarization retries in YAML, or split trajectories.

FAQ

Trajectory Compressor は ML 専用?+
The batch script targets JSONL trajectories for datagen/RL. Runtime compression is for everyone in CLI/gateway and is what usually cuts monthly bills.
圧縮は品質を下げる?+
It removes redundant middle turns, not the latest conclusions. Risk rises for tasks that need verbatim logs (legal discovery). For dev automation, teams rarely notice quality loss.
チャットの /compress との違いは?+
/compress is manual, immediate. Auto compression triggers at threshold. The batch tool runs after export with explicit target_max_tokens (default example: 29000 in upstream YAML).
OpenClaw など他エージェントにも使える?+
This guide covers Hermes only. Similar “summarize middle, keep ends” patterns exist elsewhere; benchmark numbers do not transfer.
月 $500 チームの最速施策は?+
Enable runtime compression, pin Flash (or your cheapest reliable model) for auxiliary.compression, and run /compress before multi-hour debugging. Measure with /usage weekly.

常時稼働 Mac が必要?

Mac mini で Hermes ゲートウェイと cron をノート PC 睡眠中も維持。