Class: ConsoleAgent::Configuration

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

Constant Summary collapse

PROVIDERS =
i[anthropic openai local].freeze
PRICING =
{
  'claude-sonnet-4-6' => { input: 3.0 / 1_000_000, output: 15.0 / 1_000_000 },
  'claude-opus-4-6'   => { input: 15.0 / 1_000_000, output: 75.0 / 1_000_000 },
  'claude-haiku-4-5-20251001' => { input: 0.80 / 1_000_000, output: 4.0 / 1_000_000 },
}.freeze
DEFAULT_MAX_TOKENS =
{
  'claude-sonnet-4-6' => 16_000,
  'claude-haiku-4-5-20251001' => 16_000,
  'claude-opus-4-6'   => 4_096,
}.freeze

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
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/console_agent/configuration.rb', line 27

def initialize
  @provider     = :anthropic
  @api_key      = nil
  @model        = nil
  @thinking_model = nil
  @max_tokens   = nil
  @auto_execute = false
  @temperature  = 0.2
  @timeout      = 30
  @debug        = false
  @max_tool_rounds = 200
  @storage_adapter  = nil
  @memories_enabled = true
  @session_logging  = true
  @connection_class = nil
  @admin_username   = nil
  @admin_password   = nil
  @authenticate     = nil
  @safety_guards    = nil
  @slack_bot_token  = nil
  @slack_app_token  = nil
  @slack_channel_ids = nil
  @local_url        = 'http://localhost:11434'
  @local_model      = 'qwen2.5:7b'
  @local_api_key    = nil
end

Instance Attribute Details

#admin_passwordObject

Returns the value of attribute admin_password.



17
18
19
# File 'lib/console_agent/configuration.rb', line 17

def admin_password
  @admin_password
end

#admin_usernameObject

Returns the value of attribute admin_username.



17
18
19
# File 'lib/console_agent/configuration.rb', line 17

def admin_username
  @admin_username
end

#api_keyObject

Returns the value of attribute api_key.



17
18
19
# File 'lib/console_agent/configuration.rb', line 17

def api_key
  @api_key
end

#authenticateObject

Returns the value of attribute authenticate.



17
18
19
# File 'lib/console_agent/configuration.rb', line 17

def authenticate
  @authenticate
end

#auto_executeObject

Returns the value of attribute auto_execute.



17
18
19
# File 'lib/console_agent/configuration.rb', line 17

def auto_execute
  @auto_execute
end

#connection_classObject

Returns the value of attribute connection_class.



17
18
19
# File 'lib/console_agent/configuration.rb', line 17

def connection_class
  @connection_class
end

#debugObject

Returns the value of attribute debug.



17
18
19
# File 'lib/console_agent/configuration.rb', line 17

def debug
  @debug
end

#local_api_keyObject

Returns the value of attribute local_api_key.



17
18
19
# File 'lib/console_agent/configuration.rb', line 17

def local_api_key
  @local_api_key
end

#local_modelObject

Returns the value of attribute local_model.



17
18
19
# File 'lib/console_agent/configuration.rb', line 17

def local_model
  @local_model
end

#local_urlObject

Returns the value of attribute local_url.



17
18
19
# File 'lib/console_agent/configuration.rb', line 17

def local_url
  @local_url
end

#max_tokensObject

Returns the value of attribute max_tokens.



17
18
19
# File 'lib/console_agent/configuration.rb', line 17

def max_tokens
  @max_tokens
end

#max_tool_roundsObject

Returns the value of attribute max_tool_rounds.



17
18
19
# File 'lib/console_agent/configuration.rb', line 17

def max_tool_rounds
  @max_tool_rounds
end

#memories_enabledObject

Returns the value of attribute memories_enabled.



17
18
19
# File 'lib/console_agent/configuration.rb', line 17

def memories_enabled
  @memories_enabled
end

#modelObject

Returns the value of attribute model.



17
18
19
# File 'lib/console_agent/configuration.rb', line 17

def model
  @model
end

#providerObject

Returns the value of attribute provider.



17
18
19
# File 'lib/console_agent/configuration.rb', line 17

def provider
  @provider
end

#session_loggingObject

Returns the value of attribute session_logging.



17
18
19
# File 'lib/console_agent/configuration.rb', line 17

def session_logging
  @session_logging
end

#slack_app_tokenObject

Returns the value of attribute slack_app_token.



17
18
19
# File 'lib/console_agent/configuration.rb', line 17

def slack_app_token
  @slack_app_token
end

#slack_bot_tokenObject

Returns the value of attribute slack_bot_token.



17
18
19
# File 'lib/console_agent/configuration.rb', line 17

def slack_bot_token
  @slack_bot_token
end

#slack_channel_idsObject

Returns the value of attribute slack_channel_ids.



