class Riffer::Tools::Response
Every toolβs call must return one.
Constants
- VALID_FORMATS
-
@rbs @success: bool
Attributes
Kept out of every serialized form so it never reaches an LLM or a message payload.
Public Class Methods
Source
# File lib/riffer/tools/response.rb, line 53 def self.error(message, type: :execution_error, exception: nil) new(content: message, success: false, error_message: message, error_type: type, exception: exception) end
Source
# File lib/riffer/tools/response.rb, line 40 def self.json(result) success(result, format: :json) end
Source
# File lib/riffer/tools/response.rb, line 47 def self.load_tools(tools) new(content: "", success: true, loaded_tools: tools) end
No text alongside: Anthropic rejects a tool result that mixes tool_reference blocks with text.
Source
# File lib/riffer/tools/response.rb, line 75 def initialize(content:, success:, error_message: nil, error_type: nil, exception: nil, loaded_tools: []) @content = content @success = success @error_message = error_message @error_type = error_type @exception = exception @loaded_tools = loaded_tools end
Source
# File lib/riffer/tools/response.rb, line 23 def self.success(result, format: :text) unless VALID_FORMATS.include?(format) raise Riffer::ArgumentError, "Invalid format: #{format}. Must be one of: #{VALID_FORMATS.join(', ')}" end content = format == :json ? result.to_json : result.to_s new(content: content, success: true) end
Source
# File lib/riffer/tools/response.rb, line 34 def self.text(result) success(result, format: :text) end
Public Instance Methods
Source
# File lib/riffer/tools/response.rb, line 63 def error? = !@success #-- #: () -> Hash[Symbol, untyped] def to_h { content: @content, error: @error_message, error_type: @error_type } end private #-- #: (content: String, success: bool, ?error_message: String?, ?error_type: Symbol?, ?exception: Exception?, ?loaded_tools: Array[singleton(Riffer::Tool)]) -> void def initialize(content:, success:, error_message: nil, error_type: nil, exception: nil, loaded_tools: []) @content = content @success = success @error_message = error_message @error_type = error_type @exception = exception @loaded_tools = loaded_tools end end
Source
# File lib/riffer/tools/response.rb, line 59 def success? = @success #-- #: () -> bool def error? = !@success #-- #: () -> Hash[Symbol, untyped] def to_h { content: @content, error: @error_message, error_type: @error_type } end private #-- #: (content: String, success: bool, ?error_message: String?, ?error_type: Symbol?, ?exception: Exception?, ?loaded_tools: Array[singleton(Riffer::Tool)]) -> void def initialize(content:, success:, error_message: nil, error_type: nil, exception: nil, loaded_tools: []) @content = content @success = success @error_message = error_message @error_type = error_type @exception = exception @loaded_tools = loaded_tools end
Source
# File lib/riffer/tools/response.rb, line 67 def to_h { content: @content, error: @error_message, error_type: @error_type } end