README.md

August 21, 2026 · View on GitHub

LightRSI logo

A modular runtime for recursive improvement in long-running LLM agents

framework hosts component pnpm license

95.7% fewer input tokens   |   87.0% lower cost
vs. Vanilla OpenClaw on Claw-Eval continuous mode

67.4% fewer input tokens   |   61.5% lower cost
vs. Vanilla OpenClaw on PinchBench continuous mode


🧩 Components

LightRSI separates reusable improvement capabilities from shared runtime infrastructure and host-specific integration. TokenPilot is the first production preset; memory writeback, model adaptation, and agent-architecture evolution can build on the same runtime boundaries over time.

ComponentWhat It DoesHow It WorksEffect
TokenPilotKeeps long-running agent sessions smaller, cheaper, and easier to sustainStabilizes the reusable prompt prefix, trims oversized tool output before it poisons later turns, and limits how much old context is carried forward as sessions growBetter cache reuse, lower token usage, lower cost, and less context bloat in shared sessions

📑 Table of Contents

📢 News

🔧 Installation

1. Prepare the Repository Once

Clone the repository and build the shared packages:

git clone https://github.com/zjunlp/LightRSI.git
cd LightRSI
corepack enable
pnpm install
pnpm build
pnpm lightrsi:build
pnpm lightrsi:install

2. Pick Your Host

Open the host you want and run the default install commands.

OpenClaw

Default install:

pnpm component:install:tokenpilot:openclaw

This installs the current TokenPilot OpenClaw adapter, updates ~/.openclaw/openclaw.json, enables the plugin, switches plugins.slots.contextEngine to layered-context, applies the default normal mode, and tries to restart the OpenClaw gateway automatically.

If your OpenClaw home or config path is not under the default ~/.openclaw, set:

export LIGHTRSI_OPENCLAW_HOME="/path/to/openclaw-home"
export OPENCLAW_CONFIG_PATH="/path/to/openclaw.json"

Then run the same install command again:

pnpm component:install:tokenpilot:openclaw
Codex CLI

Default install:

npm --prefix components/adapters/codex run build
npm --prefix components/adapters/codex run install:codex

This keeps your current active Codex provider name, reroutes that provider through the local TokenPilot proxy, writes ~/.codex/tokenpilot.json, registers hooks in ~/.codex/hooks.json, registers the shared tokenpilot_memory_fault_recover MCP server, and creates the standalone lightrsi CLI entrypoint at ~/.local/bin/lightrsi.

If your Codex config files are not under the default ~/.codex, set:

export CODEX_CONFIG_PATH="/path/to/config.toml"
export CODEX_HOOKS_CONFIG_PATH="/path/to/hooks.json"
export TOKENPILOT_CODEX_CONFIG="/path/to/tokenpilot.json"

Then run the same install flow:

npm --prefix components/adapters/codex run build
npm --prefix components/adapters/codex run install:codex

If lightrsi is not found after install, make sure ~/.local/bin is on your PATH.

Claude Code

Default install:

npm --prefix components/adapters/claude-code run build
npm --prefix components/adapters/claude-code run install:claude-code

This updates ~/.claude/settings.json for local gateway routing, writes ~/.claude/tokenpilot.json, registers the shared tokenpilot_memory_fault_recover MCP server in ~/.claude/.claude.json, installs a SessionStart hook that auto-starts the local gateway on first use, and preserves existing Claude files as .tokenpilot.bak backups before rewriting.

If your Claude Code files are not under the default ~/.claude, set:

export CLAUDE_CODE_SETTINGS_PATH="/path/to/settings.json"
export CLAUDE_CODE_MCP_CONFIG_PATH="/path/to/.claude.json"
export TOKENPILOT_CLAUDE_CODE_CONFIG="/path/to/tokenpilot.json"

Then run the same install flow:

npm --prefix components/adapters/claude-code run build
npm --prefix components/adapters/claude-code run install:claude-code

If lightrsi is not found after install, make sure ~/.local/bin is on your PATH.

⚡ Quick Start

Pick your host and open the matching one-pass setup below.

