Skip to content

cosmotron_mcp.inference.compiler

compile_inference

compile_inference(session_dir: str, spec_path: str, run_dry_run: bool = True) -> dict

Compile a validated InferenceSpec to Firecrown YAML + CosmoSIS INI, then dry-run it.

Deterministic templating (no LLM) — the model already chose the spec's values; this owns every emitted byte. Refuses (writing nothing) on an invalid spec, an existing label without overwrite, etc. When run_dry_run is set (default), also runs the deterministic dry-run gate — one test-sampler evaluation plus static coverage checks — and returns its verdict ("PASS"/"FAIL"). A FAIL still returns the compiled paths + report so a human can inspect; the verdict is prominent so a caller never launches a chain on a failed config by accident.

Launch a PASSing config with run_inference(session_dir, config_dir=<compiled_dir>).

Parameters:

Name Type Description Default
session_dir str

Session directory.

required
spec_path str

Path to the validated spec JSON.

required
run_dry_run bool

Run the dry-run gate after compiling (default True).

True

Returns:

Type Description
dict

The compiler result (compiled_dir, pipeline_ini, …) plus, when

dict

run_dry_run, verdict and validation_report. NOTE — sanctioned

dict

exception to the repo-relative-paths convention: these paths are

dict

ABSOLUTE, because they are consumed directly by the CosmoSIS

dict

subprocess launched from run_inference, not by another MCP tool or

dict

a dispatch message. Do not persist them into plan.json; pass

dict

compiled_dir straight to run_inference(config_dir=...).

Source code in cosmotron_mcp/server.py
@mcp.tool()
@sync_budget_guard
def compile_inference(
    session_dir: str, spec_path: str, run_dry_run: bool = True
) -> dict:
    """Compile a validated InferenceSpec to Firecrown YAML + CosmoSIS INI, then dry-run it.

    Deterministic templating (no LLM) — the model already chose the spec's values; this
    owns every emitted byte. Refuses (writing nothing) on an invalid spec, an existing
    label without overwrite, etc. When ``run_dry_run`` is set (default), also runs the
    deterministic dry-run gate — one `test`-sampler evaluation plus static coverage checks
    — and returns its ``verdict`` (``"PASS"``/``"FAIL"``). A ``FAIL`` still returns the
    compiled paths + report so a human can inspect; the verdict is prominent so a caller
    never launches a chain on a failed config by accident.

    Launch a PASSing config with ``run_inference(session_dir,
    config_dir=<compiled_dir>)``.

    Args:
        session_dir: Session directory.
        spec_path: Path to the validated spec JSON.
        run_dry_run: Run the dry-run gate after compiling (default True).

    Returns:
        The compiler result (``compiled_dir``, ``pipeline_ini``, …) plus, when
        ``run_dry_run``, ``verdict`` and ``validation_report``. NOTE — sanctioned
        exception to the repo-relative-paths convention: these paths are
        ABSOLUTE, because they are consumed directly by the CosmoSIS
        subprocess launched from `run_inference`, not by another MCP tool or
        a dispatch message. Do not persist them into `plan.json`; pass
        `compiled_dir` straight to `run_inference(config_dir=...)`.
    """
    _require_human_gates(session_dir)
    result = _compile_inference(spec_path, overwrite=True)
    if result.get("error"):
        return result
    if run_dry_run:
        report = _dry_run_inference(result["compiled_dir"])
        result["verdict"] = report["verdict"]
        result["validation_report"] = report
    _log_tool_call(session_dir, "compile_inference",
                   {"spec_path": spec_path, "run_dry_run": run_dry_run})
    return result