Class: Agents::CallbackManager

Inherits:
Object
  • Object
show all
Defined in:
lib/agents/callback_manager.rb

Overview

Manager for handling and emitting callback events in a thread-safe manner. Provides both generic emit() method and typed convenience methods.

Examples:

Using generic emit

manager.emit(:tool_start, tool_name, args)

Using typed methods

manager.emit_tool_start(tool_name, args)
manager.emit_agent_thinking(agent_name, input)

Constant Summary collapse

EVENT_TYPES =

Supported callback event types

i[
  run_start
  run_complete
  agent_complete
  tool_start
  tool_complete
  agent_thinking
  agent_handoff
].freeze

Instance Method Summary collapse

Constructor Details

#initialize(callbacks = {}) ⇒ CallbackManager



25
26
27
# File 'lib/agents/callback_manager.rb', line 25

def initialize(callbacks = {})
  @callbacks = callbacks.dup.freeze
end

Instance Method Details

#emit(event_type, *args) ⇒ Object

Generic method to emit any callback event type



33
34
35
36
37
38
39
40
41
42
# File 'lib/agents/callback_manager.rb', line 33

def emit(event_type, *args)
  callback_list = @callbacks[event_type] || []

  callback_list.each do |callback|
    callback.call(*args)
  rescue StandardError => e
    # Log callback errors but don't let them crash execution
    warn "Callback error for #{event_type}: #{e.message}"
  end
end