Skip to content

Message

A message in a conversation. Messages have a role and a list of content parts representing the different modalities of the message content.

---
title: Message
config:
  look: handDrawn
  theme: colorful
  class:
    hideEmptyMembersBox: true
---
classDiagram
    class Message {
        +string role
        +ContentPart[] parts
        +dictionary metadata
        +toTextContent() unknown [async-capable]
        +text() string [async-capable]
    }
    class ContentPart {
      <<abstract>>
        +string kind
    }
    Message *-- ContentPart
role: user
parts:
- kind: text
value: Hello!
metadata:
source: user-input
NameTypeDescription
rolestringThe role of the message sender
partsContentPart[]The content parts of the message(Related Types: TextPart, ImagePart, FilePart, AudioPart)
metadatadictionaryOptional metadata associated with the message

The following helper methods are declared via @method and must be implemented by every runtime. The schema declares the logical protocol contract; each runtime maps async-capable methods to idiomatic sync/async shapes for that language.

NameSignatureRuntime shapeDescription
toTextContenttoTextContent() -> unknownasync-capableReturn plain string if all parts are text, else a list of content part dicts for wire serialization
texttext() -> stringasync-capableConcatenate all TextPart values joined by newline

The following factory methods are declared via @factory and are generated automatically by the emitter in every language.

  • assistant(text: string)
  • system(text: string)
  • user(text: string)

The following types are composed within Message: