Class: Ask::Agent::Reflector

Inherits:
Object
  • Object
show all
Defined in:
lib/ask/agent/reflector.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(model:, max_reflections: 1) ⇒ Reflector

Returns a new instance of Reflector.



8
9
10
11
12
# File 'lib/ask/agent/reflector.rb', line 8

def initialize(model:, max_reflections: 1)
  @model = model
  @max_reflections = max_reflections
  @reflection_count = 0
end

Instance Attribute Details

#reflection_countObject (readonly)

Returns the value of attribute reflection_count.



6
7
8
# File 'lib/ask/agent/reflector.rb', line 6

def reflection_count
  @reflection_count
end

Instance Method Details

#evaluate(response:, event_emitter:) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/ask/agent/reflector.rb', line 19

def evaluate(response:, event_emitter:)
  return { decision: :deliver } unless response

  event_emitter.emit(Events::ReflectionStart.new(reflection_number: @reflection_count + 1))

  result = build_eval_chat.ask(reflection_prompt(response)) do |chunk|
    if chunk.content.to_s.strip.length > 0
      event_emitter.emit(Events::ReflectionDelta.new(content: chunk.content))
    end
  end

  decision = parse_decision(result.content.to_s)

  event_emitter.emit(Events::ReflectionEnd.new(
    decision: decision[:decision],
    feedback: decision[:feedback]
  ))

  @reflection_count += 1
  decision
end

#reflect?(tool_calls_made) ⇒ Boolean

Returns:

  • (Boolean)


14
15
16
17
# File 'lib/ask/agent/reflector.rb', line 14

def reflect?(tool_calls_made)
  return false if @reflection_count >= @max_reflections
  tool_calls_made > 0
end

#reset!Object



41
42
43
# File 'lib/ask/agent/reflector.rb', line 41

def reset!
  @reflection_count = 0
end