Class: RobotLab::ToolResultMessage
- Defined in:
- lib/robot_lab/message.rb
Overview
Result from executing a tool
Constant Summary
Constants inherited from Message
Message::VALID_ROLES, Message::VALID_STOP_REASONS, Message::VALID_TYPES
Instance Attribute Summary collapse
-
#tool ⇒ Object
readonly
Returns the value of attribute tool.
Attributes inherited from Message
#content, #role, #stop_reason, #type
Instance Method Summary collapse
-
#data ⇒ Object?
Returns the result data if successful.
-
#error ⇒ String?
Returns the error message if there was an error.
-
#error? ⇒ Boolean
Checks if the tool execution resulted in an error.
-
#initialize(tool:, content:, stop_reason: nil) ⇒ ToolResultMessage
constructor
Creates a new ToolResultMessage instance.
-
#success? ⇒ Boolean
Checks if the tool execution was successful.
-
#to_h ⇒ Hash
Converts the tool result message to a hash representation.
Methods inherited from Message
#assistant?, from_hash, #stopped?, #system?, #text?, #to_json, #tool_call?, #tool_result?, #tool_stop?, #user?
Constructor Details
#initialize(tool:, content:, stop_reason: nil) ⇒ ToolResultMessage
Creates a new ToolResultMessage instance.
298 299 300 301 |
# File 'lib/robot_lab/message.rb', line 298 def initialize(tool:, content:, stop_reason: nil) @tool = normalize_tool(tool) super(type: "tool_result", role: "tool_result", content: content, stop_reason: stop_reason || "tool") end |
Instance Attribute Details
#tool ⇒ Object (readonly)
Returns the value of attribute tool.
291 292 293 |
# File 'lib/robot_lab/message.rb', line 291 def tool @tool end |
Instance Method Details
#data ⇒ Object?
Returns the result data if successful.
320 321 322 |
# File 'lib/robot_lab/message.rb', line 320 def data content[:data] if success? end |
#error ⇒ String?
Returns the error message if there was an error.
327 328 329 |
# File 'lib/robot_lab/message.rb', line 327 def error content[:error] if error? end |
#error? ⇒ Boolean
Checks if the tool execution resulted in an error.
313 314 315 |
# File 'lib/robot_lab/message.rb', line 313 def error? content.is_a?(Hash) && content.key?(:error) end |
#success? ⇒ Boolean
Checks if the tool execution was successful.
306 307 308 |
# File 'lib/robot_lab/message.rb', line 306 def success? content.is_a?(Hash) && content.key?(:data) end |
#to_h ⇒ Hash
Converts the tool result message to a hash representation.
334 335 336 337 338 339 340 341 342 |
# File 'lib/robot_lab/message.rb', line 334 def to_h { type: type, role: role, tool: tool.to_h, content: content, stop_reason: stop_reason } end |