lex-agentic-inference 0.1.1 → 0.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (34) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +9 -0
  3. data/README.md +2 -2
  4. data/lex-agentic-inference.gemspec +8 -0
  5. data/lib/legion/extensions/agentic/inference/abductive/runners/abductive_reasoning.rb +19 -19
  6. data/lib/legion/extensions/agentic/inference/affordance/runners/affordance.rb +6 -6
  7. data/lib/legion/extensions/agentic/inference/analogical/runners/analogical_reasoning.rb +17 -14
  8. data/lib/legion/extensions/agentic/inference/argument_mapping/runners/argument_mapping.rb +10 -10
  9. data/lib/legion/extensions/agentic/inference/bayesian/runners/bayesian_belief.rb +14 -14
  10. data/lib/legion/extensions/agentic/inference/causal_attribution/runners/causal_attribution.rb +13 -13
  11. data/lib/legion/extensions/agentic/inference/causal_reasoning/runners/causal_reasoning.rb +14 -14
  12. data/lib/legion/extensions/agentic/inference/coherence/runners/cognitive_coherence.rb +16 -16
  13. data/lib/legion/extensions/agentic/inference/counterfactual/runners/counterfactual.rb +11 -11
  14. data/lib/legion/extensions/agentic/inference/debugging/runners/cognitive_debugging.rb +29 -29
  15. data/lib/legion/extensions/agentic/inference/enactive_cognition/runners/enactive_cognition.rb +17 -17
  16. data/lib/legion/extensions/agentic/inference/expectation_violation/runners/expectation_violation.rb +12 -12
  17. data/lib/legion/extensions/agentic/inference/gravity/runners/gravity.rb +16 -16
  18. data/lib/legion/extensions/agentic/inference/horizon/runners/cognitive_horizon.rb +10 -10
  19. data/lib/legion/extensions/agentic/inference/hypothesis_testing/runners/hypothesis_testing.rb +11 -11
  20. data/lib/legion/extensions/agentic/inference/magnet/helpers/magnet_engine.rb +2 -0
  21. data/lib/legion/extensions/agentic/inference/magnet/runners/cognitive_magnet.rb +13 -13
  22. data/lib/legion/extensions/agentic/inference/momentum/runners/cognitive_momentum.rb +16 -16
  23. data/lib/legion/extensions/agentic/inference/perceptual_inference/helpers/perceptual_field.rb +2 -0
  24. data/lib/legion/extensions/agentic/inference/perceptual_inference/runners/perceptual_inference.rb +12 -12
  25. data/lib/legion/extensions/agentic/inference/prediction/runners/prediction.rb +9 -9
  26. data/lib/legion/extensions/agentic/inference/predictive_coding/runners/predictive_coding.rb +13 -13
  27. data/lib/legion/extensions/agentic/inference/predictive_processing/runners/predictive_processing.rb +11 -11
  28. data/lib/legion/extensions/agentic/inference/reality_testing/helpers/reality_engine.rb +5 -3
  29. data/lib/legion/extensions/agentic/inference/reality_testing/runners/reality_testing.rb +4 -4
  30. data/lib/legion/extensions/agentic/inference/schema/runners/schema.rb +8 -8
  31. data/lib/legion/extensions/agentic/inference/uncertainty_tolerance/runners/uncertainty_tolerance.rb +14 -14
  32. data/lib/legion/extensions/agentic/inference/version.rb +1 -1
  33. data/spec/spec_helper.rb +21 -23
  34. metadata +99 -1
@@ -12,16 +12,16 @@ module Legion
12
12
 
13
13
  def add_causal_variable(name:, domain: :general, **)
14
14
  if graph.variable_exists?(name)
15
- Legion::Logging.warn "[causal] add_variable duplicate: name=#{name}"
15
+ log.warn "[causal] add_variable duplicate: name=#{name}"
16
16
  return { success: false, reason: :limit_or_duplicate, name: name }
17
17
  end
18
18
 
19
19
  variable = graph.add_variable(name: name, domain: domain)
20
20
  if variable
21
- Legion::Logging.debug "[causal] add_variable: name=#{name} domain=#{domain}"
21
+ log.debug "[causal] add_variable: name=#{name} domain=#{domain}"
22
22
  { success: true, variable: variable }
23
23
  else
24
- Legion::Logging.warn "[causal] add_variable failed (limit): name=#{name}"
24
+ log.warn "[causal] add_variable failed (limit): name=#{name}"
25
25
  { success: false, reason: :limit_or_duplicate, name: name }
26
26
  end
27
27
  end
@@ -32,42 +32,42 @@ module Legion
32
32
  edge_type: edge_type, domain: domain, strength: strength)
33
33
  if edge
34
34
  str = edge.strength.round(2)
