Compress tool outputs, logs, files, and RAG chunks before they reach the LLM. 20% fewer tokens for coding agents, 60-95% fewer tokens for JSON, same answers. Library, proxy, MCP server.
Python agentaianthropicclaude-codecompressioncontext-engineeringcontext-windowcursorfastapilangchainllmmcpopenaiprompt-engineeringproxypythonragtoken-optimizationtokenstypescript
Fix test failures: update hash test for MD5, handle unicode surrogates
chopratejascfd44b3f6ab1
diff --git a/headroom/utils.py b/headroom/utils.pyindex 8840b4046..b9d94f604 100644--- a/headroom/utils.py+++ b/headroom/utils.py@@ -23,7 +23,7 @@ def generate_request_id() -> str:def compute_hash(data: str | bytes) -> str:"""Compute SHA256 hash, returning hex string."""if isinstance(data, str):- data = data.encode("utf-8")+ data = data.encode("utf-8", errors="surrogatepass")return hashlib.sha256(data).hexdigest()diff --git a/tests/test_compression_store.py b/tests/test_compression_store.pyindex 6e77f650a..2e2f4b5a2 100644--- a/tests/test_compression_store.py+++ b/tests/test_compression_store.py@@ -1249,10 +1249,10 @@ class TestHashCollisionDetection:# Should not have collision warningassert "Hash collision detected" not in caplog.text- def test_hash_uses_sha256_truncated(self, store: CompressionStore):- """Hash is SHA256 truncated to 24 characters."""+ def test_hash_uses_md5_truncated(self, store: CompressionStore):+ """Hash is MD5 truncated to 24 characters (fast, non-crypto)."""content = "test content"- expected_hash = hashlib.sha256(content.encode()).hexdigest()[:24]+ expected_hash = hashlib.md5(content.encode()).hexdigest()[:24]hash_key = store.store(original=content, compressed="[]")