Class: Legion::Extensions::Agentic::Self::Anchor::Helpers::Anchor

Inherits:
Object
  • Object
show all
Defined in:
lib/legion/extensions/agentic/self/anchor/helpers/anchor.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(anchor_type:, domain:, content:, reference_value: nil, grip: nil, weight: nil) ⇒ Anchor

Returns a new instance of Anchor.



14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/legion/extensions/agentic/self/anchor/helpers/anchor.rb', line 14

def initialize(anchor_type:, domain:, content:,
               reference_value: nil, grip: nil, weight: nil)
  validate_anchor_type!(anchor_type)
  @id              = SecureRandom.uuid
  @anchor_type     = anchor_type.to_sym
  @domain          = domain.to_sym
  @content         = content.to_s
  @reference_value = (reference_value || 0.5).to_f.clamp(0.0, 1.0).round(10)
  @grip            = (grip || 0.7).to_f.clamp(0.0, 1.0).round(10)
  @weight          = (weight || 0.5).to_f.clamp(0.0, 1.0).round(10)
  @created_at      = Time.now.utc
end

Instance Attribute Details

#anchor_typeObject (readonly)

Returns the value of attribute anchor_type.



10
11
12
# File 'lib/legion/extensions/agentic/self/anchor/helpers/anchor.rb', line 10

def anchor_type
  @anchor_type
end

#contentObject (readonly)

Returns the value of attribute content.



10
11
12
# File 'lib/legion/extensions/agentic/self/anchor/helpers/anchor.rb', line 10

def content
  @content
end

#created_atObject (readonly)

Returns the value of attribute created_at.



10
11
12
# File 'lib/legion/extensions/agentic/self/anchor/helpers/anchor.rb', line 10

def created_at
  @created_at
end

#domainObject (readonly)

Returns the value of attribute domain.



10
11
12
# File 'lib/legion/extensions/agentic/self/anchor/helpers/anchor.rb', line 10

def domain
  @domain
end

#gripObject

Returns the value of attribute grip.



12
13
14
# File 'lib/legion/extensions/agentic/self/anchor/helpers/anchor.rb', line 12

def grip
  @grip
end

#idObject (readonly)

Returns the value of attribute id.



10
11
12
# File 'lib/legion/extensions/agentic/self/anchor/helpers/anchor.rb', line 10

def id
  @id
end

#reference_valueObject (readonly)

Returns the value of attribute reference_value.



10
11
12
# File 'lib/legion/extensions/agentic/self/anchor/helpers/anchor.rb', line 10

def reference_value
  @reference_value
end

#weightObject

Returns the value of attribute weight.



12
13
14
# File 'lib/legion/extensions/agentic/self/anchor/helpers/anchor.rb', line 12

def weight
  @weight
end

Instance Method Details

#bias_pull(new_value) ⇒ Object



35
36
37
38
39
# File 'lib/legion/extensions/agentic/self/anchor/helpers/anchor.rb', line 35

def bias_pull(new_value)
  pull_strength = @grip * @weight
  adjusted = new_value + ((reference_value - new_value) * pull_strength)
  adjusted.clamp(0.0, 1.0).round(10)
end

#drag!(rate: Constants::DRAG_RATE) ⇒ Object



27
28
29
# File 'lib/legion/extensions/agentic/self/anchor/helpers/anchor.rb', line 27

def drag!(rate: Constants::DRAG_RATE)
  @grip = (@grip + rate.abs).clamp(0.0, 1.0).round(10)
end

#drift!(rate: Constants::DRIFT_RATE) ⇒ Object



31
32
33
# File 'lib/legion/extensions/agentic/self/anchor/helpers/anchor.rb', line 31

def drift!(rate: Constants::DRIFT_RATE)
  @grip = (@grip - rate.abs).clamp(0.0, 1.0).round(10)
end

#drifting?Boolean

Returns:

  • (Boolean)


45
46
47
# File 'lib/legion/extensions/agentic/self/anchor/helpers/anchor.rb', line 45

def drifting?
  @grip < 0.2
end

#grip_labelObject



57
58
59
# File 'lib/legion/extensions/agentic/self/anchor/helpers/anchor.rb', line 57

def grip_label
  Constants.label_for(Constants::GRIP_LABELS, @grip)
end

#heavy?Boolean

Returns:

  • (Boolean)


49
50
51
# File 'lib/legion/extensions/agentic/self/anchor/helpers/anchor.rb', line 49

def heavy?
  @weight >= 0.7
end

#ironclad?Boolean

Returns:

  • (Boolean)


41
42
43
# File 'lib/legion/extensions/agentic/self/anchor/helpers/anchor.rb', line 41

def ironclad?
  @grip >= 0.8
end

#light?Boolean

Returns:

  • (Boolean)


53
54
55
# File 'lib/legion/extensions/agentic/self/anchor/helpers/anchor.rb', line 53

def light?
  @weight < 0.3
end

#to_hObject



61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# File 'lib/legion/extensions/agentic/self/anchor/helpers/anchor.rb', line 61

def to_h
  {
    id:              @id,
    anchor_type:     @anchor_type,
    domain:          @domain,
    content:         @content,
    reference_value: @reference_value,
    grip:            @grip,
    weight:          @weight,
    grip_label:      grip_label,
    ironclad:        ironclad?,
    drifting:        drifting?,
    created_at:      @created_at
  }
end