Class: SwarmSDK::Observer::Config

Inherits:
Object
  • Object
show all
Defined in:
lib/swarm_sdk/observer/config.rb

Overview

Configuration for an observer agent

Holds the agent name, event handlers (blocks that return prompts or nil), and execution options.

Examples:

config = Observer::Config.new(:profiler)
config.add_handler(:swarm_start) { |event| "Analyze: #{event[:prompt]}" }
config.options[:timeout] = 120

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(agent_name) ⇒ Config

Initialize a new observer configuration

Parameters:

  • agent_name (Symbol)

    Name of the agent to use as observer



20
21
22
23
24
25
26
27
28
# File 'lib/swarm_sdk/observer/config.rb', line 20

def initialize(agent_name)
  @agent_name = agent_name
  @event_handlers = {} # { event_type => block }
  @options = {
    max_concurrent: nil,
    timeout: 60,
    fire_and_forget: true,
  }
end

Instance Attribute Details

#agent_nameObject (readonly)

Returns the value of attribute agent_name.



15
16
17
# File 'lib/swarm_sdk/observer/config.rb', line 15

def agent_name
  @agent_name
end

#event_handlersObject (readonly)

Returns the value of attribute event_handlers.



15
16
17
# File 'lib/swarm_sdk/observer/config.rb', line 15

def event_handlers
  @event_handlers
end

#optionsObject (readonly)

Returns the value of attribute options.



15
16
17
# File 'lib/swarm_sdk/observer/config.rb', line 15

def options
  @options
end

Instance Method Details

#add_handler(event_type) {|Hash| ... } ⇒ void

This method returns an undefined value.

Add an event handler for a specific event type

The block receives the event hash and should return:

  • A prompt string to trigger the observer agent
  • nil to skip execution for this event

Parameters:

  • event_type (Symbol)

    Type of event to handle (e.g., :swarm_start, :tool_call)

Yields:

  • (Hash)

    Event hash with type, agent, and other data

Yield Returns:

  • (String, nil)

    Prompt to execute or nil to skip



40
41
42
# File 'lib/swarm_sdk/observer/config.rb', line 40

def add_handler(event_type, &block)
  @event_handlers[event_type] = block
end