OpenClaw
  1. Start or restart OpenClaw.
  2. Open a session with a lightrsi/<model> model such as lightrsi/gpt-5.4-mini.
  3. Run:
/lightrsi status

You should see a status block similar to:

  • plugin entry enabled
  • config enabled
  • mode normal
  • context engine slot layered-context
  • stabilizer enabled
  • reduction enabled

For a fuller runtime summary, run:

/lightrsi report
/lightrsi doctor
/lightrsi visual
/lightrsi mode normal

/lightrsi doctor is the quickest integration self-check for the current OpenClaw adapter surface. /lightrsi visual opens the local visual inspector for stability, reduction, and eviction snapshots. /lightrsi mode <conservative|normal|aggressive> switches preset runtime behavior.

You can also use the standalone CLI outside OpenClaw:

lightrsi openclaw status
lightrsi openclaw report
lightrsi openclaw doctor
lightrsi openclaw visual
lightrsi openclaw mode normal
Codex CLI

The current Codex path uses the standalone CLI plus Codex hooks.

  1. Run the Codex install flow shown above.
  2. Start Codex normally.
  3. If Codex asks you to review or trust the installed TokenPilot hooks, approve them.
  4. Open a new Codex session so SessionStart can start the local proxy.
  5. In another terminal, verify the adapter:
lightrsi codex status
lightrsi codex doctor
lightrsi codex report
lightrsi codex mode normal
lightrsi codex reduction status
lightrsi codex stabilizer target user

Expected first-run shape:

  • lightrsi codex doctor reports proxy healthy: yes
  • lightrsi codex status shows stabilizer and reduction enabled
  • after a few turns, lightrsi codex report no longer says No TokenPilot session stats yet.

Install success does not always mean the proxy is already running before the first trusted session. If doctor still reports proxy healthy: no after trusting hooks and opening a new Codex session, use the manual fallback:

tokenpilot-codex status
tokenpilot-codex start
Claude Code

The current Claude Code path also uses the standalone CLI, but routes requests through a local Anthropic-compatible gateway and a shared MCP recovery server.

  1. Run the Claude Code install flow shown above.
  2. Start Claude Code normally.
  3. Open a new Claude Code session so SessionStart can auto-start the local gateway.
  4. In another terminal, verify the adapter:
lightrsi claude-code status
lightrsi claude-code doctor
lightrsi claude-code report
lightrsi claude-code mode normal
lightrsi claude-code reduction status
lightrsi claude-code stabilizer target developer

Expected first-run shape:

  • lightrsi claude-code doctor reports proxy healthy: yes
  • lightrsi claude-code status shows stabilizer and reduction enabled
  • after a few turns, lightrsi claude-code report no longer says No TokenPilot session stats yet.

Like Codex, install success does not guarantee that the gateway is already healthy before the first real session triggers SessionStart.

🖼️ Visual Results

The screenshots below come from the built-in visual inspector opened with:

lightrsi visual
TokenPilot runtime effects

Stable-prefix view:

TokenPilot stabilizer view

Reduction view:

TokenPilot reduction view

Eviction view:

TokenPilot eviction view

🏗️ Architecture

The current public repository separates reusable capabilities, verified presets, host adapters, and user-facing products.

At a high level:

  • components/packages
    • shared foundation and independently composable feature packages
  • components/presets
    • verified feature combinations such as TokenPilot
  • components/adapters
    • host-specific integration, install surfaces, runtime hooks, and product registration
  • components/products
    • shared CLI, Visual launcher, and MCP recovery surfaces
LightRSI/
├── components/
│   ├── packages/
│   │   ├── foundation/           # contracts, runtime, host, history, artifact, product infrastructure
│   │   └── features/             # stabilizer, reduction, eviction, and memory
│   ├── presets/
│   │   └── tokenpilot/           # Stabilizer + Reduction + Eviction composition contract
│   ├── adapters/
│   │   ├── openclaw/             # OpenClaw adapter
│   │   ├── codex/                # Codex CLI adapter
│   │   └── claude-code/          # Claude Code adapter
│   └── products/
│       ├── cli/                  # shared lightrsi CLI and browser visual launcher
│       └── mcp/                  # shared memory_fault_recover MCP server
├── docs/                         # Public-facing notes and smoke helpers for the current runtime path
├── website/                      # Documentation site
└── README.md

