Class: Legion::Extensions::Agentic::Executive::Planning::Helpers::Plan
- Inherits:
-
Object
- Object
- Legion::Extensions::Agentic::Executive::Planning::Helpers::Plan
- Defined in:
- lib/legion/extensions/agentic/executive/planning/helpers/plan.rb
Instance Attribute Summary collapse
-
#contingencies ⇒ Object
readonly
Returns the value of attribute contingencies.
-
#created_at ⇒ Object
readonly
Returns the value of attribute created_at.
-
#description ⇒ Object
readonly
Returns the value of attribute description.
-
#goal ⇒ Object
readonly
Returns the value of attribute goal.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#parent_plan_id ⇒ Object
readonly
Returns the value of attribute parent_plan_id.
-
#priority ⇒ Object
readonly
Returns the value of attribute priority.
-
#replan_count ⇒ Object
readonly
Returns the value of attribute replan_count.
-
#status ⇒ Object
Returns the value of attribute status.
-
#steps ⇒ Object
readonly
Returns the value of attribute steps.
-
#updated_at ⇒ Object
Returns the value of attribute updated_at.
Instance Method Summary collapse
- #active_step ⇒ Object
- #advance!(step_id, result: nil) ⇒ Object
- #complete? ⇒ Boolean
- #completed_step_ids ⇒ Object
- #fail_step!(step_id, reason: nil) ⇒ Object
- #failed? ⇒ Boolean
- #increment_replan! ⇒ Object
-
#initialize(goal:, steps: [], priority: :medium, contingencies: {}, parent_plan_id: nil, description: nil) ⇒ Plan
constructor
A new instance of Plan.
- #progress ⇒ Object
- #replace_remaining_steps!(new_steps) ⇒ Object
- #stale? ⇒ Boolean
- #to_h ⇒ Object
Constructor Details
#initialize(goal:, steps: [], priority: :medium, contingencies: {}, parent_plan_id: nil, description: nil) ⇒ Plan
Returns a new instance of Plan.
16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/legion/extensions/agentic/executive/planning/helpers/plan.rb', line 16 def initialize(goal:, steps: [], priority: :medium, contingencies: {}, parent_plan_id: nil, description: nil, **) @id = SecureRandom.uuid @goal = goal @description = description @priority = priority @status = :forming @steps = steps.dup @contingencies = contingencies.dup @parent_plan_id = parent_plan_id @created_at = Time.now.utc @updated_at = Time.now.utc @replan_count = 0 end |
Instance Attribute Details
#contingencies ⇒ Object (readonly)
Returns the value of attribute contingencies.
12 13 14 |
# File 'lib/legion/extensions/agentic/executive/planning/helpers/plan.rb', line 12 def contingencies @contingencies end |
#created_at ⇒ Object (readonly)
Returns the value of attribute created_at.
12 13 14 |
# File 'lib/legion/extensions/agentic/executive/planning/helpers/plan.rb', line 12 def created_at @created_at end |
#description ⇒ Object (readonly)
Returns the value of attribute description.
12 13 14 |
# File 'lib/legion/extensions/agentic/executive/planning/helpers/plan.rb', line 12 def description @description end |
#goal ⇒ Object (readonly)
Returns the value of attribute goal.
12 13 14 |
# File 'lib/legion/extensions/agentic/executive/planning/helpers/plan.rb', line 12 def goal @goal end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
12 13 14 |
# File 'lib/legion/extensions/agentic/executive/planning/helpers/plan.rb', line 12 def id @id end |
#parent_plan_id ⇒ Object (readonly)
Returns the value of attribute parent_plan_id.
12 13 14 |
# File 'lib/legion/extensions/agentic/executive/planning/helpers/plan.rb', line 12 def parent_plan_id @parent_plan_id end |
#priority ⇒ Object (readonly)
Returns the value of attribute priority.
12 13 14 |
# File 'lib/legion/extensions/agentic/executive/planning/helpers/plan.rb', line 12 def priority @priority end |
#replan_count ⇒ Object (readonly)
Returns the value of attribute replan_count.
12 13 14 |
# File 'lib/legion/extensions/agentic/executive/planning/helpers/plan.rb', line 12 def replan_count @replan_count end |
#status ⇒ Object
Returns the value of attribute status.
14 15 16 |
# File 'lib/legion/extensions/agentic/executive/planning/helpers/plan.rb', line 14 def status @status end |
#steps ⇒ Object (readonly)
Returns the value of attribute steps.
12 13 14 |
# File 'lib/legion/extensions/agentic/executive/planning/helpers/plan.rb', line 12 def steps @steps end |
#updated_at ⇒ Object
Returns the value of attribute updated_at.
14 15 16 |
# File 'lib/legion/extensions/agentic/executive/planning/helpers/plan.rb', line 14 def updated_at @updated_at end |
Instance Method Details
#active_step ⇒ Object
37 38 39 |
# File 'lib/legion/extensions/agentic/executive/planning/helpers/plan.rb', line 37 def active_step @steps.find { |s| s.status == :active } end |
#advance!(step_id, result: nil) ⇒ Object
45 46 47 48 49 50 51 52 53 |
# File 'lib/legion/extensions/agentic/executive/planning/helpers/plan.rb', line 45 def advance!(step_id, result: nil) step = @steps.find { |s| s.id == step_id } return nil unless step step.complete!(result: result) @updated_at = Time.now.utc @status = :completed if progress >= Constants::COMPLETION_THRESHOLD step end |
#complete? ⇒ Boolean
64 65 66 |
# File 'lib/legion/extensions/agentic/executive/planning/helpers/plan.rb', line 64 def complete? @status == :completed || progress >= Constants::COMPLETION_THRESHOLD end |
#completed_step_ids ⇒ Object
41 42 43 |
# File 'lib/legion/extensions/agentic/executive/planning/helpers/plan.rb', line 41 def completed_step_ids @steps.select { |s| %i[completed skipped].include?(s.status) }.map(&:id) end |
#fail_step!(step_id, reason: nil) ⇒ Object
55 56 57 58 59 60 61 62 |
# File 'lib/legion/extensions/agentic/executive/planning/helpers/plan.rb', line 55 def fail_step!(step_id, reason: nil) step = @steps.find { |s| s.id == step_id } return nil unless step step.fail!(reason: reason) @updated_at = Time.now.utc step end |
#failed? ⇒ Boolean
68 69 70 |
# File 'lib/legion/extensions/agentic/executive/planning/helpers/plan.rb', line 68 def failed? @status == :failed end |
#increment_replan! ⇒ Object
76 77 78 79 |
# File 'lib/legion/extensions/agentic/executive/planning/helpers/plan.rb', line 76 def increment_replan! @replan_count += 1 @updated_at = Time.now.utc end |
#progress ⇒ Object
30 31 32 33 34 35 |
# File 'lib/legion/extensions/agentic/executive/planning/helpers/plan.rb', line 30 def progress return 0.0 if @steps.empty? done = @steps.count { |s| %i[completed skipped].include?(s.status) } done.to_f / @steps.size end |
#replace_remaining_steps!(new_steps) ⇒ Object
81 82 83 84 85 86 |
# File 'lib/legion/extensions/agentic/executive/planning/helpers/plan.rb', line 81 def replace_remaining_steps!(new_steps) pending = @steps.reject { |s| %i[completed skipped failed].include?(s.status) } pending.each { |s| @steps.delete(s) } new_steps.each { |s| @steps << s } @updated_at = Time.now.utc end |
#stale? ⇒ Boolean
72 73 74 |
# File 'lib/legion/extensions/agentic/executive/planning/helpers/plan.rb', line 72 def stale? (Time.now.utc - @updated_at) > Constants::STALE_PLAN_THRESHOLD end |
#to_h ⇒ Object
88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 |
# File 'lib/legion/extensions/agentic/executive/planning/helpers/plan.rb', line 88 def to_h { id: @id, goal: @goal, description: @description, priority: @priority, status: @status, progress: progress.round(4), steps: @steps.map(&:to_h), contingencies: @contingencies, parent_plan_id: @parent_plan_id, replan_count: @replan_count, created_at: @created_at, updated_at: @updated_at } end |