ToolCallMessage¶
Tool invocation request from the LLM.
Class: RobotLab::ToolCallMessage¶
message = ToolCallMessage.new(
id: "call_abc123",
name: "get_weather",
input: { city: "New York", units: "fahrenheit" }
)
Constructor¶
Parameters:
| Name | Type | Description |
|---|---|---|
id |
String |
Unique call identifier |
name |
String |
Tool name |
input |
Hash |
Tool parameters |
Attributes¶
id¶
Unique identifier for this tool call. Used to match with ToolResultMessage.
name¶
Name of the tool being invoked.
input¶
Parameters passed to the tool.
role¶
Always returns :assistant (the LLM initiates tool calls).
Methods¶
to_h¶
Hash representation.
Returns:
{
role: :assistant,
tool_call: {
id: "call_abc123",
name: "get_weather",
input: { city: "New York", units: "fahrenheit" }
}
}
to_json¶
JSON representation.
Examples¶
Basic Tool Call¶
call = ToolCallMessage.new(
id: "call_1",
name: "search_orders",
input: { user_id: "123", status: "pending" }
)
Processing Tool Calls¶
result.output.each do |msg|
case msg
when ToolCallMessage
puts "Tool called: #{msg.name}"
puts "Parameters: #{msg.input.inspect}"
when ToolResultMessage
puts "Result for #{msg.id}: #{msg.result}"
end
end
In Tool Execution Flow¶
# LLM returns a tool call
tool_call = ToolCallMessage.new(
id: "call_weather_1",
name: "get_weather",
input: { city: "Seattle" }
)
# Tool is executed
result = tool.call(tool_call.input, state: state)
# Result is recorded
tool_result = ToolResultMessage.new(
id: tool_call.id,
result: result
)