Class: RubyLLM::Agents::StreamEvent
- Inherits:
-
Object
- Object
- RubyLLM::Agents::StreamEvent
- Defined in:
- lib/ruby_llm/agents/stream_event.rb
Overview
Typed event emitted during streaming execution.
When stream_events: true is passed to an agent call, the stream
block receives StreamEvent objects instead of raw RubyLLM chunks.
This provides visibility into the full execution lifecycle —
text chunks, tool invocations, and errors.
Instance Attribute Summary collapse
-
#data ⇒ Hash
readonly
Event-specific data.
-
#type ⇒ Symbol
readonly
Event type (:chunk, :tool_start, :tool_end, :error).
Instance Method Summary collapse
-
#chunk? ⇒ Boolean
Whether this is a text chunk event.
-
#error? ⇒ Boolean
Whether this is an error event.
-
#initialize(type, data = {}) ⇒ StreamEvent
constructor
Creates a new StreamEvent.
- #to_h ⇒ Object
-
#tool_event? ⇒ Boolean
Whether this is a tool lifecycle event.
Constructor Details
#initialize(type, data = {}) ⇒ StreamEvent
Creates a new StreamEvent
33 34 35 36 |
# File 'lib/ruby_llm/agents/stream_event.rb', line 33 def initialize(type, data = {}) @type = type @data = data end |
Instance Attribute Details
#data ⇒ Hash (readonly)
Returns Event-specific data.
27 28 29 |
# File 'lib/ruby_llm/agents/stream_event.rb', line 27 def data @data end |
#type ⇒ Symbol (readonly)
Returns Event type (:chunk, :tool_start, :tool_end, :error).
24 25 26 |
# File 'lib/ruby_llm/agents/stream_event.rb', line 24 def type @type end |
Instance Method Details
#chunk? ⇒ Boolean
Returns Whether this is a text chunk event.
39 40 41 |
# File 'lib/ruby_llm/agents/stream_event.rb', line 39 def chunk? @type == :chunk end |
#error? ⇒ Boolean
Returns Whether this is an error event.
49 50 51 |
# File 'lib/ruby_llm/agents/stream_event.rb', line 49 def error? @type == :error end |
#to_h ⇒ Object
53 54 55 |
# File 'lib/ruby_llm/agents/stream_event.rb', line 53 def to_h {type: @type, data: @data} end |
#tool_event? ⇒ Boolean
Returns Whether this is a tool lifecycle event.
44 45 46 |
# File 'lib/ruby_llm/agents/stream_event.rb', line 44 def tool_event? @type == :tool_start || @type == :tool_end end |