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 2026-11-16 on LongMemEval-S, 500 questions, with gpt-6-luna
answering: 96.6 % correct, judged automatically (previous version
88.0 %); 98.6 % after a manual review of 10 answers, each listed in the
document above. On 100 LoCoMo questions it was never tuned on, it scored
the same as the previous version (80 and 81 of 100).
Read those figures with three caveats. The rules in the helper were written against the same 500 questions. The judge is not the GPT-4o used in the LongMemEval paper, so the figures are not directly comparable to other published scores. And they 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.
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. Nine tools, no extra dependencies, and three 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.6.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| cap_shield-0.6.0.tar.gz | 92.0 kB | Without provenance | Details for cap_shield-0.6.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| cap_shield-0.6.0-py3-none-any.whl | Python 3 | none | any | Details for cap_shield-0.6.0-py3-none-any.whl |
Total release size: 186.9 kB
Release files / cap_shield-0.6.0.tar.gz
| Download URL | cap_shield-0.6.0.tar.gz |
|---|---|
| Size | 92.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
b2512b783d9d223ab69f7bd8c0f9a056e4538ae4d7a927affadd0d77ea2f4105
|
|
BLAKE2b-256 checksum How to use checksums |
577b072171c2bff55a3cf11b1ad018be2da08c6f50974af0cc5e579b699960d8
|
| 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.0-py3-none-any.whl
| Download URL | cap_shield-0.6.0-py3-none-any.whl |
|---|---|
| Size | 94.9 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
3b73594b62d4cb7ecfbe456d4f0c1c9d8bb4f11f9be7975bd14356eab078e2ca
|
|
BLAKE2b-256 checksum How to use checksums |
f16a14cbcc1514f911ffd52c661608735bb5648a8874b3b5e158bd27afcf6ad7
|
| 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.0
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.