Skip to main content

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.

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. Powered by PowerAI Labs. Apache-2.0; provided "as is", without warranty — use at your own risk (LICENSE §7–8).

Project details


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.0.tar.gz (21.8 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.0-py3-none-any.whl (17.4 kB view details)

Uploaded Python 3

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

Hashes for cendor_contextkit-1.0.0.tar.gz
Algorithm Hash digest
SHA256 240286bc29d3863c8c65406303af52b3b3c4aeb8f5ab20e2cfabe839b2389eeb
MD5 d9e6e05476b87bb19504a0dc3f8e06cd
BLAKE2b-256 f854154046730cc827160844115479dcc7ca8408260f1fdc9dde7809b875b573

See more details on using hashes here.

Provenance

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

Publisher: release.yml on cendorhq/Cendor

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.0-py3-none-any.whl.

File metadata

File hashes

Hashes for cendor_contextkit-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 f1bae16173fcbf658274ec0933b12aace2c0f06bafa1913b00f51cff091673c4
MD5 722502a04f7488423ead3ec49eb7abb1
BLAKE2b-256 0ce18644c8650bbfe79ed40da18c22a20b3872bd1f1676c4423790da379f944b

See more details on using hashes here.

Provenance

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

Publisher: release.yml on cendorhq/Cendor

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

Supported by

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