Class: Riffer::Tool
- Inherits:
-
Object
- Object
- Riffer::Tool
- Extended by:
- Registrable, Riffer::Tools::Toolable
- Defined in:
- lib/riffer/tool.rb,
sig/manual/riffer/tool.rbs,
sig/generated/riffer/tool.rbs
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, Mcp::Tool, Skills::ActivateTool
Constant Summary
Constants included from Riffer::Tools::Toolable
Riffer::Tools::Toolable::DEFAULT_TIMEOUT
Class Method Summary collapse
Instance Method Summary collapse
-
#call(context:, **kwargs) ⇒ Riffer::Tools::Response
Executes the tool with the given arguments.
-
#call_with_validation(context:, **kwargs) ⇒ Riffer::Tools::Response
Executes the tool with validation and timeout, folding every
StandardErrorinto an error Response. -
#error(message, type: :execution_error) ⇒ Riffer::Tools::Response
Creates an error response.
-
#json(result) ⇒ Riffer::Tools::Response
Creates a JSON response.
-
#text(result) ⇒ Riffer::Tools::Response
Creates a text response.
Methods included from Riffer::Tools::Toolable
description, extended, identifier, kind, name, parameters_schema, params, timeout, to_tool_schema, validate_as_tool!
Methods included from Registrable
Class Method Details
.all ⇒ Array[singleton(Riffer::Tool)]
6 |
# File 'sig/manual/riffer/tool.rbs', line 6
def self.all: () -> Array[singleton(Riffer::Tool)]
|
.find ⇒ singleton(Riffer::Tool)?
4 |
# File 'sig/manual/riffer/tool.rbs', line 4
def self.find: (String | Symbol) -> singleton(Riffer::Tool)?
|
Instance Method Details
#call(context:, **kwargs) ⇒ Riffer::Tools::Response
Executes the tool with the given arguments.
: (context: Riffer::Agent::Context?, **untyped) -> Riffer::Tools::Response
31 32 33 |
# File 'lib/riffer/tool.rb', line 31 def call(context:, **kwargs) raise NotImplementedError, "#{self.class} must implement #call" end |
#call_with_validation(context:, **kwargs) ⇒ Riffer::Tools::Response
Executes the tool with validation and timeout, folding every StandardError
into an error Response. Anything outside StandardError — an unimplemented
#call above all — still propagates, because a broken tool is a broken
deploy rather than a bad request.
-- : (context: Riffer::Agent::Context?, **untyped) -> Riffer::Tools::Response
66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 |
# File 'lib/riffer/tool.rb', line 66 def call_with_validation(context:, **kwargs) params_builder = self.class.params begin validated_args = params_builder ? params_builder.validate(kwargs) : kwargs rescue Riffer::ValidationError => e return Riffer::Tools::Response.error(e., type: :validation_error) end result = Timeout.timeout(self.class.timeout, Riffer::TimeoutError) 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 Riffer::TimeoutError Riffer::Tools::Response.error( "Tool execution timed out after #{self.class.timeout} seconds", type: :timeout_error, ) rescue Riffer::ToolExecutionError => e Riffer::Tools::Response.error(e., type: :execution_error) rescue StandardError => e Riffer::Tools::Response.error( "Error executing tool: #{e.class}: #{e.}", type: :unhandled_error, exception: e, ) end |
#error(message, type: :execution_error) ⇒ Riffer::Tools::Response
Creates an error response.
-- : (String, ?type: Symbol) -> Riffer::Tools::Response
55 56 57 |
# File 'lib/riffer/tool.rb', line 55 def error(, type: :execution_error) Riffer::Tools::Response.error(, type: type) end |
#json(result) ⇒ Riffer::Tools::Response
Creates a JSON response.
-- : (untyped) -> Riffer::Tools::Response
47 48 49 |
# File 'lib/riffer/tool.rb', line 47 def json(result) Riffer::Tools::Response.json(result) end |
#text(result) ⇒ Riffer::Tools::Response
Creates a text response.
-- : (untyped) -> Riffer::Tools::Response
39 40 41 |
# File 'lib/riffer/tool.rb', line 39 def text(result) Riffer::Tools::Response.text(result) end |