Class: Legion::Extensions::Agentic::Integration::PhenomenalBinding::Helpers::BindingEngine
- Inherits:
-
Object
- Object
- Legion::Extensions::Agentic::Integration::PhenomenalBinding::Helpers::BindingEngine
show all
- Includes:
- Constants
- Defined in:
- lib/legion/extensions/agentic/integration/phenomenal_binding/helpers/binding_engine.rb
Constant Summary
Constants included
from Constants
Constants::BINDING_BOOST, Constants::BINDING_DECAY, Constants::BINDING_TYPES, Constants::COHERENCE_LABELS, Constants::COHERENCE_THRESHOLD, Constants::DEFAULT_SALIENCE, Constants::MAX_BINDINGS, Constants::MAX_STREAMS, Constants::STREAM_TYPES
Instance Method Summary
collapse
Constructor Details
Returns a new instance of BindingEngine.
12
13
14
15
|
# File 'lib/legion/extensions/agentic/integration/phenomenal_binding/helpers/binding_engine.rb', line 12
def initialize
@streams = {}
@bindings = {}
end
|
Instance Method Details
#binding_by_type(binding_type:) ⇒ Object
76
77
78
|
# File 'lib/legion/extensions/agentic/integration/phenomenal_binding/helpers/binding_engine.rb', line 76
def binding_by_type(binding_type:)
@bindings.values.select { |b| b.binding_type == binding_type }
end
|
#consciousness_report ⇒ Object
100
101
102
103
104
105
106
107
108
109
110
111
112
|
# File 'lib/legion/extensions/agentic/integration/phenomenal_binding/helpers/binding_engine.rb', line 100
def consciousness_report
experience = unified_experience
distribution = coherence_distribution
{
unified_experience: experience&.to_h,
fragmentation_index: fragmentation_index,
coherence_distribution: distribution,
stream_count: @streams.size,
binding_count: @bindings.size,
unbound_count: unbound_streams.size
}
end
|
#create_binding(stream_ids:, binding_type:, attention_weight: 0.5) ⇒ Object
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
|
# File 'lib/legion/extensions/agentic/integration/phenomenal_binding/helpers/binding_engine.rb', line 31
def create_binding(stream_ids:, binding_type:, attention_weight: 0.5)
return nil unless BINDING_TYPES.include?(binding_type)
prune_bindings_if_full
valid_ids = stream_ids.select { |id| @streams.key?(id) }
coherence = compute_initial_coherence(valid_ids)
binding = BindingUnit.new(
stream_ids: valid_ids,
binding_type: binding_type,
coherence: coherence,
attention_weight: attention_weight
)
@bindings[binding.id] = binding
binding
end
|
#decay_all ⇒ Object
92
93
94
|
# File 'lib/legion/extensions/agentic/integration/phenomenal_binding/helpers/binding_engine.rb', line 92
def decay_all
@bindings.each_value(&:decay!)
end
|
#dissolve_binding(binding_id:) ⇒ Object
55
56
57
58
59
60
|
# File 'lib/legion/extensions/agentic/integration/phenomenal_binding/helpers/binding_engine.rb', line 55
def dissolve_binding(binding_id:)
return { status: :not_found, binding_id: binding_id } unless @bindings.key?(binding_id)
@bindings.delete(binding_id)
{ status: :dissolved, binding_id: binding_id }
end
|
#fragmentation_index ⇒ Object
69
70
71
72
73
74
|
# File 'lib/legion/extensions/agentic/integration/phenomenal_binding/helpers/binding_engine.rb', line 69
def fragmentation_index
total = @streams.size
return 0.0 if total.zero?
(unbound_streams.size.to_f / total).round(10)
end
|
#prune_incoherent ⇒ Object
96
97
98
|
# File 'lib/legion/extensions/agentic/integration/phenomenal_binding/helpers/binding_engine.rb', line 96
def prune_incoherent
@bindings.delete_if { |_, b| !b.coherent? }
end
|
#register_stream(stream_type:, content:, salience: DEFAULT_SALIENCE, domain: nil) ⇒ Object
17
18
19
20
21
22
23
24
25
26
27
28
29
|
# File 'lib/legion/extensions/agentic/integration/phenomenal_binding/helpers/binding_engine.rb', line 17
def register_stream(stream_type:, content:, salience: DEFAULT_SALIENCE, domain: nil)
return nil unless STREAM_TYPES.include?(stream_type)
prune_streams_if_full
stream = Stream.new(
stream_type: stream_type,
content: content,
salience: salience,
domain: domain
)
@streams[stream.id] = stream
stream
end
|
#reinforce_binding(binding_id:) ⇒ Object
47
48
49
50
51
52
53
|
# File 'lib/legion/extensions/agentic/integration/phenomenal_binding/helpers/binding_engine.rb', line 47
def reinforce_binding(binding_id:)
binding = @bindings[binding_id]
return { status: :not_found, binding_id: binding_id } unless binding
binding.reinforce!
{ status: :reinforced, binding_id: binding_id, coherence: binding.coherence }
end
|
#streams_for_binding(binding_id:) ⇒ Object
80
81
82
83
84
85
|
# File 'lib/legion/extensions/agentic/integration/phenomenal_binding/helpers/binding_engine.rb', line 80
def streams_for_binding(binding_id:)
binding = @bindings[binding_id]
return [] unless binding
binding.stream_ids.filter_map { |id| @streams[id] }
end
|
#to_h ⇒ Object
114
115
116
117
118
119
120
121
|
# File 'lib/legion/extensions/agentic/integration/phenomenal_binding/helpers/binding_engine.rb', line 114
def to_h
{
stream_count: @streams.size,
binding_count: @bindings.size,
unbound_count: unbound_streams.size,
fragmentation: fragmentation_index
}
end
|
#unbound_streams ⇒ Object
87
88
89
90
|
# File 'lib/legion/extensions/agentic/integration/phenomenal_binding/helpers/binding_engine.rb', line 87
def unbound_streams
bound_ids = @bindings.values.flat_map(&:stream_ids).to_set
@streams.values.reject { |s| bound_ids.include?(s.id) }
end
|
#unified_experience ⇒ Object
62
63
64
65
66
67
|
# File 'lib/legion/extensions/agentic/integration/phenomenal_binding/helpers/binding_engine.rb', line 62
def unified_experience
coherent = @bindings.values.select(&:coherent?)
return nil if coherent.empty?
coherent.max_by { |b| b.coherence * b.attention_weight }
end
|