17
18
19
# File 'lib/console_agent/configuration.rb', line 17

def slack_channel_ids
  @slack_channel_ids
end

#storage_adapterObject

Returns the value of attribute storage_adapter.



17
18
19
# File 'lib/console_agent/configuration.rb', line 17

def storage_adapter
  @storage_adapter
end

#temperatureObject

Returns the value of attribute temperature.



17
18
19
# File 'lib/console_agent/configuration.rb', line 17

def temperature
  @temperature
end

#thinking_modelObject

Returns the value of attribute thinking_model.



17
18
19
# File 'lib/console_agent/configuration.rb', line 17

def thinking_model
  @thinking_model
end

#timeoutObject

Returns the value of attribute timeout.



17
18
19
# File 'lib/console_agent/configuration.rb', line 17

def timeout
  @timeout
end

Instance Method Details

#resolved_api_keyObject



99
100
101
102
103
104
105
106
107
108
109
110
# File 'lib/console_agent/configuration.rb', line 99

def resolved_api_key
  return @api_key if @api_key && !@api_key.empty?

  case @provider
  when :anthropic
    ENV['ANTHROPIC_API_KEY']
  when :openai
    ENV['OPENAI_API_KEY']
  when :local
    @local_api_key || 'no-key'
  end
end

#resolved_max_tokensObject



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

def resolved_max_tokens
  return @max_tokens if @max_tokens

  DEFAULT_MAX_TOKENS.fetch(resolved_model, 4096)
end

#resolved_modelObject



112
113
114
115
116
117
118
119
120
121
122
123
# File 'lib/console_agent/configuration.rb', line 112

def resolved_model
  return @model if @model && !@model.empty?

  case @provider
  when :anthropic
    'claude-sonnet-4-6'
  when :openai
    'gpt-5.3-codex'
  when :local
    @local_model
  end
end

#resolved_thinking_modelObject



131
132
133
134
135
136
137
138
139
140
141
142
# File 'lib/console_agent/configuration.rb', line 131

def resolved_thinking_model
  return @thinking_model if @thinking_model && !@thinking_model.empty?

  case @provider
  when :anthropic
    'claude-opus-4-6'
  when :openai
    'gpt-5.3-codex'
  when :local
    @local_model
  end
end

#resolved_timeoutObject



144
145
146
# File 'lib/console_agent/configuration.rb', line 144

def resolved_timeout
  @provider == :local ? [@timeout, 300].max : @timeout
end

#safety_guard(name, &block) ⇒ Object

Register a custom safety guard by name with an around-block.

config.safety_guard :mailers do |&execute|
  ActionMailer::Base.perform_deliveries = false
  execute.call
ensure
  ActionMailer::Base.perform_deliveries = true
end


69
70
71
# File 'lib/console_agent/configuration.rb', line 69

def safety_guard(name, &block)
  safety_guards.add(name, &block)
end

#safety_guardsObject



54
55
56
57
58
59
# File 'lib/console_agent/configuration.rb', line 54

def safety_guards
  @safety_guards ||= begin
    require 'console_agent/safety_guards'
    SafetyGuards.new
  end
end

#use_builtin_safety_guard(name, allow: nil) ⇒ Object

Register a built-in safety guard by name. Available: :database_writes, :http_mutations, :mailers

Options:

allow: Array of strings or regexps to allowlist for this guard.
  - :http_mutations  


80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
# File 'lib/console_agent/configuration.rb', line 80

def use_builtin_safety_guard(name, allow: nil)
  require 'console_agent/safety_guards'
  guard_name = name.to_sym
  case guard_name
  when :database_writes
    safety_guards.add(:database_writes, &BuiltinGuards.database_writes)
  when :http_mutations
    safety_guards.add(:http_mutations, &BuiltinGuards.http_mutations)
  when :mailers
    safety_guards.add(:mailers, &BuiltinGuards.mailers)
  else
    raise ConfigurationError, "Unknown built-in safety guard: #{name}. Available: database_writes, http_mutations, mailers"
  end

  if allow
    Array(allow).each { |key| safety_guards.allow(guard_name, key) }
  end
end

#validate!Object



148
149
150
151
152
153
154
155
156
157
158
159
160
161
# File 'lib/console_agent/configuration.rb', line 148

def validate!
  unless PROVIDERS.include?(@provider)
    raise ConfigurationError, "Unknown provider: #{@provider}. Valid: #{PROVIDERS.join(', ')}"
  end

  if @provider == :local
    raise ConfigurationError, "No local_url configured for :local provider." unless @local_url && !@local_url.empty?
  else
    unless resolved_api_key
      env_var = @provider == :anthropic ? 'ANTHROPIC_API_KEY' : 'OPENAI_API_KEY'
      raise ConfigurationError, "No API key. Set config.api_key or #{env_var} env var."
    end
  end
end