UserMessage¶
User input with conversation metadata.
Class: RobotLab::UserMessage¶
message = UserMessage.new(
"What's my order status?",
thread_id: "thread_123",
system_prompt: "Be concise",
metadata: { source: "web" }
)
Constructor¶
Parameters:
| Name | Type | Description |
|---|---|---|
content |
String |
Message text |
thread_id |
String, nil |
Conversation thread ID |
system_prompt |
String, nil |
Override system prompt |
metadata |
Hash |
Additional metadata |
Attributes¶
content¶
The message text.
thread_id¶
Conversation thread identifier for history persistence.
system_prompt¶
Optional system prompt override for this message.
metadata¶
Arbitrary metadata (source, timestamp, user info, etc.).
id¶
Unique message identifier.
created_at¶
Message creation timestamp.
role¶
Always returns :user.
Methods¶
to_h¶
Hash representation.
Returns:
{
role: :user,
content: "What's my order status?",
id: "uuid-here",
thread_id: "thread_123",
created_at: "2024-01-15T10:30:00Z"
}
to_json¶
JSON representation.
Examples¶
Basic Message¶
With Thread ID¶
With System Prompt Override¶
message = UserMessage.new(
"Translate this",
system_prompt: "You are a translator. Respond in Spanish."
)
With Metadata¶
message = UserMessage.new(
"Help with my account",
metadata: {
source: "mobile_app",
user_id: "user_123",
session_id: "sess_456",
locale: "en-US"
}
)
Creating State¶
message = UserMessage.new("Help", thread_id: "thread_123")
state = RobotLab.create_state(message: message)
state.thread_id # => "thread_123"