Interface MessagePart
- All Known Implementing Classes:
MediaPart,ReasoningPart,TextPart,ToolCallPart,ToolResultPart,UnknownPart
public sealed interface MessagePart
permits MediaPart, ReasoningPart, TextPart, ToolCallPart, ToolResultPart, UnknownPart
One element of the ordered content of a chat message.
A message is a list of parts in the order the model produced or the caller supplied
them, so interleavings such as reasoning, tool call, text, tool call survive a round
trip through memory and back to the provider. The hierarchy is sealed: provider
adapters live in the Spring AI repository and dispatch over the permitted types, while
UnknownPart keeps anything an adapter does not model yet.
Parts are serialized with a type discriminator. A type value this
version does not know deserializes to an UnknownPart instead of failing.
- Since:
- 2.1.0
- Author:
- Christian Tzolov
-
Method Summary
Modifier and TypeMethodDescriptionFree-form, serialization-safe attributes of this part, such as a streaming part index or a provider item id.@Nullable OpaquePayloadpayload()Provider-owned data that must be replayed verbatim to the same provider, such as a thinking signature or encrypted reasoning, ornullwhen the part carries none.withAttributes(Map<String, String> attributes) Returns a copy of this part with the given attributes replacing the current ones.
-
Method Details
-
payload
@Nullable OpaquePayload payload()Provider-owned data that must be replayed verbatim to the same provider, such as a thinking signature or encrypted reasoning, ornullwhen the part carries none.- Returns:
- the opaque payload, or
null
-
attributes
Free-form, serialization-safe attributes of this part, such as a streaming part index or a provider item id. Nevernull, never modifiable.- Returns:
- the attributes
-
withAttributes
Returns a copy of this part with the given attributes replacing the current ones. All other components are unchanged.- Parameters:
attributes- the new attributes, copied- Returns:
- the copy
-