LLMSlim Memory

MCP文档知识

提供方 未标注

文档知识 stdio · 本地进程 API Key 社区 / 第三方 ClaudeCursorVS CodeGemini CLI
查看接入方式

为 MCP 客户端提供长期记忆,无需调用 LLM。将消息逐字存储在本地 SQLite 中,并在 token 预算内召回能够回答问题的消息。

一句话选型结论

按资料字段整理

LLMSlim Memory 属于文档知识类 MCP 服务器,stdio · 本地进程,API Key,可直接接入 Claude、Cursor、VS Code 等,有可直接执行的安装命令。接入前先确认权限范围;涉及写入、删除或付款的操作,建议先在测试环境验证。

分类文档知识 传输方式stdio · 本地进程 鉴权API Key 部署方式本地部署
GitHub 星标 未标注 仓库热度,无公开仓库时显示未标注
工具数 未标注 暴露给模型的工具数量
资源 / 提示词 0 / 0 资源与提示词模板数量
维护方 社区 / 第三方 核验等级 仅资料核对

工具与能力

文档知识
数量来自来源目录的标注,具体工具清单以官方文档为准
工具数量未标注暴露给模型可调用的工具个数
资源数量0可读取的资源条目
提示词数量0内置提示词模板数量

能力标签

支持客户端

适用场景

记忆

安装与配置

stdio · 本地进程 API Key
客户端在本机拉起子进程,数据不出本机
claude mcp add llmslim -- uvx --from "llmslim[mcp]" llmslim mcp

这条命令只是入口,具体启动参数请按官方文档补齐,不要直接照搬到别的服务器。

  1. 1
    准备运行环境

    stdio 服务在本地起进程,需要先装好 Node.js 等运行时,再按安装命令拉取依赖。

  2. 2
    安装服务

    复制上面的安装命令执行;命令里带占位符的位置,换成自己的密钥或路径。

  3. 3
    写入客户端配置

    在客户端的 MCP 配置里填好启动命令和参数,保存后完全退出客户端再打开,让新配置生效。

  4. 4
    验证是否可用

    连接成功后随便调一个只读工具,确认能返回结果,再接入正式流程。

典型使用场景

3 类
按分类与标签整理的常见用法,具体以官方文档为准
文档检索问答

在你的文档库里按问题找答案。

知识库读写

把新资料写进知识库,随用随取。

内容整理

把零散资料归纳成结构化笔记。

选择建议

选之前先看这几条
按条目字段给出的判断,不替你决定用不用

值得选的地方

  • 有现成的安装命令,不用自己找入口,照着跑就能起服务。
  • 已适配 Claude、Cursor、VS Code,换客户端不用重新研究配置。

先想清楚的地方

  • stdio 方式要求本地装好运行时(如 Node.js),换机器要重新装一遍。
  • 使用前要准备好API Key对应的凭据,并按最小权限配置。
  • 资料没标注工具数量,实际能力要装好后确认。
  • 版本更新与行为细节以官方仓库为准。

更适合

  • 需要在文档知识场景里让模型直接调用外部能力的人。
  • 已经在用 Claude、Cursor 的用户,接入路径最短。
  • 想先快速试一下、能接受在本地或自有环境跑服务的人。

不太适合

  • 完全不想在本地装环境的人。
  • 不方便管理密钥或第三方授权的人。
  • 需要厂商级 SLA 和技术支持的生产环境。

同类对比

6 个同类
同分类里挑最接近的几条,字段以各自详情页为准
MCP 服务器工具数传输方式部署方式安装命令最后核验
LLMSlim Memory当前 未标注 stdio · 本地进程 本地部署 有 2026-11-20
dify 未标注 stdio · 本地进程 本地部署 有 2026-04-11
open-webui 未标注 stdio · 本地进程 本地部署 有 2026-04-11
JeecgBoot 未标注 stdio · 本地进程 本地部署 有 2026-04-11
Cherry Studio 未标注 未标注 未标注 无 2026-05-17
mempalace 未标注 stdio · 本地进程 本地部署 有 2026-04-11

服务器档案