35
- Legion::Logging.debug "[causal] add_edge: #{cause}->#{effect} type=#{edge_type} str=#{str}"
35
+ log.debug "[causal] add_edge: #{cause}->#{effect} type=#{edge_type} str=#{str}"
36
36
  { success: true, edge: edge.to_h }
37
37
  else
38
- Legion::Logging.warn "[causal] add_edge failed: cause=#{cause} effect=#{effect} type=#{edge_type}"
38
+ log.warn "[causal] add_edge failed: cause=#{cause} effect=#{effect} type=#{edge_type}"
39
39
  { success: false, reason: :limit_or_invalid_type, cause: cause, effect: effect }
40
40
  end
41
41
  end
42
42
 
43
43
  def find_causes(variable:, **)
44
44
  edges = graph.causes_of(variable: variable)
45
- Legion::Logging.debug "[causal] find_causes: variable=#{variable} count=#{edges.size}"
45
+ log.debug "[causal] find_causes: variable=#{variable} count=#{edges.size}"
46
46
  { success: true, variable: variable, causes: edges.map(&:to_h), count: edges.size }
47
47
  end
48
48
 
49
49
  def find_effects(variable:, **)
50
50
  edges = graph.effects_of(variable: variable)
51
- Legion::Logging.debug "[causal] find_effects: variable=#{variable} count=#{edges.size}"
51
+ log.debug "[causal] find_effects: variable=#{variable} count=#{edges.size}"
52
52
  { success: true, variable: variable, effects: edges.map(&:to_h), count: edges.size }
53
53
  end
54
54
 
55
55
  def trace_causal_chain(from:, to:, max_depth: 5, **)
56
56
  paths = graph.causal_chain(from: from, to: to, max_depth: max_depth)
57
- Legion::Logging.debug "[causal] trace_chain: from=#{from} to=#{to} paths=#{paths.size}"
57
+ log.debug "[causal] trace_chain: from=#{from} to=#{to} paths=#{paths.size}"
58
58
  { success: true, from: from, to: to, paths: paths, path_count: paths.size }
59
59
  end
60
60
 
61
61
  def causal_intervention(variable:, value:, **)
62
62
  result = graph.intervene(variable: variable, value: value)
63
63
  count = result[:downstream_effects].size
64
- Legion::Logging.info "[causal] intervention: do(#{variable}=#{value}) downstream=#{count}"
64
+ log.info "[causal] intervention: do(#{variable}=#{value}) downstream=#{count}"
65
65
  { success: true }.merge(result)
66
66
  end
67
67
 
68
68
  def find_confounders(var_a:, var_b:, **)
69
69
  common = graph.confounders(var_a: var_a, var_b: var_b)
70
- Legion::Logging.debug "[causal] confounders: #{var_a} <-> #{var_b} count=#{common.size}"
70
+ log.debug "[causal] confounders: #{var_a} <-> #{var_b} count=#{common.size}"
71
71
  { success: true, var_a: var_a, var_b: var_b, confounders: common, count: common.size }
72
72
  end
73
73
 
@@ -76,10 +76,10 @@ module Legion
76
76
  if edge
77
77
  cnt = edge.evidence_count
78
78
  str = edge.strength.round(2)
79
- Legion::Logging.debug "[causal] add_evidence: edge=#{edge_id} count=#{cnt} strength=#{str}"
79
+ log.debug "[causal] add_evidence: edge=#{edge_id} count=#{cnt} strength=#{str}"
80
80
  { success: true, edge_id: edge_id, evidence_count: edge.evidence_count, strength: edge.strength }
81
81
  else
82
- Legion::Logging.warn "[causal] add_evidence failed: edge=#{edge_id} not found"
82
+ log.warn "[causal] add_evidence failed: edge=#{edge_id} not found"
83
83
  { success: false, reason: :edge_not_found, edge_id: edge_id }
84
84
  end
85
85
  end
@@ -87,13 +87,13 @@ module Legion
87
87
  def update_causal_reasoning(**)
88
88
  decayed = graph.decay_all
89
89
  pruned = graph.prune_weak
90
- Legion::Logging.debug "[causal] update: decayed=#{decayed} pruned=#{pruned}"
90
+ log.debug "[causal] update: decayed=#{decayed} pruned=#{pruned}"
91
91
  { success: true, decayed: decayed, pruned: pruned }
92
92
  end
93
93
 
94
94
  def causal_reasoning_stats(**)
95
95
  stats = graph.to_h
96
- Legion::Logging.debug "[causal] stats: #{stats.inspect}"
96
+ log.debug "[causal] stats: #{stats.inspect}"
97
97
  { success: true }.merge(stats)
98
98
  end
99
99
 
@@ -16,10 +16,10 @@ module Legion
16
16
 
