Class: Events::LLMResponded

Inherits:
Object
  • Object
show all
Defined in:
lib/events/llm_responded.rb

Overview

Emitted by the drain loop after a single LLM round-trip completes. Carries the raw Anthropic response so downstream subscribers can persist messages, transition session state, and dispatch tool execution when the response is a tool_use.

The drain loop hands off via this event — it does not persist Messages or release the session itself. Single responsibility: one subscriber pumps PendingMessages into the LLM, another owns the aftermath.

Constant Summary collapse

TYPE =
"session.llm_responded"

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(session_id:, response:, api_metrics: nil) ⇒ LLMResponded

Returns a new instance of LLMResponded.

Parameters:

  • session_id (Integer)

    session that made the LLM call

  • response (Hash)

    raw Anthropic response (with content and stop_reason)

  • api_metrics (Hash, nil) (defaults to: nil)

    rate-limit and usage metrics from the provider



21
22
23
24
25
# File 'lib/events/llm_responded.rb', line 21

def initialize(session_id:, response:, api_metrics: nil)
  @session_id = session_id
  @response = response
  @api_metrics = api_metrics
end

Instance Attribute Details

#api_metricsObject (readonly)

Returns the value of attribute api_metrics.



16
17
18
# File 'lib/events/llm_responded.rb', line 16

def api_metrics
  @api_metrics
end

#responseObject (readonly)

Returns the value of attribute response.



16
17
18
# File 'lib/events/llm_responded.rb', line 16

def response
  @response
end

#session_idObject (readonly)

Returns the value of attribute session_id.



16
17
18
# File 'lib/events/llm_responded.rb', line 16

def session_id
  @session_id
end

Instance Method Details

#event_nameObject



27
28
29
# File 'lib/events/llm_responded.rb', line 27

def event_name
  "#{Bus::NAMESPACE}.#{TYPE}"
end

#to_hObject



31
32
33
# File 'lib/events/llm_responded.rb', line 31

def to_h
  {type: TYPE, session_id:, response:, api_metrics:}
end