Class: Legion::Extensions::Agentic::Homeostasis::Temporal::Helpers::TemporalStore

Inherits:
Object
  • Object
show all
Defined in:
lib/legion/extensions/agentic/homeostasis/temporal/helpers/temporal_store.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeTemporalStore

Returns a new instance of TemporalStore.



12
13
14
15
# File 'lib/legion/extensions/agentic/homeostasis/temporal/helpers/temporal_store.rb', line 12

def initialize
  @perception = TimePerception.new
  @patterns = {}
end

Instance Attribute Details

#patternsObject (readonly)

Returns the value of attribute patterns.



10
11
12
# File 'lib/legion/extensions/agentic/homeostasis/temporal/helpers/temporal_store.rb', line 10

def patterns
  @patterns
end

#perceptionObject (readonly)

Returns the value of attribute perception.



10
11
12
# File 'lib/legion/extensions/agentic/homeostasis/temporal/helpers/temporal_store.rb', line 10

def perception
  @perception
end

Instance Method Details

#all_patternsObject



46
47
48
# File 'lib/legion/extensions/agentic/homeostasis/temporal/helpers/temporal_store.rb', line 46

def all_patterns
  @patterns.values.map(&:to_h)
end

#detect_patterns_for(event, domain: :general) ⇒ Object



41
42
43
44
# File 'lib/legion/extensions/agentic/homeostasis/temporal/helpers/temporal_store.rb', line 41

def detect_patterns_for(event, domain: :general)
  pattern_key = "#{domain}:#{event}"
  @patterns[pattern_key]&.to_h
end

#elapsed(event, domain: :general) ⇒ Object



23
24
25
# File 'lib/legion/extensions/agentic/homeostasis/temporal/helpers/temporal_store.rb', line 23

def elapsed(event, domain: :general)
  @perception.elapsed_since(event, domain: domain)
end

#periodic_patternsObject



50
51
52
# File 'lib/legion/extensions/agentic/homeostasis/temporal/helpers/temporal_store.rb', line 50

def periodic_patterns
  @patterns.values.select(&:periodic?).map(&:to_h)
end

#predict_next(event, domain: :general) ⇒ Object



27
28
29
30
31
32
33
# File 'lib/legion/extensions/agentic/homeostasis/temporal/helpers/temporal_store.rb', line 27

def predict_next(event, domain: :general)
  pattern_key = "#{domain}:#{event}"
  pattern = @patterns[pattern_key]
  return nil unless pattern

  pattern.predict_next
end

#record_event(event, domain: :general) ⇒ Object



17
18
19
20
21
# File 'lib/legion/extensions/agentic/homeostasis/temporal/helpers/temporal_store.rb', line 17

def record_event(event, domain: :general)
  key = @perception.mark_event(event, domain: domain)
  update_pattern(domain, event)
  key
end

#record_prediction_outcome(event, actual_time:, domain: :general) ⇒ Object



35
36
37
38
39
# File 'lib/legion/extensions/agentic/homeostasis/temporal/helpers/temporal_store.rb', line 35

def record_prediction_outcome(event, actual_time:, domain: :general)
  pattern_key = "#{domain}:#{event}"
  pattern = @patterns[pattern_key]
  pattern&.record_actual(actual_time)
end

#temporal_summaryObject



54
55
56
57
58
59
60
61
62
63
# File 'lib/legion/extensions/agentic/homeostasis/temporal/helpers/temporal_store.rb', line 54

def temporal_summary
  {
    perception:        @perception.to_h,
    pattern_count:     @patterns.size,
    periodic_count:    @patterns.values.count(&:periodic?),
    bursty_count:      @patterns.values.count(&:bursty?),
    overall_urgency:   @perception.overall_urgency,
    overdue_deadlines: @perception.overdue_deadlines.size
  }
end