Class: Agents::CallbackManager
- Inherits:
-
Object
- Object
- Agents::CallbackManager
- 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.
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
-
#emit(event_type, *args) ⇒ Object
Generic method to emit any callback event type.
-
#initialize(callbacks = {}) ⇒ CallbackManager
constructor
A new instance of CallbackManager.
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 |