Class: Legion::Extensions::Agentic::Inference::Intuition::Helpers::Heuristic

Inherits:
Object
  • Object
show all
Includes:
Constants
Defined in:
lib/legion/extensions/agentic/inference/intuition/helpers/heuristic.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

#initialize(id:, name:, heuristic_type:, domain: :general) ⇒ Heuristic

Returns a new instance of Heuristic.



14
15
16
17
18
19
20
21
# File 'lib/legion/extensions/agentic/inference/intuition/helpers/heuristic.rb', line 14

def initialize(id:, name:, heuristic_type:, domain: :general)
  @id             = id
  @name           = name
  @heuristic_type = resolve_type(heuristic_type)
  @domain         = domain
  @uses           = 0
  @successes      = 0
end

Instance Attribute Details

#domainObject (readonly)

Returns the value of attribute domain.



12
13
14
# File 'lib/legion/extensions/agentic/inference/intuition/helpers/heuristic.rb', line 12

def domain
  @domain
end

#heuristic_typeObject (readonly)

Returns the value of attribute heuristic_type.



12
13
14
# File 'lib/legion/extensions/agentic/inference/intuition/helpers/heuristic.rb', line 12

def heuristic_type
  @heuristic_type
end

#idObject (readonly)

Returns the value of attribute id.



12
13
14
# File 'lib/legion/extensions/agentic/inference/intuition/helpers/heuristic.rb', line 12

def id
  @id
end

#nameObject (readonly)

Returns the value of attribute name.



12
13
14
# File 'lib/legion/extensions/agentic/inference/intuition/helpers/heuristic.rb', line 12

def name
  @name
end

#successesObject (readonly)

Returns the value of attribute successes.



12
13
14
# File 'lib/legion/extensions/agentic/inference/intuition/helpers/heuristic.rb', line 12

def successes
  @successes
end

#usesObject (readonly)

Returns the value of attribute uses.



12
13
14
# File 'lib/legion/extensions/agentic/inference/intuition/helpers/heuristic.rb', line 12

def uses
  @uses
end

Instance Method Details

#applyObject



23
24
25
# File 'lib/legion/extensions/agentic/inference/intuition/helpers/heuristic.rb', line 23

def apply
  @uses += 1
end

#effective?Boolean

Returns:

  • (Boolean)


37
38
39
# File 'lib/legion/extensions/agentic/inference/intuition/helpers/heuristic.rb', line 37

def effective?
  @uses >= 3 && success_rate >= 0.6
end

#record_outcome(success:) ⇒ Object



27
28
29
# File 'lib/legion/extensions/agentic/inference/intuition/helpers/heuristic.rb', line 27

def record_outcome(success:)
  @successes += 1 if success
end

#success_rateObject



31
32
33
34
35
# File 'lib/legion/extensions/agentic/inference/intuition/helpers/heuristic.rb', line 31

def success_rate
  return 0.0 if @uses.zero?

  @successes.to_f / @uses
end

#to_hObject



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

def to_h
  {
    id:             @id,
    name:           @name,
    heuristic_type: @heuristic_type,
    domain:         @domain,
    uses:           @uses,
    successes:      @successes,
    success_rate:   success_rate.round(4),
    effective:      effective?
  }
end