Class: Clacky::Tools::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/clacky/tools/base.rb

Class Attribute Summary collapse

Instance Method Summary collapse

Class Attribute Details

.tool_categoryObject

Returns the value of attribute tool_category.



9
10
11
# File 'lib/clacky/tools/base.rb', line 9

def tool_category
  @tool_category
end

.tool_descriptionObject

Returns the value of attribute tool_description.



9
10
11
# File 'lib/clacky/tools/base.rb', line 9

def tool_description
  @tool_description
end

.tool_nameObject

Returns the value of attribute tool_name.



9
10
11
# File 'lib/clacky/tools/base.rb', line 9

def tool_name
  @tool_name
end

.tool_parametersObject

Returns the value of attribute tool_parameters.



9
10
11
# File 'lib/clacky/tools/base.rb', line 9

def tool_parameters
  @tool_parameters
end

Instance Method Details

#categoryObject



24
25
26
# File 'lib/clacky/tools/base.rb', line 24

def category
  self.class.tool_category || "general"
end

#descriptionObject



16
17
18
# File 'lib/clacky/tools/base.rb', line 16

def description
  self.class.tool_description
end

#execute(**_args) ⇒ Object

Execute the tool - must be implemented by subclasses

Raises:

  • (NotImplementedError)


29
30
31
# File 'lib/clacky/tools/base.rb', line 29

def execute(**_args)
  raise NotImplementedError, "#{self.class.name} must implement #execute"
end

#format_call(args) ⇒ String

Format tool call for display - can be overridden by subclasses

Parameters:

  • args (Hash)

    The arguments passed to the tool

Returns:

  • (String)

    Formatted call description (e.g., "Read(file.rb)")



60
61
62
# File 'lib/clacky/tools/base.rb', line 60

def format_call(args)
  "#{name}(...)"
end

#format_result(result) ⇒ String

Format tool result for display - can be overridden by subclasses

Parameters:

  • result (Object)

    The result returned by execute

Returns:

  • (String)

    Formatted result summary (e.g., "Read 150 lines")



67
68
69
70
71
72
73
74
75
# File 'lib/clacky/tools/base.rb', line 67

def format_result(result)
  if result.is_a?(Hash) && result[:message]
    result[:message]
  elsif result.is_a?(String)
    result.length > 100 ? "#{result[0..100]}..." : result
  else
    "Done"
  end
end

#nameObject



12
13
14
# File 'lib/clacky/tools/base.rb', line 12

def name
  self.class.tool_name
end

#parametersObject



20
21
22
# File 'lib/clacky/tools/base.rb', line 20

def parameters
  self.class.tool_parameters
end

#to_function_definitionObject

Convert to OpenAI function calling format



78
79
80
81
82
83
84
85
86
87
# File 'lib/clacky/tools/base.rb', line 78

def to_function_definition
  {
    type: "function",
    function: {
      name: name,
      description: description,
      parameters: parameters
    }
  }
end