Class: RSmolagent::Tools::CustomToolBase
- Inherits:
-
Object
- Object
- RSmolagent::Tools::CustomToolBase
- 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
-
#description ⇒ Object
readonly
Returns the value of attribute description.
-
#input_schema ⇒ Object
readonly
Returns the value of attribute input_schema.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Instance Method Summary collapse
-
#fetch_url(url) ⇒ Object
Helper methods that custom tools can use.
-
#initialize(name, description, input_schema = {}) ⇒ CustomToolBase
constructor
A new instance of CustomToolBase.
- #parse_json(json_string) ⇒ Object
-
#read_file(path) ⇒ Object
Additional helper methods for safe file operations.
-
#run(args = {}) ⇒ Object
This method must be implemented by subclasses.
- #to_tool ⇒ Object
- #write_file(path, content) ⇒ Object
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
#description ⇒ Object (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_schema ⇒ Object (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 |
#name ⇒ Object (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
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_tool ⇒ Object
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 |