Module: Legion::Extensions::Agentic::Inference::EnactiveCognition::Runners::EnactiveCognition

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

Instance Method Summary collapse

Instance Method Details

#adapt_sensorimotor_coupling(coupling_id:, new_perception:) ⇒ Object



41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/legion/extensions/agentic/inference/enactive_cognition/runners/enactive_cognition.rb', line 41

def adapt_sensorimotor_coupling(coupling_id:, new_perception:, **)
  result = enaction_engine.adapt_coupling(
    coupling_id:    coupling_id,
    new_perception: new_perception
  )
  unless result[:success]
    log.debug "[enactive_cognition] adapt failed: #{coupling_id[0..7]} not found"
    return result
  end

  log.info "[enactive_cognition] adapted #{coupling_id[0..7]} new_perception=#{new_perception}"
  result
end

#coupled_sensorimotor_loopsObject



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

def coupled_sensorimotor_loops(**)
  loops = enaction_engine.coupled_loops
  log.debug "[enactive_cognition] coupled loops count=#{loops.size}"
  { loops: loops.map(&:to_h), count: loops.size }
end

#create_sensorimotor_coupling(action:, perception:, domain:, loop_type: :sensorimotor) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/legion/extensions/agentic/inference/enactive_cognition/runners/enactive_cognition.rb', line 13

def create_sensorimotor_coupling(action:, perception:, domain:, loop_type: :sensorimotor, **)
  type = loop_type.is_a?(Symbol) ? loop_type : loop_type.to_sym
  loop = enaction_engine.create_coupling(
    action:     action,
    perception: perception,
    domain:     domain,
    loop_type:  type
  )
  log.debug "[enactive_cognition] created coupling id=#{loop.id[0..7]} " \
            "action=#{action} domain=#{domain} type=#{type}"
  { success: true, coupling: loop.to_h }
end

#domain_couplings(domain:) ⇒ Object



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

def domain_couplings(domain:, **)
  loops = enaction_engine.by_domain(domain: domain)
  log.debug "[enactive_cognition] domain=#{domain} loops=#{loops.size}"
  { domain: domain, loops: loops.map(&:to_h), count: loops.size }
end

#enactive_cognition_statsObject



99
100
101
102
103
104
# File 'lib/legion/extensions/agentic/inference/enactive_cognition/runners/enactive_cognition.rb', line 99

def enactive_cognition_stats(**)
  stats = enaction_engine.to_h
  log.debug "[enactive_cognition] stats couplings=#{stats[:coupling_count]} " \
            "coupled=#{stats[:coupled_count]}"
  { success: true, stats: stats }
end

#execute_enactive_action(coupling_id:, actual_perception:) ⇒ Object



26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/legion/extensions/agentic/inference/enactive_cognition/runners/enactive_cognition.rb', line 26

def execute_enactive_action(coupling_id:, actual_perception:, **)
  result = enaction_engine.execute_action(
    coupling_id:       coupling_id,
    actual_perception: actual_perception
  )
  unless result[:success]
    log.debug "[enactive_cognition] execute failed: #{coupling_id[0..7]} not found"
    return result
  end

  log.debug "[enactive_cognition] executed #{coupling_id[0..7]} " \
            "match=#{result[:match]} label=#{result[:coupling_label]}"
  result
end

#find_action_for_perception(perception:) ⇒ Object



55
56
57
58
59
60
61
62
63
64
# File 'lib/legion/extensions/agentic/inference/enactive_cognition/runners/enactive_cognition.rb', line 55

def find_action_for_perception(perception:, **)
  loop = enaction_engine.find_action_for(perception: perception)
  unless loop
    log.debug "[enactive_cognition] no coupled action found for perception=#{perception}"
    return { found: false, perception: perception }
  end

  log.debug "[enactive_cognition] found action=#{loop.action} for perception=#{perception}"
  { found: true, action: loop.action, coupling: loop.to_h }
end

#overall_enactive_couplingObject



84
85
86
87
88
89
# File 'lib/legion/extensions/agentic/inference/enactive_cognition/runners/enactive_cognition.rb', line 84

def overall_enactive_coupling(**)
  strength = enaction_engine.overall_coupling
  label    = coupling_label_for(strength)
  log.debug "[enactive_cognition] overall_coupling=#{strength.round(3)} label=#{label}"
  { overall_coupling: strength, coupling_label: label }
end

#strongest_couplings(limit: 5) ⇒ Object



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

def strongest_couplings(limit: 5, **)
  loops = enaction_engine.strongest_couplings(limit: limit)
  log.debug "[enactive_cognition] strongest couplings limit=#{limit} found=#{loops.size}"
  { loops: loops.map(&:to_h), count: loops.size }
end

#update_enactive_cognition(decay: false, prune: false) ⇒ Object



91
92
93
94
95
96
97
# File 'lib/legion/extensions/agentic/inference/enactive_cognition/runners/enactive_cognition.rb', line 91

def update_enactive_cognition(decay: false, prune: false, **)
  enaction_engine.decay_all if decay
  enaction_engine.prune_decoupled if prune
  log.debug "[enactive_cognition] update decay=#{decay} prune=#{prune} " \
            "remaining=#{enaction_engine.count}"
  { success: true, decay: decay, prune: prune, coupling_count: enaction_engine.count }
end