Class: Legion::Extensions::Agentic::Executive::Autopilot::Helpers::Routine
- Inherits:
-
Object
- Object
- Legion::Extensions::Agentic::Executive::Autopilot::Helpers::Routine
- Includes:
- Constants
- Defined in:
- lib/legion/extensions/agentic/executive/autopilot/helpers/routine.rb
Constant Summary
Constants included from Constants
Constants::AUTOPILOT_COST, Constants::AUTOPILOT_THRESHOLD, Constants::DEFAULT_ENERGY, Constants::DELIBERATE_COST, Constants::DELIBERATE_THRESHOLD, Constants::ENERGY_LABELS, Constants::FAMILIARITY_BOOST, Constants::FAMILIARITY_DECAY, Constants::FAMILIARITY_LABELS, Constants::MAX_EVENTS, Constants::MAX_ROUTINES, Constants::MODE_LABELS, Constants::OVERRIDE_COST, Constants::PROCESSING_MODES, Constants::TASK_DOMAINS
Instance Attribute Summary collapse
-
#created_at ⇒ Object
readonly
Returns the value of attribute created_at.
-
#domain ⇒ Object
readonly
Returns the value of attribute domain.
-
#execution_count ⇒ Object
readonly
Returns the value of attribute execution_count.
-
#failure_count ⇒ Object
readonly
Returns the value of attribute failure_count.
-
#familiarity ⇒ Object
readonly
Returns the value of attribute familiarity.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#last_executed_at ⇒ Object
readonly
Returns the value of attribute last_executed_at.
-
#pattern ⇒ Object
readonly
Returns the value of attribute pattern.
-
#success_count ⇒ Object
readonly
Returns the value of attribute success_count.
Instance Method Summary collapse
- #autopilot_ready? ⇒ Boolean
- #decay! ⇒ Object
- #execute!(success: true) ⇒ Object
- #familiarity_label ⇒ Object
-
#initialize(pattern:, domain: :routine, familiarity: 0.0) ⇒ Routine
constructor
A new instance of Routine.
- #novel? ⇒ Boolean
- #success_rate ⇒ Object
- #to_h ⇒ Object
Methods included from Constants
Constructor Details
#initialize(pattern:, domain: :routine, familiarity: 0.0) ⇒ Routine
Returns a new instance of Routine.
17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/legion/extensions/agentic/executive/autopilot/helpers/routine.rb', line 17 def initialize(pattern:, domain: :routine, familiarity: 0.0) @id = SecureRandom.uuid @pattern = pattern @domain = validate_domain(domain) @familiarity = familiarity.to_f.clamp(0.0, 1.0).round(10) @execution_count = 0 @success_count = 0 @failure_count = 0 @created_at = Time.now.utc @last_executed_at = nil end |
Instance Attribute Details
#created_at ⇒ Object (readonly)
Returns the value of attribute created_at.
14 15 16 |
# File 'lib/legion/extensions/agentic/executive/autopilot/helpers/routine.rb', line 14 def created_at @created_at end |
#domain ⇒ Object (readonly)
Returns the value of attribute domain.
14 15 16 |
# File 'lib/legion/extensions/agentic/executive/autopilot/helpers/routine.rb', line 14 def domain @domain end |
#execution_count ⇒ Object (readonly)
Returns the value of attribute execution_count.
14 15 16 |
# File 'lib/legion/extensions/agentic/executive/autopilot/helpers/routine.rb', line 14 def execution_count @execution_count end |
#failure_count ⇒ Object (readonly)
Returns the value of attribute failure_count.
14 15 16 |
# File 'lib/legion/extensions/agentic/executive/autopilot/helpers/routine.rb', line 14 def failure_count @failure_count end |
#familiarity ⇒ Object (readonly)
Returns the value of attribute familiarity.
14 15 16 |
# File 'lib/legion/extensions/agentic/executive/autopilot/helpers/routine.rb', line 14 def familiarity @familiarity end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
14 15 16 |
# File 'lib/legion/extensions/agentic/executive/autopilot/helpers/routine.rb', line 14 def id @id end |
#last_executed_at ⇒ Object (readonly)
Returns the value of attribute last_executed_at.
14 15 16 |
# File 'lib/legion/extensions/agentic/executive/autopilot/helpers/routine.rb', line 14 def last_executed_at @last_executed_at end |
#pattern ⇒ Object (readonly)
Returns the value of attribute pattern.
14 15 16 |
# File 'lib/legion/extensions/agentic/executive/autopilot/helpers/routine.rb', line 14 def pattern @pattern end |
#success_count ⇒ Object (readonly)
Returns the value of attribute success_count.
14 15 16 |
# File 'lib/legion/extensions/agentic/executive/autopilot/helpers/routine.rb', line 14 def success_count @success_count end |
Instance Method Details
#autopilot_ready? ⇒ Boolean
47 48 49 |
# File 'lib/legion/extensions/agentic/executive/autopilot/helpers/routine.rb', line 47 def autopilot_ready? @familiarity >= AUTOPILOT_THRESHOLD end |
#decay! ⇒ Object
42 43 44 45 |
# File 'lib/legion/extensions/agentic/executive/autopilot/helpers/routine.rb', line 42 def decay! @familiarity = (@familiarity - FAMILIARITY_DECAY).clamp(0.0, 1.0).round(10) self end |
#execute!(success: true) ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/legion/extensions/agentic/executive/autopilot/helpers/routine.rb', line 29 def execute!(success: true) @execution_count += 1 @last_executed_at = Time.now.utc if success @success_count += 1 @familiarity = (@familiarity + FAMILIARITY_BOOST).clamp(0.0, 1.0).round(10) else @failure_count += 1 @familiarity = (@familiarity - FAMILIARITY_BOOST).clamp(0.0, 1.0).round(10) end self end |
#familiarity_label ⇒ Object
61 |
# File 'lib/legion/extensions/agentic/executive/autopilot/helpers/routine.rb', line 61 def familiarity_label = Constants.label_for(FAMILIARITY_LABELS, @familiarity) |
#novel? ⇒ Boolean
51 52 53 |
# File 'lib/legion/extensions/agentic/executive/autopilot/helpers/routine.rb', line 51 def novel? @familiarity <= DELIBERATE_THRESHOLD end |
#success_rate ⇒ Object
55 56 57 58 59 |
# File 'lib/legion/extensions/agentic/executive/autopilot/helpers/routine.rb', line 55 def success_rate return 0.0 if @execution_count.zero? (@success_count.to_f / @execution_count).round(10) end |
#to_h ⇒ Object
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/legion/extensions/agentic/executive/autopilot/helpers/routine.rb', line 63 def to_h { id: @id, pattern: @pattern, domain: @domain, familiarity: @familiarity, familiarity_label: familiarity_label, autopilot_ready: autopilot_ready?, novel: novel?, execution_count: @execution_count, success_rate: success_rate, created_at: @created_at, last_executed_at: @last_executed_at } end |