Class: SharedTools::Tools::CurrentDateTimeTool

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

Overview

A tool that returns the current date, time, and timezone information. Useful for AI assistants that need to know the current time context.

Examples:

tool = SharedTools::Tools::CurrentDateTimeTool.new
result = tool.execute
puts result[:date]      # "2025-12-17"
puts result[:time]      # "13:45:30"
puts result[:timezone]  # "America/Chicago"

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(logger: nil) ⇒ CurrentDateTimeTool



50
51
52
# File 'lib/shared_tools/tools/current_date_time_tool.rb', line 50

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

Class Method Details

.nameObject



18
# File 'lib/shared_tools/tools/current_date_time_tool.rb', line 18

def self.name = 'current_date_time'

Instance Method Details

#execute(format: 'full') ⇒ Hash

Execute the date/time query



58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# File 'lib/shared_tools/tools/current_date_time_tool.rb', line 58

def execute(format: 'full')
  @logger.info("DateTimeTool#execute format=#{format.inspect}")

  now = Time.now

  case format.to_s.downcase
  when 'date_only'
    date_only_response(now)
  when 'time_only'
    time_only_response(now)
  when 'iso8601'
    iso8601_response(now)
  else
    full_response(now)
  end
end