Class: RobotLab::ToolMessage

Inherits:
Object
  • Object
show all
Defined in:
lib/robot_lab/message.rb

Overview

Represents a tool/function definition for tool calls

Examples:

ToolMessage.new(
  id: "call_123",
  name: "get_weather",
  input: { location: "Berlin" }
)

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(id:, name:, input:) ⇒ ToolMessage

Creates a new ToolMessage instance.

Parameters:

  • id (String)

    the unique identifier for this tool call

  • name (String)

    the name of the tool

  • input (Hash, nil)

    the input arguments



181
182
183
184
185
# File 'lib/robot_lab/message.rb', line 181

def initialize(id:, name:, input:)
  @id = id
  @name = name
  @input = input || {}
end

Instance Attribute Details

#idString (readonly)

Returns the unique identifier for this tool call.

Returns:

  • (String)

    the unique identifier for this tool call



174
175
176
# File 'lib/robot_lab/message.rb', line 174

def id
  @id
end

#inputObject (readonly)

Returns the value of attribute input.



174
# File 'lib/robot_lab/message.rb', line 174

attr_reader :id, :name, :input

#nameString (readonly)

Returns the name of the tool being called.

Returns:

  • (String)

    the name of the tool being called



174
# File 'lib/robot_lab/message.rb', line 174

attr_reader :id, :name, :input

Class Method Details

.from_hash(hash) ⇒ ToolMessage

Creates a ToolMessage from a hash.

Parameters:

  • hash (Hash)

    the hash representation

Returns:



211
212
213
214
215
216
217
218
# File 'lib/robot_lab/message.rb', line 211

def self.from_hash(hash)
  hash = hash.transform_keys(&:to_sym)
  new(
    id: hash[:id],
    name: hash[:name],
    input: hash[:input] || hash[:arguments] || {}
  )
end

Instance Method Details

#to_hHash

Converts the tool message to a hash representation.

Returns:

  • (Hash)

    a hash containing the tool call data



190
191
192
193
194
195
196
197
# File 'lib/robot_lab/message.rb', line 190

def to_h
  {
    type: "tool",
    id: id,
    name: name,
    input: input
  }
end

#to_json(*args) ⇒ String

Converts the tool message to JSON.

Parameters:

  • args (Array)

    arguments passed to to_json

Returns:

  • (String)

    JSON representation



203
204
205
# File 'lib/robot_lab/message.rb', line 203

def to_json(*args)
  to_h.to_json(*args)
end