Index
axm_smelt
axm-smelt - Deterministic token compaction for LLM inputs.
CounterBackend
Bases: StrEnum
Backend used to produce a token count.
Currently only :attr:TIKTOKEN exists; the enum is retained as the seam
for a future HuggingFace/SentencePiece backend (Llama/Mistral/Gemma).
Source code in packages/axm-smelt/src/axm_smelt/core/counter.py
Format
SmeltReport
Bases: BaseModel
Report produced by the smelt pipeline.
Source code in packages/axm-smelt/src/axm_smelt/core/models.py
check(text=None, *, parsed=None)
Analyze text without transforming it.
The report carries two distinct savings figures:
strategy_estimatesmaps each registry strategy to the reduction it achieves in isolation, measured against the unmutated input. These estimates are independent and non-additive: summing them overstates the achievable gain, because strategies overlap (e.g.minifyalready removes whitespace thatcollapse_whitespacewould also target).savings_pctis the real cumulative gain — the reduction obtained by chaining the default strategy set (resolve_strategies(None, None), i.e. thesafepreset, exactly what :func:smeltapplies with no explicit strategies). It equals what a user would actually get fromsmelt(text).
original and compacted stay identical: check never transforms
its input, it only measures.
Source code in packages/axm-smelt/src/axm_smelt/core/pipeline.py
count(text, model='o200k_base')
Return the token count for text.
Uses tiktoken with model encoding; a claude* or unknown model is
routed to the o200k_base proxy.
Source code in packages/axm-smelt/src/axm_smelt/core/counter.py
smelt(text=None, strategies=None, preset=None, *, parsed=None)
Run the compaction pipeline and return a report.
Baseline for savings_pct:
text=path: the baseline is the provided raw string, unchanged.parsed=path: the baseline is the pretty serializationjson.dumps(parsed, indent=2, ensure_ascii=False), not the compact dump. A parsed object has no canonical textual form, so measuring savings against an already-minified compact baseline would structurally under-report the reduction. The pretty baseline reflects the indented form a user would otherwise have read, sosavings_pctmatches the perceived reduction.report.originalstill holds the compact serialization (the pipeline's working text).