文档知识
字段来自项目仓库与公开索引,中文说明由本站标注
提供方未标注上游标注的维护方 未标注
分类文档知识本站按上游分类展示
连接方式stdio · 本地进程客户端在本机拉起子进程,数据不出本机
鉴权方式API Key远程服务建议用最小权限凭据
维护方社区 / 第三方核验等级 仅资料核对
包名 / 运行时未标注 · 未标注本地安装时用到的包标识与运行时
部署类型本地部署上游给出的部署形态
最近核验2026-11-20上游最后核验时间

详细介绍

53.8 KB
来自项目仓库与上游目录的原文,未做删改

LLMSlim

Long-term memory and context selection for AI agents and coding tools, with no LLM call.

LLMSlim stores what users and agents say word for word, then returns the parts that answer a question within a
token budget you set. It runs as an MCP server, a Python library or a small HTTP server.

Examples • Documentation • Live Studio Playground • Sarvam Integration • Benchmarks • Changelog

A real Python session with llmslim 0.11.1 from PyPI, typed by a script and recorded with asciinema (script, recording).

Sponsored by

Neon Open Source Program · LLMSlim memory on Neon

Use it in 30 seconds

Each MCP setup below starts the same server, llmslim mcp, with uv (Python 3.10 or
newer). Memory goes to a local SQLite file, ~/.llmslim/memory.db.

One click:

Tool Run
Claude Code claude mcp add llmslim -- uvx --from "llmslim[mcp]" llmslim mcp
Claude Code plugin /plugin marketplace add Thanatos9404/llmslim, then /plugin install llmslim@llmslim
Codex codex mcp add llmslim -- uvx --from "llmslim[mcp]" llmslim mcp
GitHub Copilot CLI copilot mcp add llmslim -- uvx --from "llmslim[mcp]" llmslim mcp
Gemini CLI gemini extensions install https://github.com/Thanatos9404/llmslim
Hermes Agent hermes plugins install llmslim --enable, then hermes config set context.engine llmslim: a context engine that compacts long conversations locally (plugin)

The first start downloads LLMSlim and its dependencies. If a client gives up waiting, run
uvx --from "llmslim[mcp]" llmslim mcp --help once to fill uv's cache, then restart the client.

Python (pip install llmslim, Python 3.10 or newer):```python
from llmslim.memory import Memory

mem = Memory("memory.db") # a SQLite file; or "postgresql://..." (llmslim[postgres]), "mongodb://..." (llmslim[mongodb])
mem.add([{"role": "user", "content": "I'm allergic to peanuts."}], user_id="asha")
context = mem.search("Am I allergic to anything?", user_id="asha", budget=1500)
print(context.text) # put it in your prompt as data, not instructions


**TypeScript** (`npm install llmslim`, Node 18 or newer), against `llmslim serve` (`pip install "llmslim[server]"`):```ts
import { LLMSlim } from "llmslim";

const slim = new LLMSlim(); // http://127.0.0.1:8080 unless LLMSLIM_BASE_URL is set
await slim.memories.add({ userId: "asha", messages: "I'm allergic to peanuts." });
const context = await slim.memories.search({ userId: "asha", query: "Am I allergic to anything?", budget: 1500 });

Runnable examples, each with a test: Claude Code memory,
LangChain agent, Pydantic AI agent,
big logs and TypeScript.

If LLMSlim is useful, a star helps others find it. Feedback is welcome in issues.

What it does

  • Five MCP tools: remember, recall, list_memories, forget and fit_context.
  • Stores messages word for word in SQLite, Postgres or MongoDB. Nothing is summarized or extracted on the way in.
  • Recalls within a token budget. recall returns the stored messages that answer a question, under their dates
    and whole where they fit, within the budget you set. fit_context shrinks a long log or document to a budget.
  • Fixes the scope at server start. The user and agent ids are set when the server starts, not by the model, so a
    model steered by injected text can't read or delete another user's memory.
  • Makes no LLM call. By default, storing and recalling are plain code: no model, no embedding API, no API key.
  • MIT licensed. The library and the MCP server need Python 3.10 or newer.

Beyond memory, LLMSlim Core also compresses and plans prompts, chat history, retrieved documents and tool schemas
into token budgets: see the sections below.

Why no LLM call

