Class: RSmolagent::Tools::CustomToolFactory

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

Overview

Factory for creating tools from custom tool classes

Class Method Summary collapse

Class Method Details

.create_from_code(code) ⇒ Object



58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
# File 'lib/rsmolagent/tools/custom_tool_base.rb', line 58

def self.create_from_code(code)
  # Create a clean binding
  context = Object.new.instance_eval { binding }
  
  # Make CustomToolBase available in the context
  context.eval("CustomToolBase = RSmolagent::Tools::CustomToolBase")
  
  # Evaluate the code to define the class
  context.eval(code)
  
  # Find the class name
  class_name = extract_class_name(code)
  
  # Create an instance of the class
  tool_instance = context.eval("#{class_name}.new")
  
  # Ensure it's a CustomToolBase
  unless tool_instance.is_a?(CustomToolBase)
    raise "The class must inherit from CustomToolBase"
  end
  
  # Convert to a Tool
  tool_instance.to_tool
end