Class: Legion::Extensions::Agentic::Executive::Volition::Helpers::IntentionStack
- Inherits:
-
Object
- Object
- Legion::Extensions::Agentic::Executive::Volition::Helpers::IntentionStack
- Defined in:
- lib/legion/extensions/agentic/executive/volition/helpers/intention_stack.rb
Instance Attribute Summary collapse
-
#intentions ⇒ Object
readonly
Returns the value of attribute intentions.
Instance Method Summary collapse
- #active ⇒ Object
- #active_count ⇒ Object
- #by_domain(domain) ⇒ Object
- #by_drive(drive) ⇒ Object
- #complete(intention_id) ⇒ Object
- #decay_all ⇒ Object
- #find(intention_id) ⇒ Object
-
#initialize ⇒ IntentionStack
constructor
A new instance of IntentionStack.
- #push(intention) ⇒ Object
- #reinforce(intention_id, amount: 0.1) ⇒ Object
- #resume(intention_id) ⇒ Object
- #size ⇒ Object
- #stats ⇒ Object
- #suspend(intention_id) ⇒ Object
- #top ⇒ Object
Constructor Details
#initialize ⇒ IntentionStack
Returns a new instance of IntentionStack.
12 13 14 |
# File 'lib/legion/extensions/agentic/executive/volition/helpers/intention_stack.rb', line 12 def initialize @intentions = [] end |
Instance Attribute Details
#intentions ⇒ Object (readonly)
Returns the value of attribute intentions.
10 11 12 |
# File 'lib/legion/extensions/agentic/executive/volition/helpers/intention_stack.rb', line 10 def intentions @intentions end |
Instance Method Details
#active ⇒ Object
25 26 27 |
# File 'lib/legion/extensions/agentic/executive/volition/helpers/intention_stack.rb', line 25 def active @intentions.select { |i| Intention.active?(i) } end |
#active_count ⇒ Object
100 101 102 |
# File 'lib/legion/extensions/agentic/executive/volition/helpers/intention_stack.rb', line 100 def active_count active.size end |
#by_domain(domain) ⇒ Object
37 38 39 |
# File 'lib/legion/extensions/agentic/executive/volition/helpers/intention_stack.rb', line 37 def by_domain(domain) @intentions.select { |i| i[:domain] == domain.to_sym && Intention.active?(i) } end |
#by_drive(drive) ⇒ Object
33 34 35 |
# File 'lib/legion/extensions/agentic/executive/volition/helpers/intention_stack.rb', line 33 def by_drive(drive) @intentions.select { |i| i[:drive] == drive.to_sym && Intention.active?(i) } end |
#complete(intention_id) ⇒ Object
45 46 47 48 49 50 51 52 |
# File 'lib/legion/extensions/agentic/executive/volition/helpers/intention_stack.rb', line 45 def complete(intention_id) intention = find(intention_id) return :not_found unless intention intention[:state] = :completed intention[:completed_at] = Time.now.utc :completed end |
#decay_all ⇒ Object
71 72 73 74 75 76 77 78 79 80 81 82 83 84 |
# File 'lib/legion/extensions/agentic/executive/volition/helpers/intention_stack.rb', line 71 def decay_all @intentions.each do |intention| next unless Intention.active?(intention) updated = Intention.decay(intention) intention.merge!(updated) intention[:state] = :expired if Intention.expired?(intention) end expired_count = @intentions.count { |i| i[:state] == :expired } prune_expired expired_count end |
#find(intention_id) ⇒ Object
41 42 43 |
# File 'lib/legion/extensions/agentic/executive/volition/helpers/intention_stack.rb', line 41 def find(intention_id) @intentions.find { |i| i[:intention_id] == intention_id } end |
#push(intention) ⇒ Object
16 17 18 19 20 21 22 23 |
# File 'lib/legion/extensions/agentic/executive/volition/helpers/intention_stack.rb', line 16 def push(intention) return :duplicate if duplicate?(intention) return :capacity_full if @intentions.size >= Constants::MAX_INTENTIONS @intentions << intention sort! :pushed end |
#reinforce(intention_id, amount: 0.1) ⇒ Object
86 87 88 89 90 91 92 93 94 |
# File 'lib/legion/extensions/agentic/executive/volition/helpers/intention_stack.rb', line 86 def reinforce(intention_id, amount: 0.1) intention = find(intention_id) return :not_found unless intention updated = Intention.reinforce(intention, amount: amount) intention.merge!(updated) sort! :reinforced end |
#resume(intention_id) ⇒ Object
62 63 64 65 66 67 68 69 |
# File 'lib/legion/extensions/agentic/executive/volition/helpers/intention_stack.rb', line 62 def resume(intention_id) intention = find(intention_id) return :not_found unless intention return :not_suspended unless intention[:state] == :suspended intention[:state] = :active :resumed end |
#size ⇒ Object
96 97 98 |
# File 'lib/legion/extensions/agentic/executive/volition/helpers/intention_stack.rb', line 96 def size @intentions.size end |
#stats ⇒ Object
104 105 106 107 108 109 110 111 112 113 114 |
# File 'lib/legion/extensions/agentic/executive/volition/helpers/intention_stack.rb', line 104 def stats by_state = @intentions.each_with_object(Hash.new(0)) { |i, h| h[i[:state]] += 1 } by_drive = active.each_with_object(Hash.new(0)) { |i, h| h[i[:drive]] += 1 } { total: @intentions.size, active: active_count, by_state: by_state, by_drive: by_drive, top_intention: top&.slice(:intention_id, :drive, :domain, :goal, :salience) } end |
#suspend(intention_id) ⇒ Object
54 55 56 57 58 59 60 |
# File 'lib/legion/extensions/agentic/executive/volition/helpers/intention_stack.rb', line 54 def suspend(intention_id) intention = find(intention_id) return :not_found unless intention intention[:state] = :suspended :suspended end |
#top ⇒ Object
29 30 31 |
# File 'lib/legion/extensions/agentic/executive/volition/helpers/intention_stack.rb', line 29 def top active.first end |