Class: Legion::Extensions::Agentic::Inference::Affordance::Helpers::AffordanceItem

Inherits:
Object
  • Object
show all
Includes:
Constants
Defined in:
lib/legion/extensions/agentic/inference/affordance/helpers/affordance_item.rb

Constant Summary

Constants included from Constants

Constants::ACTIONABLE_THRESHOLD, Constants::AFFORDANCE_TYPES, Constants::CAPABILITY_MATCH_THRESHOLD, Constants::DEFAULT_RELEVANCE, Constants::MAX_AFFORDANCES, Constants::MAX_CAPABILITIES, Constants::MAX_ENVIRONMENT_PROPS, Constants::MAX_HISTORY, Constants::RELEVANCE_DECAY, Constants::RELEVANCE_FLOOR, Constants::RELEVANCE_LABELS, Constants::URGENCY_BOOST

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(id:, action:, domain:, affordance_type:, requires: [], relevance: DEFAULT_RELEVANCE) ⇒ AffordanceItem

Returns a new instance of AffordanceItem.



15
16
17
18
19
20
21
22
23
# File 'lib/legion/extensions/agentic/inference/affordance/helpers/affordance_item.rb', line 15

def initialize(id:, action:, domain:, affordance_type:, requires: [], relevance: DEFAULT_RELEVANCE)
  @id              = id
  @action          = action
  @domain          = domain
  @affordance_type = affordance_type
  @requires        = Array(requires)
  @relevance       = relevance.to_f.clamp(0.0, 1.0)
  @detected_at     = Time.now.utc
end

Instance Attribute Details

#actionObject (readonly)

Returns the value of attribute action.



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

def action
  @action
end

#affordance_typeObject (readonly)

Returns the value of attribute affordance_type.



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

def affordance_type
  @affordance_type
end

#detected_atObject (readonly)

Returns the value of attribute detected_at.



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

def detected_at
  @detected_at
end

#domainObject (readonly)

Returns the value of attribute domain.



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

def domain
  @domain
end

#idObject (readonly)

Returns the value of attribute id.



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

def id
  @id
end

#relevanceObject

Returns the value of attribute relevance.



13
14
15
# File 'lib/legion/extensions/agentic/inference/affordance/helpers/affordance_item.rb', line 13

def relevance
  @relevance
end

#requiresObject (readonly)

Returns the value of attribute requires.



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

def requires
  @requires
end

Instance Method Details

#actionable?Boolean

Returns:

  • (Boolean)


25
26
27
28
# File 'lib/legion/extensions/agentic/inference/affordance/helpers/affordance_item.rb', line 25

def actionable?
  %i[action_possible resource_available opportunity].include?(@affordance_type) &&
    @relevance >= ACTIONABLE_THRESHOLD
end

#blocked?Boolean

Returns:

  • (Boolean)


30
31
32
# File 'lib/legion/extensions/agentic/inference/affordance/helpers/affordance_item.rb', line 30

def blocked?
  @affordance_type == :action_blocked
end

#decayObject



42
43
44
# File 'lib/legion/extensions/agentic/inference/affordance/helpers/affordance_item.rb', line 42

def decay
  @relevance = [@relevance - RELEVANCE_DECAY, 0.0].max
end

#faded?Boolean

Returns:

  • (Boolean)


46
47
48
# File 'lib/legion/extensions/agentic/inference/affordance/helpers/affordance_item.rb', line 46

def faded?
  @relevance <= RELEVANCE_FLOOR
end

#relevance_labelObject



50
51
52
53
# File 'lib/legion/extensions/agentic/inference/affordance/helpers/affordance_item.rb', line 50

def relevance_label
  RELEVANCE_LABELS.each { |range, lbl| return lbl if range.cover?(@relevance) }
  :negligible
end

#risky?Boolean

Returns:

  • (Boolean)


34
35
36
# File 'lib/legion/extensions/agentic/inference/affordance/helpers/affordance_item.rb', line 34

def risky?
  @affordance_type == :action_risky
end

#threatening?Boolean

Returns:

  • (Boolean)


38
39
40
# File 'lib/legion/extensions/agentic/inference/affordance/helpers/affordance_item.rb', line 38

def threatening?
  @affordance_type == :threat
end

#to_hObject



55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/legion/extensions/agentic/inference/affordance/helpers/affordance_item.rb', line 55

def to_h
  {
    id:              @id,
    action:          @action,
    domain:          @domain,
    affordance_type: @affordance_type,
    requires:        @requires,
    relevance:       @relevance.round(4),
    relevance_label: relevance_label,
    actionable:      actionable?,
    blocked:         blocked?,
    risky:           risky?
  }
end