Class AssistantMessage.Builder<B extends AssistantMessage.Builder<B>>

java.lang.Object
org.springframework.ai.chat.messages.AssistantMessage.Builder<B>
Type Parameters:
B - the concrete builder type, for subclass builders
Direct Known Subclasses:
DeepSeekAssistantMessage.AbstractBuilder
Enclosing class:
AssistantMessage

public static class AssistantMessage.Builder<B extends AssistantMessage.Builder<B>> extends Object
Builder for AssistantMessage.

Parts added through part(MessagePart), parts(List) and reasoning(ReasoningPart) come first, in the order they were added. The legacy setters (content(String), toolCalls(List), media(List)) are stored and materialized after them at build() time in the legacy order (text, tool calls, media), so the setter call order does not affect the result.

  • Field Details

  • Constructor Details

    • Builder

      protected Builder()
  • Method Details

    • self

      protected B self()
    • part

      public B part(MessagePart part)
      Appends a content part.
      Parameters:
      part - the part
      Returns:
      this builder
      Since:
      2.1.0
    • supportsParts

      protected boolean supportsParts()
      Whether build() of this builder honors part(MessagePart), parts(List) and reasoning(ReasoningPart). The base builder does. A subclass builder that overrides build() must override this method to return true and construct its message from buildParts(); otherwise part(MessagePart) throws so parts are never dropped silently.
      Returns:
      whether explicit parts are supported
      Since:
      2.1.0
    • buildParts

      protected List<MessagePart> buildParts()
      The parts this builder would put in the message: explicit parts first, then the legacy text, tool calls and media in that order.
      Returns:
      the parts, in message order
      Since:
      2.1.0
    • parts

      public B parts(List<MessagePart> parts)
      Appends content parts in order.
      Parameters:
      parts - the parts
      Returns:
      this builder
      Since:
      2.1.0
    • reasoning

      public B reasoning(ReasoningPart reasoning)
      Appends a reasoning part. Equivalent to part(MessagePart), since ReasoningPart is a MessagePart.
      Parameters:
      reasoning - the reasoning part
      Returns:
      this builder
      Since:
      2.1.0
    • reasoning

      public B reasoning(List<ReasoningPart> reasoning)
      Appends reasoning parts in order.
      Parameters:
      reasoning - the reasoning parts
      Returns:
      this builder
      Since:
      2.1.0
    • content

      public B content(@Nullable String content)
    • properties

      public B properties(Map<String,Object> properties)
    • toolCalls

      public B toolCalls(List<AssistantMessage.ToolCall> toolCalls)
    • media

      public B media(List<Media> media)
    • build

      public AssistantMessage build()