Class: Legion::Extensions::Agentic::Inference::Affordance::Helpers::AffordanceField
- Inherits:
-
Object
- Object
- Legion::Extensions::Agentic::Inference::Affordance::Helpers::AffordanceField
show all
- Includes:
- Constants
- Defined in:
- lib/legion/extensions/agentic/inference/affordance/helpers/affordance_field.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
Returns a new instance of AffordanceField.
14
15
16
17
18
19
20
|
# File 'lib/legion/extensions/agentic/inference/affordance/helpers/affordance_field.rb', line 14
def initialize
@affordances = {}
@capabilities = {}
@environment = {}
@counter = 0
@history = []
end
|
Instance Attribute Details
#affordances ⇒ Object
Returns the value of attribute affordances.
12
13
14
|
# File 'lib/legion/extensions/agentic/inference/affordance/helpers/affordance_field.rb', line 12
def affordances
@affordances
end
|
#capabilities ⇒ Object
Returns the value of attribute capabilities.
12
13
14
|
# File 'lib/legion/extensions/agentic/inference/affordance/helpers/affordance_field.rb', line 12
def capabilities
@capabilities
end
|
#environment ⇒ Object
Returns the value of attribute environment.
12
13
14
|
# File 'lib/legion/extensions/agentic/inference/affordance/helpers/affordance_field.rb', line 12
def environment
@environment
end
|
Instance Method Details
#actionable_affordances ⇒ Object
56
57
58
|
# File 'lib/legion/extensions/agentic/inference/affordance/helpers/affordance_field.rb', line 56
def actionable_affordances
@affordances.values.select(&:actionable?).sort_by { |a| -a.relevance }.map(&:to_h)
end
|
#affordances_in(domain:) ⇒ Object
64
65
66
|
# File 'lib/legion/extensions/agentic/inference/affordance/helpers/affordance_field.rb', line 64
def affordances_in(domain:)
@affordances.values.select { |a| a.domain == domain }.map(&:to_h)
end
|
#decay_all ⇒ Object
68
69
70
71
|
# File 'lib/legion/extensions/agentic/inference/affordance/helpers/affordance_field.rb', line 68
def decay_all
@affordances.each_value(&:decay)
@affordances.reject! { |_, a| a.faded? }
end
|
#detect_affordance(action:, domain:, affordance_type:, requires: [], relevance: DEFAULT_RELEVANCE) ⇒ Object
34
35
36
37
38
39
40
41
42
43
44
45
46
47
|
# File 'lib/legion/extensions/agentic/inference/affordance/helpers/affordance_field.rb', line 34
def detect_affordance(action:, domain:, affordance_type:, requires: [], relevance: DEFAULT_RELEVANCE)
return nil unless AFFORDANCE_TYPES.include?(affordance_type)
return nil if @affordances.size >= MAX_AFFORDANCES
@counter += 1
aff_id = :"aff_#{@counter}"
aff = AffordanceItem.new(
id: aff_id, action: action, domain: domain,
affordance_type: affordance_type, requires: requires, relevance: relevance
)
@affordances[aff_id] = aff
record_detection(aff)
aff
end
|
#evaluate_action(action:, domain:) ⇒ Object
49
50
51
52
53
54
|
# File 'lib/legion/extensions/agentic/inference/affordance/helpers/affordance_field.rb', line 49
def evaluate_action(action:, domain:)
matching = @affordances.values.select { |a| a.action == action && a.domain == domain }
return { feasible: false, reason: :no_affordance } if matching.empty?
check_blockers(matching) || build_evaluation(matching)
end
|
#register_capability(name:, domain: :general, level: 1.0) ⇒ Object
22
23
24
25
26
|
# File 'lib/legion/extensions/agentic/inference/affordance/helpers/affordance_field.rb', line 22
def register_capability(name:, domain: :general, level: 1.0)
return nil if @capabilities.size >= MAX_CAPABILITIES
@capabilities[name] = { domain: domain, level: level.to_f.clamp(0.0, 1.0) }
end
|
#set_environment(property:, value:, domain: :general) ⇒ Object
28
29
30
31
32
|
# File 'lib/legion/extensions/agentic/inference/affordance/helpers/affordance_field.rb', line 28
def set_environment(property:, value:, domain: :general)
return nil if @environment.size >= MAX_ENVIRONMENT_PROPS && !@environment.key?(property)
@environment[property] = { value: value, domain: domain, updated_at: Time.now.utc }
end
|
#threats ⇒ Object
60
61
62
|
# File 'lib/legion/extensions/agentic/inference/affordance/helpers/affordance_field.rb', line 60
def threats
@affordances.values.select(&:threatening?).map(&:to_h)
end
|
#to_h ⇒ Object
73
74
75
76
77
78
79
80
81
82
83
|
# File 'lib/legion/extensions/agentic/inference/affordance/helpers/affordance_field.rb', line 73
def to_h
{
affordance_count: @affordances.size,
capability_count: @capabilities.size,
environment_props: @environment.size,
actionable_count: @affordances.values.count(&:actionable?),
blocked_count: @affordances.values.count(&:blocked?),
threat_count: @affordances.values.count(&:threatening?),
history_size: @history.size
}
end
|