Skip to content

Hyperdistillation

Trace synthesis component — reasoning-to-code learning pipeline.

Cluster: ML & Optimisation | Type: component | MCP Tools: 29

Overview

Reasoning-to-code learning pipeline that captures LLM reasoning traces from JSONL event logs, synthesizes deterministic Python artifacts, verifies them, and maintains a searchable artifact library with Bayesian confidence tracking. Six core operations (capture, check_library, execute_artifact, list_artifacts, get_artifact, delete_artifact) cover the learn-store-reuse lifecycle that closes the G6 self-improvement loop.

When to use:

  • Converting successful solver or agent traces into reusable, verified Python functions
  • Checking whether a known-good artifact already solves a new problem before invoking the LLM
  • Running the learn loop that continuously grows G6's library of distilled deterministic solutions

Production behavior:

  • Artifact execution is statically checked before runtime
  • Runtime execution occurs in an isolated Python subprocess with a timeout
  • Imports, dunder traversal, dynamic evaluation, file access, and network access are rejected
  • Usage outcomes update artifact confidence through Bayesian tracking

Example:

from mvp.hyperdistillation import HyperdistillationBlock, DistillInput

block = HyperdistillationBlock(name="distill")
result = block.infer(DistillInput(
    op="capture",
    event_log=[{
        "event_type": "step_complete",
        "step_number": 8,
        "llm_model": "gpt-4o-mini",
        "tokens_used": 12,
        "latency_ms": 80,
        "goal": "Calculate 2+2",
        "data": {
            "status": "completed",
            "input_summary": "2+2",
            "output_summary": "4",
            "reasoning_trace": "add two and two",
        },
    }],
))

Works well with: evoskill, cegis, solver

Production Caveats

Artifact execution boundary

Hyperdistillation rejects unsafe Python syntax and executes artifacts in an isolated Python subprocess with a timeout. This prevents common artifact failures such as imports, file access, dynamic evaluation, dunder traversal, and runaway loops. It is still not a VM, container, or OS-level security boundary. Do not use it to run arbitrary untrusted code in a multi-tenant deployment without an outer container or VM sandbox.

Cache validity

A distilled artifact is evidence that a previous trace pattern worked for similar inputs. It is not proof that the artifact is correct for every future input, and it is not a substitute for domain tests, holdout evaluation, or human review on high-stakes workflows. Distribution shift should trigger fallback to fresh reasoning and re-validation.

Latency and feature flags

The default path prefers local deterministic synthesis before CEGIS. CEGIS and advanced template synthesis can be slower and should be monitored through the synthesis coverage ledger. Keep G6_ADVANCED_TEMPLATE_SYNTHESIS unset in production unless you have benchmark evidence for the target workload. For launch users, advanced template synthesis should remain an internal reliability primitive rather than a visible onboarding feature; only enable it when you can compare template_a/template_d outcomes against the default path and inspect failures.

Template synthesis verification boundary

Advanced template synthesis verifies fitted templates against supplied examples only. It requires at least three I/O samples and does not prove correctness for unseen inputs, distribution shifts, or high-stakes workflows. Treat any generated artifact as a candidate that still needs domain tests, holdout cases, and human review where consequences are material.

Data handling

Event logs, test cases, and stored artifacts can include summaries of user inputs and outputs. Treat the distillation database as sensitive application data: scope it per user/workspace, back it up intentionally, and avoid feeding secrets or regulated data into traces unless the deployment has the required data controls.

Public API

HyperdistillationBlock(AIBlock[DistillInput, DistillOutput, dict])

Trace synthesis pipeline: capture reasoning traces, synthesize artifacts, execute them.

Field Type Default
name str 'hyperdistillation'
resource_bounds ResourceBounds \| None None
usage ResourceUsage field(default_factory=ResourceUsage)
db_path str ''
execution_timeout_secs float 2.0

Methods:

infer(data: DistillInput) -> Result[DistillOutput]

seed_library() -> int

Load packaged cold-start artifacts into the artifact library.

list_patterns() -> dict[str, object]

Return the applied deterministic-reliability pattern catalog.

health() -> dict

Return health status for production monitoring.

close() -> None

Close the underlying SQLite connection.

TraceSegment(BaseModel)

A slice of reasoning from the JSONL event log.

Field Type Default
step_number int required
input_summary str required
output_summary str required
llm_model str required
tokens_consumed int required
latency_ms int required
success bool required
reasoning_trace str required

DistilledArtifact(BaseModel)

Synthesized deterministic Python code with metadata.

Field Type Default
artifact_id str required
source_project_ids list[str] required
step_number int required
problem_signature str required
algorithm_source str required
test_cases list[dict] required
confidence float required
times_used int 0
times_succeeded int 0
created_at str required
last_used_at str \| None None
cegis_iterations int 0
verified_by str 'replay'

DistillInput(BaseModel)

Input to trace synthesis (HyperdistillationBlock).

Field Type Default
op _DISTILL_OPS required
event_log list[dict] \| None None
step_number int \| None None
project_state dict \| None None
artifact_id str \| None None
request_id str \| None None
task_id str \| None None
run_id str \| None None

DistillOutput(BaseModel)

Output from trace synthesis (HyperdistillationBlock).

Field Type Default
op str required
success bool required
artifact DistilledArtifact \| None None
artifacts list[DistilledArtifact] \| None None
result dict \| None None
error str \| None None
artifacts_created int 0
degraded bool False
degradation_reason str \| None None
completion_state CompletionState 'qualified-draft'
warning_card dict[str, Any] \| None None
evidence dict[str, Any] {}
request_id str \| None None
task_id str \| None None
run_id str \| None None

ArtifactSynthesizer

Synthesize artifacts by selecting the best trace output.

Constructor:

Parameter Type Default
library - required
registry - None

Methods:

synthesize_from_traces(traces: list[TraceSegment], step_number: int, goal: str = '') -> Result[DistilledArtifact]

Select the best quality trace and store its output as an artifact.

VerificationResult(BaseModel)

Multi-dimensional verification scores.

Field Type Default
test_pass_rate float required
formal_score float required
ast_score float required
overall_confidence float required
issues list[str] required

ArtifactVerifier

Verifies synthesized artifacts via tests, formal methods, and AST analysis.

Constructor:

Parameter Type Default
registry - None

Methods:

verify(algorithm_source: str, test_cases: list[dict], step_number: int) -> Result[VerificationResult]

Run all verification checks and return combined result.

MCP Tools

Operation Source
capture_traces distill_mcp
check_library distill_mcp
execute_artifact distill_mcp
list_artifacts distill_mcp
get_artifact distill_mcp
delete_artifact distill_mcp
synthesize_artifact distill_mcp
verify_artifact distill_mcp
get_synthesis_status distill_mcp
list_pending_synthesis distill_mcp
search_artifacts distill_mcp
get_statistics distill_mcp
export_library distill_mcp
import_library distill_mcp
prune_artifacts distill_mcp
get_confidence_history distill_mcp
update_confidence distill_mcp
get_usage_stats distill_mcp
compare_artifacts distill_mcp
benchmark_artifact distill_mcp
get_config distill_mcp
update_config distill_mcp
get_feature_flags distill_mcp
set_feature_flags distill_mcp
get_health distill_mcp
capabilities distill_mcp
verified distill_mcp
qualified-draft distill_mcp
blocked-escalated distill_mcp