Skip to content

Smelt

smelt

SmeltTool — MCP entry point for axm-smelt.

SmeltTool

Bases: AXMTool

Compact text/data for LLM consumption.

Registered as smelt via axm.tools entry point.

Source code in packages/axm-smelt/src/axm_smelt/tools/smelt.py
Python
class SmeltTool(AXMTool):
    """Compact text/data for LLM consumption.

    Registered as ``smelt`` via axm.tools entry point.
    """

    agent_hint: str = (
        "Compact text/JSON data for LLM consumption — apply minify, tabular, "
        "strip_quotes, and other strategies to reduce token count"
    )

    @property
    def name(self) -> str:
        """Return tool name for registry lookup."""
        return "smelt"

    def execute(
        self,
        *,
        data: str | Any = "",
        strategies: list[str] | None = None,
        preset: str | None = None,
        **kwargs: Any,
    ) -> ToolResult:
        """Run the smelt compaction pipeline.

        Args:
            data: Text or JSON data to compact.
            strategies: Optional list of strategy names.
            preset: Optional preset name.

        Returns:
            ToolResult with compacted output and metrics.
        """
        try:
            if data is None:
                msg = "data must not be None"
                raise ValueError(msg)

            from axm_smelt.core.pipeline import smelt

            if not isinstance(data, str):
                report = smelt(parsed=data, strategies=strategies, preset=preset)
            else:
                report = smelt(data, strategies=strategies, preset=preset)

            return ToolResult(
                success=True,
                data={
                    "compacted": report.compacted,
                    "format": report.format.value,
                    "original_tokens": report.original_tokens,
                    "compacted_tokens": report.compacted_tokens,
                    "savings_pct": round(report.savings_pct, 2),
                    "strategies_applied": report.strategies_applied,
                },
            )
        except Exception as exc:  # noqa: BLE001
            return ToolResult(success=False, error=str(exc))
name property

Return tool name for registry lookup.

execute(*, data='', strategies=None, preset=None, **kwargs)

Run the smelt compaction pipeline.

Parameters:

Name Type Description Default
data str | Any

Text or JSON data to compact.

''
strategies list[str] | None

Optional list of strategy names.

None
preset str | None

Optional preset name.

None

Returns:

Type Description
ToolResult

ToolResult with compacted output and metrics.

Source code in packages/axm-smelt/src/axm_smelt/tools/smelt.py
Python
def execute(
    self,
    *,
    data: str | Any = "",
    strategies: list[str] | None = None,
    preset: str | None = None,
    **kwargs: Any,
) -> ToolResult:
    """Run the smelt compaction pipeline.

    Args:
        data: Text or JSON data to compact.
        strategies: Optional list of strategy names.
        preset: Optional preset name.

    Returns:
        ToolResult with compacted output and metrics.
    """
    try:
        if data is None:
            msg = "data must not be None"
            raise ValueError(msg)

        from axm_smelt.core.pipeline import smelt

        if not isinstance(data, str):
            report = smelt(parsed=data, strategies=strategies, preset=preset)
        else:
            report = smelt(data, strategies=strategies, preset=preset)

        return ToolResult(
            success=True,
            data={
                "compacted": report.compacted,
                "format": report.format.value,
                "original_tokens": report.original_tokens,
                "compacted_tokens": report.compacted_tokens,
                "savings_pct": round(report.savings_pct, 2),
                "strategies_applied": report.strategies_applied,
            },
        )
    except Exception as exc:  # noqa: BLE001
        return ToolResult(success=False, error=str(exc))