Class: SharedTools::Tools::SystemInfoTool

Inherits:
RubyLLM::Tool
  • Object
show all
Defined in:
lib/shared_tools/tools/system_info_tool.rb

Overview

Returns OS, CPU, memory, disk, network, and Ruby runtime information.

Examples:

tool = SharedTools::Tools::SystemInfoTool.new
tool.execute                     # all categories
tool.execute(category: 'cpu')    # CPU only

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(logger: nil) ⇒ SystemInfoTool

Returns a new instance of SystemInfoTool.

Parameters:

  • logger (Logger) (defaults to: nil)

    optional logger



36
37
38
# File 'lib/shared_tools/tools/system_info_tool.rb', line 36

def initialize(logger: nil)
  @logger = logger || RubyLLM.logger
end

Class Method Details

.nameObject



14
# File 'lib/shared_tools/tools/system_info_tool.rb', line 14

def self.name = 'system_info_tool'

Instance Method Details

#execute(category: 'all') ⇒ Hash

Returns system information.

Parameters:

  • category (String) (defaults to: 'all')

    which subsystem to query

Returns:

  • (Hash)

    system information



42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/shared_tools/tools/system_info_tool.rb', line 42

def execute(category: 'all')
  @logger.info("SystemInfoTool#execute category=#{category}")

  case category.to_s.downcase
  when 'os'      then { success: true }.merge(os_info)
  when 'cpu'     then { success: true }.merge(cpu_info)
  when 'memory'  then { success: true }.merge(memory_info)
  when 'disk'    then { success: true }.merge(disk_info)
  when 'network' then { success: true }.merge(network_info)
  when 'ruby'    then { success: true }.merge(ruby_info)
  else
    { success: true }
      .merge(os_info)
      .merge(cpu_info)
      .merge(memory_info)
      .merge(disk_info)
      .merge(network_info)
      .merge(ruby_info)
  end
rescue => e
  @logger.error("SystemInfoTool error: #{e.message}")
  { success: false, error: e.message }
end