TokenPilot is now a preset rather than a source-code parent directory. Each adapter explicitly binds the preset and contributes host discovery metadata; the shared CLI and Visual surface consume those registrations.

🧪 Experiment Reproduction

Benchmark tasks, runners, profiles, and analysis are maintained in the separate TokenPilot experiment repository. LightRSI contains the runtime and plugin platform; it no longer vendors the experiment harness.

Experiment entrypoints:

💡 Commands

Use the basic commands first, then the session-aware and advanced ones when you need them.

Shared standalone CLI patterns:

lightrsi report
lightrsi visual
lightrsi use openclaw
lightrsi use codex session <session-id>
lightrsi context
lightrsi <host> session <session-id> report
  • lightrsi report shows the latest available report across hosts
  • lightrsi visual opens the shared browser visual and lets you switch hosts and sessions
  • lightrsi use <host> sets the default host for hostless CLI commands
  • lightrsi use <host> session <session-id> pins the default session for later report and visual
  • lightrsi context shows the current default host, pinned session, and remembered config target
  • lightrsi <host> session <session-id> report reads one specific session directly

Pick your host for the command surface below.

OpenClaw

Inside an OpenClaw session:

/lightrsi status
/lightrsi report
/lightrsi doctor
/lightrsi visual
/lightrsi mode normal
/lightrsi stabilizer target developer
/lightrsi reduction mode balanced
/lightrsi eviction on
/lightrsi help

Outside OpenClaw, the standalone CLI supports the same host directly:

lightrsi openclaw status
lightrsi openclaw report
lightrsi openclaw doctor
lightrsi openclaw visual
lightrsi openclaw mode normal
lightrsi openclaw session <session-id> report

Useful OpenClaw-only controls:

  • mode aggressive enables the most aggressive runtime policy preset
  • eviction ... controls lifecycle-aware context eviction
  • settings details on expands status output with more runtime detail
  • stabilizer ... and reduction ... let you tune prefix stabilization and observation reduction directly
Codex CLI

Use the standalone CLI:

lightrsi codex status
lightrsi codex report
lightrsi codex doctor
lightrsi codex visual
lightrsi codex session <session-id> report
lightrsi codex reduction status
lightrsi codex stabilizer target developer
lightrsi codex mode normal
lightrsi codex reduction mode balanced
lightrsi codex help

Useful Codex controls:

  • stabilizer on|off toggles stable-prefix rewriting
  • stabilizer target <developer|user> chooses where dynamic context is attached
  • reduction on|off toggles observation reduction
  • reduction mode <light|balanced> switches between lighter and stronger trimming
  • reduction pass toolPayloadTrim off disables one specific reduction pass
Claude Code

Use the standalone CLI:

lightrsi claude-code status
lightrsi claude-code report
lightrsi claude-code doctor
lightrsi claude-code visual
lightrsi claude-code session <session-id> report
lightrsi claude-code reduction status
lightrsi claude-code stabilizer target developer
lightrsi claude-code mode normal
lightrsi claude-code reduction mode balanced
lightrsi claude-code help

Useful Claude Code controls:

  • stabilizer on|off toggles stable-prefix rewriting
  • stabilizer target <developer|user> chooses where dynamic context is attached
  • reduction on|off toggles observation reduction
  • reduction mode <light|balanced> switches between lighter and stronger trimming
  • reduction pass toolPayloadTrim off disables one specific reduction pass

📁 Experimental Results

The tables below summarize the current LightRSI runtime path, implemented today through the TokenPilot component, on PinchBench and Claw-Eval.

Isolated mode evaluates each task in a fresh session, focusing on single-task behavior without cross-task history carryover. Continuous mode evaluates longer-running shared-session workflows, where context accumulation and cache reuse matter much more.

For exact reproduction commands and benchmark-specific setup, start from the TokenPilot reproduction guide.

PinchBench

PinchBench logs and output bundles: PinchBench Result

Isolated Mode

