Reasoning Traces & Explainability
Every inference in Kompile — whether from Datalog/FOL rules, Probabilistic Soft Logic (PSL), MEBN/Bayesian networks, Subjective Logic fusion, quantitative formulas, or process mining — can be normalized into a single, walkable, serializable proof tree: ReasoningTrace.
Instead of exposing opaque scores or engine-specific internals, reasoning traces give agents, auditors, and UIs one consistent contract to inspect why a conclusion holds, which sources support or rebut it, what evidence is missing or contested, and how to export provenance to W3C PROV.
1. The unified ReasoningTrace model
A ReasoningTrace is a rooted tree of immutable ReasoningTrace.Step records. The root is the conclusion; each step's premises are the sub-steps that derived it, down to observed FACT or ASSUMPTION leaves.
Step fields
| Field | Type | Meaning |
|---|---|---|
kind | StepKind | Category of reasoning step (11 kinds, listed below) |
conclusion | String | Claim, atom, or value established by this step |
operation | String | Rule ID, solver operation, or operator (e.g. observed, psl-map value=0.72, w=2.0 d=0.05 dir=up) |
confidence | double | Scalar confidence in [0.0, 1.0] (NaN sentinel coerced to 0.0) |
source | String | Optional provenance source identifier (document, chunk, fact ID, run ID) |
premises | List<Step> | Supporting or rebutting child steps (empty for leaves) |
opinion | Opinion (nullable) | Optional full Subjective Logic opinion (belief, disbelief, uncertainty, baseRate) |
meta | Map<String, String> | Arbitrary annotations (e.g. learnedScore, revision state, rule metadata) |
The 11 StepKind categories
StepKind | Role in the proof tree |
|---|---|
FACT | Observed base fact from the graph or corpus (leaf) |
ASSUMPTION | Hypothesized or counterfactual input (leaf) |
RULE | Logical (FOL / Datalog / OWL-RL) rule application |
FUSION | Subjective-logic or multi-signal evidence fusion |
INFERENCE | Probabilistic inference (PSL / HL-MRF, Bayesian network, MEBN) |
QUERY | Retrieval or graph lookup step |
CALCULATION | Deterministic numeric calculation or aggregation |
VALIDATION | Unit, dimensional, replay, or reconciliation check |
OPTIMIZATION | Goal-seek (SOLVE_TARGET) or constrained optimization step |
REBUTTAL | Counter-evidence or argument that attacks/rebuts the parent conclusion |
REVISION | Belief-revision event (prior conclusion revised or retracted by BeliefReviser) |
2. How each reasoning engine produces traces
| Engine / Component | Adapter / Producer | What the trace captures |
|---|---|---|
| FOL / Datalog / TMS | ReasoningTrace.fromDerivation(DerivationTree) | Full rule-firing derivation tree down to observed FACT leaves, preserving provenance and surfacing REBUTTAL / REVISION steps when BeliefReviser accepts defeating evidence or retracts facts. |
| PSL / HL-MRF (ADMM) | PslTraceAdapter | KKT rule-force view: root INFERENCE (psl-map value=...) → up to 12 strongest RULE premises sorted by weighted potential (w, distance d, push direction dir=up/down, pot) → observed FACT leaves with Fact.sourceId() provenance. |
| Subjective Logic Fusion | OpinionTree, EvidenceAccumulator, ask_graph_explain_fused | Preserves per-step Opinion(b, d, u, a) across modalities (ModalityKind, ModalityEvidence, ConfidenceBreakdown) rather than collapsing disagreement into one float. |
| Dialectical Claim Adjudication (QBAF) | DossierAdjudicator + ClaimAdjudicator | Converts a ClaimDossier into PRO supporters and CON attackers scored under DF-QuAD semantics (DfQuadSemantics), surfacing refuting items as first-class REBUTTAL steps. |
| Quantitative Models | graph_reasoning_query (CALCULATE / SCENARIO / SOLVE_TARGET) | Deterministic CALCULATION, VALIDATION, and OPTIMIZATION steps recording inputs, baseline vs. intervention deltas, and goal-seek convergence. |
| Process Mining | ProcessReasoningTraceBuilder, ProcessReasoningTraceStore, ProcessReasoningTraceSseBridge | Mined-process discovery and suggestion traces, persisted under models/process/reasoning-traces/v1/ and mirrored into ReasoningTraceStore for chat/UI streaming. |
Example PSL KKT trace structure
INFERENCE "isActive(alice)" "psl-map value=0.72" confidence=0.72
RULE "worksFor(x, org) & activeOrg(org) -> isActive(x)" "w=2.0 d=0.05 dir=up pot=0.10" confidence=0.95
FACT "worksFor(alice, acme)" "observed" confidence=0.90 source=doc:hr-roster#chunk-4
FACT "activeOrg(acme)" "observed" confidence=1.00 source=doc:filing-2026#chunk-1
REBUTTAL "onLeave(alice)" "observed" confidence=0.40 source=doc:calendar#chunk-93. Rendering, citeable attribution & gap analysis
Kompile separates rendering for LLMs, structured citation indexing, and deterministic gap detection over the same step IDs:
Compact LLM rendering & attribution index (ReasoningTraceRenderer)
toLlmContext(trace, maxLines): renders anyReasoningTrace,ReasoningTrail,CompositeReasoningTrail, orDerivationTreeinto bounded plain text (default20lines,280chars/line) preserving target, confidence, opinions, modalities, rules, and derivation hierarchy.attributionIndex(...): produces a flat list of citeableAttributionStep(stepId, kind, conclusion, operation, confidence, source, evidenceRefs). EachEvidenceReferenceparses structured identifiers (nodeId,edgeId,documentId,chunkId,factSheetId,runId,atomKey,findingKey,ruleId,modality) so downstream agents and UIs can link directly back to source chunks and graph elements.
Deterministic gap analysis (ReasoningTraceGapAnalyzer)
ReasoningTraceGapAnalyzer.traceGaps(trace) answers "what should the agent or user verify next?" by emitting bounded, step-ID-addressable TraceGap(gapType, severity, question, reason, relatedStepIds) records (default cap: 12):
gapType | Trigger condition |
|---|---|
UNCERTAIN_OPINION | A step carries an Opinion with uncertainty >= 0.6 (thin evidence — takes precedence over scalar LOW_CONFIDENCE). |
CONTESTED_EVIDENCE | A step carries an Opinion with both belief >= 0.3 and disbelief >= 0.3, or sibling premises have pairwise conflict >= 0.25. |
LOW_CONFIDENCE | Scalar-only root step (no Opinion) has confidence < 0.60 (HIGH severity below 0.40, MEDIUM otherwise). |
MODALITY_DISAGREEMENT | Multiple reasoning modalities disagree by >= 0.35. |
MISSING_PROVENANCE | A step lacks citeable source/document/chunk references. |
MISSING_SUPPORT / MISSING_SUPPORT_FINDINGS | Derived conclusion or entailment has no grounded base support. |
UNCERTAIN_EVIDENCE | Step text contains fallback/uncertainty markers (unknown, unavailable, no signal, missing, failed). |
MISSING_TRACE / MISSING_CONFIDENCE | Trace payload or confidence value is absent. |
MISSING_MODALITIES / MISSING_MODALITY_DETAIL | Composite trail is missing expected modality breakdowns. |
4. Portable JSON, .kgraph storage & W3C PROV export
Bounded portable JSON (ReasoningTraceJsonCodec)
ReasoningTraceJsonCodec serializes and validates traces in a strict, bounded envelope (format: "kompile.reasoning-trace", formatVersion: 1):
- Hard safety bounds: 1 MiB max payload, 512 max steps, depth 64, 64 premises/step, 64 metadata entries/step, 4,096 bytes max text field.
- Preserves step IDs,
Opinion(b, d, u, a), andmetamaps without Java serialization.
.kgraph trace artifacts & compact graph context (CompactGraphContextService)
Traces can travel inside a .kgraph ZIP container under models/:
.kgraph artifact | Contents |
|---|---|
models/reasoning/traces.json | Persisted reasoning trace DTOs |
models/process/suggestions.json | Process-mining suggestion payloads |
models/process/reasoning-traces/v1/<id>.json | Versioned kompile.reasoning-trace v1 process traces |
When building grounded chat context (kompile.compact-graph.v1), CompactGraphContextService enforces strict scoping and provenance hygiene:
- Only neighborhood nodes and relations for the retrieved seeds are read (bounded at 32 nodes / 96 relations / 4 traces / 16 steps).
- A reasoning trace is included only if it references at least one retrieved node.
- Stored opinions are emitted as
learnedScore, never conflated with raw extraction confidence.
W3C PROV export (ProvSerializer)
For external compliance, auditing, or lineage pipelines, ProvSerializer exports any ReasoningTrace to standard W3C PROV-N or PROV-JSON (export-only):
ReasoningTrace step | W3C PROV-DM mapping |
|---|---|
FACT (leaf) | prov:Entity (deduplicated by conclusion) |
ASSUMPTION (leaf) | prov:Entity annotated with kompile:assumed "true" |
RULE / INFERENCE / FUSION / QUERY / derived | prov:Entity (conclusion) + prov:Activity (operation), linked via prov:wasGeneratedBy, prov:used, and prov:wasDerivedFrom |
5. Inspecting traces via MCP tools
Agents inspect reasoning traces directly through Kompile's MCP grounding tools (working both folder-locally over .kgraph and against a Kompile server):
| Tool | What it returns | Example call |
|---|---|---|
ask_graph_explain | Step-by-step derivation tree rendered via ReasoningTraceRenderer, showing which rules fired and which observed facts produced the verdict. | ask_graph_explain atom="worksFor(Alice, Acme)" |
ask_graph_explain_fused | Fused Subjective Logic breakdown (belief, disbelief, uncertainty, support vs. counter-evidence) across reasoning modalities. | ask_graph_explain_fused target="worksFor(Alice, Acme)" |
graph_reason | One-call verdict or entity dossier combining evidence, learned scores, and rendered reasoning trace. | graph_reason target="worksFor(Alice, Acme)" |
graph_reasoning_query | Typed VERIFY, WHY (why a relation holds), and WHY_NOT (why it fails and what missing facts/paths would change it) with compact trace output, opinions, and learned scores. | graph_reasoning_query operation="WHY_NOT" entity="Alice" target="Acme" relationTypes=["WORKS_FOR"] |
ask_graph_claim | Multi-signal claim dossier + dialectical QBAF adjudication (DossierAdjudicator) with PRO support and CON REBUTTAL steps. | ask_graph_claim claim="Alice leads Platform Engineering" |
process_mining | Process discovery and conformance results with a reasoningTraceId (mirrored to ReasoningTraceStore via ProcessReasoningTraceSseBridge on server deployments). | process_mining action="discover" fact_sheet_id=1 |
Related pages
- Knowledge Graphs & Grounded Reasoning — golden-path MCP workflow and reasoning engine overview
- Ontologies, Type Schemas & Fuzzy Types —
GraphSchema, OWL-RL (ontology.ttl),FuzzyTypeMembership, and conformance - KGraph Portability Contract —
.kgraphv2/v3 layout and local execution rules - Auditing & Provenance — harness-level audit trails and tool provenance