Module: Legion::Extensions::Agentic::Learning::Anchoring::Runners::Anchoring

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

Instance Method Summary collapse

Instance Method Details

#anchoring_statsObject



83
84
85
86
87
# File 'lib/legion/extensions/agentic/learning/anchoring/runners/anchoring.rb', line 83

def anchoring_stats(**)
  stats = anchor_store.to_h
  log.debug "[anchoring] stats domains=#{stats[:domain_count]} total=#{stats[:total_anchors]}"
  { success: true }.merge(stats)
end

#de_anchor(estimate:, domain: :general) ⇒ Object



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/legion/extensions/agentic/learning/anchoring/runners/anchoring.rb', line 33

def de_anchor(estimate:, domain: :general, **)
  anchor = anchor_store.strongest(domain: domain)
  if anchor.nil?
    log.debug "[anchoring] de_anchor domain=#{domain} no anchor found"
    return { success: true, corrected_estimate: estimate.to_f, anchor_bias: 0.0, domain: domain }
  end

  biased    = anchor.pull(estimate: estimate)
  bias      = biased - estimate.to_f
  corrected = estimate.to_f - bias

  log.debug "[anchoring] de_anchor domain=#{domain} estimate=#{estimate} " \
            "corrected=#{corrected.round(4)} bias=#{bias.round(4)}"

  {
    success:            true,
    corrected_estimate: corrected,
    original_estimate:  estimate.to_f,
    anchor_bias:        bias,
    anchor_value:       anchor.value,
    domain:             domain
  }
end

#domain_anchors(domain:) ⇒ Object



69
70
71
72
73
74
75
76
77
78
79
80
81
# File 'lib/legion/extensions/agentic/learning/anchoring/runners/anchoring.rb', line 69

def domain_anchors(domain:, **)
  domain   = domain.to_sym
  anchor   = anchor_store.strongest(domain: domain)
  all_list = anchor_store.instance_variable_get(:@anchors)[domain] || []
  log.debug "[anchoring] domain_anchors domain=#{domain} count=#{all_list.size}"
  {
    success:   true,
    domain:    domain,
    count:     all_list.size,
    strongest: anchor&.to_h,
    anchors:   all_list.map(&:to_h)
  }
end

#evaluate_estimate(estimate:, domain: :general) ⇒ Object



19
20
21
22
23
24
# File 'lib/legion/extensions/agentic/learning/anchoring/runners/anchoring.rb', line 19

def evaluate_estimate(estimate:, domain: :general, **)
  result = anchor_store.evaluate(estimate: estimate, domain: domain)
  log.debug "[anchoring] evaluate_estimate domain=#{domain} estimate=#{estimate} " \
            "anchored=#{result[:anchored_estimate].round(4)} pull=#{result[:pull_strength].round(4)}"
  { success: true }.merge(result)
end

#record_anchor(value:, domain: :general) ⇒ Object



13
14
15
16
17
# File 'lib/legion/extensions/agentic/learning/anchoring/runners/anchoring.rb', line 13

def record_anchor(value:, domain: :general, **)
  anchor = anchor_store.add(value: value, domain: domain)
  log.debug "[anchoring] record_anchor domain=#{domain} value=#{value} id=#{anchor.id}"
  { success: true, anchor: anchor.to_h }
end

#reference_frame(value:, domain: :general) ⇒ Object



26
27
28
29
30
31
# File 'lib/legion/extensions/agentic/learning/anchoring/runners/anchoring.rb', line 26

def reference_frame(value:, domain: :general, **)
  result = anchor_store.reference_frame(value: value, domain: domain)
  log.debug "[anchoring] reference_frame domain=#{domain} value=#{value} " \
            "gain_or_loss=#{result[:gain_or_loss]}"
  { success: true }.merge(result)
end

#shift_reference(domain:, new_reference:) ⇒ Object



57
58
59
60
61
# File 'lib/legion/extensions/agentic/learning/anchoring/runners/anchoring.rb', line 57

def shift_reference(domain:, new_reference:, **)
  result = anchor_store.shift_reference(domain: domain, new_reference: new_reference)
  log.info "[anchoring] shift_reference domain=#{domain} new=#{new_reference} significant=#{result[:significant]}"
  { success: true }.merge(result)
end

#update_anchoringObject



63
64
65
66
67
# File 'lib/legion/extensions/agentic/learning/anchoring/runners/anchoring.rb', line 63

def update_anchoring(**)
  pruned = anchor_store.decay_all
  log.debug "[anchoring] update_anchoring pruned=#{pruned}"
  { success: true, pruned: pruned }
end