Class: Agentic::AdaptationEngine

Inherits:
Object
  • Object
show all
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

Constructor Details

#initialize(options = {}) ⇒ AdaptationEngine

Initialize a new AdaptationEngine.

Parameters:

  • options (Hash) (defaults to: {})

    Configuration options for the adaptation engine

Options Hash (options):

  • :logger (Logger)

    Custom logger instance

  • :adaptation_threshold (Integer)

    Minimum confidence score to trigger adaptation (0-100)

  • :auto_adapt (Boolean)

    Whether to automatically apply adaptations



14
15
16
17
18
19
20
# File 'lib/agentic/adaptation_engine.rb', line 14

def initialize(options = {})
  @logger = options[:logger] || Agentic.logger
  @adaptation_threshold = options[:adaptation_threshold] || 75
  @auto_adapt = options.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

Parameters:

  • component (Symbol) (defaults to: nil)

    The component to get history for

Returns:

  • (Array<Hash>)

    History of adaptations for the 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

Parameters:

  • feedback (Hash)

    The feedback data to use for adaptation

Returns:

  • (Hash)

    Result of the adaptation attempt



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.message,
      component: component
    }
  end
end

#process_feedback(feedback) ⇒ Hash

Process feedback and determine if adaptation is needed

Parameters:

  • feedback (Hash)

    The feedback data to process

Options Hash (feedback):

  • :component (Symbol)

    The component receiving feedback

  • :target (Object)

    The specific instance to adapt

  • :metrics (Hash)

    Performance metrics

  • :outcome (String, Symbol)

    Success/failure indicator

  • :suggestion (String)

    Suggested improvement

Returns:

  • (Hash)

    Result of the adaptation process



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

Parameters:

  • component (Symbol)

    The component or context to adapt (e.g., :agent, :task, :prompt)

  • strategy (Proc)

    A callable that implements the adaptation logic

Returns:

  • (Boolean)

    True if registration was successful



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