17
17
  prop_id = engine.add_proposition(content: content, domain: domain, acceptance: acceptance)
18
18
  if prop_id
19
- Legion::Logging.debug "[cognitive_coherence] add_proposition domain=#{domain} id=#{prop_id[0..7]}"
19
+ log.debug "[cognitive_coherence] add_proposition domain=#{domain} id=#{prop_id[0..7]}"
20
20
  { success: true, proposition_id: prop_id, domain: domain, acceptance: acceptance }
21
21
  else
22
- Legion::Logging.warn '[cognitive_coherence] add_proposition failed: max propositions reached'
22
+ log.warn '[cognitive_coherence] add_proposition failed: max propositions reached'
23
23
  { success: false, reason: :max_propositions_reached }
24
24
  end
25
25
  end
@@ -37,8 +37,8 @@ module Legion
37
37
  positive: positive
38
38
  )
39
39
 
40
- Legion::Logging.debug "[cognitive_coherence] add_constraint type=#{constraint_type} " \
41
- "positive=#{positive} success=#{result[:success]}"
40
+ log.debug "[cognitive_coherence] add_constraint type=#{constraint_type} " \
41
+ "positive=#{positive} success=#{result[:success]}"
42
42
  result
43
43
  end
44
44
 
@@ -47,34 +47,34 @@ module Legion
47
47
  prop = engine.propositions[proposition_id]
48
48
 
49
49
  unless prop
50
- Legion::Logging.debug "[cognitive_coherence] compute_coherence: #{proposition_id[0..7]} not found"
50
+ log.debug "[cognitive_coherence] compute_coherence: #{proposition_id[0..7]} not found"
51
51
  return { success: false, reason: :not_found }
52
52
  end
53
53
 
54
- Legion::Logging.debug '[cognitive_coherence] compute_coherence ' \
55
- "id=#{proposition_id[0..7]} score=#{score.round(3)}"
54
+ log.debug '[cognitive_coherence] compute_coherence ' \
55
+ "id=#{proposition_id[0..7]} score=#{score.round(3)}"
56
56
  { success: true, proposition_id: proposition_id, coherence_score: score, state: prop.state }
57
57
  end
58
58
 
59
59
  def maximize_coherence(**)
60
60
  result = engine.maximize_coherence
61
61
  overall = result[:overall_coherence]&.round(3)
62
- Legion::Logging.info '[cognitive_coherence] maximize_coherence ' \
63
- "overall=#{overall} props=#{result[:proposition_count]}"
62
+ log.info '[cognitive_coherence] maximize_coherence ' \
63
+ "overall=#{overall} props=#{result[:proposition_count]}"
64
64
  result
65
65
  end
66
66
 
67
67
  def find_contradictions(**)
68
68
  pairs = engine.find_contradictions
69
- Legion::Logging.debug "[cognitive_coherence] find_contradictions count=#{pairs.size}"
69
+ log.debug "[cognitive_coherence] find_contradictions count=#{pairs.size}"
70
70
  { success: true, contradictions: pairs, count: pairs.size }
71
71
  end
72
72
 
73
73
  def coherence_partition(**)
74
74
  result = engine.partition
75
75
  totals = result.transform_values(&:size)
76
- Legion::Logging.debug "[cognitive_coherence] partition accepted=#{totals[:accepted]} " \
77
- "rejected=#{totals[:rejected]} undecided=#{totals[:undecided]}"
76
+ log.debug "[cognitive_coherence] partition accepted=#{totals[:accepted]} " \
77
+ "rejected=#{totals[:rejected]} undecided=#{totals[:undecided]}"
78
78
  { success: true, partition: result, counts: totals }
79
79
  end
80
80
 
@@ -83,8 +83,8 @@ module Legion
83
83
  decay_result = engine.decay_all
84
84
 
85
85
  overall = coherence_result[:overall_coherence]&.round(3)
