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

Creates a new tool result message.

content

String - the tool execution result

tool_call_id

String - the ID of the tool call

name

String - the tool name

error

String or nil - optional error message

error_type

Symbol or nil - optional error type



42
43
44
45
46
47
48
# File 'lib/riffer/messages/tool.rb', line 42

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.

Returns String or nil.



28
29
30
# File 'lib/riffer/messages/tool.rb', line 28

def error
  @error
end

#error_typeObject (readonly)

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

Returns Symbol or nil.



33
34
35
# File 'lib/riffer/messages/tool.rb', line 33

def error_type
  @error_type
end

#nameObject (readonly)

The name of the tool that was called.

Returns String.



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

def name
  @name
end

#tool_call_idObject (readonly)

The ID of the tool call this result responds to.

Returns String.



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

def tool_call_id
  @tool_call_id
end

Instance Method Details

#error?Boolean

Returns true if the tool execution resulted in an error.

Returns Boolean.

Returns:

  • (Boolean)


53
54
55
# File 'lib/riffer/messages/tool.rb', line 53

def error?
  !@error.nil?
end

#roleObject

Returns :tool.



58
59
60
# File 'lib/riffer/messages/tool.rb', line 58

def role
  :tool
end

#to_hObject

Converts the message to a hash.

Returns Hash with message data including error info if present.



65
66
67
68
69
70
71
72
# File 'lib/riffer/messages/tool.rb', line 65

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