Class: Legion::Extensions::Agentic::Inference::Intuition::Helpers::IntuitionEngine
- Inherits:
-
Object
- Object
- Legion::Extensions::Agentic::Inference::Intuition::Helpers::IntuitionEngine
show all
- Includes:
- Constants
- Defined in:
- lib/legion/extensions/agentic/inference/intuition/helpers/intuition_engine.rb
Constant Summary
Constants included
from Constants
Constants::CONFIDENCE_CEILING, Constants::CONFIDENCE_FLOOR, Constants::CONFIDENCE_LABELS, Constants::DECAY_RATE, Constants::DEFAULT_CONFIDENCE, Constants::HEURISTIC_TYPES, Constants::INTUITION_MODES, Constants::MAX_HEURISTICS, Constants::MAX_HISTORY, Constants::MAX_PATTERNS, Constants::PATTERN_STATES, Constants::RECOGNITION_THRESHOLD, Constants::REINFORCEMENT_RATE, Constants::SPEED_MULTIPLIER, Constants::STATE_THRESHOLDS
Instance Attribute Summary collapse
Instance Method Summary
collapse
Constructor Details
Returns a new instance of IntuitionEngine.
14
15
16
17
18
19
20
|
# File 'lib/legion/extensions/agentic/inference/intuition/helpers/intuition_engine.rb', line 14
def initialize
@patterns = {}
@heuristics = {}
@pattern_count = 0
@heuristic_count = 0
@history = []
end
|
Instance Attribute Details
#heuristics ⇒ Object
Returns the value of attribute heuristics.
12
13
14
|
# File 'lib/legion/extensions/agentic/inference/intuition/helpers/intuition_engine.rb', line 12
def heuristics
@heuristics
end
|
#history ⇒ Object
Returns the value of attribute history.
12
13
14
|
# File 'lib/legion/extensions/agentic/inference/intuition/helpers/intuition_engine.rb', line 12
def history
@history
end
|
#patterns ⇒ Object
Returns the value of attribute patterns.
12
13
14
|
# File 'lib/legion/extensions/agentic/inference/intuition/helpers/intuition_engine.rb', line 12
def patterns
@patterns
end
|
Instance Method Details
#add_heuristic(name:, heuristic_type:, domain: :general) ⇒ Object
71
72
73
74
75
76
77
78
79
80
81
82
83
|
# File 'lib/legion/extensions/agentic/inference/intuition/helpers/intuition_engine.rb', line 71
def add_heuristic(name:, heuristic_type:, domain: :general)
return nil if @heuristics.size >= MAX_HEURISTICS
@heuristic_count += 1
heuristic = Heuristic.new(
id: :"heur_#{@heuristic_count}",
name: name,
heuristic_type: heuristic_type,
domain: domain
)
@heuristics[heuristic.id] = heuristic
heuristic
end
|
#apply_heuristic(heuristic_id:) ⇒ Object
85
86
87
88
89
90
91
92
|
# File 'lib/legion/extensions/agentic/inference/intuition/helpers/intuition_engine.rb', line 85
def apply_heuristic(heuristic_id:)
heuristic = @heuristics[heuristic_id]
return nil unless heuristic
heuristic.apply
record_event(:apply_heuristic, heuristic_id: heuristic_id)
heuristic.to_h
end
|
#decay_all ⇒ Object
117
118
119
|
# File 'lib/legion/extensions/agentic/inference/intuition/helpers/intuition_engine.rb', line 117
def decay_all
@patterns.each_value(&:decay)
end
|
#effective_heuristics ⇒ Object
109
110
111
|
# File 'lib/legion/extensions/agentic/inference/intuition/helpers/intuition_engine.rb', line 109
def effective_heuristics
@heuristics.values.select(&:effective?).map(&:to_h)
end
|
#expert_patterns ⇒ Object
105
106
107
|
# File 'lib/legion/extensions/agentic/inference/intuition/helpers/intuition_engine.rb', line 105
def expert_patterns
@patterns.values.select(&:expert?).map(&:to_h)
end
|
#intuit(input_cue:, domain: nil) ⇒ Object
47
48
49
50
51
52
53
54
55
56
57
58
59
60
|
# File 'lib/legion/extensions/agentic/inference/intuition/helpers/intuition_engine.rb', line 47
def intuit(input_cue:, domain: nil)
matches = recognize(input_cue: input_cue, domain: domain)
return nil if matches.empty?
best = matches.first
record_event(:intuit, pattern_id: best[:pattern].id, score: best[:score])
{
response: best[:pattern].response,
pattern_id: best[:pattern].id,
confidence: best[:pattern].strength,
match: best[:score],
mode: intuition_mode(best)
}
end
|
#learn_pattern(cue:, response:, domain: :general, strength: DEFAULT_CONFIDENCE) ⇒ Object
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
|
# File 'lib/legion/extensions/agentic/inference/intuition/helpers/intuition_engine.rb', line 22
def learn_pattern(cue:, response:, domain: :general, strength: DEFAULT_CONFIDENCE)
return nil if @patterns.size >= MAX_PATTERNS
@pattern_count += 1
pattern = Pattern.new(
id: :"pat_#{@pattern_count}",
cue: cue,
response: response,
domain: domain,
strength: strength
)
@patterns[pattern.id] = pattern
record_event(:learn, pattern_id: pattern.id)
pattern
end
|
#patterns_in(domain:) ⇒ Object
113
114
115
|
# File 'lib/legion/extensions/agentic/inference/intuition/helpers/intuition_engine.rb', line 113
def patterns_in(domain:)
domain_patterns(domain).map(&:to_h)
end
|
#recognize(input_cue:, domain: nil) ⇒ Object
38
39
40
41
42
43
44
45
|
# File 'lib/legion/extensions/agentic/inference/intuition/helpers/intuition_engine.rb', line 38
def recognize(input_cue:, domain: nil)
candidates = domain ? domain_patterns(domain) : @patterns.values
matches = candidates.filter_map do |p|
score = p.match_score(input_cue)
{ pattern: p, score: score } if score >= RECOGNITION_THRESHOLD
end
matches.sort_by { |m| -m[:score] }
end
|
#record_heuristic_outcome(heuristic_id:, success:) ⇒ Object
94
95
96
97
98
99
|
# File 'lib/legion/extensions/agentic/inference/intuition/helpers/intuition_engine.rb', line 94
def record_heuristic_outcome(heuristic_id:, success:)
heuristic = @heuristics[heuristic_id]
return nil unless heuristic
heuristic.record_outcome(success: success)
end
|
#reinforce_pattern(pattern_id:, success:) ⇒ Object
62
63
64
65
66
67
68
69
|
# File 'lib/legion/extensions/agentic/inference/intuition/helpers/intuition_engine.rb', line 62
def reinforce_pattern(pattern_id:, success:)
pattern = @patterns[pattern_id]
return nil unless pattern
pattern.reinforce(success: success)
record_event(:reinforce, pattern_id: pattern_id, success: success)
pattern.strength
end
|
#reliable_patterns ⇒ Object
101
102
103
|
# File 'lib/legion/extensions/agentic/inference/intuition/helpers/intuition_engine.rb', line 101
def reliable_patterns
@patterns.values.select(&:reliable?).map(&:to_h)
end
|
#to_h ⇒ Object
121
122
123
124
125
126
127
128
129
130
|
# File 'lib/legion/extensions/agentic/inference/intuition/helpers/intuition_engine.rb', line 121
def to_h
{
pattern_count: @patterns.size,
heuristic_count: @heuristics.size,
reliable_pattern_count: @patterns.values.count(&:reliable?),
expert_pattern_count: @patterns.values.count(&:expert?),
effective_heuristic_count: @heuristics.values.count(&:effective?),
history_size: @history.size
}
end
|