Class: Riffer::Tool Abstract
- Inherits:
-
Object
- Object
- Riffer::Tool
- Extended by:
- Helpers::ClassNameConverter
- Defined in:
- lib/riffer/tool.rb
Overview
This class is abstract.
Subclasses must implement the ‘call` method.
Riffer::Tool is the base class for all tools in the Riffer framework.
Provides a DSL for defining tool description and parameters.
Class Method Summary collapse
-
.description(value = nil) ⇒ String?
Gets or sets the tool description.
-
.identifier(value = nil) ⇒ String
(also: name)
Gets or sets the tool identifier/name.
-
.parameters_schema ⇒ Hash
Returns the JSON Schema for the tool’s parameters.
-
.params { ... } ⇒ Riffer::Tools::Params?
Defines parameters using the Params DSL.
Instance Method Summary collapse
-
#call(context:, **kwargs) ⇒ Object
Executes the tool with the given arguments.
-
#call_with_validation(context:, **kwargs) ⇒ Object
Executes the tool with validation (used by Agent).
Class Method Details
.description(value = nil) ⇒ String?
Gets or sets the tool description
31 32 33 34 |
# File 'lib/riffer/tool.rb', line 31 def description(value = nil) return @description if value.nil? @description = value.to_s end |
.identifier(value = nil) ⇒ String Also known as: name
Gets or sets the tool identifier/name
39 40 41 42 |
# File 'lib/riffer/tool.rb', line 39 def identifier(value = nil) return @identifier || class_name_to_path(Module.instance_method(:name).bind_call(self)) if value.nil? @identifier = value.to_s end |
.parameters_schema ⇒ Hash
Returns the JSON Schema for the tool’s parameters
58 59 60 |
# File 'lib/riffer/tool.rb', line 58 def parameters_schema @params_builder&.to_json_schema || empty_schema end |
.params { ... } ⇒ Riffer::Tools::Params?
Defines parameters using the Params DSL
50 51 52 53 54 |
# File 'lib/riffer/tool.rb', line 50 def params(&block) return @params_builder if block.nil? @params_builder = Riffer::Tools::Params.new @params_builder.instance_eval(&block) end |
Instance Method Details
#call(context:, **kwargs) ⇒ Object
Executes the tool with the given arguments
74 75 76 |
# File 'lib/riffer/tool.rb', line 74 def call(context:, **kwargs) raise NotImplementedError, "#{self.class} must implement #call" end |
#call_with_validation(context:, **kwargs) ⇒ Object
Executes the tool with validation (used by Agent)
83 84 85 86 87 |
# File 'lib/riffer/tool.rb', line 83 def call_with_validation(context:, **kwargs) params_builder = self.class.params validated_args = params_builder ? params_builder.validate(kwargs) : kwargs call(context: context, **validated_args) end |