Class: Legion::Extensions::Agentic::Self::Agency::Helpers::OutcomeEvent

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(domain:, outcome_type:, source: :mastery, magnitude: 1.0, attribution: :full_agency) ⇒ OutcomeEvent

Returns a new instance of OutcomeEvent.



14
15
16
17
18
19
20
21
22
# File 'lib/legion/extensions/agentic/self/agency/helpers/outcome_event.rb', line 14

def initialize(domain:, outcome_type:, source: :mastery, magnitude: 1.0, attribution: :full_agency)
  @id          = SecureRandom.uuid
  @domain      = domain
  @outcome_type = outcome_type
  @source      = source
  @magnitude   = magnitude.clamp(0.0, 1.0)
  @attribution = attribution
  @timestamp   = Time.now.utc
end

Instance Attribute Details

#attributionObject (readonly)

Returns the value of attribute attribution.



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

def attribution
  @attribution
end

#domainObject (readonly)

Returns the value of attribute domain.



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

def domain
  @domain
end

#idObject (readonly)

Returns the value of attribute id.



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

def id
  @id
end

#magnitudeObject (readonly)

Returns the value of attribute magnitude.



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

def magnitude
  @magnitude
end

#outcome_typeObject (readonly)

Returns the value of attribute outcome_type.



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

def outcome_type
  @outcome_type
end

#sourceObject (readonly)

Returns the value of attribute source.



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

def source
  @source
end

#timestampObject (readonly)

Returns the value of attribute timestamp.



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

def timestamp
  @timestamp
end

Instance Method Details

#attributed_magnitudeObject



28
29
30
31
# File 'lib/legion/extensions/agentic/self/agency/helpers/outcome_event.rb', line 28

def attributed_magnitude
  level = Constants::ATTRIBUTION_LEVELS[@attribution] || 0.5
  @magnitude * level
end

#success?Boolean

Returns:

  • (Boolean)


24
25
26
# File 'lib/legion/extensions/agentic/self/agency/helpers/outcome_event.rb', line 24

def success?
  %i[success partial_success].include?(@outcome_type)
end

#to_hObject



33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/legion/extensions/agentic/self/agency/helpers/outcome_event.rb', line 33

def to_h
  {
    id:                   @id,
    domain:               @domain,
    outcome_type:         @outcome_type,
    source:               @source,
    magnitude:            @magnitude,
    attribution:          @attribution,
    success:              success?,
    attributed_magnitude: attributed_magnitude.round(4),
    timestamp:            @timestamp
  }
end