← 返回
AI智能 中文

TokenRanger

Install, configure, and operate the TokenRanger OpenClaw plugin. Use when you want to reduce cloud LLM token costs by 50-80% via local Ollama context compres...
安装、配置并运行 TokenRanger OpenClaw 插件。用于通过本地 Ollama 上下文压缩将云端 LLM 令牌成本降低 50‑80%。
synchronic1
AI智能 clawhub v1.0.0 1 版本 99808.8 Key: 无需
★ 0
Stars
📥 522
下载
💾 26
安装
1
版本
#compression#cost-reduction#latest#ollama#performance#tokens

概述

TokenRanger

TokenRanger compresses session context through a local Ollama SLM before sending to cloud LLMs — reducing input token costs by 50–80% per turn with graceful fallthrough if anything goes wrong.

  • Plugin repo: https://github.com/peterjohannmedina/openclaw-plugin-tokenranger
  • npm: openclaw-plugin-tokenranger
  • Maintained by: @peterjohannmedina

When to Load This Skill

  • User asks to install, configure, or troubleshoot TokenRanger
  • User wants to reduce token costs or enable context compression
  • User runs /tokenranger commands and needs help interpreting output
  • User wants to switch compression strategy (GPU/CPU/off)
  • User asks about upgrading or uninstalling TokenRanger

How It Works

User message → OpenClaw gateway
  → before_agent_start hook
  → Turn 1: skip (full fidelity)
  → Turn 2+: send history to localhost:8100/compress
  → FastAPI sidecar runs LangChain LCEL chain via Ollama
  → Compressed summary prepended to context
  → Cloud LLM receives compressed context instead of full history

Inference strategy is auto-selected by GPU availability:

StrategyTriggerModelApproach
------------
fullGPU availablemistral:7bDeep semantic summarization
lightCPU onlyphi3.5:3bExtractive bullet points
passthroughOllama unreachableTruncate to last 20 lines

Install

Step 1 — Install the plugin

openclaw plugins install openclaw-plugin-tokenranger

To pin an exact version:

openclaw plugins install openclaw-plugin-tokenranger@1.0.0 --pin

Step 2 — First-time setup

openclaw tokenranger setup

This pulls Ollama models, creates the Python venv, installs FastAPI/LangChain deps,

and registers the sidecar as a system service (systemd on Linux, launchd on macOS).

Step 3 — Restart gateway

openclaw gateway restart

Step 4 — Verify

openclaw tokenranger

Should show current settings and sidecar status (reachable / unreachable).


Configuration

Set config values with:

openclaw config set plugins.entries.tokenranger.config.<key> <value>
openclaw gateway restart
KeyDefaultDescription
---------
serviceUrlhttp://127.0.0.1:8100TokenRanger sidecar URL
timeoutMs10000Max wait before fallthrough
minPromptLength500Min chars before compressing
ollamaUrlhttp://127.0.0.1:11434Ollama API URL
preferredModelmistral:7bModel for GPU strategy
compressionStrategyautoauto / full / light / passthrough
inferenceModeautoauto / cpu / gpu / remote

Force CPU-only mode:

openclaw config set plugins.entries.tokenranger.config.compressionStrategy light
openclaw config set plugins.entries.tokenranger.config.inferenceMode cpu
openclaw gateway restart

Commands

CommandDescription
------
/tokenrangerShow current settings and sidecar health
/tokenranger mode gpuForce GPU (full) compression
/tokenranger mode cpuForce CPU (light) compression
/tokenranger mode offDisable compression (passthrough)
/tokenranger modelList available Ollama models
/tokenranger toggleEnable / disable the plugin

Upgrading

# Check for updates (dry run)
openclaw plugins update tokenranger --dry-run

# Apply update
openclaw plugins update tokenranger
openclaw tokenranger setup   # re-runs setup if sidecar deps changed
openclaw gateway restart

To pin a specific version:

openclaw plugins install openclaw-plugin-tokenranger@2026.3.1 --pin
openclaw tokenranger setup
openclaw gateway restart

List all published versions:

npm view openclaw-plugin-tokenranger versions --json

Uninstalling

openclaw plugins uninstall tokenranger
openclaw gateway restart

Remove the sidecar service manually:

# Linux
systemctl --user stop tokenranger && systemctl --user disable tokenranger
rm ~/.config/systemd/user/tokenranger.service

# macOS
launchctl unload ~/Library/LaunchAgents/com.peterjohannmedina.tokenranger.plist
rm ~/Library/LaunchAgents/com.peterjohannmedina.tokenranger.plist

Troubleshooting

Sidecar unreachable after setup:

# Linux
systemctl --user status tokenranger
journalctl --user -u tokenranger -n 50

# macOS
launchctl list | grep tokenranger
cat ~/Library/Logs/tokenranger.log

# Manual start (any platform)
~/.openclaw/extensions/tokenranger/service/start.sh

Ollama not found:

curl http://127.0.0.1:11434/api/tags
# If not running:
ollama serve

Compression not reducing tokens:

  • Check minPromptLength — default 500 chars; short conversations are skipped by design
  • Run /tokenranger to confirm strategy is not passthrough
  • Check sidecar logs for errors

Graceful degradation: TokenRanger never blocks a message. Any failure → silent fallthrough to uncompressed cloud LLM call.


Performance Reference

5-turn Discord benchmark (GPU, mistral:7b-instruct):

TurnInput tokensCompressedReduction
------------
273212582.9%
31,18015087.3%
41,68521287.4%
52,02827786.3%

Cumulative: 5,866 → 885 tokens (84.9% reduction)

版本历史

共 1 个版本

  • v1.0.0 当前
    2026-03-30 07:53 安全 安全

安全检测

腾讯云安全 (Keen)

安全,无风险
查看报告

腾讯云安全 (Sanbu)

安全,无风险
查看报告

🔗 相关推荐

ai-intelligence

Self-Improving + Proactive Agent

ivangdavila
自我反思+自我批评+自我学习+自组织记忆。智能体评估自身工作、发现错误并持续改进。
★ 1,356 📥 318,069
ai-intelligence

Nano Banana Pro

steipete
使用 Nano Banana Pro (Gemini 3 Pro Image) 生成或编辑图像。支持文生图、图生图及 1K/2K/4K 分辨率,适用于图像创建、修改及编辑请求,使用 --input-image 指定输入图像。
★ 417 📥 115,160
ai-intelligence

ontology

oswalpalash
类型化知识图谱,用于结构化智能体记忆与可组合技能。支持创建/查询实体(人员、项目、任务、事件、文档)及关联...
★ 711 📥 243,717