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 (2026-09-28): 97.1 % 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. Current figures: https://cap-shield-robin.fly.dev/.well-known/cap-shield.json

Answers from memory, with your own model

For questions the narrow selection cannot answer (dates, counts across sessions, details that ranked low), escalation_context() fetches a wider, date-headed context. The escalation helper shipped in the same package answers it with your model key, from your machine. cap_shield itself still never calls a model and never sees the key.

from cap_escalate_helper import eskalera_om_behovs_v6

fraga = "Which bike did I fix last weekend?"
ctx = cap.escalation_context("support", fraga)
svar = eskalera_om_behovs_v6(ctx, fraga, modell="openai",
                             modell_namn="gpt-6-luna",
                             dagens_datum="2026/11/16")  # OPENAI_API_KEY in your env
print(svar["svar"])

Measured on LongMemEval-S, 500 questions, with gpt-6-luna answering and judged exactly as in the LongMemEval paper (GPT-4o as judge, the official judge prompts): 481 of 500 correct (96.2 %). Our own automatic judging of the same answers gives 96.6 % (previous helper version 88.0 %).

On 200 LoCoMo questions held out and never read during development, v6.2 answered 170 correctly, against 148 for v6.1. The gain is on questions about a person the conversation says nothing about: v6.2 checks which speaker a fact belongs to before answering.

Read those figures with three caveats. The rules in the helper were written against the same 500 LongMemEval questions. The answer model is our own choice, so the judging is comparable with other published LongMemEval scores but the setup is not identical. And the figures depend on the answer model.

escalation_context() returns the raw context, so you can also run your own model call on it instead of the helper.

Energy and time

A model spends energy and time on every token it reads. Measured 2026-11-17 with the GPU's own energy counter (NVIDIA GeForce RTX 4070, llama3.2:1b, idle power subtracted), 50 LongMemEval-S questions, against the whole history (median 104 652 tokens): 95 % less energy and 94.4 % less time for the model to read the context, with the selection at budget 32 000 and every session holding the answer included in 90 % of questions.

The model reads Tokens (median) Less energy Less time All evidence included
Selection, budget 32 000 18 248 95 % 94.4 % 90 %
Selection, budget 16 000 12 672 97.2 % 96.5 % 80 %
Selection, budget 8 000 6 158 98.7 % 97.9 % 50 %
Selection, budget 4 000 3 094 99.3 % 98.5 % 22 %
Selection, budget 2 000 1 080 99.7 % 98.8 % 14 %, 9 empty
Escalation context 75 066 39.3 % 37.4 % 98 %

Per reading of the context, on one GPU with a small model; larger models have not been measured. A shorter history leaves less to remove. The escalation helper reads its context at least twice per question. If the budget is too small for the best match, the response says so in budget_warning (in context() results: .raw["budget_warning"]) and suggests a budget that fits it.

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. Fifteen tools, no extra dependencies, and four of them work without an account (measure_traffic, list_packages, start_sandbox, verify_pass).

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 the tools that store or retrieve memory, pack data or issue passes. Leave it out and measure_traffic, list_packages, start_sandbox and verify_pass still work; start_sandbox gives a 24-hour key for trying memory without an account.

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.6.2

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.6.2
File Size Uploaded Provenance Actions
cap_shield-0.6.2.tar.gz 98.3 kB Without provenance Details for cap_shield-0.6.2.tar.gz

Built distribution (wheel)

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

Total release size: 199.0 kB

Release files / cap_shield-0.6.2.tar.gz

Download URL cap_shield-0.6.2.tar.gz
Size 98.3 kB
Tags Source
SHA-256 checksum
How to use checksums
6d8c7dc253aa6c38b717a26132cbbe5aad7d45ca07e9bdb7237a0f13062a5244
BLAKE2b-256 checksum
How to use checksums
b02927c85a5e6fd31fe1d2c93edf415a539616ac77569c3a0be527b38901fa1d
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.6.2-py3-none-any.whl

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

Security for cap-shield 0.6.2

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

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