Skip to main content

Deterministic token compaction for LLM inputs

Project description

AXM Logo

axm-smelt — Deterministic token compaction for LLM inputs

CI axm-smelt Coverage PyPI Python 3.12+ Docs


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.

📖 Full documentation

Features

  • Format detection — auto-detect JSON, YAML, XML, TOML, CSV, Markdown, and plain text
  • Token counting — exact counts via tiktoken (o200k_base), with len//4 fallback
  • 7 strategiesminify, drop_nulls, flatten, tabular, dedup_values, strip_quotes, round_numbers
  • Composable pipeline — chain strategies explicitly or use presets (safe, moderate, aggressive)
  • CLIaxm-smelt compact|check|count|version with --preset/--strategies/--file/--output flags
  • MCP toolSmeltTool for use by AI agents via axm-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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

axm_smelt-0.1.0.tar.gz (47.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

axm_smelt-0.1.0-py3-none-any.whl (31.1 kB view details)

Uploaded Python 3

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

Hashes for axm_smelt-0.1.0.tar.gz
Algorithm Hash digest
SHA256 ef84b89086cd25fb99797fc04261ac43294379e85c8b1a838825d2cb26003963
MD5 de46df0b72740d8823f44c9461fd12cf
BLAKE2b-256 80182f7c419f9d824f51ec26505f7858c0fa3fa75a0620df58c4d3b529a81f4c

See more details on using hashes here.

Provenance

The following attestation bundles were made for axm_smelt-0.1.0.tar.gz:

Publisher: publish.yml on axm-protocols/axm-forge

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

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

Hashes for axm_smelt-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 bce361c4d01862910a37db2b68a1259a0df57a41934dcb60ff656030aed624ce
MD5 69859bdaf5493a618dd966a81ee8c38a
BLAKE2b-256 e5333c0ac314534160d85c1bee84caac825bbb34ad86de9a129e48b1a207e601

See more details on using hashes here.

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

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