Class: Agentic::Learning::ExecutionHistoryStore
- Inherits:
-
Object
- Object
- Agentic::Learning::ExecutionHistoryStore
- Defined in:
- lib/agentic/learning/execution_history_store.rb
Overview
ExecutionHistoryStore is responsible for capturing, storing, and retrieving execution metrics and performance data for agent tasks and plans.
Instance Method Summary collapse
-
#cleanup_old_records ⇒ Integer
Delete all history older than retention_days.
-
#get_history(filters = {}) ⇒ Array<Hash>
Retrieve execution history based on filter criteria.
-
#get_metric(metric_name, filters = {}, aggregation = :avg) ⇒ Float, Integer
Retrieve aggregated metrics from execution history.
-
#initialize(options = {}) ⇒ ExecutionHistoryStore
constructor
Initialize a new ExecutionHistoryStore with the given options.
-
#record_execution(execution_data) ⇒ Boolean
Record a new execution in the history store.
Constructor Details
#initialize(options = {}) ⇒ ExecutionHistoryStore
Initialize a new ExecutionHistoryStore with the given options
33 34 35 36 37 38 39 40 41 42 |
# File 'lib/agentic/learning/execution_history_store.rb', line 33 def initialize( = {}) @logger = [:logger] || Agentic.logger @storage_path = [:storage_path] || default_storage_path @retention_days = [:retention_days] || 30 @anonymize = .fetch(:anonymize, true) @memory_cache = [] @cache_size_limit = [:cache_size_limit] || 1000 ensure_storage_path_exists end |
Instance Method Details
#cleanup_old_records ⇒ Integer
Delete all history older than retention_days
118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 |
# File 'lib/agentic/learning/execution_history_store.rb', line 118 def cleanup_old_records cutoff_date = Date.today - @retention_days count = 0 Dir.glob(File.join(@storage_path, "**/*.json")).each do |file| date_str = File.basename(file, ".json") date = begin Date.parse(date_str) rescue nil end if date && date < cutoff_date File.delete(file) count += 1 end end @logger.info("Cleaned up #{count} old history records") count end |
#get_history(filters = {}) ⇒ Array<Hash>
Retrieve execution history based on filter criteria
85 86 87 88 89 |
# File 'lib/agentic/learning/execution_history_store.rb', line 85 def get_history(filters = {}) records = load_records(filters) limit = filters[:limit] || records.size records.first(limit) end |
#get_metric(metric_name, filters = {}, aggregation = :avg) ⇒ Float, Integer
Retrieve aggregated metrics from execution history
101 102 103 104 105 106 107 108 109 110 111 112 113 |
# File 'lib/agentic/learning/execution_history_store.rb', line 101 def get_metric(metric_name, filters = {}, aggregation = :avg) records = get_history(filters) values = records.map { |r| r.dig(:metrics, metric_name.to_s) }.compact return nil if values.empty? case aggregation when :avg then values.sum / values.size.to_f when :sum then values.sum when :min then values.min when :max then values.max end end |
#record_execution(execution_data) ⇒ Boolean
Record a new execution in the history store
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/agentic/learning/execution_history_store.rb', line 55 def record_execution(execution_data) record = build_record(execution_data) # Add to memory cache @memory_cache << record @memory_cache.shift if @memory_cache.size > @cache_size_limit # Persist to storage save_record(record) # Clean up old records periodically cleanup_old_records if rand < 0.05 # 5% chance to trigger cleanup true rescue => e @logger.error("Failed to record execution history: #{e.}") false end |