UserMessage¶
User input with conversation metadata.
Class: RobotLab::UserMessage¶
message = UserMessage.new(
"What's my order status?",
session_id: "session_123",
system_prompt: "Be concise",
metadata: { source: "web" }
)
Note: UserMessage is a standalone class, not a subclass of Message.
Constructor¶
Parameters:
| Name | Type | Description |
|---|---|---|
content |
String |
Message text |
session_id |
String, nil |
Conversation session ID |
system_prompt |
String, nil |
Override system prompt |
metadata |
Hash, nil |
Additional metadata |
id |
String, nil |
Unique message ID (defaults to UUID) |
Attributes¶
content¶
The message text.
session_id¶
Conversation session 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.
Methods¶
to_h¶
Hash representation.
Returns:
{
content: "What's my order status?",
session_id: "session_123",
system_prompt: "Be concise",
metadata: { source: "web" },
id: "uuid-here",
created_at: "2024-01-15T10:30:00Z"
}
to_json¶
JSON representation.
to_message¶
Converts to a TextMessage with role "user" for use in conversation history.
to_s¶
Returns the content string.
self.from¶
Creates a UserMessage from a String, Hash, or existing UserMessage.
Examples¶
Basic Message¶
With Session 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 from Various Inputs¶
# From a string
msg = UserMessage.from("Hello!")
# From a hash
msg = UserMessage.from(content: "Hello!", session_id: "123")
# From an existing UserMessage (returns as-is)
msg = UserMessage.from(existing_message)