Class: RobotLab::ToolMessage
- Inherits:
-
Object
- Object
- RobotLab::ToolMessage
- Defined in:
- lib/robot_lab/message.rb
Overview
Represents a tool/function definition for tool calls
Instance Attribute Summary collapse
-
#id ⇒ String
readonly
The unique identifier for this tool call.
-
#input ⇒ Object
readonly
Returns the value of attribute input.
-
#name ⇒ String
readonly
The name of the tool being called.
Class Method Summary collapse
-
.from_hash(hash) ⇒ ToolMessage
Creates a ToolMessage from a hash.
Instance Method Summary collapse
-
#initialize(id:, name:, input:) ⇒ ToolMessage
constructor
Creates a new ToolMessage instance.
-
#to_h ⇒ Hash
Converts the tool message to a hash representation.
-
#to_json(*args) ⇒ String
Converts the tool message to JSON.
Constructor Details
#initialize(id:, name:, input:) ⇒ ToolMessage
Creates a new ToolMessage instance.
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
#id ⇒ String (readonly)
Returns the unique identifier for this tool call.
174 175 176 |
# File 'lib/robot_lab/message.rb', line 174 def id @id end |
#input ⇒ Object (readonly)
Returns the value of attribute input.
174 |
# File 'lib/robot_lab/message.rb', line 174 attr_reader :id, :name, :input |
#name ⇒ String (readonly)
Returns 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.
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_h ⇒ Hash
Converts the tool message to a hash representation.
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.
203 204 205 |
# File 'lib/robot_lab/message.rb', line 203 def to_json(*args) to_h.to_json(*args) end |