
Token Compressor
io.github.base76-research-lab由 GitHub 帳號 base76-research-lab 發布v0.1.1更新於 Oct 24, 2026
Compress prompts 40-60% using local LLM + embedding validation. Preserves all conditionals.
概覽
一個本機 MCP 伺服器,在提示詞送進大型語言模型前先用本機 Ollama 模型壓縮,並以向量相似度驗證,減少 token 用量。
- 可以做什麼
- 用本機 Ollama 模型把提示詞改寫成語意最精簡的形式,保留條件語句與否定表達。以餘弦相似度比對原文與壓縮後文字,低於門檻時原樣回傳原文。回傳壓縮後文字與統計資訊,包含模式、覆蓋度以及輸入、輸出與節省的估算 token 數。對低於可設定 token 下限的短輸入略過壓縮。
- 適用情境
- 適合反覆把長提示詞送給大型語言模型、在意 token 成本或上下文長度的情況,且希望壓縮在本機完成並有防止語意流失的驗證。短提示詞會被略過,效益有限。
- 執行需求
- 以本機 Python 套件執行(需 Python 3.10 以上),可透過 uvx 或 python3 啟動。需要在本機執行 Ollama,並已拉取 llama3.2:1b 與 nomic-embed-text 兩個模型,另需 ollama 與 numpy 相依套件。未宣告帳號、API 金鑰或標頭。
安裝
在 SourceWeft 中
- 開啟 儀表板中的 Token Compressor,將其新增到工作區。
- 為需要使用其工具的對話啟用該服務。
Desktop only,透過 STDIO。 STDIO 服務會啟動本機處理程序,因此需要 SourceWeft 桌面主機。
其他 MCP 客戶端
參照 儲存庫 中的啟動說明。
README
token-compressor
Reduce LLM prompt tokens by 30–70% while preserving semantic meaning.
mcp-name: io.github.base76-research-lab/token-compressor
Semantic prompt compression for LLM workflows. Reduce token usage by 40–60% without losing meaning.
[License: MIT] [Requires: Ollama] [MCP Compatible]
Built by Base76 Research Lab — research into epistemic AI architecture.
Live demo
Intent Compiler MVP is now live and uses this project as part of the idea -> spec -> compressed output flow:
- Live: https://intent-compiler-mvp.pages.dev
- Product repo: https://github.com/base76-research-lab/token-compressor
What it does
token-compressor is a two-stage pipeline that compresses prompts before they reach an LLM:
- LLM compression — a local model (llama3.2:1b via Ollama) rewrites the prompt to its semantic minimum, preserving all conditionals and negations
- Embedding validation — cosine similarity between original and compressed embeddings must exceed a threshold (default: 0.85) — if not, the original is sent unchanged
The result: shorter prompts, lower costs, same intent.
Key design principle: conditionality is never sacrificed. If your prompt says "only do X if Y", that constraint survives compression.
Requirements
- Python 3.10+
- Ollama running locally
- Two models pulled:
- Python dependencies:
Quick start
Result object:
CLI usage
Output: compressed text on stdout, stats on stderr.
Claude Code hook (recommended setup)
Add to your ~/.claude/settings.json under hooks → UserPromptSubmit:
This runs on every prompt submission and writes the compressed version to a temp file, which can be injected back into context via a second hook or MCP server.
MCP server
The MCP server exposes compression as a tool callable from Claude Code and any MCP-compatible client.
Install:
Tool: compress_prompt
- Input:
text(string) - Output: compressed text + stats footer
Claude Code MCP config (~/.claude/settings.json):
Or from source:
Configuration
How it works
Stage 1 — LLM compression
The compression prompt instructs the model to:
- Preserve all conditionals (
if,only if,unless,when,but only) - Preserve all negations
- Remove filler, hedging, redundancy
- Target 40–60% of original length
Stage 2 — Embedding validation
Computes cosine similarity between the original and compressed text using nomic-embed-text. If similarity falls below threshold, the original is returned unchanged. This prevents silent meaning loss.
Results
Tested across Swedish and English prompts, technical and natural language:
Research background
This tool implements the architecture from:
Wikström, B. (2026). When Alignment Reduces Uncertainty: Epistemic Variance Collapse and Its Implications for Metacognitive AI. DOI: 10.5281/zenodo.18731535
Part of the Base76 Research Lab toolchain for epistemic AI infrastructure.
License
MIT — Base76 Research Lab, Sweden
來源:README.md,提交 1f5e39e
工具
0版本歷史
1- v0.1.1最新Sep 16, 2026
評分
已滿足適用檢查項的 50%
該評分衡量此收錄條目的完整程度,依據註冊中心條目、端點與公開來源計算得出。它不是對伺服器本身的評價,也不表示伺服器安全或目前可用:可連通性是帶日期的檢查結果,評分也不包含安裝量或使用者評價。
- 近 30 天內可連通25 分
請保持端點能夠回應 MCP 握手;SourceWeft 每 30 天探測一次。
- 已宣告認證方式10 分
請在註冊中心條目中宣告憑證請求標頭,或保持端點能夠回應探測,以便判定其認證方式。
- 已列出工具15 分
請讓伺服器在無憑證時回應 tools/list,或發布可在沙箱中無憑證啟動的軟體包。
- 描述必需15 分
- 圖示10 分
- 文件15 分
- 授權條款10 分