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.

은유: 생각 일기 vs 요약 보고서

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.

아키텍처: 두 계층 압축, 하나의 목표

LayerEntry pointStorageWhen it runs
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:

SettingTotal tokens (in+out)Est. cost per run¹Notes
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.

SettingMonthly tokensEst. monthly bill¹
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

Is Trajectory Compressor only for ML training?+
The batch script targets JSONL trajectories for datagen/RL. Runtime compression is for everyone in CLI/gateway and is what usually cuts monthly bills.
Does compression change model quality?+
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.
How is this different from /compress in chat?+
/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).
Can I compress OpenClaw or other agents?+
This guide covers Hermes only. Similar “summarize middle, keep ends” patterns exist elsewhere; benchmark numbers do not transfer.
Fastest win for $500/month teams?+
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 유지.