Skip to content

TextMessage

Assistant text response.

Class: RobotLab::TextMessage

message = TextMessage.new("Hello! How can I help you today?")

Constructor

TextMessage.new(content)

Parameters:

Name Type Description
content String Response text

Attributes

content

message.content  # => String

The response text.

role

message.role  # => :assistant

Always returns :assistant.

Methods

to_h

message.to_h  # => Hash

Hash representation.

Returns:

{
  role: :assistant,
  content: "Hello! How can I help you today?"
}

to_json

message.to_json  # => String

JSON representation.

Examples

Basic Response

message = TextMessage.new("Your order has shipped!")

In Robot Results

result = robot.run(state: state)

# Extract text messages
result.output.each do |msg|
  if msg.is_a?(TextMessage)
    puts msg.content
  end
end

Filtering Text Content

# Get only text responses from results
text_responses = state.results.flat_map(&:output).select do |msg|
  msg.is_a?(TextMessage)
end.map(&:content)

See Also