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.2.tar.gz (22.4 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.2-py3-none-any.whl (17.6 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for cendor_contextkit-1.0.2.tar.gz
Algorithm Hash digest
SHA256 a739d1496723e6f8686d5173fec0a283db06c5d34a6725ad993f6644e574a333
MD5 5bde4668efbd6fe519bdc0435074cd2a
BLAKE2b-256 522eaf8898f554d325fc06f118ef6888a364560a849eb98796ad35c6499acbf8

See more details on using hashes here.

Provenance

The following attestation bundles were made for cendor_contextkit-1.0.2.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.2-py3-none-any.whl.

File metadata

File hashes

Hashes for cendor_contextkit-1.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 b5ec73ea35ffe1f3a4803d32e7db0dabc96ee86a7af8d8bb0da07c63720c4919
MD5 9b02276e7985173936c735ae662e893a
BLAKE2b-256 c690b10cbd095aafc9f375b2733ac9b7fb896855dcab0fb403a911f66f853e4a

See more details on using hashes here.

Provenance

The following attestation bundles were made for cendor_contextkit-1.0.2-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

This release

1.0.2 This release

2 files

1.0.1

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