Repository navigation
v0.1.0
Initial release.
Added
pack()/ContextPacker: allocate a fixed token budget across competing
Sections using declared priority, with ties broken deterministically by
section name.min_tokens/max_tokensguarantees per section. Infeasible minimums
raiseBudgetTooSmallErrorinstead of silently violating one.reserved_output: hold back tokens for the model's reply so it is never
offered to a section.- Eviction strategies:
truncate(default),drop_oldest,drop_newest,
lowest_score_first,all_or_nothing. Custom strategies plug in via
Strategy+register_strategy()with no change to the allocator. - Pinned items (
Item(..., pinned=True)) that are never dropped or cut,
and raiseSectionOverflowErrorif they genuinely cannot fit. - Tokenizer adapters: dependency-free
CharTokenizer(default), any plain
str -> intcallable, and an optionalTiktokenTokenizerfor exact
OpenAI-family counts. PackResultaudit trail:used_tokens,remaining_tokens,complete,
per-sectionSectionReports, and a fullItemDecisionfor every item
with a human-readable reason. Serializes viato_dict()/to_json().- Fully typed and PEP 561 compliant: a
py.typedmarker ships in the
wheel, so type checkers in consuming projects honour these annotations. - Value semantics on
Item: hashable (usable in sets and as dict keys),
withmetadatacopied on construction so packing stays a pure function
and no caller dict can be mutated out from under you. - Eviction is linear in tokenizer calls, not quadratic -- token counts are
computed once and the running total maintained incrementally. Packing 400
messages costs 405 tokenizer calls rather than 80,603, and the gap widens
with size. - Zero runtime dependencies in the core install.