Class AssistantMessage
- All Implemented Interfaces:
Message,Content,MediaContent
- Direct Known Subclasses:
DeepSeekAssistantMessage
The message content is an ordered list of MessageParts, inherited from
AbstractMessage so that UserMessage can carry the same kind of content.
The text, tool calls, media and reasoning accessors are views over that list:
AbstractMessage.getText() joins the TextParts, getToolCalls() selects the
ToolCallParts, getMedia() selects the MediaParts and
getReasoning() selects the ReasoningParts, in part order. Because
reasoning is a part like any other, a message preserves the exact interleaving some
providers stream between reasoning, tool calls, text and media (for example a reasoning
block immediately followed by the tool call it justified). Messages built through the
legacy constructor or builder setters get their parts in the legacy order: text, tool
calls, media.
- Since:
- 1.0.0
- Author:
- Mark Pollack, Christian Tzolov, Thomas Vitale, guan xu
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classAssistantMessage.Builder<B extends AssistantMessage.Builder<B>>Builder forAssistantMessage.static final record -
Field Summary
FieldsModifier and TypeFieldDescriptionDeprecated, for removal: This API element is subject to removal in a future version.Fields inherited from class org.springframework.ai.chat.messages.AbstractMessage
MESSAGE_TYPE, messageType, metadata, textContent -
Constructor Summary
ConstructorsModifierConstructorDescriptionAssistantMessage(@Nullable String content) protectedAssistantMessage(@Nullable String content, Map<String, Object> properties, List<AssistantMessage.ToolCall> toolCalls, List<Media> media) protectedAssistantMessage(List<MessagePart> parts, Map<String, Object> properties) Creates a message from an ordered list of content parts, which may includeReasoningParts interleaved with the rest of the content. -
Method Summary
Methods inherited from class org.springframework.ai.chat.messages.AbstractMessage
equals, getMessageType, getMetadata, getParts, getText, hashCode, legacyParts, selectMethods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface org.springframework.ai.content.Content
getMetadata, getText
-
Field Details
-
media
Deprecated, for removal: This API element is subject to removal in a future version.since 2.1.0 in favor ofgetMedia(); kept so existing subclasses that read the field keep compiling. Will be removed in a future release.The media of this message, derived from itsMediaParts.
-
-
Constructor Details
-
AssistantMessage
-
AssistantMessage
-
AssistantMessage
Creates a message from an ordered list of content parts, which may includeReasoningParts interleaved with the rest of the content.- Parameters:
parts- the parts, in orderproperties- the message metadata- Since:
- 2.1.0
-
-
Method Details
-
getReasoning
The reasoning parts of this message, in part order.- Returns:
- an unmodifiable list of reasoning parts
- Since:
- 2.1.0
-
getToolCalls
-
hasToolCalls
public boolean hasToolCalls() -
getMedia
Description copied from interface:MediaContentGet the media associated with the content.- Specified by:
getMediain interfaceMediaContent
-
copy
-
mutate
-
toString
-
builder
-
getMedia(); kept so existing subclasses that read the field keep compiling.