86
- Legion::Logging.info "[cognitive_coherence] update overall=#{overall} " \
87
- "decayed=#{decay_result[:decayed_count]}"
86
+ log.info "[cognitive_coherence] update overall=#{overall} " \
87
+ "decayed=#{decay_result[:decayed_count]}"
88
88
  {
89
89
  success: true,
90
90
  overall_coherence: coherence_result[:overall_coherence],
@@ -96,8 +96,8 @@ module Legion
96
96
  def cognitive_coherence_stats(**)
97
97
  part = engine.partition
98
98
  counts = part.transform_values(&:size)
99
- Legion::Logging.debug "[cognitive_coherence] stats propositions=#{engine.propositions.size} " \
100
- "coherence=#{engine.overall_coherence.round(3)}"
99
+ log.debug "[cognitive_coherence] stats propositions=#{engine.propositions.size} " \
100
+ "coherence=#{engine.overall_coherence.round(3)}"
101
101
  {
102
102
  success: true,
103
103
  proposition_count: engine.propositions.size,
@@ -33,62 +33,62 @@ module Legion
33
33
  plausibility: plausibility
34
34
  )
35
35
 
36
- Legion::Logging.debug "[counterfactual] imagined: type=#{scenario_type} " \
37
- "domain=#{domain} id=#{scenario.id[0..7]}"
36
+ log.debug "[counterfactual] imagined: type=#{scenario_type} " \
37
+ "domain=#{domain} id=#{scenario.id[0..7]}"
38
38
 
39
39
  { success: true, scenario: scenario.to_h }
40
40
  end
41
41
 
42
42
  def generate_alternatives(actual_outcome:, domain:, **)
43
43
  alternatives = engine.generate_alternatives(actual_outcome: actual_outcome, domain: domain)
44
- Legion::Logging.debug "[counterfactual] generated #{alternatives.size} alternatives for domain=#{domain}"
44
+ log.debug "[counterfactual] generated #{alternatives.size} alternatives for domain=#{domain}"
45
45
  { success: true, alternatives: alternatives.map(&:to_h), count: alternatives.size }
46
46
  end
47
47
 
48
48
  def resolve_counterfactual(scenario_id:, lesson:, **)
49
49
  scenario = engine.resolve(scenario_id: scenario_id, lesson: lesson)
50
50
  if scenario
51
- Legion::Logging.info "[counterfactual] resolved: id=#{scenario_id[0..7]} lesson=#{lesson[0..40]}"
51
+ log.info "[counterfactual] resolved: id=#{scenario_id[0..7]} lesson=#{lesson[0..40]}"
52
52
  { success: true, scenario: scenario.to_h }
53
53
  else
54
- Legion::Logging.debug "[counterfactual] resolve failed: id=#{scenario_id[0..7]} not found"
54
+ log.debug "[counterfactual] resolve failed: id=#{scenario_id[0..7]} not found"
55
55
  { success: false, reason: :not_found }
56
56
  end
57
57
  end
58
58
 
59
59
  def compute_regret(scenario_id:, **)
60
60
  regret = engine.compute_regret(scenario_id: scenario_id)
61
- Legion::Logging.debug "[counterfactual] regret: id=#{scenario_id[0..7]} value=#{regret.round(4)}"
61
+ log.debug "[counterfactual] regret: id=#{scenario_id[0..7]} value=#{regret.round(4)}"
62
62
  { success: true, scenario_id: scenario_id, regret: regret }
63
63
  end
64
64
 
65
65
  def net_regret_level(**)
66
66
  net = engine.net_regret
67
- Legion::Logging.debug "[counterfactual] net_regret=#{net.round(4)}"
67
+ log.debug "[counterfactual] net_regret=#{net.round(4)}"
68
68
  { success: true, net_regret: net }
69
69
  end
70
70
 
71
71
  def domain_regret(domain:, **)
72
72
  regret = engine.domain_regret(domain: domain)
73
- Legion::Logging.debug "[counterfactual] domain_regret: domain=#{domain} value=#{regret.round(4)}"
73
+ log.debug "[counterfactual] domain_regret: domain=#{domain} value=#{regret.round(4)}"
74
74
  { success: true, domain: domain, regret: regret }
75
75
  end
76
76
 
77
77
  def lessons_learned(**)
78
78
  lessons = engine.lessons_learned
79
- Legion::Logging.debug "[counterfactual] lessons_learned: count=#{lessons.size}"
79
+ log.debug "[counterfactual] lessons_learned: count=#{lessons.size}"
80
80
  { success: true, lessons: lessons.map(&:to_h), count: lessons.size }
81
81
  end
82
82
 
83
83
  def update_counterfactual(**)
84
84
  engine.regret_decay
85
- Legion::Logging.debug '[counterfactual] regret decay applied'
85
+ log.debug '[counterfactual] regret decay applied'
86
86
  { success: true, action: :regret_decay }
87
87
  end
88
88
 
89
89
  def counterfactual_stats(**)
90
90
  stats = engine.to_h
91
- Legion::Logging.debug "[counterfactual] stats: total=#{stats[:total]} unresolved=#{stats[:unresolved]}"
91
+ log.debug "[counterfactual] stats: total=#{stats[:total]} unresolved=#{stats[:unresolved]}"
92
92
  { success: true, stats: stats }
93
93
  end
94
94
 
@@ -12,7 +12,7 @@ module Legion
12
12
 
13
13
  def detect_error(error_type:, description:, severity:, source_phase:, confidence_at_detection: 0.5, **)
14
14
  unless Helpers::Constants::ERROR_TYPES.include?(error_type)
15
- Legion::Logging.debug "[cognitive_debugging] detect_error: invalid error_type=#{error_type}"
15
+ log.debug "[cognitive_debugging] detect_error: invalid error_type=#{error_type}"
16
16
  return { success: false, error: :invalid_error_type, valid: Helpers::Constants::ERROR_TYPES }
17
17
  end
18
18
 
@@ -25,11 +25,11 @@ module Legion
25
25
  )
