Deterministic token compaction for LLM inputs
Project description
axm-smelt — Deterministic token compaction for LLM inputs
axm-smelt reduces token consumption for LLM inputs by applying deterministic compaction strategies — lossless whitespace removal, structural transforms, and optional lossy simplifications. It works as a CLI, Python API, and MCP tool for AI agents.
Features
- Format detection — auto-detect JSON, YAML, XML, TOML, CSV, Markdown, and plain text
- Token counting — exact counts via tiktoken (
o200k_base), withlen//4fallback - 7 strategies —
minify,drop_nulls,flatten,tabular,dedup_values,strip_quotes,round_numbers - Composable pipeline — chain strategies explicitly or use presets (
safe,moderate,aggressive) - CLI —
axm-smelt compact|check|count|versionwith--preset/--strategies/--file/--outputflags - MCP tool —
SmeltToolfor use by AI agents viaaxm-mcp - Modern Python — 3.12+ with strict typing
Installation
uv add axm-smelt
Quick Start
CLI
# Compact from stdin (uses safe preset by default)
echo '{"name": "Alice", "age": 30}' | axm-smelt compact
# Compact a file with the aggressive preset
axm-smelt compact --file data.json --preset aggressive
# Compact with specific strategies, write output to file
axm-smelt compact --file data.json --strategies minify,drop_nulls --output out.json
# Analyze token waste without modifying (shows per-strategy estimates)
axm-smelt check --file data.json
# Count tokens
echo 'hello world' | axm-smelt count
Python API
from axm_smelt import smelt, check, count
# Compact using the safe preset (default)
report = smelt('{\n "name": "Alice",\n "age": 30\n}')
print(f"{report.savings_pct:.1f}% saved")
# Tokens: 14 -> 9
# Compact with explicit strategies
report = smelt(data, strategies=["minify", "drop_nulls"])
# Compact with a preset
report = smelt(data, preset="aggressive")
# Analyze without transforming
report = check('{"data": [1, 2, 3]}')
for strat, pct in report.strategy_estimates.items():
print(f" {strat}: {pct:.1f}%")
# Count tokens
tokens = count("hello world")
MCP (AI Agent)
axm-smelt is available as an MCP tool via axm-mcp. AI agents can call smelt_compact(data, preset="moderate") directly.
See the MCP how-to guide for details.
CLI Commands
| Command | Description |
|---|---|
axm-smelt compact |
Read from stdin/file, output compacted text; savings reported to stderr |
axm-smelt check |
Analyze token waste without transforming; shows strategies with positive savings |
axm-smelt count |
Print token count |
axm-smelt version |
Print version string |
All commands accept --file PATH to read from a file instead of stdin. compact additionally accepts --strategies LIST, --preset NAME, and --output PATH.
Strategies
| Name | Category | Description |
|---|---|---|
minify |
whitespace | Lossless JSON whitespace compaction |
drop_nulls |
structural | Recursively remove None, "", [], {} values |
flatten |
structural | Collapse single-child wrapper dicts ({"a":{"b":1}} → {"a.b":1}) |
tabular |
structural | Convert list[dict] JSON to pipe-separated tables |
dedup_values |
structural | Replace repeated long strings (≥20 chars, ≥2 occurrences) with aliases |
strip_quotes |
cosmetic | Remove quotes on simple alphanumeric JSON keys |
round_numbers |
cosmetic | Round floats to N decimal places (default: 2) |
Presets
| Preset | Strategies | Use when |
|---|---|---|
safe |
minify |
Lossless only — output is semantically identical |
moderate |
minify, drop_nulls, flatten, dedup_values, tabular, strip_quotes |
Structural transforms are acceptable |
aggressive |
minify, drop_nulls, flatten, tabular, round_numbers, dedup_values, strip_quotes |
Maximum savings, may alter float precision |
Development
This package is part of the axm-forge workspace.
git clone https://github.com/axm-protocols/axm-forge.git
cd axm-forge
uv sync --all-groups
uv run --package axm-smelt --directory packages/axm-smelt pytest -x -q
License
Apache-2.0 — © 2026 axm-protocols
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file axm_smelt-0.1.0.tar.gz.
File metadata
- Download URL: axm_smelt-0.1.0.tar.gz
- Upload date:
- Size: 47.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ef84b89086cd25fb99797fc04261ac43294379e85c8b1a838825d2cb26003963
|
|
| MD5 |
de46df0b72740d8823f44c9461fd12cf
|
|
| BLAKE2b-256 |
80182f7c419f9d824f51ec26505f7858c0fa3fa75a0620df58c4d3b529a81f4c
|
Provenance
The following attestation bundles were made for axm_smelt-0.1.0.tar.gz:
Publisher:
publish.yml on axm-protocols/axm-forge
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
axm_smelt-0.1.0.tar.gz -
Subject digest:
ef84b89086cd25fb99797fc04261ac43294379e85c8b1a838825d2cb26003963 - Sigstore transparency entry: 1278960960
- Sigstore integration time:
-
Permalink:
axm-protocols/axm-forge@f1a3c4be2e69e4e13e0e4583d3408d73fece7ce9 -
Branch / Tag:
refs/tags/smelt/v0.1.0 - Owner: https://github.com/axm-protocols
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@f1a3c4be2e69e4e13e0e4583d3408d73fece7ce9 -
Trigger Event:
push
-
Statement type:
File details
Details for the file axm_smelt-0.1.0-py3-none-any.whl.
File metadata
- Download URL: axm_smelt-0.1.0-py3-none-any.whl
- Upload date:
- Size: 31.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
bce361c4d01862910a37db2b68a1259a0df57a41934dcb60ff656030aed624ce
|
|
| MD5 |
69859bdaf5493a618dd966a81ee8c38a
|
|
| BLAKE2b-256 |
e5333c0ac314534160d85c1bee84caac825bbb34ad86de9a129e48b1a207e601
|
Provenance
The following attestation bundles were made for axm_smelt-0.1.0-py3-none-any.whl:
Publisher:
publish.yml on axm-protocols/axm-forge
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
axm_smelt-0.1.0-py3-none-any.whl -
Subject digest:
bce361c4d01862910a37db2b68a1259a0df57a41934dcb60ff656030aed624ce - Sigstore transparency entry: 1278960977
- Sigstore integration time:
-
Permalink:
axm-protocols/axm-forge@f1a3c4be2e69e4e13e0e4583d3408d73fece7ce9 -
Branch / Tag:
refs/tags/smelt/v0.1.0 - Owner: https://github.com/axm-protocols
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@f1a3c4be2e69e4e13e0e4583d3408d73fece7ce9 -
Trigger Event:
push
-
Statement type: