Observed since 20 Oct, 21:46 UTC
No superseded metadata states collected. Unchanged observations do not create new revisions.
Smart context compression for LLM agents — preserve critical info, reduce tokens 40-80%
Smart context compression for LLM agents. Preserves critical information (decisions, errors, preferences, code) while reducing token usage by 40-80%.
LLM context windows are expensive. 90% of agent conversations contain filler — greetings, acknowledgments, repeated tool outputs, verbose explanations. But naive truncation drops critical info like decisions, errors, and user preferences.
Context Compressor scores every message by importance, then strategically drops low-value content while guaranteeing critical information is preserved.
Before: 603 tokens, 14 messages
After: 410 tokens, 5 messages (32% compressed, 98.7% confidence)
pip install agent-ctx-compress
With optional dependencies:
# For API server
pip install agent-ctx-compress[server]
# For accurate token counting
pip install agent-ctx-compress[tiktoken]
# For LLM summarization
pip install agent-ctx-compress[openai]
# Everything
pip install agent-ctx-compress[all]
from context_compressor import compress
messages = [
{"role": "system", "content": "You are a helpful assistant."},
{"role": "user", "content": "yo"},
{"role": "assistant", "content": "Hey! How can I help?"},
{"role": "user", "content": "deploy the app to production"},
{"role": "assistant", "content": "Deployed! Status: ✅ running"},
{"role": "user", "content": "thanks"},
{"role": "assistant", "content": "👍"},
]
result = compress(messages, target_ratio=0.3)
print(f"Saved {result.tokens_saved} tokens ({result.compression_ratio:.0%})")
print(f"Confidence: {result.confidence:.0%}")
print(result.compressed)
# Install from PyPI
pip install agent-ctx-compress
# Compress from file
cat conversation.json | ctxcompress --ratio 0.3
# Compress with stats
ctxcompress --input chat.json --ratio 0.2 --format full
# Stats only
ctxcompress --input chat.json --stats-only
# JSON output
ctxcompress --input chat.json --json
# Install with server deps
pip install agent-ctx-compress[server]
# Start server
ctxcompress-server
# → http://localhost:8000
# Compress via API
curl -X POST http://localhost:8000/compress \
-H "Content-Type: application/json" \
-d '{
"messages": [
{"role": "user", "content": "hello"},
{"role": "assistant", "content": "Hi!"},
{"role": "user", "content": "deploy app"},
{"role": "assistant", "content": "Deployed successfully"}
],
"target_ratio": 0.3
}'
Input Messages
│
▼
┌─────────────┐
│ Scorer │ Classify: decision/error/code/preference/noise
└──────┬──────┘
│
▼
┌─────────────┐
│ Deduplicat │ Remove near-duplicate messages
└──────┬──────┘
│
▼
┌─────────────┐
│ Merge Tool │ Combine consecutive tool results
└──────┬──────┘
│
▼
┌─────────────┐
│ Priority │ Drop lowest-scored until target ratio
│ Drop │ Preserve CRITICAL messages always
└──────┬──────┘
│
▼
┌─────────────┐
│ Summarize │ Compress long messages instead of dropping
└──────┬──────┘
│
▼
Compressed Context + Metadata
| Category | Importance | Droppable | Examples |
|---|---|---|---|
| system | CRITICAL | ❌ | System prompts |
| decision | CRITICAL | ❌ | "Let's use approach A" |
| error | CRITICAL | ❌ | Error messages, fixes |
| preference | CRITICAL | ❌ | "I prefer dark mode" |
| code | HIGH | ⚠️ | Code blocks, scripts |
| tool_result | HIGH | ⚠️ | API responses, outputs |
| user_query | HIGH | ⚠️ | User questions |
| structured_response | MEDIUM | ✅ | Lists, explanations |
| explanation | MEDIUM | ✅ | Long explanations |
| brief_response | LOW | ✅ | Short replies |
| noise | NOISE | ✅ | "yo", "sip", "👍" |
MIT
Download counts and popularity will appear here as the collector receives them.
| Version | Published | Direct dependencies | Open version |
|---|---|---|---|
| 0.2.0 | 2 Jul 2026 | 5 |
This describes our collected data; it is not a security assessment.
Shared repository data · GitHub
Public sponsor counts have not been collected. These signals belong to the repository owner.
github · 1 observations shown. Missing days are unknown.
| Date / source period | Value | Observed at |
|---|---|---|
| 2026-10-21 | 0 | 2026-10-21T14:14:56.0417128Z |
Observed since 20 Oct, 21:46 UTC
No superseded metadata states collected. Unchanged observations do not create new revisions.
package:ac938e201acdf77cfced54adf20545235de52de3b1383d907d68687cfbbefefa