module Riffer::Tools::Toolable
Shared class-level DSL for anything that presents as a tool to an LLM. Extend it to make a class discoverable as a tool; instance-level execution (call, call_with_validation) lives on Riffer::Tool instead.
class MyTool extend Riffer::Tools::Toolable description "Does something useful" params do required :input, String end end
Constants
- DEFAULT_TIMEOUT
-
@rbs self.@extenders: Array? @rbs @description: String? @rbs @identifier: String? @rbs @timeout: (Integer | Float)? @rbs @params_builder: Riffer::Params? @rbs @kind: Symbol?
Public Class Methods
Source
# File lib/riffer/tools/toolable.rb, line 41 def self.all @extenders || [] end
Returns all classes that have extended Toolable.
Source
# File lib/riffer/tools/toolable.rb, line 32 def self.extended(base) extenders = (@extenders ||= []) #: Array[Module] extenders << base end
Tracks all classes that extend Toolable.
Public Instance Methods
Source
# File lib/riffer/tools/toolable.rb, line 49 def description(value = nil) return @description if value.nil? @description = value.to_s end
Gets or sets the tool description.
Source
# File lib/riffer/tools/toolable.rb, line 58 def identifier(value = nil) return @identifier || Riffer::Helpers::ClassNameConverter.convert(Module.instance_method(:name).bind_call(self)) if value.nil? @identifier = value.to_s end
Gets or sets the tool identifier/name.
Source
# File lib/riffer/tools/toolable.rb, line 103 def kind(value = nil) return @kind || :tool if value.nil? @kind = value.to_sym end
Returns the kind of toolable entity; defaults to :tool.
Source
# File lib/riffer/tools/toolable.rb, line 67 def name(value = nil) return identifier(value) unless value.nil? identifier end
Alias for identifier β used by providers.
Source
# File lib/riffer/tools/toolable.rb, line 96 def parameters_schema(strict: false) @params_builder&.to_json_schema(strict: strict) || empty_schema end
Returns the JSON Schema for the toolβs parameters.
Source
# File lib/riffer/tools/toolable.rb, line 85 def params(&block) return @params_builder if block.nil? builder = Riffer::Params.new builder.instance_eval(&block) @params_builder = builder end
Defines parameters using the Params DSL.
Source
# File lib/riffer/tools/toolable.rb, line 76 def timeout(value = nil) return @timeout || DEFAULT_TIMEOUT if value.nil? @timeout = value.to_f end
Gets or sets the tool timeout in seconds.
Source
# File lib/riffer/tools/toolable.rb, line 112 def to_tool_schema(strict: false) { name: name, description: description, parameters_schema: parameters_schema(strict: strict) } end
Returns a provider-agnostic tool schema hash.
Source
# File lib/riffer/tools/toolable.rb, line 126 def validate_as_tool! raise Riffer::ArgumentError, "#{self} must define a description" if description.nil? || description.to_s.strip.empty? raise Riffer::ArgumentError, "#{self} must have an identifier" if identifier.nil? || identifier.to_s.strip.empty? true end
Validates that the minimum required metadata is present for LLM tool use.
Raises Riffer::ArgumentError if validation fails.