Class: DebugAgent::EngineStreamHandler

Inherits:
StreamHandler show all
Defined in:
lib/debug_agent/engine.rb

Overview

StreamHandler implementation used internally by the engine

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(callback) ⇒ EngineStreamHandler

Returns a new instance of EngineStreamHandler.



8
9
10
11
12
13
14
# File 'lib/debug_agent/engine.rb', line 8

def initialize(callback)
  @callback = callback
  @tool_calls = []
  @usage = nil
  @had_error = false
  @content = +''
end

Instance Attribute Details

#contentObject (readonly)

Returns the value of attribute content.



6
7
8
# File 'lib/debug_agent/engine.rb', line 6

def content
  @content
end

#had_errorObject (readonly)

Returns the value of attribute had_error.



6
7
8
# File 'lib/debug_agent/engine.rb', line 6

def had_error
  @had_error
end

#tool_callsObject (readonly)

Returns the value of attribute tool_calls.



6
7
8
# File 'lib/debug_agent/engine.rb', line 6

def tool_calls
  @tool_calls
end

#usageObject (readonly)

Returns the value of attribute usage.



6
7
8
# File 'lib/debug_agent/engine.rb', line 6

def usage
  @usage
end

Instance Method Details

#on_complete(tool_calls, finish_reason, usage) ⇒ Object



21
22
23
24
# File 'lib/debug_agent/engine.rb', line 21

def on_complete(tool_calls, finish_reason, usage)
  @tool_calls = tool_calls
  @usage = usage
end

#on_content(chunk) ⇒ Object



16
17
18
19
# File 'lib/debug_agent/engine.rb', line 16

def on_content(chunk)
  @content << chunk
  @callback.on_content(chunk)
end

#on_error(error) ⇒ Object



26
27
28
29
# File 'lib/debug_agent/engine.rb', line 26

def on_error(error)
  @had_error = true
  @callback.on_error("LLM API error: #{error.message}")
end