AI 요금 월 $500→$50: Hermes Trajectory Compressor 실전(2026)
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.
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 |
/compress | Manual “trim the diary now” before you hit red on the context bar | Power users in long debug sessions |
trajectory_compressor.py | Post-processes saved JSONL trajectories to a target_max_tokens budget | Teams exporting logs for training or audit |
| Cheap summarization model | Pins summarization to e.g. Gemini Flash via auxiliary.compression.model | Anyone 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.
아키텍처: 두 계층 압축, 하나의 목표
| Layer | Entry point | Storage | When it runs |
|---|---|---|---|
| Live session | ~/.hermes/config.yaml → compression: | SQLite session in ~/.hermes/state.db | During chat; status bar shows 🗜️ N after first auto-compress |
| Batch trajectory | python trajectory_compressor.py --input=... | Reads/writes JSONL under your datagen folder | After 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:
| Setting | Total tokens (in+out) | Est. cost per run¹ | Notes |
|---|---|---|---|
| A — Compression off | 412,000 | $2.47 | Context bar orange by step 9; no /compress |
B — Runtime on (threshold: 0.50) | 94,000 | $0.56 | Auto-compress fired twice (🗜️ 2) |
| C — B + Flash summarizer | 94,000 | $0.18 | Summary passes billed at Flash rates |
¹Illustrative pricing: $3/1M input, $15/1M output, 70/30 in/out split—adjust for your provider.
| Setting | Monthly tokens | Est. 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.
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
- Cap parallel tools; reject unbounded “try again” loops in prompts
- Use
[SILENT]on monitoring crons (see Hermes cron Discord 다이제스트) - Route MCP filesystem roots narrowly per MCP Mac 개발 도구체인
문제 해결
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
/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).auxiliary.compression, and run /compress before multi-hour debugging. Measure with /usage weekly.