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 except streamed tool-call argument deltas, 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
Modifier and TypeMethodDescriptionstatic AssistantMessage.Builder<?>builder()copy()getMedia()Get the media associated with the content.The reasoning parts of this message, in part order.The tool calls of this message, in part order.booleanWhether this message holds a tool call.mutate()A builder pre-populated with this message's parts and metadata.toString()Methods inherited from class org.springframework.ai.chat.messages.AbstractMessage
equals, firstIndexOf, getMessageType, getMetadata, getParts, getText, hashCode, legacyParts, replace, 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
The tool calls of this message, in part order. A streamed tool-call argument delta, aToolCallPartmarkedpartial, is not a tool call and is skipped.- Returns:
- an unmodifiable list of tool calls
-
hasToolCalls
public boolean hasToolCalls()Whether this message holds a tool call. A streamed tool-call argument delta does not count, seegetToolCalls().- Returns:
trueif the message holds at least one tool call
-
getMedia
Description copied from interface:MediaContentGet the media associated with the content.- Specified by:
getMediain interfaceMediaContent
-
copy
-
mutate
A builder pre-populated with this message's parts and metadata. CallingAssistantMessage.Builder.content(String),AssistantMessage.Builder.toolCalls(List)orAssistantMessage.Builder.media(List)on it replaces the corresponding parts in place, so rewriting the text keeps the reasoning and tool calls where they were and vice versa.- Returns:
- the builder
-
toString
-
builder
-
getMedia(); kept so existing subclasses that read the field keep compiling.