Storing is a database write and recall is deterministic ranking code. So what comes back is what was said, not a
model's rewrite of it, and the same history and question always give the same context, which makes recall easy to
test. The memory server and llmslim serve make no network calls of their own. What does reach the network:
installing from PyPI (including uvx's first run of a version) and tiktoken downloading its tokenizer file once.

The trade-off: the default lexical mode matches words, not meanings, so a question phrased differently from the
stored message can miss it. relevance="semantic" adds an optional cross-encoder for that (llmslim[semantic],
which downloads the model the first time). See the limits.


Compress a prompt in 60 seconds

1. Install LLMSlim Core from PyPI (Python 3.10+). Running it needs no API key, model, or network call:```bash
pip install llmslim


**2. Run** this snippet:```python
from llmslim import compress

ticket = """
Hi team, I hope you are all doing well and had a good weekend.
I am writing about invoice INV-2291, which charged us $480 instead of $240.
We upgraded to the Pro plan on 3 September, but the old Basic plan was billed as well.
Our finance lead was asking about this during the weekly sync, which ran long as usual.
Please refund the duplicate $240 charge to the card ending 4417.
Thanks so much, and let me know if you need anything else from me.
"""

result = compress(ticket, target_ratio=0.6)  # target: keep about 60% of the tokens
print(result.compressed_text)
print(f"{result.original_tokens} -> {result.compressed_tokens} tokens ({result.reduction_percent:.1f}% fewer)")

3. What you should see (llmslim 0.11.1, base install):```text
Hi team, I hope you are all doing well and had a good weekend. I am writing about invoice INV-2291, which charged us $480 instead of $240. We upgraded to the Pro plan on 3 September, but the old Basic plan was billed as well. Please refund the duplicate $240 charge to the card ending 4417.
112 -> 72 tokens (35.7% fewer)


Two of the six sentences are dropped; the invoice number, amounts, plan change,
and refund request are kept. The default extractive mode only selects sentences
from your input, so the same input always gives the same output. The base install
estimates tokens at about 4 characters per token and prints a one-line warning
saying so. With `pip install "llmslim[fast-tokens]"`, tokens are counted with
tiktoken instead: on this input the same four sentences are kept, and the count
reads `107 -> 72 tokens (32.7% fewer)`.

**Next:** Docs • Pricing • Vault beta • Issues

---

## LLMSlim Core, Orbit and Vault

**The context layer for production AI agents.**
*This repository is **LLMSlim Core** (v0.12.0, MIT): local-first context planning and compression that fits prompts, conversation history, RAG, memory, and tool schemas into real token budgets while preserving instructions and execution boundaries.*

| | **LLMSlim Core** | **LLMSlim Orbit** | **LLMSlim Vault** |
|---|---|---|---|
| What it is | The open-source library, MCP server and HTTP server | The hosted edition, run by us | The self-hosted edition, run in your own VPC (formerly LLMSlim Platform) |
| Version | 0.12.0 | Opens with LLMSlim 1.0 | 0.9.1 beta |
| License | MIT, this repository | Proprietary, paid plans | Proprietary, private beta |
| Get it | `pip install llmslim` | Join the founding list at llmslim.app/pricing | By invitation; not published to PyPI |
| What it does | Compresses, plans, and traces model-visible context inside your Python process | A hosted memory API, remote MCP with OAuth for Claude.ai, ChatGPT, Cursor and Claude Code, team memory, a context console with traces and replay, and a truth timeline | Builds on Core: a verifiable timeline of agent state, explainable and replayable context decisions, and outcome-driven context policies that start in shadow mode |

Core is and stays fully open source. Orbit and Vault are separate products that depend on
Core; none of their code lives in this repository. Plans and prices are at
llmslim.app/pricing; read about Vault and request beta access at
llmslim.app/vault.

What's new in Core: the agent context runtime (v0.7.0)
and the cache-aware context runtime (v0.7.1).
Both are in the PyPI package from 0.7.1 onward; 0.7.0 was tagged but not published to PyPI.

---

## Adaptive Context Planner (v0.6.0)

LLMSlim is no longer only a fixed-ratio prompt compressor. The Adaptive
Context Planner chooses safe representations for each context item, then uses
a deterministic constrained allocator to fit the highest-value context into a
finite model budget. The original `compress()` API remains fully supported.

The v0.6.0 release adds explainable per-item decisions, explicit infeasibility
reporting, post-plan validation, token and cost telemetry, policy presets, and
optional Sarvam AI, Zoho, and MongoDB integrations while keeping the base
installation local-first and provider-neutral.```python
from llmslim import plan_context

plan = plan_context(
    messages=[
        {"role": "system", "content": "Answer only from verified context."},
        {"role": "user", "content": "When does Acme renew?"},
    ],
    documents=[{"content": "CRM: Acme renews on 2026-11-30."}],
    query="Acme renewal date",
    model="sarvam-105b",
    max_input_tokens=8_000,
    reserve_output_tokens=512,
)
assert plan.feasible
print(plan.final_context)
print(plan.metrics.planned_tokens, plan.metrics.estimated_input_cost_after)

Planning works offline with the base install. Optional integrations are
isolated behind extras:```bash
pip install "llmslim[sarvam]" # Sarvam provider (official sarvamai SDK)
pip install "llmslim[zoho]" # CRM and WorkDrive context sources
pip install "llmslim[mongodb]" # MongoStore memory, explicit context memory and Atlas retrieval


See the architecture,
algorithm, security model,
CLI, and measured offline benchmark.

---

## Startup programs

LLMSlim is part of 21 startup programs. They provide credits, tools, and guidance;
none of them is an investor, and membership does not imply endorsement.

| Program | Company |
|---|---|
| Sarvam Startup Program | Sarvam AI |
| Zoho for Startups | Zoho |
| MongoDB for Startups | MongoDB |
| Claude for Startups | Anthropic |
| OpenAI for Startups | OpenAI |
| Auth0 for Startups | Okta (Auth0) |
| Zendesk for Startups | Zendesk |
| Mixpanel for Startups | Mixpanel |
| Sentry for Startups | Sentry |
| Descope Hello World Startup Program | Descope |
| Pulumi for Startups | Pulumi |
| Honeycomb for Builders | Honeycomb |
| Exa Startup Grants | Exa |
| Neo4j Startup Program | Neo4j |
| Cartesia Startups Grant Program | Cartesia |
| Nebius AI Builder Program | Nebius |
| Notion for Startups | Notion |
| Snyk Secure Developer Program | Snyk |
| Gitar Open Source Program | Sonar (Gitar) |
| Composio Startup Program | Composio |
| Future AGI for Startups | Future AGI |

Logos are trademarks of their owners and identify each program.

---

## Sarvam Startup Program and Sarvam integration

> ### ✦ Accepted into the Sarvam Startup Program
>
> LLMSlim has been accepted into the **Sarvam Startup Program**. This is program
> membership only: it is not a partnership, and it does not imply an endorsement
> by Sarvam AI.

Separately, LLMSlim Core ships an optional Sarvam integration (`llmslim[sarvam]`)
built on the official `sarvamai` Python SDK. You plan and compress context locally,
then send only the planned context to a Sarvam model such as `sarvam-105b`.

- **Local planning**: retrieved documents are planned and compressed in your Python process before any request is sent.
- **Local-first**: sensitive retrieved context stays local; only the planned context is sent to the model.
- **Your application stays in charge**: LLMSlim is a pre-processor. Your application owns API keys, prompts, and inference, and nothing is sent to Sarvam unless your code calls the provider.

### Quickstart: Adaptive Planning + Sarvam```bash
pip install "llmslim[sarvam]"
export SARVAM_API_KEY="..."   # your own Sarvam API key
``````python
from llmslim import plan_context
from llmslim.integrations.sarvam import SarvamProvider

documents = [
    {"content": "Q3 filing: new data-localisation rules take effect in April 2027."},
    {"content": "Q3 filing: two pending licence renewals carry a regulatory risk of delay."},
]

plan = plan_context(
    messages=[{"role": "system", "content": "Answer from verified context."}],
    documents=documents,
    query="Summarize the key regulatory risks.",
    model="sarvam-105b",
    max_input_tokens=8_000,
    reserve_output_tokens=256,
)
provider = SarvamProvider.from_env(model="sarvam-105b", max_tokens=256)
answer = provider.chat([{"role": "user", "content": plan.final_context}])
print(answer, provider.last_usage)

👉 Read the Sarvam integration guide (also in docs/integrations/SARVAM.md)


🔮 What is LLMSlim?

LLMSlim Holographic Engine: Multi-stage token compression condensing sparse context streams into dense information cores with zero contract mutation.

Modern LLM systems suffer from the Context Window Dilemma:
1. Financial Tax: Re-sending large prompts on every turn means you pay for the same input tokens again and again.
2. Latency Bottleneck: Large prompts inflate Time-To-First-Token (TTFT) and queue times.
3. Lost-In-The-Middle Syndrome: Models can miss or misuse information buried in the middle of long contexts.
4. Security Risks: Untrusted RAG content can smuggle indirect prompt injections into system instructions.

LLMSlim fixes this at the source. It provides deterministic, contract-preserving compression that runs natively in your application layer before calling any model.

💎 Core Architectural Pillars

Pillar How LLMSlim Solves It
🏎️ Ultra-Low Overhead Pure Python + NumPy/Scikit-learn. Median 0.026 ms per sample (p95 1.889 ms) in the 24-sample, mostly short-text Phase 2 evaluation, with no model calls on the default path. Longer inputs take longer.
🔒 Deterministic by Default The default extractive mode only selects sentences from your input, so output is reproducible and contains no generated text. It can still drop a fact you need, so check results for your use case. Rewrite and hybrid modes call your own LLM.
🛡️ Provenance Security ContextRole hierarchy isolates untrusted RAG/tool text so prompt injections cannot escalate to system priority.
🧩 Contract-Safe Tool Schemas Canonical JSON normalization, SHA-256 contract fingerprints, and zero execution rewrites for agent tooling.
🔌 Provider-Neutral Execution-free request builders for Sarvam, OpenAI, Anthropic, Gemini, and vLLM, plus an OpenAI Agents SDK bridge. Works with any framework that can pass plain message or document lists.

🖥️ Live Studio Playground (www.llmslim.app)

Paste a long chat, a stack of search results or a CI log, ask a question, and watch LLMSlim keep what
answers it. The Studio shows the tokens and cost saved, whether the answer survived, and what plain truncation to
the same size would have kept instead.

  • Ready-made scenarios: a six-month support chat, help-centre search results, and a CI log with one failure,
    each with a question whose answer is known.
  • Your own text: paste up to about 16,000 tokens and choose how much to keep.
  • In place: kept lines are highlighted inside the original, next to the exact text the model would receive.
  • No model call: the Studio runs Core on the server and calls no provider. Nothing you paste is stored.

See the security policy. The website's source, the Studio included, lives in a private repository;
Core, everything pip install llmslim installs, is here under the MIT license.

👉 Open Interactive Studio


🌐 Modern Developer Website & Documentation

Explore our redesigned dark/light documentation site covering end-to-end integration patterns:


📦 Installation```bash

Core package (Deterministic extractive engine, 0 external LLM dependencies)

pip install llmslim

With optional Model Context Protocol (MCP) catalog ingestion

pip install "llmslim[mcp]"

With optional OpenAI Agents SDK host bridge

pip install "llmslim[agents]"

With optional local multilingual semantic retrieval

pip install "llmslim[semantic]"

Sarvam: chat providers, language tools and document source (official sarvamai SDK)

pip install "llmslim[sarvam]"

Exa web search as an untrusted RAG context source (spend capped in USD)

pip install "llmslim[exa]"

Neo4j temporal agent memory with auditable supersession

pip install "llmslim[neo4j]"

Read-only Zoho CRM and WorkDrive context sources

pip install "llmslim[zoho]"

MongoDB: Memory("mongodb://...") keeps memory there, plus explicit context memory and Atlas retrieval

pip install "llmslim[mongodb]"

LangChain, LlamaIndex and Haystack adapters

pip install "llmslim[langchain]"
pip install "llmslim[llamaindex]"
pip install "llmslim[haystack]"

Agent history: gptme (0.34+) and Pydantic AI adapters.

Hermes Agent needs no extra: install llmslim into Hermes's environment.

pip install "llmslim[gptme]"
pip install "llmslim[pydantic-ai]"

All optional extensions

pip install "llmslim[all]"


*Requirements: Python 3.10 or higher. No provider SDK, PyTorch, sentence-transformers, or cloud service is required for the default installation.*

---

## ⚡ Quick Start & Usage Patterns

### 1. Basic Extractive Compression (Default)```python
from llmslim import ContextRole, compress

text = """
The Apollo program was conceived in 1960 during the Eisenhower administration.
NASA announced the program as a follow-up to Project Mercury.
The spacecraft was designed to carry three astronauts.
Apollo succeeded in landing the first humans on the Moon in 1969.
Funding for the program peaked in 1966 with over $4.5 billion appropriated.
"""

result = compress(
    text,
    target_ratio=0.5,                    # Target: keep about 50% of the tokens
    strategy="extractive",               # Deterministic sentence selection
    context_role=ContextRole.GENERAL,
)

print("Compressed Output:")
print(result.compressed_text)
print(f"Original: {result.original_tokens} tokens | Compressed: {result.compressed_tokens} tokens")
print(f"Saved: {result.tokens_saved} tokens ({result.reduction_percent:.1f}%)")
print(f"Sentences kept: {result.sentences_kept} of {result.sentences_total}")

Extractive selection keeps whole sentences, not meaning: always check that the
sentences you need survived. On this text, the 0.7.1 base install keeps three of
the five sentences and drops the 1969 Moon landing sentence; with
llmslim[fast-tokens] (tiktoken counts) it keeps that sentence and drops another.


2. Multi-Document RAG Compression

Compress each retrieved chunk before you build the prompt. compress_documents
takes plain strings and returns one result per document, in order:```python
from llmslim import compress_documents

documents = [
"Q3 revenue grew 23% year-over-year to $1.2B. "
"Growth came mainly from enterprise subscriptions in India and Southeast Asia. "
"The board met twice during the quarter. "
"The office cafeteria menu was updated in August. "
"A new logo was unveiled at the annual offsite. "
"Net revenue retention reached 118%, up from 109% a year earlier.",
"Operating expenses rose 11% because of AI research infrastructure. "
"Most of the increase was GPU capacity for model evaluation. "
"Travel costs were flat. "
"The parking garage was repainted in September. "
"Employees voted on a new name for the meeting rooms. "
"Headcount in engineering grew by 40 people.",
]

results = compress_documents(
documents,
query="What drove Q3 revenue and cost changes?",
target_ratio=0.5,
)

context = "\n\n".join(r.compressed_text for r in results)
print(context)
print(f"Saved {sum(r.tokens_saved for r in results)} tokens across {len(results)} documents")


With a query, the documents share one budget and it goes where the query points. Relevance is lexical by default
(BM25 with feedback: no model, deterministic, tens of milliseconds on a 3k-token context). For RAG and long chat
memory, where the answer often shares few words with the question, add the optional reranker:```python
# pip install "llmslim[semantic]"   (sentence-transformers; uses a GPU when there is one)
results = compress_documents(documents, query=question, target_ratio=0.25, relevance="semantic")

relevance also accepts any callable scorer(query, texts) -> scores, such as a hosted reranking API.

Retrieving with LangChain, LlamaIndex or Haystack? Use the
framework adapters instead of calling
compress_documents yourself.

> [!NOTE]
> compress_documents treats documents as untrusted (ContextRole.RAG) by default,
> so imperative wording inside a retrieved document is never force-kept as a
> protected instruction. It does not remove injected text: an injected sentence
> can still survive compression. To mark retrieved content as untrusted in the final
> prompt, use plan_context or
> ContextRuntime, which wrap every document in a
> trusted="false" provenance tag and ignore any role a document claims for itself.


3. Multi-Turn Chat Conversation Compression

Compress long earlier turns while passing system instructions and user questions through unchanged:```python
from llmslim import compress_chat_messages

review = (
"Here are my suggestions for your schema. First, add a composite index on "
"(customer_id, created_at) because most of your queries filter by customer and sort by "
"date. Second, the orders table stores the shipping address inline, which duplicates "
"data across rows; move it to an addresses table. Third, the status column is a "
"free-text string, so use an enum or a lookup table instead. Fourth, the price column "
"uses FLOAT, which loses precision for money; use DECIMAL(12, 2). Finally, add ON "
"DELETE RESTRICT to the foreign key from orders to customers so that deleting a "
"customer cannot silently orphan their orders."
)

messages = [
{"role": "system", "content": "You are a specialized code review engineer."},
{"role": "user", "content": "Can you review my database schema design?"},
{"role": "assistant", "content": review},
{"role": "user", "content": "What about the foreign key constraint on line 42?"},
]

compressed_messages = compress_chat_messages(
messages,
target_ratio=0.5,
compressible_roles=("assistant",), # Only compress assistant turns; system and user pass through
min_tokens=60, # Turns shorter than this are never compressed
)

for message in compressed_messages:
print(f"{message['role']}: {message['content']}")


---

### 4. Hybrid Prompt Optimization (Extractive + Rewrite)

Combine ultra-fast extractive pre-filtering with your own LLM provider for deep semantic paraphrasing:```python
from llmslim import CallableProvider, compress
import openai

client = openai.OpenAI()  # reads OPENAI_API_KEY; requires `pip install openai`

long_raw_text = """
The Apollo program was conceived in 1960 during the Eisenhower administration.
NASA announced the program as a follow-up to Project Mercury.
The spacecraft was designed to carry three astronauts.
Apollo succeeded in landing the first humans on the Moon in 1969.
Funding for the program peaked in 1966 with over $4.5 billion appropriated.
"""

# Define your own provider callback (LLMSlim does not bundle vendor SDKs).
# The callback receives a RewriteRequest with ready-made prompts and returns text.
provider = CallableProvider(
    lambda req: client.chat.completions.create(
        model="gpt-4o-mini",
        messages=[
            {"role": "system", "content": req.system_prompt},
            {"role": "user", "content": req.user_prompt},
        ],
    ).choices[0].message.content
)

result = compress(
    long_raw_text,
    target_ratio=0.3,
    strategy="hybrid",                   # 1. Extractive filter -> 2. LLM semantic rewrite
    provider=provider,
)

meta = result.rewrite_metadata
print(result.compressed_text)
print(f"Strategy: {meta.strategy} | Rewrite accepted: {meta.accepted} | Fell back to extractive: {meta.fallback_used}")
print("Validation failures:", meta.failure_reasons)

Every rewrite is validated for structure, instruction retention, entity retention,
and similarity. If a hybrid rewrite fails validation, LLMSlim returns the extractive
result instead and reports why in rewrite_metadata.failure_reasons.


Coding agents: llmslim wrap claude

Claude Code resends the whole conversation on every turn. So long test logs, build output, search results and web
pages get paid for again and again, and they add to the context that Claude Code eventually compacts.

llmslim wrap claude runs Claude Code through a local proxy:
- It shrinks such output the first time the model sees it. Lines that look like errors, failures or warnings come
first, then the lines related to the command.
- It sends exactly the same bytes on every later request, so the prompt cache keeps hitting and Claude's thinking
stays valid.
- Output of Claude Code's own Read, Edit and Write tools is never touched. A file printed through the shell
(cat, head) counts as shell output.

llmslim wrap and llmslim proxy are experimental: they may change in a minor release
(API stability).```bash
pip install "llmslim[proxy]"
llmslim wrap claude
llmslim proxy stats


**What it does to the bill, measured** on real Claude Code 2.1.296 with Claude Haiku 5.5, on eight small synthetic
tasks. We counted list-price dollars from the API's usage, with cache reads priced separately, and published all 572
runs in benchmarks/claude_code_cost. The primary result has both arms in
Claude Code's default permission mode; a second run has both in auto mode.
- **Long logs:** a simulated failing CI run (about 12 KB of log, the cause in the middle) cost 26-32% less, and a lint
  run with three errors among 240 warnings 17-21% less.
- **Test runs:** about 4% less in default mode, within noise for every task; 2-15% less in auto mode. Agents already
  trim test output with `tail`.
- **Over 8 tasks:** +5.3% in default mode (95% interval +1.5% to +9.4%), mostly from one task where shortened JSON
  cost about twice as much; -5.1% in auto mode. JSON is left alone by default since 0.11.1.
- **Real sessions:** in an offline replay of the maintainer's own transcripts (32 sessions and the 412 subagent runs
  they started, almost all Claude Opus 5.5, at list prices), tool output was a small part of the bill: with the same
  turns, all shell, search and web output costing nothing would have cut it by 13.4%. Re-reading long context was the
  big part. Claude Code's `/autocompact` setting decides when it compacts; what that does to cost is not measured
  here.

Without the byte-for-byte replay, an edited history invalidates Claude's thinking: in our API check on Claude Haiku
5.5 the request was rejected with HTTP 400, the default for accounts created on or after 31 August 2026. With the
replay, cache reads grew on every request of a 7-request API test. See docs/PROXY.md for what is compressed, the
limits and security.

**As a Claude Code plugin.** The plugin adds LLMSlim's memory server (below) and two commands:
- `/llmslim:wrap-claude` walks you through starting Claude Code through the proxy;
- `/llmslim:savings` shows how many tool-output tokens the proxy kept out of your requests: an estimate counted
  before prompt-cache discounts, not dollars saved.```text
/plugin marketplace add Thanatos9404/llmslim
/plugin install llmslim@llmslim

On Claude Code 2.1.275 or later, /plugin install llmslim --marketplace Thanatos9404/llmslim does both in one step.
The memory server runs with uvx, so it needs uv.

Memory for agents, with no LLM in the loop

llmslim.memory stores every turn verbatim and selects, at read time, the turns that answer a question within a
token budget. There is no extraction model on the way in and no model call on the way out.```python
from llmslim.memory import Memory

memory = Memory("memory.db") # SQLite, built into Python
memory.add([{"role": "user", "content": "I'm allergic to peanuts."}], user_id="asha")
context = memory.search("Am I allergic to anything?", user_id="asha", budget=1500)
print(context.text) # put it in the prompt as untrusted data


On BEAM's 1M-token conversations (held-out, run once), `Memory.search` with its reranker scored on par with Mem0 at
2,500 and 10,000 tokens (+1.2 and +0.6 points, neither significant), 60x and 28.6x cheaper per 1,000 questions at
list prices, and 7.5 to 9.9 points ahead of Zep (on 30 conversations). Its weak spots are published alongside the results
(Round 6). Coming from Mem0?
`from llmslim.memory.compat import Mem0Memory as Memory` keeps Mem0's method names, and `llmslim import mem0
export.json` brings your memories along. `llmslim import` also reads Claude Code transcripts and ChatGPT and
Claude.ai exports (docs/IMPORT.md). See
docs/MEMORY.md for scopes, stores, evidence and limits, and the 1.0 roadmap.

### In Claude, Cursor or any MCP client

`llmslim mcp` serves this memory over MCP, with a `fit_context` tool for long text. It needs `pip install "llmslim[mcp]"`
on Python 3.10+.```bash
claude mcp add llmslim -- llmslim mcp
  • Tools: remember, recall, list_memories, forget and fit_context.
  • Scope: the server fixes it with --user-id, so the model can't read another user's memory.
  • Storage: a local SQLite file; the server makes no network calls of its own (the tokenizer downloads one file once and caches it).
  • Several machines (experimental): llmslim mcp --transport http (1.0 and newer) serves the same memory over
    HTTP behind bearer keys, so your laptop and desktop share it; see
    docs/MCP.md.
  • More: client configs and options are in docs/MCP.md.

…(正文过长,页面只展示前面部分,完整内容见仓库)

常见问题

8 问
答案由本站依据条目字段整理,不引用上游原文
LLMSlim Memory 怎么安装?

在客户端按下面的安装命令接入:claude mcp add llmslim -- uvx --from "llmslim[mcp]" llmslim mcp。装完在客户端配置里引用同一个包或端点。

LLMSlim Memory 怎么在 Claude、Cursor、VS Code 里配置?

它的传输方式是stdio · 本地进程,在客户端的 MCP 配置里填好启动命令和参数,保存后完全退出客户端再打开,配置才会生效。

LLMSlim Memory 收费吗?

本站不代收费用,也没有标注具体价格。是否收费取决于服务本身和背后的接口额度,正式使用前按官方说明确认。

LLMSlim Memory 需要 API Key 吗?

资料标注需要API Key认证,使用前准备好对应凭据,并按最小权限配置。

LLMSlim Memory 支持哪些客户端?

资料标注支持 Claude、Cursor、VS Code、Gemini CLI、Codex、Zed;其他客户端只要能配置 MCP Server,也能用同样的命令或地址接入。

LLMSlim Memory 能提供哪些能力?

资料显示能力标签包括 记忆。具体工具清单以官方文档为准。

LLMSlim Memory 需要什么运行环境?

属于本地进程,需要在本机装好运行环境。

LLMSlim Memory 是本地还是远程?

它是本地进程(stdio),由客户端在本机拉起。传输方式为stdio · 本地进程。

热门专题

按标签挑服务器
全部专题 →

服务器信息以作者仓库与官方文档为准;分类、传输方式与鉴权方式的中文说明为中文整理,最近核验 2026-11-20。