26
26
 
27
27
  if err
28
- Legion::Logging.info "[cognitive_debugging] error detected: id=#{err.id[0..7]} type=#{error_type} " \
29
- "phase=#{source_phase} severity=#{err.severity_label}"
28
+ log.info "[cognitive_debugging] error detected: id=#{err.id[0..7]} type=#{error_type} " \
29
+ "phase=#{source_phase} severity=#{err.severity_label}"
30
30
  { success: true, error_id: err.id, error_type: error_type, severity_label: err.severity_label }
31
31
  else
32
- Legion::Logging.warn '[cognitive_debugging] detect_error: engine returned nil (cap reached?)'
32
+ log.warn '[cognitive_debugging] detect_error: engine returned nil (cap reached?)'
33
33
  { success: false, error: :cap_reached }
34
34
  end
35
35
  end
@@ -43,29 +43,29 @@ module Legion
43
43
  )
44
44
 
45
45
  if trace
46
- Legion::Logging.info "[cognitive_debugging] error traced: error_id=#{error_id[0..7]} " \
47
- "trace_id=#{trace.id[0..7]} depth=#{trace.depth} root_cause=#{root_cause}"
46
+ log.info "[cognitive_debugging] error traced: error_id=#{error_id[0..7]} " \
47
+ "trace_id=#{trace.id[0..7]} depth=#{trace.depth} root_cause=#{root_cause}"
48
48
  { success: true, trace_id: trace.id, depth: trace.depth, root_cause: root_cause }
49
49
  else
50
- Legion::Logging.debug "[cognitive_debugging] trace_error: error_id=#{error_id[0..7]} not found or cap"
50
+ log.debug "[cognitive_debugging] trace_error: error_id=#{error_id[0..7]} not found or cap"
51
51
  { success: false, error: :not_found_or_cap }
52
52
  end
53
53
  end
54
54
 
55
55
  def propose_correction(error_id:, strategy:, description:, **)
56
56
  unless Helpers::Constants::CORRECTION_STRATEGIES.include?(strategy)
57
- Legion::Logging.debug "[cognitive_debugging] propose_correction: invalid strategy=#{strategy}"
57
+ log.debug "[cognitive_debugging] propose_correction: invalid strategy=#{strategy}"
58
58
  return { success: false, error: :invalid_strategy, valid: Helpers::Constants::CORRECTION_STRATEGIES }
59
59
  end
60
60
 
61
61
  correction = engine.propose_correction(error_id: error_id, strategy: strategy, description: description)
62
62
 
63
63
  if correction
64
- Legion::Logging.info "[cognitive_debugging] correction proposed: error_id=#{error_id[0..7]} " \
65
- "correction_id=#{correction.id[0..7]} strategy=#{strategy}"
64
+ log.info "[cognitive_debugging] correction proposed: error_id=#{error_id[0..7]} " \
65
+ "correction_id=#{correction.id[0..7]} strategy=#{strategy}"
66
66
  { success: true, correction_id: correction.id, strategy: strategy }
67
67
  else
68
- Legion::Logging.debug "[cognitive_debugging] propose_correction: error_id=#{error_id[0..7]} not found"
68
+ log.debug "[cognitive_debugging] propose_correction: error_id=#{error_id[0..7]} not found"
69
69
  { success: false, error: :not_found }
70
70
  end
71
71
  end
@@ -74,10 +74,10 @@ module Legion
74
74
  correction = engine.apply_correction(correction_id: correction_id)
75
75
 
76
76
  if correction
77
- Legion::Logging.info "[cognitive_debugging] correction applied: id=#{correction_id[0..7]}"
77
+ log.info "[cognitive_debugging] correction applied: id=#{correction_id[0..7]}"
78
78
  { success: true, correction_id: correction_id, applied: true }
79
79
  else
80
- Legion::Logging.debug "[cognitive_debugging] apply_correction: id=#{correction_id[0..7]} not found"
80
+ log.debug "[cognitive_debugging] apply_correction: id=#{correction_id[0..7]} not found"
81
81
  { success: false, error: :not_found }
82
82
  end
83
83
  end
@@ -86,12 +86,12 @@ module Legion
86
86
  correction = engine.measure_correction(correction_id: correction_id, effectiveness: effectiveness)
87
87
 
88
88
  if correction
