Message
A message in a conversation. Messages have a role and a list of content parts representing the different modalities of the message content.
Class Diagram
Section titled “Class Diagram”---
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
Yaml Example
Section titled “Yaml Example”role: userparts: - kind: text value: Hello!metadata: source: user-inputProperties
Section titled “Properties”| Name | Type | Description |
|---|---|---|
| role | string | The role of the message sender |
| parts | ContentPart[] | The content parts of the message(Related Types: TextPart, ImagePart, FilePart, AudioPart) |
| metadata | dictionary | Optional metadata associated with the message |
Helper Methods
Section titled “Helper Methods”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.
| Name | Signature | Runtime shape | Description |
|---|---|---|---|
toTextContent | toTextContent() -> unknown | async-capable | Return plain string if all parts are text, else a list of content part dicts for wire serialization |
text | text() -> string | async-capable | Concatenate all TextPart values joined by newline |
Factory Methods
Section titled “Factory Methods”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)
Composed Types
Section titled “Composed Types”The following types are composed within Message: