Speed Up Local LLMs: How Headroom Cuts Agent Context by 95% for Snappy Tool Responses (2026)
You pointed Ollama, DeepSeek, or Llama 3 at a coding agent on a Mac mini—then asked it to grep a monorepo, tail a 200 MB log, or read a migration SQL dump. The UI froze. Tokens per second collapsed. On 8B–14B locals, tool output inflation hurts more than model IQ: every uncompressed byte hits the same unified memory bus at ~20–40 tok/s.
Headroom is an open-source context compression layer (Apache 2.0) that shrinks tool outputs, logs, and file reads before they enter the LLM—typically 60–95% fewer tokens, with CCR (Compress-Cache-Retrieve) so the model can fetch originals on demand. This guide targets local-first setups, not cloud API bill shaving (see Hermes Trajectory Compressor for that path).
Why local agents “hang” on big tool output
Local inference latency scales with context length and memory bandwidth, not just “smartness.”
| Symptom | Typical cause | What you see |
|---|---|---|
| 30–120 s “thinking” after one tool | 50k–200k tokens of stdout in context | Progress bar stuck; GPU at 100% |
| Answers get dumber mid-session | KV cache full; old tool dumps still resident | Model ignores recent instructions |
| App feels frozen | Swap on 8–16 GB Mac mini | Fans spin; Activity Monitor red pressure |
| Agent repeats failed grep | Model lost error line in noise | Same tool call loop |
Quotable definition: Local LLM tool latency is the wall-clock delay between a tool returning and the model producing the next token—dominated by prefill time over uncompressed context, not by tool execution itself.
A 200 KB JSON tool payload can add 50,000+ tokens on some tokenizers—at 25 tok/s prefill that is 30+ minutes of compute before the model answers “yes.” Headroom’s README cites a live example: 10,144 → 1,260 tokens while still surfacing the same FATAL log line. That is the difference between a usable home-lab agent and a tab you abandon.
On Apple Silicon, pair compression with 8 GB memory budgeting if you also run OpenClaw or MLX sidecars.
Headroom architecture: compress before prefill
Agent (Cursor, OpenClaw, custom)
│ tool results · file reads · logs
▼
┌──────────────────────────────┐
│ Headroom (local) │
│ CacheAligner → ContentRouter │
│ ├─ SmartCrusher (JSON) │
│ ├─ CodeCompressor (AST) │
│ └─ Kompress-base (text) │
│ CCR store (reversible) │
└──────────────────────────────┘
│ compressed messages + headroom_retrieve
▼
Ollama / llama.cpp / MLX API
From the project README benchmark table (reproducible via python -m headroom.evals suite):
| Workload | Tokens before | After | Savings |
|---|---|---|---|
| Code search (100 results) | 17,765 | 1,408 | 92% |
| SRE incident debugging | 65,694 | 5,118 | 92% |
| GitHub issue triage | 54,174 | 14,761 | 73% |
CCR: originals stay on disk; the model calls headroom_retrieve when it needs a full file—aggressive compression without permanent deletion.
External docs: Headroom quickstart, CCR reversible compression.
Decision matrix: what to use on a Mac mini agent
| Approach | Token cut | Reversible | Best for |
|---|---|---|---|
head -n 50 manual truncation | High | No — errors lost | Quick hacks |
Hermes compression.* / /compress | Medium | Partial (session) | Hermes Agent loops |
| Headroom proxy | 60–95% | Yes (CCR) | Any OpenAI-compatible local endpoint |
| Headroom MCP | Same engines | Yes | MCP-native agents (OpenClaw plugin supported) |
| Smaller quant only | 0% on tool bloat | N/A | Wrong lever if logs are huge |
If you run OpenClaw on Mac mini: Headroom lists OpenClaw as a supported wrap target and ContextEngine plugin—compress gateway tool traffic without rewriting agents.
If X, do Y: If prefill exceeds 10 s on a 7B local model after a single cat, enable Headroom before buying a bigger GPU or cloud fallback.
Scenario A — Ollama + Headroom proxy (zero agent code changes)
Point your agent’s OpenAI base URL at Headroom; Headroom forwards to Ollama.
Stack: Mac mini M2/M3/M4, Ollama with qwen2.5-coder:7b or deepseek-r1:8b, Headroom proxy on 8787.
Expected: Tool-heavy turns drop from 45–90 s to 8–15 s in community reports on 7B locals when JSON/log compressors strip duplicate lines (your mileage varies—benchmark your repo).
Scenario B — OpenClaw + Headroom MCP on a home server
Use MCP tools headroom_compress, headroom_retrieve, headroom_stats inside OpenClaw’s MCP stack. Keeps parallelism caps meaningful—fewer tokens means you can afford 2 concurrent tasks on 16 GB where you previously needed 1.
Seven-step runbook: Headroom + Ollama on Mac mini
Step 1 — Install Headroom (Python 3.10+)
brew install python@3.12
pip install "headroom-ai[proxy,mcp]"
headroom --version
Step 2 — Start Ollama with a coding model
ollama pull qwen2.5-coder:7b-instruct-q4_K_M
ollama serve # default :11434
Step 3 — Launch Headroom proxy toward Ollama
export OLLAMA_HOST=http://127.0.0.1:11434
headroom proxy --port 8787 --backend ollama
(If your build uses env-only routing, set OPENAI_BASE_URL / provider docs per proxy guide.)
Step 4 — Point the agent at localhost:8787
Example OpenAI-compatible client:
export OPENAI_API_BASE=http://127.0.0.1:8787/v1
export OPENAI_API_KEY=ollama # placeholder for local
Cursor / Aider / custom scripts: set base URL to http://127.0.0.1:8787/v1.
Step 5 — Baseline vs compressed soak test
Run the same prompt twice:
- Direct Ollama — “Search repo for
TODO, paste all matches.” - Via Headroom — same prompt.
Log headroom perf or MCP headroom_stats for token counts.
Step 6 — Enable retrieve when debugging
If the model misses a stack trace, instruct: “Use headroom_retrieve for the full log segment around ERROR.” CCR should return cached originals.
Step 7 — Persist as LaunchAgent (optional 24/7 gateway)
Wrap proxy + Ollama in separate LaunchAgents; cap Node heap per memory guide. Restart order: Ollama first, Headroom second, agent third.
Troubleshooting
Symptom: Still slow after Headroom
Pattern: headroom_stats shows low compression ratio on binary/protobuf tools.
Fix: Route those tools through JSON/text formatters first; enable CodeCompressor for source dumps; reduce parallel file reads.
Symptom: Model “lost” the failing test line
Pattern: Aggressive log crush removed the only FAIL row.
Fix: Call headroom_retrieve; tighten SmartCrusher to keep error keywords; pre-filter with rg --json ERROR before agent sees output.
Symptom: Proxy connects but 404 on /v1/chat/completions
Pattern: Wrong backend env; Ollama not running.
Fix: Run curl http://127.0.0.1:11434/api/tags; restart headroom proxy with correct --backend per installed version docs.
Recommended path
| Setup | Recommendation |
|---|---|
| Solo dev, Cursor + Ollama | headroom proxy --port 8787 + 7B coder quant |
| OpenClaw home gateway | Headroom MCP plugin + concurrency 1–2 on 16 GB |
| Hermes 8B loops | Headroom plus 8B tuning—compression does not fix JSON tool drift |
| MLX local routing | Headroom on tool path; MLX for inference per MLX hybrid guide |
FAQ
Need a dedicated Mac mini?
Run Ollama and Headroom on a headless host while you keep your daily driver light.