89
- Legion::Logging.info "[cognitive_debugging] correction measured: id=#{correction_id[0..7]} " \
90
- "effectiveness=#{correction.effectiveness} effective=#{correction.effective?}"
89
+ log.info "[cognitive_debugging] correction measured: id=#{correction_id[0..7]} " \
90
+ "effectiveness=#{correction.effectiveness} effective=#{correction.effective?}"
91
91
  { success: true, correction_id: correction_id, effectiveness: correction.effectiveness,
92
92
  effective: correction.effective? }
93
93
  else
94
- Legion::Logging.debug "[cognitive_debugging] measure_correction: id=#{correction_id[0..7]} not found"
94
+ log.debug "[cognitive_debugging] measure_correction: id=#{correction_id[0..7]} not found"
95
95
  { success: false, error: :not_found }
96
96
  end
97
97
  end
@@ -100,67 +100,67 @@ module Legion
100
100
  err = engine.resolve_error(error_id: error_id)
101
101
 
102
102
  if err
103
- Legion::Logging.info "[cognitive_debugging] error resolved: id=#{error_id[0..7]}"
103
+ log.info "[cognitive_debugging] error resolved: id=#{error_id[0..7]}"
104
104
  { success: true, error_id: error_id, resolved: true }
105
105
  else
106
- Legion::Logging.debug "[cognitive_debugging] resolve_error: id=#{error_id[0..7]} not found"
106
+ log.debug "[cognitive_debugging] resolve_error: id=#{error_id[0..7]} not found"
107
107
  { success: false, error: :not_found }
108
108
  end
109
109
  end
110
110
 
111
111
  def active_errors(**)
112
112
  errors = engine.active_errors
113
- Legion::Logging.debug "[cognitive_debugging] active_errors: count=#{errors.size}"
113
+ log.debug "[cognitive_debugging] active_errors: count=#{errors.size}"
114
114
  { success: true, errors: errors.map(&:to_h), count: errors.size }
115
115
  end
116
116
 
117
117
  def resolved_errors(**)
118
118
  errors = engine.resolved_errors
119
- Legion::Logging.debug "[cognitive_debugging] resolved_errors: count=#{errors.size}"
119
+ log.debug "[cognitive_debugging] resolved_errors: count=#{errors.size}"
120
120
  { success: true, errors: errors.map(&:to_h), count: errors.size }
121
121
  end
122
122
 
123
123
  def errors_by_type(**)
124
124
  tally = engine.errors_by_type
125
- Legion::Logging.debug "[cognitive_debugging] errors_by_type: types=#{tally.keys.join(',')}"
125
+ log.debug "[cognitive_debugging] errors_by_type: types=#{tally.keys.join(',')}"
126
126
  { success: true, tally: tally }
127
127
  end
128
128
 
129
129
  def errors_by_phase(**)
130
130
  tally = engine.errors_by_phase
131
- Legion::Logging.debug "[cognitive_debugging] errors_by_phase: phases=#{tally.keys.join(',')}"
131
+ log.debug "[cognitive_debugging] errors_by_phase: phases=#{tally.keys.join(',')}"
132
132
  { success: true, tally: tally }
133
133
  end
134
134
 
135
135
  def most_common_error_type(**)
136
136
  type = engine.most_common_error_type
137
- Legion::Logging.debug "[cognitive_debugging] most_common_error_type: type=#{type}"
137
+ log.debug "[cognitive_debugging] most_common_error_type: type=#{type}"
138
138
  { success: true, error_type: type }
139
139
  end
140
140
 
141
141
  def most_effective_strategy(**)
142
142
  strategy = engine.most_effective_strategy
143
- Legion::Logging.debug "[cognitive_debugging] most_effective_strategy: strategy=#{strategy}"
143
+ log.debug "[cognitive_debugging] most_effective_strategy: strategy=#{strategy}"
144
144
  { success: true, strategy: strategy }
145
145
  end
146
146
 
147
147
  def correction_success_rate(**)
148
148
  rate = engine.correction_success_rate
149
- Legion::Logging.debug "[cognitive_debugging] correction_success_rate: rate=#{rate}"
149
+ log.debug "[cognitive_debugging] correction_success_rate: rate=#{rate}"
150
150
  { success: true, rate: rate }
151
151
  end
152
152
 
153
153
  def debugging_report(**)
154
154
  report = engine.debugging_report
155
- Legion::Logging.info "[cognitive_debugging] debugging_report: total_errors=#{report[:total_errors]} " \
156
- "active=#{report[:active_errors]}"
155
+ log.info "[cognitive_debugging] debugging_report: total_errors=#{report[:total_errors]} " \
156
+ "active=#{report[:active_errors]}"
157
157
  { success: true, report: report }
158
158
  end
159
159
 
160
160
  def snapshot(**)
161
161
  data = engine.to_h
