Module: Legion::Extensions::Agentic::Inference::PredictiveProcessing::Runners::PredictiveProcessing

Includes:
Helpers::Lex
Included in:
Client
Defined in:
lib/legion/extensions/agentic/inference/predictive_processing/runners/predictive_processing.rb

Instance Method Summary collapse

Instance Method Details

#active_inference_candidatesObject



67
68
69
70
71
# File 'lib/legion/extensions/agentic/inference/predictive_processing/runners/predictive_processing.rb', line 67

def active_inference_candidates(**)
  candidates = default_processor.active_inference_candidates
  log.debug "[predictive_processing] active_inference_candidates count=#{candidates.size}"
  { count: candidates.size, domains: candidates }
end

#add_generative_model(domain:) ⇒ Object



13
14
15
16
17
18
19
# File 'lib/legion/extensions/agentic/inference/predictive_processing/runners/predictive_processing.rb', line 13

def add_generative_model(domain:, **)
  return { added: false, reason: :missing_domain } if domain.nil? || domain.to_s.strip.empty?

  result = default_processor.add_model(domain: domain.to_sym)
  log.debug "[predictive_processing] add_model domain=#{domain} added=#{result[:added]}"
  result
end

#free_energy(domain: nil) ⇒ Object



50
51
52
53
54
55
56
57
58
59
# File 'lib/legion/extensions/agentic/inference/predictive_processing/runners/predictive_processing.rb', line 50

def free_energy(domain: nil, **)
  if domain
    fe = default_processor.free_energy_for(domain.to_sym)
    return { domain: domain, free_energy: nil, reason: :domain_not_found } if fe.nil?

    { domain: domain, free_energy: fe }
  else
    { global_free_energy: default_processor.global_free_energy }
  end
end

#inference_mode(domain:) ⇒ Object



42
43
44
45
46
47
48
# File 'lib/legion/extensions/agentic/inference/predictive_processing/runners/predictive_processing.rb', line 42

def inference_mode(domain:, **)
  return { mode: nil, reason: :missing_domain } if domain.nil?

  mode = default_processor.inference_mode(domain.to_sym)
  log.debug "[predictive_processing] inference_mode domain=#{domain} mode=#{mode}"
  { domain: domain, mode: mode }
end

#models_needing_updateObject



61
62
63
64
65
# File 'lib/legion/extensions/agentic/inference/predictive_processing/runners/predictive_processing.rb', line 61

def models_needing_update(**)
  needing = default_processor.models_needing_update
  log.debug "[predictive_processing] models_needing_update count=#{needing.size}"
  { count: needing.size, models: needing }
end

#observe_outcome(domain:, actual:, predicted:) ⇒ Object



30
31
32
33
34
35
36
37
38
39
40
# File 'lib/legion/extensions/agentic/inference/predictive_processing/runners/predictive_processing.rb', line 30

def observe_outcome(domain:, actual:, predicted:, **)
  return { observed: false, reason: :missing_domain } if domain.nil?

  result = default_processor.observe(
    domain:    domain.to_sym,
    actual:    actual,
    predicted: predicted
  )
  log_observe(domain, result)
  result
end

#predict_from_model(domain:, context: {}) ⇒ Object



21
22
23
24
25
26
27
28
# File 'lib/legion/extensions/agentic/inference/predictive_processing/runners/predictive_processing.rb', line 21

def predict_from_model(domain:, context: {}, **)
  return { predicted: false, reason: :missing_domain } if domain.nil?

  prediction = default_processor.predict(domain: domain.to_sym, context: context)
  log.debug "[predictive_processing] predict domain=#{domain} " \
            "expected=#{prediction[:expected_value]&.round(3)}"
  { predicted: true, domain: domain, prediction: prediction }
end

#predictive_processing_statsObject



79
80
81
82
83
# File 'lib/legion/extensions/agentic/inference/predictive_processing/runners/predictive_processing.rb', line 79

def predictive_processing_stats(**)
  stats = default_processor.to_h
  log.debug "[predictive_processing] stats global_fe=#{stats[:global_free_energy]&.round(3)}"
  { success: true, stats: stats }
end

#update_predictive_processingObject



73
74
75
76
77
# File 'lib/legion/extensions/agentic/inference/predictive_processing/runners/predictive_processing.rb', line 73

def update_predictive_processing(**)
  default_processor.tick
  log.debug '[predictive_processing] tick: precision decayed on all models'
  { ticked: true, model_count: default_processor.models.size }
end