Message

sealed interface Message(source)

Represents a message exchanged in a chat with LLM. Messages can be categorized by their type and role, denoting the purpose and source of the message.

Represents both a message from LLM and a message to LLM from user or environment.

Inheritors

Types

Link copied to clipboard
data class Assistant @JvmOverloads constructor(val parts: List<MessagePart.ResponsePart>, val metaInfo: ResponseMetaInfo, val finishReason: String? = null, val rawResponse: JsonObject? = null, val id: String? = null) : Message

An assistant-role message returned by the LLM. May contain text, reasoning, and/or tool calls.

Link copied to clipboard

Defines the role of the message in the chat (e.g., system, user, assistant).

Link copied to clipboard
data class System @JvmOverloads constructor(val parts: List<MessagePart.Text>, val metaInfo: RequestMetaInfo, val id: String? = null) : Message

A system-role message used to set the behaviour or persona of the assistant. Only MessagePart.Text parts are supported.

Link copied to clipboard
data class User @JvmOverloads constructor(val parts: List<MessagePart.RequestPart>, val metaInfo: RequestMetaInfo, val id: String? = null) : Message

A user-role message sent to the LLM. May contain text, attachments, or tool results.

Properties

Link copied to clipboard
abstract val id: String?

The unique identifier of the message.

Link copied to clipboard

Stores metadata information for the current message instance, such as token count and timestamp.

Link copied to clipboard
abstract val parts: List<MessagePart>

The list of message parts: text, reasoning, tool calls and results

Link copied to clipboard
abstract val role: Message.Role

The role associated with the message.

Functions

Link copied to clipboard
open fun textContent(): String

Extracts and concatenates the textual content from all MessagePart.Text elements in the message. Messages are joined by a newline character ("\n").

open fun textContent(separator: String): String

Extracts and concatenates the textual content from all MessagePart.Text elements in the message.