Class: Agentic::AdaptationEngine
- Inherits:
-
Object
- Object
- Agentic::AdaptationEngine
- Defined in:
- lib/agentic/adaptation_engine.rb
Overview
The AdaptationEngine enables feedback-driven adjustments to agents and tasks. It is part of the Verification Layer and focuses on applying learned improvements based on feedback, outcomes, and performance metrics.
Instance Method Summary collapse
-
#adaptation_history(component = nil) ⇒ Array<Hash>
Retrieve adaptation history for a specific component.
-
#apply_adaptation(feedback) ⇒ Hash
Apply an adaptation based on feedback.
-
#initialize(options = {}) ⇒ AdaptationEngine
constructor
Initialize a new AdaptationEngine.
-
#process_feedback(feedback) ⇒ Hash
Process feedback and determine if adaptation is needed.
-
#register_adaptation_strategy(component, strategy) ⇒ Boolean
Register an adaptation strategy for a specific component/context.
Constructor Details
#initialize(options = {}) ⇒ AdaptationEngine
Initialize a new AdaptationEngine.
14 15 16 17 18 19 20 |
# File 'lib/agentic/adaptation_engine.rb', line 14 def initialize( = {}) @logger = [:logger] || Agentic.logger @adaptation_threshold = [:adaptation_threshold] || 75 @auto_adapt = .fetch(:auto_adapt, false) @adaptation_registry = {} @feedback_history = [] end |
Instance Method Details
#adaptation_history(component = nil) ⇒ Array<Hash>
Retrieve adaptation history for a specific component
95 96 97 98 99 100 101 |
# File 'lib/agentic/adaptation_engine.rb', line 95 def adaptation_history(component = nil) if component @feedback_history.select { |f| f[:component] == component } else @feedback_history end end |
#apply_adaptation(feedback) ⇒ Hash
Apply an adaptation based on feedback
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 |
# File 'lib/agentic/adaptation_engine.rb', line 64 def apply_adaptation(feedback) component = feedback[:component] unless @adaptation_registry.key?(component) return {adapted: false, reason: "No adaptation strategy registered for #{component}"} end strategy = @adaptation_registry[component] begin result = strategy.call(feedback) { adapted: true, component: component, target: feedback[:target], result: result } rescue => e @logger.error("Adaptation failed: #{e.message}") { adapted: false, error: e., component: component } end end |
#process_feedback(feedback) ⇒ Hash
Process feedback and determine if adaptation is needed
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/agentic/adaptation_engine.rb', line 43 def process_feedback(feedback) record_feedback(feedback) adaptation_needed = determine_if_adaptation_needed(feedback) return {adapted: false, reason: "Adaptation threshold not met"} unless adaptation_needed if @auto_adapt apply_adaptation(feedback) else { adapted: false, adaptation_suggested: true, suggestion: feedback[:suggestion] } end end |
#register_adaptation_strategy(component, strategy) ⇒ Boolean
Register an adaptation strategy for a specific component/context
27 28 29 30 31 32 |
# File 'lib/agentic/adaptation_engine.rb', line 27 def register_adaptation_strategy(component, strategy) return false unless strategy.respond_to?(:call) @adaptation_registry[component] = strategy true end |