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)


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

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).

Returns:

  • (Symbol, nil)


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

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)


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

def error?
  !@error.nil?
end

#roleSymbol

-- : () -> Symbol

Returns:

  • (Symbol)


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

def role
  :tool
end

#to_hHash[Symbol, untyped]

Converts the message to a hash.

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

Returns:

  • (Hash[Symbol, untyped])


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

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