Skip to main content

Compilation

Compilation transforms a semantic Concept definition into a deterministic ExecutionGraph (IR). The same definition version always produces the same ir_hash — this is the foundation of the system's reproducibility guarantees.

Invariant

ir_hash is deterministic. Same definition version → same ir_hash on any machine. Use canonical serialisation (sorted keys, stable field order) before hashing.


Compile Definition

POST /compile

Compiles a Concept definition into a fully resolved, typed, immutable ExecutionGraph. The returned graph_id is stable for a given definition version. Cache it at service startup and use POST /execute/graph in the hot path.

Request — CompileRequest

FieldTypeRequiredDescription
idstrRequiredFully qualified concept id.
versionstrRequiredExplicit version.

Response — ExecutionGraph

FieldTypeRequiredDescription
graph_idstrAlwaysPass to POST /execute/graph.
ir_hashstrAlwaysDeterministic hash. Same definition → same hash.
nodeslistAlwaysGraphNode[]. Each: id, op, inputs, params, output_type.
edgeslistAlwaysGraphEdge[]. Each: from, to, data_type.

Response Codes

StatusDescription
200ExecutionGraph.
400graph_error (circular dependency), type_error, or semantic_error.
401Unauthorised.
404Definition not found.

Python Startup Pattern

GRAPH_CACHE: dict[str, str] = {}  # 'namespace.id:version' → graph_id

async def startup():
for concept_id, version in ACTIVE_DEFINITIONS:
graph = await client.compile(id=concept_id, version=version)
GRAPH_CACHE[f'{concept_id}:{version}'] = graph.graph_id

# Then in the hot path:
graph_id = GRAPH_CACHE['org.churn_risk:1.2']
result = await client.execute_graph(graph_id=graph_id, entity=entity, timestamp=ts)

Compile Semantic View

POST /compile/semantic

Returns the semantic view of a compiled concept — the meaning layer, not the execution layer. Exposes semantic_hash, resolved features, and the normalised canonical form. Use for deduplication checks and as input to the LLM semantic-refine loop.

Response — SemanticGraph

FieldTypeRequiredDescription
semantic_hashstrAlwaysIdentical for semantically equivalent concepts regardless of structure.
featureslistAlwaysSemanticFeature[]. Each: name, layer, meaning, meaning_hash.
normalized_formdictAlwaysCanonical compiler-normalised form.
dependencieslistAlwaysSemanticDependency[]. Each: id, version, type, depth.
equivalenceslistOptionalConcepts with the same semantic_hash.

Response Codes

StatusDescription
200SemanticGraph.
400Validation error.
401Unauthorised.
404Not found.

Compile Explain Plan

POST /compile/explain-plan

Returns the planned execution order and parallelizable node groups without executing. The SQL EXPLAIN equivalent. Use to understand graph topology before running and identify concurrent node groups.

Response — ExecutionPlan

FieldTypeRequiredDescription
stepslistAlwaysWorkflowStep[] in execution sequence.
parallelizable_groupslistOptionalGroups of node IDs that can execute concurrently.
optimizations_appliedlistOptionalPasses applied: node_deduplication, dead_node_elimination.

Response Codes

StatusDescription
200ExecutionPlan.
400Validation error.
401Unauthorised.
404Not found.