Class: RSmolagent::Tools::CustomToolBase

Inherits:
Object
  • Object
show all
Defined in:
lib/rsmolagent/tools/custom_tool_base.rb

Overview

Base class that custom tools can inherit from when using the CustomClassExecutorTool

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, description, input_schema = {}) ⇒ CustomToolBase

Returns a new instance of CustomToolBase.



7
8
9
10
11
# File 'lib/rsmolagent/tools/custom_tool_base.rb', line 7

def initialize(name, description, input_schema = {})
  @name = name
  @description = description
  @input_schema = input_schema
end

Instance Attribute Details

#descriptionObject (readonly)

Returns the value of attribute description.



5
6
7
# File 'lib/rsmolagent/tools/custom_tool_base.rb', line 5

def description
  @description
end

#input_schemaObject (readonly)

Returns the value of attribute input_schema.



5
6
7
# File 'lib/rsmolagent/tools/custom_tool_base.rb', line 5

def input_schema
  @input_schema
end

#nameObject (readonly)

Returns the value of attribute name.



5
6
7
# File 'lib/rsmolagent/tools/custom_tool_base.rb', line 5

def name
  @name
end

Instance Method Details

#fetch_url(url) ⇒ Object

Helper methods that custom tools can use



20
21
22
23
24
25
26
# File 'lib/rsmolagent/tools/custom_tool_base.rb', line 20

def fetch_url(url)
  require 'net/http'
  require 'uri'
  
  uri = URI(url)
  Net::HTTP.get(uri)
end

#parse_json(json_string) ⇒ Object



28
29
30
31
# File 'lib/rsmolagent/tools/custom_tool_base.rb', line 28

def parse_json(json_string)
  require 'json'
  JSON.parse(json_string)
end

#read_file(path) ⇒ Object

Additional helper methods for safe file operations



45
46
47
48
# File 'lib/rsmolagent/tools/custom_tool_base.rb', line 45

def read_file(path)
  # Only allow reading files from a specific directory in a real implementation
  File.read(path)
end

#run(args = {}) ⇒ Object

This method must be implemented by subclasses

Raises:

  • (NotImplementedError)


14
15
16
# File 'lib/rsmolagent/tools/custom_tool_base.rb', line 14

def run(args = {})
  raise NotImplementedError, "Subclasses must implement the 'run' method"
end

#to_toolObject



33
34
35
36
37
38
39
40
41
42
# File 'lib/rsmolagent/tools/custom_tool_base.rb', line 33

def to_tool
  # Convert this custom tool to a RSmolagent::Tool
  RSmolagent::Tool.new(
    name: @name,
    description: @description,
    input_schema: @input_schema
  ) do |args|
    run(args)
  end
end

#write_file(path, content) ⇒ Object



50
51
52
53
# File 'lib/rsmolagent/tools/custom_tool_base.rb', line 50

def write_file(path, content)
  # Only allow writing files to a specific directory in a real implementation
  File.write(path, content)
end