Class: Legion::Extensions::Agentic::Inference::CausalAttribution::Helpers::Attribution

Inherits:
Object
  • Object
show all
Defined in:
lib/legion/extensions/agentic/inference/causal_attribution/helpers/attribution.rb

Constant Summary collapse

MAX_ATTRIBUTIONS =
200
MAX_HISTORY =
300
LOCUS_VALUES =
%i[internal external].freeze
STABILITY_VALUES =
%i[stable unstable].freeze
CONTROLLABILITY_VALUES =
%i[controllable uncontrollable].freeze
DEFAULT_CONFIDENCE =
0.5
CONFIDENCE_FLOOR =
0.0
CONFIDENCE_CEILING =
1.0
DECAY_RATE =
0.02
ATTRIBUTION_EMOTIONS =
{
  %i[internal stable controllable]     => :guilt,
  %i[internal stable uncontrollable]   => :shame,
  %i[internal unstable controllable]   => :regret,
  %i[internal unstable uncontrollable] => :surprise,
  %i[external stable controllable]     => :anger,
  %i[external stable uncontrollable]   => :helplessness,
  %i[external unstable controllable]   => :frustration,
  %i[external unstable uncontrollable] => :relief
}.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(event:, outcome:, domain:, locus:, stability:, controllability:, confidence: DEFAULT_CONFIDENCE) ⇒ Attribution

Returns a new instance of Attribution.



38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/legion/extensions/agentic/inference/causal_attribution/helpers/attribution.rb', line 38

def initialize(event:, outcome:, domain:, locus:, stability:, controllability:,
               confidence: DEFAULT_CONFIDENCE)
  @id                = SecureRandom.uuid
  @event             = event
  @outcome           = outcome
  @domain            = domain
  @locus             = locus
  @stability         = stability
  @controllability   = controllability
  @confidence        = confidence.clamp(CONFIDENCE_FLOOR, CONFIDENCE_CEILING)
  @emotional_response = ATTRIBUTION_EMOTIONS[pattern]
  @created_at        = Time.now.utc
end

Instance Attribute Details

#confidenceObject (readonly)

Returns the value of attribute confidence.



35
36
37
# File 'lib/legion/extensions/agentic/inference/causal_attribution/helpers/attribution.rb', line 35

def confidence
  @confidence
end

#controllabilityObject (readonly)

Returns the value of attribute controllability.



35
36
37
# File 'lib/legion/extensions/agentic/inference/causal_attribution/helpers/attribution.rb', line 35

def controllability
  @controllability
end

#created_atObject (readonly)

Returns the value of attribute created_at.



35
36
37
# File 'lib/legion/extensions/agentic/inference/causal_attribution/helpers/attribution.rb', line 35

def created_at
  @created_at
end

#domainObject (readonly)

Returns the value of attribute domain.



35
36
37
# File 'lib/legion/extensions/agentic/inference/causal_attribution/helpers/attribution.rb', line 35

def domain
  @domain
end

#emotional_responseObject (readonly)

Returns the value of attribute emotional_response.



35
36
37
# File 'lib/legion/extensions/agentic/inference/causal_attribution/helpers/attribution.rb', line 35

def emotional_response
  @emotional_response
end

#eventObject (readonly)

Returns the value of attribute event.



35
36
37
# File 'lib/legion/extensions/agentic/inference/causal_attribution/helpers/attribution.rb', line 35

def event
  @event
end

#idObject (readonly)

Returns the value of attribute id.



35
36
37
# File 'lib/legion/extensions/agentic/inference/causal_attribution/helpers/attribution.rb', line 35

def id
  @id
end

#locusObject (readonly)

Returns the value of attribute locus.



35
36
37
# File 'lib/legion/extensions/agentic/inference/causal_attribution/helpers/attribution.rb', line 35

def locus
  @locus
end

#outcomeObject (readonly)

Returns the value of attribute outcome.



35
36
37
# File 'lib/legion/extensions/agentic/inference/causal_attribution/helpers/attribution.rb', line 35

def outcome
  @outcome
end

#stabilityObject (readonly)

Returns the value of attribute stability.



35
36
37
# File 'lib/legion/extensions/agentic/inference/causal_attribution/helpers/attribution.rb', line 35

def stability
  @stability
end

Instance Method Details

#controllable?Boolean

Returns:

  • (Boolean)


68
69
70
# File 'lib/legion/extensions/agentic/inference/causal_attribution/helpers/attribution.rb', line 68

def controllable?
  controllability == :controllable
end

#external?Boolean

Returns:

  • (Boolean)


60
61
62
# File 'lib/legion/extensions/agentic/inference/causal_attribution/helpers/attribution.rb', line 60

def external?
  locus == :external
end

#internal?Boolean

Returns:

  • (Boolean)


56
57
58
# File 'lib/legion/extensions/agentic/inference/causal_attribution/helpers/attribution.rb', line 56

def internal?
  locus == :internal
end

#patternObject



52
53
54
# File 'lib/legion/extensions/agentic/inference/causal_attribution/helpers/attribution.rb', line 52

def pattern
  [locus, stability, controllability]
end

#stable?Boolean

Returns:

  • (Boolean)


64
65
66
# File 'lib/legion/extensions/agentic/inference/causal_attribution/helpers/attribution.rb', line 64

def stable?
  stability == :stable
end

#to_hObject



72
73
74
75
76
77
78
79
80
81
82
83
84
85
# File 'lib/legion/extensions/agentic/inference/causal_attribution/helpers/attribution.rb', line 72

def to_h
  {
    id:                 id,
    event:              event,
    outcome:            outcome,
    domain:             domain,
    locus:              locus,
    stability:          stability,
    controllability:    controllability,
    confidence:         confidence,
    emotional_response: emotional_response,
    created_at:         created_at
  }
end