Class: Riffer::Tool
- Inherits:
-
Object
- Object
- Riffer::Tool
- Extended by:
- Riffer::Tools::Toolable
- Defined in:
- lib/riffer/tool.rb
Overview
Base class for all tools in the Riffer framework. Subclasses must implement the call method.
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
Direct Known Subclasses
Evals::Judge::EvaluationTool, Mcp::SearchTool, Skills::ActivateTool
Constant Summary
Constants included from Riffer::Tools::Toolable
Riffer::Tools::Toolable::DEFAULT_TIMEOUT
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 and timeout (used by Agent).
-
#error(message, type: :execution_error) ⇒ Object
Creates an error response.
-
#json(result) ⇒ Object
Creates a JSON response.
-
#text(result) ⇒ Object
Creates a text response.
Methods included from Riffer::Tools::Toolable
all, description, extended, identifier, kind, name, parameters_schema, params, timeout, to_tool_schema, validate_as_tool!
Instance Method Details
#call(context:, **kwargs) ⇒ Object
Executes the tool with the given arguments. – : (context: Riffer::Agent::Context?, **untyped) -> Riffer::Tools::Response
30 31 32 |
# File 'lib/riffer/tool.rb', line 30 def call(context:, **kwargs) raise NotImplementedError, "#{self.class} must implement #call" end |
#call_with_validation(context:, **kwargs) ⇒ Object
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.
– : (context: Riffer::Agent::Context?, **untyped) -> Riffer::Tools::Response
66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'lib/riffer/tool.rb', line 66 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) #: untyped 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 |
#error(message, type: :execution_error) ⇒ Object
Creates an error response.
– : (String, ?type: Symbol) -> Riffer::Tools::Response
54 55 56 |
# File 'lib/riffer/tool.rb', line 54 def error(, type: :execution_error) Riffer::Tools::Response.error(, type: type) end |