Module: RubyLLM::Agents::AlertManager

Defined in:
lib/ruby_llm/agents/infrastructure/alert_manager.rb

Overview

Alert notification dispatcher for governance events

Sends notifications via user-provided handler and ActiveSupport::Notifications when important events occur like budget exceedance or circuit breaker activation.

Examples:

Configure an alert handler

RubyLLM::Agents.configure do |config|
  config.on_alert = ->(event, payload) {
    case event
    when :budget_hard_cap
      Slack::Notifier.new(ENV["SLACK_WEBHOOK"]).ping("Budget exceeded")
    end
  }
end

Subscribe via ActiveSupport::Notifications

ActiveSupport::Notifications.subscribe(/^ruby_llm_agents\.alert\./) do |name, _, _, _, payload|
  event = name.sub("ruby_llm_agents.alert.", "").to_sym
  MyAlertService.handle(event, payload)
end

See Also:

Class Method Summary collapse

Class Method Details

.notify(event, payload) ⇒ void

This method returns an undefined value.

Sends a notification to the configured handler and emits AS::N

Parameters:

  • event (Symbol)

    The event type (e.g., :budget_soft_cap, :breaker_open)

  • payload (Hash)

    Event-specific data



35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/ruby_llm/agents/infrastructure/alert_manager.rb', line 35

def notify(event, payload)
  full_payload = build_payload(event, payload)

  # Call user-provided handler (if set)
  call_handler(event, full_payload)

  # Always emit ActiveSupport::Notification
  emit_notification(event, full_payload)

  # Store in cache for dashboard display
  store_for_dashboard(event, full_payload)
rescue => e
  Rails.logger.error("[RubyLLM::Agents::AlertManager] Failed: #{e.message}")
end