Class: RobotLab::ToolCallMessage

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

Overview

Message containing one or more tool calls from the assistant

Examples:

ToolCallMessage.new(
  role: :assistant,
  tools: [
    ToolMessage.new(id: "call_1", name: "get_weather", input: { location: "Berlin" })
  ]
)

Constant Summary

Constants inherited from Message

Message::VALID_ROLES, Message::VALID_STOP_REASONS, Message::VALID_TYPES

Instance Attribute Summary collapse

Attributes inherited from Message

#content, #role, #stop_reason, #type

Instance Method Summary collapse

Methods inherited from Message

#assistant?, from_hash, #stopped?, #system?, #text?, #to_json, #tool_call?, #tool_result?, #tool_stop?, #user?

Constructor Details

#initialize(role:, tools:, stop_reason: nil) ⇒ ToolCallMessage

Creates a new ToolCallMessage instance.

Parameters:

  • role (String, Symbol)

    the message role (usually assistant)

  • tools (Array<ToolMessage, Hash>)

    the tool calls

  • stop_reason (String, Symbol, nil) (defaults to: nil)

    the stop reason (defaults to “tool”)



241
242
243
244
# File 'lib/robot_lab/message.rb', line 241

def initialize(role:, tools:, stop_reason: nil)
  @tools = normalize_tools(tools)
  super(type: "tool_call", role: role, content: nil, stop_reason: stop_reason || "tool")
end

Instance Attribute Details

#toolsObject (readonly)

Returns the value of attribute tools.



234
235
236
# File 'lib/robot_lab/message.rb', line 234

def tools
  @tools
end

Instance Method Details

#to_hHash

Converts the tool call message to a hash representation.

Returns:

  • (Hash)

    a hash containing the tool call data



249
250
251
252
253
254
255
256
# File 'lib/robot_lab/message.rb', line 249

def to_h
  {
    type: type,
    role: role,
    tools: tools.map(&:to_h),
    stop_reason: stop_reason
  }
end