MethodOverallProdResWriteCodeAnalCSVLogMeetMemSkillIntegCache Read (M)Cache Miss (M)Output (M)Cost ($)
Vanilla80.587.268.784.186.075.183.094.781.486.570.355.36.1848.7530.2858.31
LLMLingua-276.989.364.082.186.980.879.684.466.385.079.672.114.2413.9750.3845.78
SelectiveContext76.588.564.573.083.782.681.192.863.386.982.877.211.2734.6420.3245.79
LCM77.890.164.979.685.481.381.087.167.585.081.780.616.0183.0640.3565.10
Pichay78.985.458.971.879.088.379.883.684.091.369.863.36.7173.3330.2384.07
Summary79.580.766.383.577.982.187.577.281.392.567.254.412.3033.0090.2964.51
MemoBrain78.186.862.188.985.782.688.385.463.692.576.169.710.2002.1070.2333.36
AgentSwing78.489.871.980.279.583.580.883.777.992.565.735.04.5347.1290.2416.77
Keep-Last-N80.486.070.082.480.177.678.391.584.392.570.187.812.8132.6570.2914.26
MemOS79.484.254.483.182.378.281.197.277.692.585.980.229.0184.5730.4927.81
LightRSI81.089.071.280.072.688.985.395.279.495.095.258.08.8931.9330.2443.22

Continuous Mode

MethodOverallProdResWriteCodeAnalCSVLogMeetMemSkillIntegCache Read (M)Cache Miss (M)Output (M)Cost ($)
Vanilla79.283.558.486.880.078.587.894.677.695.055.883.625.0155.9430.2027.24
LLMLingua-273.885.858.480.374.379.682.884.263.490.079.183.620.5742.1830.1944.06
SelectiveContext74.085.464.283.175.478.877.391.262.289.571.080.325.4752.6080.1964.75
LCM77.088.163.290.175.778.585.488.965.182.880.878.218.7082.4170.2224.21
Pichay76.588.066.776.281.077.683.584.267.6100.063.875.311.6986.8740.2607.20
Summary78.489.164.473.882.969.681.693.680.395.061.775.320.6876.2490.1967.12
MemoBrain78.087.765.085.584.975.981.089.072.390.386.684.712.9172.2830.2323.73
AgentSwing78.586.367.389.079.182.487.468.172.493.861.783.812.6805.4760.3146.47
Keep-Last-N79.186.367.087.887.077.085.477.375.995.056.875.118.1174.4810.2095.66
MemOS80.987.559.085.487.182.081.095.078.192.587.484.130.8598.9390.30810.41
LightRSI81.376.776.990.684.186.085.689.173.695.077.280.18.5511.5490.2192.79

PinchBench abbreviations: Prod=Productivity, Res=Research, Write=Writing, Code=Coding, Anal=Analysis, CSV=CSV Analysis, Log=Log Analysis, Meet=Meeting Analysis, Mem=Memory, Skill=Skills, Integ=Integrations.

Claw-Eval

Claw-Eval logs and output bundles: Claw-Eval Result

Isolated Mode

MethodOverallWkflOpsFinOffCommProdOprnSafeTermMMOthCache Read (M)Cache Miss (M)Output (M)Cost ($)
Vanilla64.565.470.845.744.473.270.977.774.056.841.069.29.4294.6370.2165.16
LLMLingua-261.958.767.557.643.362.970.162.461.049.644.075.28.1694.0430.1824.44
SelectiveContext60.759.168.246.336.961.575.559.267.253.144.074.78.2713.8620.1814.31
LCM61.259.067.351.147.765.976.658.458.651.441.572.29.7763.5430.1724.17
Pichay59.357.362.138.239.468.565.091.664.125.655.076.54.6483.9440.1864.14
Summary62.070.071.032.220.680.068.582.849.220.041.071.42.9352.8710.1743.16
MemoBrain58.064.560.526.137.656.159.971.063.420.041.075.318.1825.1180.3326.69
AgentSwing60.964.266.544.145.767.852.885.857.225.653.668.84.5803.5850.1943.91
Keep-Last-N61.867.173.844.721.654.563.686.238.439.455.069.14.2291.8450.1862.54
MemOS61.664.774.240.925.271.232.073.680.220.056.274.612.5822.7090.3634.61
LightRSI63.168.175.447.022.371.865.072.047.837.045.669.94.4361.1540.2392.27

