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.3.tar.gz (24.5 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.3-py3-none-any.whl (19.7 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: cendor_contextkit-1.0.3.tar.gz
  • Upload date:
  • Size: 24.5 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.3.tar.gz
Algorithm Hash digest
SHA256 5e0f61f34ee91cd08f558b6d411a30d363ce1fa55cdd459717eca6c610e971e3
MD5 90732119b1efddf901edc098320459a5
BLAKE2b-256 ff2af6350e8487e64d5aa3ef580ab547ddc72e113ca06461ab8ddd2e1b7dfb66

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for cendor_contextkit-1.0.3-py3-none-any.whl
Algorithm Hash digest
SHA256 c43494bd0549e6d906c845d10e3b1d86506bbcd596d0b3210aa8ead268dfe991
MD5 15cb6c2d03b582847c111fdfafc5db46
BLAKE2b-256 fa55bb5b66343d7038ed975637ae70124337c17b2271aa0fa0a56a21920b56ae

See more details on using hashes here.

Provenance

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

This release

1.0.3 This release

2 files

1.0.2

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