162
- Legion::Logging.debug "[cognitive_debugging] snapshot: errors=#{data[:errors].size} " \
163
- "traces=#{data[:traces].size} corrections=#{data[:corrections].size}"
162
+ log.debug "[cognitive_debugging] snapshot: errors=#{data[:errors].size} " \
163
+ "traces=#{data[:traces].size} corrections=#{data[:corrections].size}"
164
164
  { success: true, snapshot: data }
165
165
  end
166
166
 
@@ -18,8 +18,8 @@ module Legion
18
18
  domain: domain,
19
19
  loop_type: type
20
20
  )
21
- Legion::Logging.debug "[enactive_cognition] created coupling id=#{loop.id[0..7]} " \
22
- "action=#{action} domain=#{domain} type=#{type}"
21
+ log.debug "[enactive_cognition] created coupling id=#{loop.id[0..7]} " \
22
+ "action=#{action} domain=#{domain} type=#{type}"
23
23
  { success: true, coupling: loop.to_h }
24
24
  end
25
25
 
@@ -29,12 +29,12 @@ module Legion
29
29
  actual_perception: actual_perception
30
30
  )
31
31
  unless result[:success]
32
- Legion::Logging.debug "[enactive_cognition] execute failed: #{coupling_id[0..7]} not found"
32
+ log.debug "[enactive_cognition] execute failed: #{coupling_id[0..7]} not found"
33
33
  return result
34
34
  end
35
35
 
36
- Legion::Logging.debug "[enactive_cognition] executed #{coupling_id[0..7]} " \
37
- "match=#{result[:match]} label=#{result[:coupling_label]}"
36
+ log.debug "[enactive_cognition] executed #{coupling_id[0..7]} " \
37
+ "match=#{result[:match]} label=#{result[:coupling_label]}"
38
38
  result
39
39
  end
40
40
 
@@ -44,62 +44,62 @@ module Legion
44
44
  new_perception: new_perception
45
45
  )
46
46
  unless result[:success]
47
- Legion::Logging.debug "[enactive_cognition] adapt failed: #{coupling_id[0..7]} not found"
47
+ log.debug "[enactive_cognition] adapt failed: #{coupling_id[0..7]} not found"
48
48
  return result
49
49
  end
50
50
 
51
- Legion::Logging.info "[enactive_cognition] adapted #{coupling_id[0..7]} new_perception=#{new_perception}"
51
+ log.info "[enactive_cognition] adapted #{coupling_id[0..7]} new_perception=#{new_perception}"
52
52
  result
53
53
  end
54
54
 
55
55
  def find_action_for_perception(perception:, **)
56
56
  loop = enaction_engine.find_action_for(perception: perception)
57
57
  unless loop
58
- Legion::Logging.debug "[enactive_cognition] no coupled action found for perception=#{perception}"
58
+ log.debug "[enactive_cognition] no coupled action found for perception=#{perception}"
59
59
  return { found: false, perception: perception }
60
60
  end
61
61
 
62
- Legion::Logging.debug "[enactive_cognition] found action=#{loop.action} for perception=#{perception}"
62
+ log.debug "[enactive_cognition] found action=#{loop.action} for perception=#{perception}"
63
63
  { found: true, action: loop.action, coupling: loop.to_h }
64
64
  end
65
65
 
66
66
  def coupled_sensorimotor_loops(**)
67
67
  loops = enaction_engine.coupled_loops
68
- Legion::Logging.debug "[enactive_cognition] coupled loops count=#{loops.size}"
68
+ log.debug "[enactive_cognition] coupled loops count=#{loops.size}"
69
69
  { loops: loops.map(&:to_h), count: loops.size }
70
70
  end
71
71
 
72
72
  def domain_couplings(domain:, **)
73
73
  loops = enaction_engine.by_domain(domain: domain)
74
- Legion::Logging.debug "[enactive_cognition] domain=#{domain} loops=#{loops.size}"
74
+ log.debug "[enactive_cognition] domain=#{domain} loops=#{loops.size}"
75
75
  { domain: domain, loops: loops.map(&:to_h), count: loops.size }
76
76
  end
77
77
 
78
78
  def strongest_couplings(limit: 5, **)
79
79
  loops = enaction_engine.strongest_couplings(limit: limit)
80
- Legion::Logging.debug "[enactive_cognition] strongest couplings limit=#{limit} found=#{loops.size}"
80
+ log.debug "[enactive_cognition] strongest couplings limit=#{limit} found=#{loops.size}"
81
81
  { loops: loops.map(&:to_h), count: loops.size }
82
82
  end
83
83
 
84
84
  def overall_enactive_coupling(**)
85
85
  strength = enaction_engine.overall_coupling
86
86
  label = coupling_label_for(strength)
