Class: Riffer::Messages::Tool

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

Overview

Represents a tool execution result in a conversation.

Instance Attribute Summary collapse

Attributes inherited from Base

#content, #id

Instance Method Summary collapse

Methods inherited from Base

#+, from_hash, #generate_id, #has_tool_calls?

Constructor Details

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

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

Parameters:

  • (String)
  • tool_call_id: (String)
  • name: (String)
  • id: (String, nil) (defaults to: nil)
  • error: (String, nil) (defaults to: nil)
  • error_type: (Symbol, nil) (defaults to: nil)


21
22
23
24
25
26
27
# File 'lib/riffer/messages/tool.rb', line 21

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

Instance Attribute Details

#errorString? (readonly)

The error message if the tool execution failed.

Returns:

  • (String, nil)


13
14
15
# File 'lib/riffer/messages/tool.rb', line 13

def error
  @error
end

#error_typeSymbol? (readonly)

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

Returns:

  • (Symbol, nil)


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

def error_type
  @error_type
end

#nameString (readonly)

The name of the tool that was called.

Returns:

  • (String)


10
11
12
# File 'lib/riffer/messages/tool.rb', line 10

def name
  @name
end

#tool_call_idString (readonly)

The ID of the tool call this result responds to.

Returns:

  • (String)


7
8
9
# File 'lib/riffer/messages/tool.rb', line 7

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:

  • (Boolean)


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

def error?
  !@error.nil?
end

#roleSymbol

-- : () -> Symbol

Returns:

  • (Symbol)


39
40
41
# File 'lib/riffer/messages/tool.rb', line 39

def role
  :tool
end

#to_hHash[Symbol, untyped]

Converts the message to a hash.

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

Returns:

  • (Hash[Symbol, untyped])


47
48
49
50
51
52
53
54
55
# File 'lib/riffer/messages/tool.rb', line 47

def to_h
  hash = { role: role, content: content, tool_call_id: tool_call_id, name: name } #: Hash[Symbol, untyped]
  hash[:id] = id if id
  if error?
    hash[:error] = error
    hash[:error_type] = error_type
  end
  hash
end