Class: Riffer::Messages::Tool

Inherits:
Base
  • Object
show all
Defined in:
lib/riffer/messages/tool.rb

Overview

Represents a tool execution result in a conversation.

msg = Riffer::Messages::Tool.new(
  "The weather is sunny.",
  tool_call_id: "call_123",
  name: "weather_tool"
)
msg.role          # => :tool
msg.tool_call_id  # => "call_123"
msg.error?        # => false

Instance Attribute Summary collapse

Attributes inherited from Base

#content

Instance Method Summary collapse

Constructor Details

#initialize(content, tool_call_id:, name:, error: nil, error_type: nil) ⇒ Tool

– : (String, tool_call_id: String, name: String, ?error: String?, ?error_type: Symbol?) -> void



30
31
32
33
34
35
36
# File 'lib/riffer/messages/tool.rb', line 30

def initialize(content, tool_call_id:, name:, error: nil, error_type: nil)
  super(content)
  @tool_call_id = tool_call_id
  @name = name
  @error = error
  @error_type = error_type
end

Instance Attribute Details

#errorObject (readonly)

The error message if the tool execution failed.



23
24
25
# File 'lib/riffer/messages/tool.rb', line 23

def error
  @error
end

#error_typeObject (readonly)

The type of error (:unknown_tool, :validation_error, :execution_error, :timeout_error).



26
27
28
# File 'lib/riffer/messages/tool.rb', line 26

def error_type
  @error_type
end

#nameObject (readonly)

The name of the tool that was called.



20
21
22
# File 'lib/riffer/messages/tool.rb', line 20

def name
  @name
end

#tool_call_idObject (readonly)

The ID of the tool call this result responds to.



17
18
19
# File 'lib/riffer/messages/tool.rb', line 17

def tool_call_id
  @tool_call_id
end

Instance Method Details

#error?Boolean

Returns true if the tool execution resulted in an error.

– : () -> bool

Returns:



42
43
44
# File 'lib/riffer/messages/tool.rb', line 42

def error?
  !@error.nil?
end

#roleObject

– : () -> Symbol



48
49
50
# File 'lib/riffer/messages/tool.rb', line 48

def role
  :tool
end

#to_hObject

Converts the message to a hash.

– : () -> Hash[Symbol, untyped]



56
57
58
59
60
61
62
63
# File 'lib/riffer/messages/tool.rb', line 56

def to_h
  hash = {role: role, content: content, tool_call_id: tool_call_id, name: name}
  if error?
    hash[:error] = error
    hash[:error_type] = error_type
  end
  hash
end