Module: Agentic::Learning
- Defined in:
- lib/agentic/learning.rb,
lib/agentic/learning/pattern_recognizer.rb,
lib/agentic/learning/strategy_optimizer.rb,
lib/agentic/learning/capability_optimizer.rb,
lib/agentic/learning/execution_history_store.rb
Overview
The Learning module provides components for capturing execution history, recognizing patterns, and optimizing strategies based on feedback and metrics.
Defined Under Namespace
Classes: CapabilityOptimizer, ExecutionHistoryStore, PatternRecognizer, StrategyOptimizer
Class Method Summary collapse
-
.create(options = {}) ⇒ Hash
Factory method to create a complete learning system.
-
.register_with_orchestrator(plan_orchestrator, learning_system) ⇒ Boolean
Register a learning system with a plan orchestrator.
Class Method Details
.create(options = {}) ⇒ Hash
Factory method to create a complete learning system
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/agentic/learning.rb', line 47 def self.create( = {}) history_store = ExecutionHistoryStore.new( logger: [:logger], storage_path: [:storage_path], anonymize: .fetch(:anonymize, true) ) pattern_recognizer = PatternRecognizer.new( logger: [:logger], history_store: history_store, min_sample_size: [:min_sample_size] || 10 ) strategy_optimizer = StrategyOptimizer.new( logger: [:logger], pattern_recognizer: pattern_recognizer, history_store: history_store, llm_client: [:llm_client], auto_apply_optimizations: .fetch(:auto_optimize, false) ) { history_store: history_store, pattern_recognizer: pattern_recognizer, strategy_optimizer: strategy_optimizer } end |
.register_with_orchestrator(plan_orchestrator, learning_system) ⇒ Boolean
Register a learning system with a plan orchestrator
80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 |
# File 'lib/agentic/learning.rb', line 80 def self.register_with_orchestrator(plan_orchestrator, learning_system) # Register execution history tracking plan_orchestrator.on(:task_completed) do |task, result| learning_system[:history_store].record_execution( task_id: task.id, plan_id: task.context[:plan_id], agent_type: task.agent_spec&.type, duration_ms: result.metrics[:duration_ms], success: result.success?, metrics: result.metrics, context: { task_description: task.description, task_type: task.type, input_size: task.input ? task.input.to_s.length : 0 } ) end plan_orchestrator.on(:plan_completed) do |plan, results| # Record overall plan execution task_durations = {} task_dependencies = {} results.each do |task_id, result| task_durations[task_id] = result.metrics[:duration_ms] if result.metrics[:duration_ms] end # Extract dependencies from plan plan.tasks.each do |task| task_dependencies[task.id] = task.dependencies if task.dependencies&.any? end learning_system[:history_store].record_execution( plan_id: plan.id, success: results.values.all?(&:success?), duration_ms: results.values.sum { |r| r.metrics[:duration_ms] || 0 }, metrics: { total_tasks: results.size, successful_tasks: results.values.count(&:success?), failed_tasks: results.values.count { |r| !r.success? } }, context: { task_durations: task_durations, task_dependencies: task_dependencies } ) end true end |