class Riffer::Tool
Riffer::Tool is the base class for all tools in the Riffer framework.
Provides a DSL for defining tool description and parameters. Subclasses must implement the call method.
See Riffer::Agent.
class WeatherLookupTool < Riffer::Tool description "Provides current weather information for a specified city." params do required :city, String, description: "The city to look up" optional :units, String, default: "celsius" end def call(context:, city:, units: nil) # Implementation end end
Public Instance Methods
Source
# File lib/riffer/tool.rb, line 37 def call(context:, **kwargs) raise NotImplementedError, "#{self.class} must implement #call" end
Executes the tool with the given arguments.
Raises NotImplementedError if not implemented by subclass.
Source
# File lib/riffer/tool.rb, line 73 def call_with_validation(context:, **kwargs) params_builder = self.class.params validated_args = params_builder ? params_builder.validate(kwargs) : kwargs result = Timeout.timeout(self.class.timeout) do call(context: context, **validated_args) end unless result.is_a?(Riffer::Tools::Response) raise Riffer::Error, "#{self.class} must return a Riffer::Tools::Response from #call" end result rescue Timeout::Error raise Riffer::TimeoutError, "Tool execution timed out after #{self.class.timeout} seconds" end
Executes the tool with validation and timeout (used by Agent).
Raises Riffer::ValidationError if validation fails. Raises Riffer::TimeoutError if execution exceeds the configured timeout. Raises Riffer::Error if the tool does not return a Response object.
Source
# File lib/riffer/tool.rb, line 61 def error(message, type: :execution_error) Riffer::Tools::Response.error(message, type: type) end
Creates an error response. Shorthand for Riffer::Tools::Response.error.
Source
# File lib/riffer/tool.rb, line 53 def json(result) Riffer::Tools::Response.json(result) end
Creates a JSON response. Shorthand for Riffer::Tools::Response.json.
Source
# File lib/riffer/tool.rb, line 45 def text(result) Riffer::Tools::Response.text(result) end
Creates a text response. Shorthand for Riffer::Tools::Response.text.