Continuous Mode

MethodOverallWkflOpsFinOffCommProdOprnSafeTermMMOthCache Read (M)Cache Miss (M)Output (M)Cost ($)
Vanilla63.470.880.326.727.862.273.478.463.620.041.069.6709.84521.9812.62281.52
LLMLingua-259.058.771.334.830.661.965.377.664.620.041.072.4575.65437.1972.63082.91
SelectiveContext56.558.171.621.821.254.774.057.766.420.041.072.3437.11448.6782.75481.69
LCM61.466.869.038.329.563.374.966.667.320.041.072.7383.00728.7142.69162.37
Pichay61.069.563.840.324.063.167.094.152.521.641.071.097.43163.5101.04659.65
Summary61.663.674.535.320.655.570.187.166.169.042.666.959.77210.1431.00116.59
MemoBrain57.965.955.024.936.747.873.564.260.620.038.481.647.49713.9901.13419.16
AgentSwing62.267.666.548.636.870.063.890.731.722.441.072.853.77610.0270.90715.63
Keep-Last-N60.765.374.035.520.854.173.691.935.759.542.464.744.8129.1060.78013.70
MemOS57.755.965.056.322.244.864.668.889.020.039.671.549.74225.4320.29324.12
LightRSI60.858.861.852.532.164.257.389.265.876.845.270.921.4309.9280.33810.58

Claw-Eval abbreviations: Wkfl=Workflow, Ops=Ops, Fin=Finance, Off=Office QA, Comm=Communication, Prod=Productivity, Oprn=Operations, Safe=Safety, Term=Terminal, MM=Multimodal, Oth=Others.

📄 Citation

Please cite our paper if you use LightRSI in your work.

@article{xu2026tokenpilot,
  title={TokenPilot: Cache-Efficient Context Management for LLM Agents},
  author={Xu, Buqiang and Xue, Zirui and Chen, Dianmou and Fu, Chenyang and Wu, Chiyu and Huang, Caiying and Jiang, Chen and Fang, Jizhan and Deng, Xinle and Chen, Yijun and others},
  journal={arXiv preprint arXiv:2606.17016},
  year={2026}
}

@inproceedings{fang2025lightmem,
  title={LightMem: Lightweight and Efficient Memory-Augmented Generation},
  author={Jizhan Fang and Xinle Deng and Haoming Xu and Ziyan Jiang and Yuqi Tang and Ziwen Xu and Shumin Deng and Yunzhi Yao and Mengru Wang and Shuofei Qiao and Huajun Chen and Ningyu Zhang},
  booktitle={The Fourteenth International Conference on Learning Representations},
  year={2026},
  url={https://openreview.net/forum?id=dyJ0GWpjJB}
}

🤝 Contributing

We welcome bug fixes, host adapter improvements, onboarding fixes, tests, and documentation updates, see CONTRIBUTING.md for more details.

🎉Contributors

We thank all the contributors to this project, more contributors are welcome!

LightMem Series

This repository belongs to ZJUNLP LightMem series, focusing on solving context bloat, excessive token consumption and low cache utilization for long-running LLM agents:

  • LightMem — A lightweight and efficient memory management framework designed for Large Language Models and AI Agents
  • LightMem-Ego — A lightweight streaming multimodal memory system for everyday-life assistance
  • LLMLingua-2 — Token-level prompt compression
  • SelectiveContext — Self-information-based context reduction
  • Pichay — Demand paging for LLM context windows
  • MemoBrain — Executive memory for long-horizon reasoning agents
  • AgentSwing — Adaptive parallel context management routing for web agents
  • MemOS — Memory operating system for LLM agents
  • Headroom — Compresses everything when AI agent reads

💬 Community

  • Discord — setup help, debugging, feedback, and user discussion
  • GitHub Issues — reproducible bugs, feature requests, and integration regressions