Skip to main content

cap-shield

Context selection for AI agents. Measured, not estimated.

pip install cap-shield
from cap_shield import CapShield

cap = CapShield(api_key="cap_live_...")

cap.remember("support", "Customer reports a delayed parcel, order 4471")
ctx = cap.context("support", "what did the customer complain about?")

print(ctx.text)              # send this to your model
print(ctx.saving_pct, "%")   # how much you did not send
print(ctx.left_behind)       # ...and how many entries were left behind

What this does

Your agent's history grows every turn, and the whole thing is billed on every call. This selects what answers the question and leaves the rest.

Measured on our corpus with cl100k_base: 80.5 % of context not sent at a 1000-token budget. Measured on LongMemEval-S, 500 questions: 93.8 % retrieval recall against 51.9 % for word matching.

That second number is the one that matters. A saving is worthless if what was dropped is what your agent needed — so we publish both.

What this does not do

It does not call your model. ctx.text goes to Claude, GPT or whatever you use. This library never sees your model provider's keys.

It is not a proxy. Your uptime does not depend on ours for the model call itself.

Measure before you commit

No account, no key:

from cap_shield import measure, print_measurement

print_measurement(measure(
    texts=["...your actual messages..."],
    query="what your agent would search for"))

Runs on your own traffic and stores nothing — the text is compressed in memory, the numbers computed, and everything discarded. No dictionary is trained on it.

Rate limited to 20 measurements per hour per IP. Enough to evaluate, not enough to use the service for free.

Two mechanisms, deliberately separate

context() saves tokens — what your model is billed for. pack() saves bytes — bandwidth and storage. The packet is decompressed before the model sees it, so it saves no tokens.

Conflating them is the most common misunderstanding about this product.

Full documentation

https://cap-shield-robin.fly.dev/docs/quickstart

MCP server

The package also contains an MCP server. Five tools, no extra dependencies, and two of them work without an account.

pip install cap-shield
{
  "mcpServers": {
    "cap-shield": {
      "command": "python",
      "args": ["-m", "cap_mcp"],
      "env": {
        "CAP_SHIELD_API_KEY": "cap_live_..."
      }
    }
  }
}

The env block is only needed for remember and assemble_context. Leave it out and measure_traffic and list_packages still work.

Source and docs: https://github.com/robinlidberg-dot/cap-shield-mcp

The server can also be fetched as a single file, for anyone who would rather not install a package:

curl -O https://cap-shield-robin.fly.dev/cap_mcp.py

Metadata

Release files for cap-shield 0.5.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for cap-shield 0.5.0
File Size Uploaded
cap_shield-0.5.0.tar.gz 20.3 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for cap-shield 0.5.0
File Interpreter ABI Platform
cap_shield-0.5.0-py3-none-any.whl Python 3 none any Details

Total release size: 42.0 kB

Release files / cap_shield-0.5.0.tar.gz

Download URL cap_shield-0.5.0.tar.gz
Size 20.3 kB
Tags Source
SHA-256 checksum
How to use checksums
fcff2e5b9c5d20d22968a32916cce1f622416dbcf6c9a3e946de06e8b7713ae4
BLAKE2b-256 checksum
How to use checksums
7948d57764c5a06503b350ef969445c400b20beb5868ea2340784d53296b9fa4
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.10

Release files / cap_shield-0.5.0-py3-none-any.whl

Download URL cap_shield-0.5.0-py3-none-any.whl
Size 21.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
c0619c8906b960882f512ba2b9a7d15c0ecc9cdb4f634d5baece6fb50bee9081
BLAKE2b-256 checksum
How to use checksums
a20daef2519e79484acc0a8c982df83070188281d2402ae83c7c6691dcd889be
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.10

Release history Release notifications | RSS feed

This release

0.5.0 This release

2 release files

0.4.1

2 release files

0.4.0

2 release files

0.3.0

2 release files

0.2.0

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page