- Home
- Skills
- Prompt & Skill Engineering
- context-compactor
Works with the AI Agents you already use
Context Compactor
by limp
Token-saving middleware that compresses long contexts using deterministic, reversible single-token symbol mapping.
Free
context-compactor
Example session with this skill installed
Compress this conversation history and show me the stats for a 15-entry dictionary. I need to see the break-even point.
- Read your context and instructions
- Compiled the context-compactor
I have analyzed the conversation history and applied deterministic dictionary encoding. By mapping the 15 most frequent multi-token phrases to single-token symbols, the input size was significantly reduced.
Compression Report
| Metric | Value |
|---|---|
| Original Tokens | 2,840 |
| Compressed Body | 1,912 |
| Legend (Dictionary) Cost | 84 |
| Total Sent Tokens | 1,996 |
| Net Savings | 29.7% |
| Break-even Turn | 1.2 rounds |
Encoded Context Preview
Dictionary: §=User Interface, ¶=Authentication, ●=Database Schema, ★=Next.js
The project requires a new § and updated ¶ logic. We need to refactor the ● to support ★ components.
Next steps
- Use
--expandwith the provided legend to verify byte-for-byte restoration. - Pass the dictionary to
AutoCompactSessionto maintain consistent mapping across multi-turn sessions. - Deploy
scripts/auto_compactor.pyas a middleware layer for your OpenAI client.
Connects securely to your tools. The creator never sees your data.
About this skill
Long-context windows are expensive and slow. When your conversation history grows or you feed massive documents into an LLM, token costs balloon and prompt caching often fails. This package provides a deterministic, reversible compression layer that maps high-frequency phrases to single-token symbols, drastically reducing overhead without losing semantic data.
What it does
- Deterministic Compression utilizes a dictionary-based approach to replace multi-token phrases with single-token symbols.
- Transparent Middleware intercepts chat completions to automatically compress history while keeping recent messages in raw text for reasoning accuracy.
- Bidirectional Mapping ensures every compressed string can be expanded back to its original byte-for-byte state.
- Hybrid Support handles mixed English n-grams and CJK (Chinese, Japanese, Korean) character strings with specialized overlap filtering.
- Usage Analytics reports original vs. compressed token counts, saved percentages, and the break-even point for dictionary overhead.
How it works
- Analyze the input text or conversation history to identify recurring phrases that provide the highest token savings.
- Build a mapping of these phrases to a verified pool of symbols that represent exactly one token in the
cl100k_baseencoding. - Compress the history by replacing phrases, prefixing a small "legend" or dictionary header so the model understands the mapping.
- Invoke the LLM with the compacted context, significantly reducing the input payload.
Frameworks & tools
This tool is built for Python environments and requires tiktoken for accurate token validation. It includes a session wrapper compatible with the OpenAI Python client and any OpenAI-compatible API.
Why this beats prompting it yourself
Prompting an LLM to "compress this text" is lossy, non-deterministic, and consumes output tokens. This skill uses a programmatic, zero-shot algorithm that guarantees 100% data retention and precise token reduction before the LLM even sees the request.
Use cases
- Long-running Chatbots where conversation history grows beyond efficient window limits.
- Technical Document Q&A containing repetitive terminology, function names, or boilerplate.
- Token Cost Optimization for high-volume API implementations using expensive models like GPT-4o.
- Fixed Terminology Enforcement by pre-loading standard dictionaries into the compression layer.
Known limitations
Requires tiktoken installed for token counting and symbol validation. Small dialogues may not see net savings due to the token cost of the dictionary header.
How to use
- 1
Connect your agent to the Agensi MCP
Copy the prompt and paste it into Claude, ChatGPT, Cursor or any agent that supports MCP. It sets up the connection for you. Manual setup
- 2
Sign in to Agensi
Your agent shows a sign-in link. Sign in and click Allow.
- 3
Ask for what you need
Your agent loads this skill and uses it on your task. It always asks before buying a skill.
Reviews
No reviews yet
Be one of the first to try it. Every listed skill goes through the trust checks below.
Security scanned
Checked by our 8-point scan before listing
Fresh listing
Recently published to Agensi
Free to use
No account required to browse
Trust & safety
Security scan
Security scan passed 15 days ago
- Free with an Agensi account
- Software
Python
use windows,need installed tiktoken,Can be used onDeepSeek Harness (DSH),Claude Code
Permissions
What's inside
Creator
limp
agent-skill开发
Frequently Asked Questions
New in Prompt & Skill Engineering
Find more skills like this on the Claude Skills Marketplace, the Codex Skills Marketplace and the Gemini Skills Marketplace, or browse Claude Skills for Prompt & Skill Engineering.