Module: ConsoleAgent

Defined in:
lib/console_agent.rb,
lib/console_agent/repl.rb,
lib/console_agent/railtie.rb,
lib/console_agent/version.rb,
lib/console_agent/executor.rb,
lib/console_agent/storage/base.rb,
lib/console_agent/configuration.rb,
lib/console_agent/providers/base.rb,
lib/console_agent/tools/registry.rb,
lib/console_agent/console_methods.rb,
lib/console_agent/context_builder.rb,
lib/console_agent/providers/openai.rb,
lib/console_agent/tools/code_tools.rb,
lib/console_agent/tools/model_tools.rb,
lib/console_agent/tools/memory_tools.rb,
lib/console_agent/tools/schema_tools.rb,
lib/console_agent/providers/anthropic.rb,
lib/console_agent/storage/file_storage.rb,
lib/generators/console_agent/install_generator.rb

Defined Under Namespace

Modules: ConsoleMethods, Generators, Providers, Storage, Tools Classes: Configuration, ConfigurationError, ContextBuilder, Executor, Railtie, Repl, TeeIO

Constant Summary collapse

VERSION =
'0.2.0'.freeze

Class Method Summary collapse

Class Method Details

.configurationObject



6
7
8
# File 'lib/console_agent.rb', line 6

def configuration
  @configuration ||= Configuration.new
end

.configure {|configuration| ... } ⇒ Object

Yields:



10
11
12
# File 'lib/console_agent.rb', line 10

def configure
  yield(configuration) if block_given?
end

.loggerObject



35
36
37
38
39
40
41
42
# File 'lib/console_agent.rb', line 35

def logger
  @logger ||= if defined?(Rails) && Rails.respond_to?(:logger) && Rails.logger
                Rails.logger
              else
                require 'logger'
                Logger.new($stderr, progname: 'ConsoleAgent')
              end
end

.logger=(log) ⇒ Object



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

def logger=(log)
  @logger = log
end

.reset_configuration!Object



14
15
16
17
# File 'lib/console_agent.rb', line 14

def reset_configuration!
  @configuration = Configuration.new
  reset_storage!
end

.reset_storage!Object



31
32
33
# File 'lib/console_agent.rb', line 31

def reset_storage!
  @storage = nil
end

.statusObject



48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/console_agent.rb', line 48

def status
  c = configuration
  key = c.resolved_api_key
  masked_key = if key.nil? || key.empty?
                 "\e[31m(not set)\e[0m"
               else
                 key[0..6] + '...' + key[-4..-1]
               end

  lines = []
  lines << "\e[36m[ConsoleAgent v#{VERSION}]\e[0m"
  lines << "  Provider:       #{c.provider}"
  lines << "  Model:          #{c.resolved_model}"
  lines << "  API key:        #{masked_key}"
  lines << "  Context mode:   #{c.context_mode}"
  lines << "  Max tokens:     #{c.max_tokens}"
  lines << "  Temperature:    #{c.temperature}"
  lines << "  Timeout:        #{c.timeout}s"
  lines << "  Max tool rounds:#{c.max_tool_rounds}" if c.context_mode == :smart
  lines << "  Auto-execute:   #{c.auto_execute}"
  lines << "  Memories:       #{c.memories_enabled}"
  lines << "  Debug:          #{c.debug}"
  $stdout.puts lines.join("\n")
  nil
end

.storageObject



19
20
21
22
23
24
25
26
27
28
29
# File 'lib/console_agent.rb', line 19

def storage
  @storage ||= begin
    adapter = configuration.storage_adapter
    if adapter
      adapter
    else
      require 'console_agent/storage/file_storage'
      Storage::FileStorage.new
    end
  end
end