runInferenceCycle method

List<Inference> runInferenceCycle(
  1. List<Concept> activeConcepts
)

Runs a complete inference cycle over activeConcepts.

Returns all Inference objects produced, sorted by confidence.

Implementation

List<Inference> runInferenceCycle(List<Concept> activeConcepts) {
  if (activeConcepts.isEmpty) return [];

  _patterns.observeBatch(activeConcepts);

  final inferences = <Inference>[];

  // 1. Rule-based forward chaining
  inferences.addAll(_forwardChain(activeConcepts));

  // 2. Causal inference from concept pairs
  final causalRels = _causal.discoverFromConcepts(activeConcepts);
  for (final rel in causalRels) {
    final cause = activeConcepts.cast<Concept?>()
        .firstWhere((c) => c?.id == rel.causeConceptId, orElse: () => null);
    final effect = activeConcepts.cast<Concept?>()
        .firstWhere((c) => c?.id == rel.effectConceptId, orElse: () => null);
    if (cause != null && effect != null) {
      inferences.add(Inference(
        id: _uuid.v4(),
        conclusion:
            '"${cause.content}" leads to "${effect.content}"',
        premises: [cause.content, effect.content],
        confidence: rel.strength,
        inferenceType: 'causal',
        generatedAt: DateTime.now(),
      ));
    }
  }

  // 3. Graph-based associative inference
  inferences.addAll(_associativeInference(activeConcepts));

  // 4. Memory-driven inference
  inferences.addAll(_memoryDrivenInference(activeConcepts));

  // De-duplicate and sort
  final unique = _deduplicateInferences(inferences);
  unique.sort((a, b) => b.confidence.compareTo(a.confidence));

  _logger.debug(
      'Inference cycle: ${unique.length} unique inference(s) '
      'from ${activeConcepts.length} concepts');

  return unique;
}