Message

@Serializable
data class Message(val id: String, val role: Role, val parts: List<Part> = emptyList(), val createdAt: Long = 0, val usage: Usage? = null, val alternatives: List<Message> = emptyList(), val metadata: JsonObject? = null)(source)

A chat message: an ordered list of Parts, the same shape as the AI SDK UIMessage. Assistant messages usually interleave reasoning, tool calls and text across several agent steps.

Constructors

Link copied to clipboard
constructor(id: String, role: Role, parts: List<Part> = emptyList(), createdAt: Long = 0, usage: Usage? = null, alternatives: List<Message> = emptyList(), metadata: JsonObject? = null)

Properties

Link copied to clipboard

Other versions of this reply (AI Elements <Branch>): regenerating keeps the previous answer here instead of discarding it. Oldest first.

Link copied to clipboard
Link copied to clipboard
val id: String
Link copied to clipboard
Link copied to clipboard
val metadata: JsonObject?

App- or protocol-defined metadata (AI SDK UIMessage.metadata), e.g. the A2A contextId / taskId a remote agent's reply belongs to.

Link copied to clipboard
Link copied to clipboard
val role: Role
Link copied to clipboard

Concatenated text of all TextParts.

Link copied to clipboard
val usage: Usage?
Link copied to clipboard

0-based position of this version within versions.

Link copied to clipboard

All versions in creation order, this one included.

Functions

Link copied to clipboard

Close every still-streaming part (end of turn, stop, or error).

Link copied to clipboard
fun Message.reduce(event: ChatEvent, now: Long): Message

Folds one ChatEvent into the assistant Message. Pure, so it is trivially unit-testable and every backend shares the exact same message semantics.