Deterministic Token Reduction Toolkit for LLM agent contexts. Compresses tool output, truncates oversized conversation messages, and applies mechanical turn-level compression — all without requiring LLM calls.
Reduction layers:
- Layer 0 — Pre-filter: ANSI strip, secret redaction, thinking block strip, path normalization
- Layer 1 — Category filters: 13 shell-command categories +
read_filestructure-aware compression - Layer 2 — Shrink: Char and token-based truncation of oversized messages
- Layer 3 — Agent-solo turn compression: mechanical shrink/dedup/filter/compact strategies for tool-call continuation payloads
Depends on archolith-maintenance for shared Archolith helper primitives. tiktoken is optional for accurate token counting.
pip install -e .
# Optional: install with accurate token counting
pip install -e ".[tokenizer]"from archolith_filter import filter_output, shrink_messages
# Compress a tool result
result = filter_output("git diff --stat\n...")
# Shrink oversized messages
messages = [{"role": "tool", "content": "..."}]
shrunk = shrink_messages(messages, max_chars=4000)# Dev dependencies: pytest, pytest-benchmark, pytest-cov, ruff
pip install -e ".[dev]"Two more optional extras:
[tokenizer]— installstiktokenfor accurate BPE token counting. Without it, the library falls back to a shape-aware heuristic: prose uses the historical ~4 chars/token estimate, while code/config-like text uses a more conservative ~3.2 chars/token estimate. This matters primarily for standalone installs that don't also havetiktokenavailable. Production deployments viaarcholith-contextandarcholith-mcp-auditalways pulltiktokenas a hard dependency, so the heuristic fallback is just a development convenience path here.[context]— installsarcholith-proxy>=0.1.0, the local clone ofarcholith-context's proxy module. Note:archolith-proxyis not published to PyPI yet, so this extra currently fails on a fresh checkout. For local development against a checked-outarcholith-contextworktree, pointpipat the local clone (pip install -e "../archolith-context[archolith_filter]") instead. Distribution is tracked in the separateARCHOLITH-FILTER-DISTRIBUTION-PLANfollow-up.
| File | Purpose |
|---|---|
| .agent/README.md | Agent context and maintenance rules |
| .agent/architecture.md | System design, filter pipeline, config reference |
| .agent/data_models.md | Data classes, enums, telemetry models |
| .agent/CHANGELOG.md | Running log of changes |
Source-available under the PolyForm Noncommercial License 1.0.0.
archolith™ is a trademark of Charles Harvey.