Class: RubyCode::Tools::Base
- Inherits:
-
Object
- Object
- RubyCode::Tools::Base
- Defined in:
- lib/rubycode/tools/base.rb
Overview
Base class for all tools that can be executed by the AI agent
Instance Attribute Summary collapse
-
#context ⇒ Object
readonly
Returns the value of attribute context.
Class Method Summary collapse
Instance Method Summary collapse
- #execute(params) ⇒ Object
-
#initialize(context:) ⇒ Base
constructor
A new instance of Base.
Constructor Details
#initialize(context:) ⇒ Base
Returns a new instance of Base.
11 12 13 |
# File 'lib/rubycode/tools/base.rb', line 11 def initialize(context:) @context = context end |
Instance Attribute Details
#context ⇒ Object (readonly)
Returns the value of attribute context.
9 10 11 |
# File 'lib/rubycode/tools/base.rb', line 9 def context @context end |
Class Method Details
.definition ⇒ Object
25 26 27 |
# File 'lib/rubycode/tools/base.rb', line 25 def self.definition @definition ||= load_schema end |
.load_schema ⇒ Object
29 30 31 32 33 34 35 36 |
# File 'lib/rubycode/tools/base.rb', line 29 def self.load_schema tool_name = name.split("::").last.downcase schema_path = File.join(__dir__, "..", "..", "..", "config", "tools", "#{tool_name}.json") raise ToolError, "Schema file not found: #{schema_path}" unless File.exist?(schema_path) JSON.parse(File.read(schema_path), symbolize_names: true) end |
Instance Method Details
#execute(params) ⇒ Object
15 16 17 18 19 20 21 22 23 |
# File 'lib/rubycode/tools/base.rb', line 15 def execute(params) validate_params!(params) result = perform(params) wrap_result(result) rescue ToolError => e raise e rescue StandardError => e raise ToolError, "Error in #{self.class.name}: #{e.}" end |