ToolResultMessage¶
Result from tool execution.
Class: RobotLab::ToolResultMessage¶
message = ToolResultMessage.new(
id: "call_abc123",
result: { temperature: 72, conditions: "sunny" }
)
Constructor¶
Parameters:
| Name | Type | Description |
|---|---|---|
id |
String |
Matching tool call ID |
result |
Object |
Tool execution result |
Attributes¶
id¶
Identifier matching the corresponding ToolCallMessage.
result¶
The result returned by the tool. Can be any serializable object.
role¶
Always returns :tool.
Methods¶
to_h¶
Hash representation.
Returns:
{
role: :tool,
tool_result: {
id: "call_abc123",
result: { temperature: 72, conditions: "sunny" }
}
}
to_json¶
JSON representation.
Examples¶
Basic Result¶
String Result¶
Array Result¶
result = ToolResultMessage.new(
id: "call_search",
result: [
{ id: 1, name: "Product A" },
{ id: 2, name: "Product B" }
]
)
Error Result¶
result = ToolResultMessage.new(
id: "call_order",
result: { success: false, error: "Order not found" }
)
Matching with Tool Calls¶
# Process all tool interactions
result.output.each_cons(2) do |a, b|
if a.is_a?(ToolCallMessage) && b.is_a?(ToolResultMessage)
if a.id == b.id
puts "#{a.name}(#{a.input}) => #{b.result}"
end
end
end
In Result History¶
# Find all tool results from execution
tool_results = state.results
.flat_map(&:output)
.select { |m| m.is_a?(ToolResultMessage) }
tool_results.each do |tr|
puts "Tool result: #{tr.result}"
end