Class: AgentHarness::Configuration

Inherits:
Object
  • Object
show all
Defined in:
lib/agent_harness/configuration.rb

Overview

Configuration for AgentHarness

Supports configuration via Ruby DSL, YAML files, and environment variables. Configuration sources are merged with priority: Ruby DSL > YAML > Environment.

Examples:

Ruby DSL configuration

AgentHarness.configure do |config|
  config.logger = Logger.new(STDOUT)
  config.default_provider = :cursor
  config.fallback_providers = [:claude, :gemini]

  config.provider :claude do |p|
    p.enabled = true
    p.timeout = 600
  end
end

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConfiguration

Returns a new instance of Configuration.



27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/agent_harness/configuration.rb', line 27

def initialize
  @logger = nil # Will use null logger if not set
  @log_level = :info
  @default_provider = :cursor
  @fallback_providers = []
  @command_executor = nil # Lazy-initialized
  @config_file_path = nil
  @default_timeout = 300
  @providers = {}
  @orchestration_config = OrchestrationConfig.new
  @callbacks = CallbackRegistry.new
  @custom_provider_classes = {}
end

Instance Attribute Details

#callbacksObject (readonly)

Returns the value of attribute callbacks.



25
26
27
# File 'lib/agent_harness/configuration.rb', line 25

def callbacks
  @callbacks
end

#command_executorCommandExecutor

Get or lazily initialize the command executor

Returns:



44
45
46
# File 'lib/agent_harness/configuration.rb', line 44

def command_executor
  @command_executor ||= CommandExecutor.new(logger: @logger)
end

#config_file_pathObject

Returns the value of attribute config_file_path.



22
23
24
# File 'lib/agent_harness/configuration.rb', line 22

def config_file_path
  @config_file_path
end

#custom_provider_classesObject (readonly)

Returns the value of attribute custom_provider_classes.



25
26
27
# File 'lib/agent_harness/configuration.rb', line 25

def custom_provider_classes
  @custom_provider_classes
end

#default_providerObject

Returns the value of attribute default_provider.



21
22
23
# File 'lib/agent_harness/configuration.rb', line 21

def default_provider
  @default_provider
end

#default_timeoutObject

Returns the value of attribute default_timeout.



22
23
24
# File 'lib/agent_harness/configuration.rb', line 22

def default_timeout
  @default_timeout
end

#fallback_providersObject

Returns the value of attribute fallback_providers.



21
22
23
# File 'lib/agent_harness/configuration.rb', line 21

def fallback_providers
  @fallback_providers
end

#log_levelObject

Returns the value of attribute log_level.



21
22
23
# File 'lib/agent_harness/configuration.rb', line 21

def log_level
  @log_level
end

#loggerObject

Returns the value of attribute logger.



21
22
23
# File 'lib/agent_harness/configuration.rb', line 21

def logger
  @logger
end

#orchestration_configObject (readonly)

Returns the value of attribute orchestration_config.



25
26
27
# File 'lib/agent_harness/configuration.rb', line 25

def orchestration_config
  @orchestration_config
end

#providersObject (readonly)

Returns the value of attribute providers.



25
26
27
# File 'lib/agent_harness/configuration.rb', line 25

def providers
  @providers
end

Instance Method Details

#on_circuit_close {|Hash| ... } ⇒ void

This method returns an undefined value.

Register callback for circuit close events

Yields:

  • (Hash)

    event data with :provider



105
106
107
# File 'lib/agent_harness/configuration.rb', line 105

def on_circuit_close(&block)
  @callbacks.register(:circuit_close, block)
end

#on_circuit_open {|Hash| ... } ⇒ void

This method returns an undefined value.

Register callback for circuit open events

Yields:

  • (Hash)

    event data with :provider, :failure_count



97
98
99
# File 'lib/agent_harness/configuration.rb', line 97

def on_circuit_open(&block)
  @callbacks.register(:circuit_open, block)
end

#on_provider_switch {|Hash| ... } ⇒ void

This method returns an undefined value.

Register callback for provider switch events

Yields:

  • (Hash)

    event data with :from_provider, :to_provider, :reason



89
90
91
# File 'lib/agent_harness/configuration.rb', line 89

def on_provider_switch(&block)
  @callbacks.register(:provider_switch, block)
end

#on_tokens_used {|TokenEvent| ... } ⇒ void

This method returns an undefined value.

Register callback for token usage events

Yields:

  • (TokenEvent)

    called when tokens are used



81
82
83
# File 'lib/agent_harness/configuration.rb', line 81

def on_tokens_used(&block)
  @callbacks.register(:tokens_used, block)
end

#orchestration {|OrchestrationConfig| ... } ⇒ OrchestrationConfig

Configure orchestration settings

Yields:

Returns:



52
53
54
55
# File 'lib/agent_harness/configuration.rb', line 52

def orchestration(&block)
  yield(@orchestration_config) if block_given?
  @orchestration_config
end

#provider(name) {|ProviderConfig| ... } ⇒ ProviderConfig

Configure a provider

Parameters:

  • name (Symbol, String)

    the provider name

Yields:

Returns:



62
63
64
65
66
# File 'lib/agent_harness/configuration.rb', line 62

def provider(name, &block)
  config = ProviderConfig.new(name)
  yield(config) if block_given?
  @providers[name.to_sym] = config
end

#register_provider(name, klass) ⇒ void

This method returns an undefined value.

Register a custom provider class

Parameters:

  • name (Symbol, String)

    the provider name

  • klass (Class)

    the provider class



73
74
75
# File 'lib/agent_harness/configuration.rb', line 73

def register_provider(name, klass)
  @custom_provider_classes[name.to_sym] = klass
end

#valid?Boolean

Check if configuration is valid

Returns:

  • (Boolean)

    true if valid



125
126
127
128
129
130
# File 'lib/agent_harness/configuration.rb', line 125

def valid?
  validate!
  true
rescue ConfigurationError
  false
end

#validate!void

This method returns an undefined value.

Validate the configuration

Raises:



113
114
115
116
117
118
119
120
# File 'lib/agent_harness/configuration.rb', line 113

def validate!
  errors = []

  errors << "No providers configured" if @providers.empty?
  errors << "Default provider '#{@default_provider}' not configured" unless @providers[@default_provider]

  raise ConfigurationError, errors.join(", ") unless errors.empty?
end