Assemble: declare prioritized, pinnable context blocks; pack them to a token budget with an inspectable receipt.
Project description
cendor-contextkit
Treat the context window like a packed suitcase, not a string you concatenate. Declare blocks with priorities and eviction rules; contextkit fits them to a token budget and tells you exactly what it kept, shrank, and dropped.
Every assembled prompt comes with a receipt.
·
pip install cendor-contextkit
from cendor.contextkit import Context, Block
ctx = Context(budget_tokens=8000, model="claude-opus-4-8", reserve_output=1000, order="attention")
ctx.add(Block(system_prompt, priority=10, pin=True, role="system"))
ctx.add(Block(retrieved_docs, priority=5, evict="compress")) # uses squeeze if installed
ctx.add(Block(messages=chat_history, priority=3, evict="drop_oldest")) # peels OLDEST turns
ctx.add(Block(user_msg, priority=9, pin=True, role="user"))
messages = ctx.assemble() # provider-ready, guaranteed within budget — including framing
print(ctx.report()) # the receipt: kept / truncated / dropped + token math
preview = ctx.whatif(budget_tokens=4000) # same inputs, tighter budget, no commit
Highlights
- Token-budgeted packing — declare
Blocks withpriorityandpin;assemble()fits them into the budget deterministically. Pinned blocks are never evicted (raisesBudgetErrorif they alone overflow). - Per-block eviction —
drop_oldest·truncate(keep head/tail, with a…[truncated]marker) ·summarize(sync, or async viaaassemble()) ·compress(via squeeze — reversible: the receipt'sBlockDecision.handle.expand()restores the original, and compression is sized against your model) · or any customEvictionStrategy. - Real chat-history —
Block(messages=[…])peels the oldest turns to fit (a sliding window) — never mangling a turn. - An honest receipt —
report().used == tokens.count(assemble(), model): packing charges the per-message framing providers add, so a "full" prompt never quietly overflows once sent. - Attention-aware ordering —
order="default"·"attention"(lost-in-the-middle) ·"cache"(stable prefix for prompt-cache hits). - Provider adapters & multimodal —
for_anthropic()/for_gemini()/for_bedrock(); per-imageimage_tokens(int or resolution-aware callable);whatif(budget)previews;use_compressor()swaps the compression backend.
Inbound — call it before the model call; report() flows onto core's bus, so acttrace records what the model actually saw.
See docs/contextkit.md · CHANGELOG. Part of the Cendor stack — github.com/cendorhq/Cendor. Powered by PowerAI Labs. Apache-2.0; provided "as is", without warranty — use at your own risk (LICENSE §7–8).
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file cendor_contextkit-1.0.0.tar.gz.
File metadata
- Download URL: cendor_contextkit-1.0.0.tar.gz
- Upload date:
- Size: 21.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
240286bc29d3863c8c65406303af52b3b3c4aeb8f5ab20e2cfabe839b2389eeb
|
|
| MD5 |
d9e6e05476b87bb19504a0dc3f8e06cd
|
|
| BLAKE2b-256 |
f854154046730cc827160844115479dcc7ca8408260f1fdc9dde7809b875b573
|
Provenance
The following attestation bundles were made for cendor_contextkit-1.0.0.tar.gz:
Publisher:
release.yml on cendorhq/Cendor
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
cendor_contextkit-1.0.0.tar.gz -
Subject digest:
240286bc29d3863c8c65406303af52b3b3c4aeb8f5ab20e2cfabe839b2389eeb - Sigstore transparency entry: 2063255646
- Sigstore integration time:
-
Permalink:
cendorhq/Cendor@1733d9d073230ac9448221f660fce4ab07a42c33 -
Branch / Tag:
refs/tags/contextkit-v1.0.0 - Owner: https://github.com/cendorhq
-
Access:
private
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@1733d9d073230ac9448221f660fce4ab07a42c33 -
Trigger Event:
push
-
Statement type:
File details
Details for the file cendor_contextkit-1.0.0-py3-none-any.whl.
File metadata
- Download URL: cendor_contextkit-1.0.0-py3-none-any.whl
- Upload date:
- Size: 17.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f1bae16173fcbf658274ec0933b12aace2c0f06bafa1913b00f51cff091673c4
|
|
| MD5 |
722502a04f7488423ead3ec49eb7abb1
|
|
| BLAKE2b-256 |
0ce18644c8650bbfe79ed40da18c22a20b3872bd1f1676c4423790da379f944b
|
Provenance
The following attestation bundles were made for cendor_contextkit-1.0.0-py3-none-any.whl:
Publisher:
release.yml on cendorhq/Cendor
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
cendor_contextkit-1.0.0-py3-none-any.whl -
Subject digest:
f1bae16173fcbf658274ec0933b12aace2c0f06bafa1913b00f51cff091673c4 - Sigstore transparency entry: 2063255722
- Sigstore integration time:
-
Permalink:
cendorhq/Cendor@1733d9d073230ac9448221f660fce4ab07a42c33 -
Branch / Tag:
refs/tags/contextkit-v1.0.0 - Owner: https://github.com/cendorhq
-
Access:
private
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@1733d9d073230ac9448221f660fce4ab07a42c33 -
Trigger Event:
push
-
Statement type: