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 'list' object has no attribute 'strip' error
chopratejas07dfa9d25c67
diff --git a/headroom/transforms/code_compressor.py b/headroom/transforms/code_compressor.pyindex c1a48f112..098b306c8 100644--- a/headroom/transforms/code_compressor.py+++ b/headroom/transforms/code_compressor.py@@ -1201,7 +1201,8 @@ class CodeAwareCompressor(Transform):for message in messages:content = message.get("content", "")- if not content:+ # Skip empty or non-string content (multimodal messages with images)+ if not content or not isinstance(content, str):transformed_messages.append(message)continue@@ -1266,7 +1267,8 @@ class CodeAwareCompressor(Transform):for message in messages:content = message.get("content", "")- if content:+ # Only check string content (skip multimodal)+ if content and isinstance(content, str):detection = detect_content_type(content)if detection.content_type == ContentType.SOURCE_CODE:return Truediff --git a/headroom/transforms/llmlingua_compressor.py b/headroom/transforms/llmlingua_compressor.pyindex e09e57b9a..f7e0ec6b6 100644--- a/headroom/transforms/llmlingua_compressor.py+++ b/headroom/transforms/llmlingua_compressor.py@@ -430,6 +430,11 @@ class LLMLinguaCompressor(Transform):role = message.get("role", "")content = message.get("content", "")+ # Skip non-string content (multimodal messages with images)+ if not isinstance(content, str):+ transformed_messages.append(message)+ continue+# Compress tool results (highest value compression)if role == "tool" and content:result = self.compress(content, context=context, content_type="json")