TextMessage¶
Text message from system, user, or assistant.
Class: RobotLab::TextMessage¶
Constructor¶
Parameters:
| Name | Type | Description |
|---|---|---|
role |
String |
Message role ("system", "user", or "assistant") |
content |
String |
The text content |
stop_reason |
String, nil |
Stop reason ("stop" or "tool") |
Attributes¶
content¶
The text content.
role¶
Returns a String: "system", "user", or "assistant".
type¶
Always returns "text".
stop_reason¶
The stop reason, if any.
Methods¶
to_h¶
Hash representation.
Returns:
{
type: "text",
role: "assistant",
content: "Hello! How can I help you today?",
stop_reason: "stop"
}
to_json¶
JSON representation.
Predicates¶
message.text? # => true
message.tool_call? # => false
message.assistant? # => true (if role is "assistant")
message.user? # => false
message.stopped? # => true (if stop_reason is "stop")
Examples¶
System Message¶
message = TextMessage.new(role: "system", content: "You are a helpful assistant")
message.system? # => true
User Message¶
Assistant Response¶
message = TextMessage.new(
role: "assistant",
content: "Your order has shipped!",
stop_reason: "stop"
)
message.assistant? # => true
message.stopped? # => true
In Robot Results¶
result = robot.run("Tell me a joke")
# The result is a TextMessage when the assistant replies with text
if result.text?
puts result.content
end