Class AssistantMessage

java.lang.Object
org.springframework.ai.chat.messages.AbstractMessage
org.springframework.ai.chat.messages.AssistantMessage
All Implemented Interfaces:
Message, Content, MediaContent
Direct Known Subclasses:
DeepSeekAssistantMessage

public class AssistantMessage extends AbstractMessage implements MediaContent
Lets the generative know the content was generated as a response to the user. This role indicates messages that the generative has previously generated in the conversation. By including assistant messages in the series, you provide context to the generative about prior exchanges in the conversation.

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