87
- Legion::Logging.debug "[enactive_cognition] overall_coupling=#{strength.round(3)} label=#{label}"
87
+ log.debug "[enactive_cognition] overall_coupling=#{strength.round(3)} label=#{label}"
88
88
  { overall_coupling: strength, coupling_label: label }
89
89
  end
90
90
 
91
91
  def update_enactive_cognition(decay: false, prune: false, **)
92
92
  enaction_engine.decay_all if decay
93
93
  enaction_engine.prune_decoupled if prune
94
- Legion::Logging.debug "[enactive_cognition] update decay=#{decay} prune=#{prune} " \
95
- "remaining=#{enaction_engine.count}"
94
+ log.debug "[enactive_cognition] update decay=#{decay} prune=#{prune} " \
95
+ "remaining=#{enaction_engine.count}"
96
96
  { success: true, decay: decay, prune: prune, coupling_count: enaction_engine.count }
97
97
  end
98
98
 
99
99
  def enactive_cognition_stats(**)
100
100
  stats = enaction_engine.to_h
101
- Legion::Logging.debug "[enactive_cognition] stats couplings=#{stats[:coupling_count]} " \
102
- "coupled=#{stats[:coupled_count]}"
101
+ log.debug "[enactive_cognition] stats couplings=#{stats[:coupling_count]} " \
102
+ "coupled=#{stats[:coupled_count]}"
103
103
  { success: true, stats: stats }
104
104
  end
105
105
 
@@ -17,48 +17,48 @@ module Legion
17
17
  expected_value: expected_value || Helpers::Constants::DEFAULT_EXPECTATION,
18
18
  tolerance: tolerance
19
19
  )
20
- Legion::Logging.debug "[expectation_violation] create id=#{exp.id[0..7]} " \
21
- "ctx=#{context} expected=#{exp.expected_value}"
20
+ log.debug "[expectation_violation] create id=#{exp.id[0..7]} " \
21
+ "ctx=#{context} expected=#{exp.expected_value}"
22
22
  { success: true, expectation: exp.to_h }
23
23
  end
24
24
 
25
25
  def evaluate_expectation(expectation_id:, actual_value:, **)
26
26
  result = engine.evaluate_against(expectation_id: expectation_id, actual_value: actual_value)
27
- Legion::Logging.debug "[expectation_violation] evaluate id=#{expectation_id[0..7]} " \
28
- "violated=#{result[:violated]} type=#{result[:type]}"
27
+ log.debug "[expectation_violation] evaluate id=#{expectation_id[0..7]} " \
28
+ "violated=#{result[:violated]} type=#{result[:type]}"
29
29
  result
30
30
  end
31
31
 
32
32
  def adapt_expectation_value(expectation_id:, actual_value:, **)
33
33
  result = engine.adapt_expectation(expectation_id: expectation_id, actual_value: actual_value)
34
- Legion::Logging.debug "[expectation_violation] adapt id=#{expectation_id[0..7]} " \
35
- "new=#{result[:new_expected]}"
34
+ log.debug "[expectation_violation] adapt id=#{expectation_id[0..7]} " \
35
+ "new=#{result[:new_expected]}"
36
36
  result
37
37
  end
38
38
 
39
39
  def recent_violations_report(limit: 10, **)
40
40
  violations = engine.recent_violations(limit: limit)
41
- Legion::Logging.debug "[expectation_violation] recent count=#{violations.size}"
41
+ log.debug "[expectation_violation] recent count=#{violations.size}"
42
42
  { success: true, violations: violations, count: violations.size }
43
43
  end
44
44
 
45
45
  def violations_by_type_report(type:, **)
46
46
  violations = engine.violations_by_type(type: type.to_sym)
47
- Legion::Logging.debug '[expectation_violation] by_type ' \
48
- "type=#{type} count=#{violations.size}"
47
+ log.debug '[expectation_violation] by_type ' \
48
+ "type=#{type} count=#{violations.size}"
49
49
  { success: true, violations: violations, count: violations.size }
50
50
  end
51
51
 
52
52
  def most_violated_expectations(limit: 5, **)
53
53
  exps = engine.most_violated(limit: limit)
54
- Legion::Logging.debug "[expectation_violation] most_violated count=#{exps.size}"
54
+ log.debug "[expectation_violation] most_violated count=#{exps.size}"
55
55
  { success: true, expectations: exps.map(&:to_h), count: exps.size }
56
56
  end
57
57
 
58
58
  def expectation_violation_stats(**)
59
59
  stats = engine.to_h
60
- Legion::Logging.debug '[expectation_violation] stats ' \
61
- "total=#{stats[:total_expectations]}"
60
+ log.debug '[expectation_violation] stats ' \
61
+ "total=#{stats[:total_expectations]}"
62
62
  { success: true }.merge(stats)
63
63
  end
64
64