Skip to main content

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.

PyPI license · 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 with priority and pin; assemble() fits them into the budget deterministically. Pinned blocks are never evicted (raises BudgetError if they alone overflow).
  • Per-block evictiondrop_oldest · truncate (keep head/tail, with a …[truncated] marker) · summarize (sync, or async via aassemble()) · compress (via squeeze — reversible: the receipt's BlockDecision.handle.expand() restores the original, and compression is sized against your model) · or any custom EvictionStrategy.
  • Real chat-historyBlock(messages=[…]) peels the oldest turns to fit (a sliding window) — never mangling a turn.
  • An honest receiptreport().used == tokens.count(assemble(), model): packing charges the per-message framing providers add, so a "full" prompt never quietly overflows once sent.
  • Attention-aware orderingorder="default" · "attention" (lost-in-the-middle) · "cache" (stable prefix for prompt-cache hits).
  • Provider adapters & multimodalfor_anthropic() / for_gemini() / for_bedrock(); per-image image_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-libs. Powered by PowerAI Labs. Apache-2.0; provided "as is", without warranty — use at your own risk (LICENSE §7–8).

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

cendor_contextkit-1.0.1.tar.gz (21.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

cendor_contextkit-1.0.1-py3-none-any.whl (17.4 kB view details)

Uploaded Python 3

File details

Details for the file cendor_contextkit-1.0.1.tar.gz.

File metadata

  • Download URL: cendor_contextkit-1.0.1.tar.gz
  • Upload date:
  • Size: 21.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for cendor_contextkit-1.0.1.tar.gz
Algorithm Hash digest
SHA256 85f13d7a77c179472129fd2c5be9de4f30353c1a7f2c645326e239c083611de0
MD5 a400528d743e748eea98faedd9e80463
BLAKE2b-256 e6057a7b3ad92e7b1915094251e72445ef1847fc26d25e3d98c81207d0e23b51

See more details on using hashes here.

Provenance

The following attestation bundles were made for cendor_contextkit-1.0.1.tar.gz:

Publisher: release.yml on cendorhq/cendor-libs

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file cendor_contextkit-1.0.1-py3-none-any.whl.

File metadata

File hashes

Hashes for cendor_contextkit-1.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 96a77d6a85db6bdb2092b2b63402060771210e27572c029613b06c79f37bd9c1
MD5 f2f896ef9daf243517c5640b486a4709
BLAKE2b-256 8a039209058985dd877f688e091c490326a0d905a5447e02f54ecb4aa82a06ec

See more details on using hashes here.

Provenance

The following attestation bundles were made for cendor_contextkit-1.0.1-py3-none-any.whl:

Publisher: release.yml on cendorhq/cendor-libs

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Release history Release notifications | RSS feed

1.1.0

2 files

1.0.3

2 files

1.0.2

2 files

This release

1.0.1 This release

2 files

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page