# Class ChatMessage

java.lang.Object
com.codename1.ai.ChatMessage

public final class ChatMessage extends Object
A single turn in a chat conversation. Holds a `Role`, one or more `MessagePart`s, and (for assistant turns) any `ToolCall`s the model produced. Construct via the static helpers (`user(String)`, `system(String)`, etc.) for the common case, or pass parts directly for multi-modal messages.

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `ChatMessage(Role role, List<MessagePart> parts)`
  `ChatMessage(Role role, List<MessagePart> parts, List<ToolCall> toolCalls, String name, String toolCallId)`

- ## Method Summary

  Modifier and Type
  Method
  Description
  `static ChatMessage`
  `assistant(String text)`
  `String`
  `getName()`
  `List<MessagePart>`
  `getParts()`
  `Role`
  `getRole()`
  `String`
  `getText()`
  Convenience: concatenates the text of every `TextPart`.
  `String`
  `getToolCallId()`
  `List<ToolCall>`
  `getToolCalls()`
  `static ChatMessage`
  `system(String text)`
  `static ChatMessage`
  `toolResult(String toolCallId, String resultJson)`
  Builds a TOOL message wrapping the result of a previous tool call.
  `static ChatMessage`
  `user(String text)`
  `static ChatMessage`
  `userWithImage(String text, ImagePart image)`
  Builds a USER message containing both a text and image part -- the common multi-modal pattern.

  ### Methods inherited from class Object

  `clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- ## Constructor Details

  - ### ChatMessage

    public ChatMessage(Role role, List<MessagePart> parts)

  - ### ChatMessage

    public ChatMessage(Role role, List<MessagePart> parts, List<ToolCall> toolCalls, String name, String toolCallId)

- ## Method Details

  - ### system

    public static ChatMessage system(String text)

  - ### user

    public static ChatMessage user(String text)

  - ### assistant

    public static ChatMessage assistant(String text)

  - ### userWithImage

    public static ChatMessage userWithImage(String text, ImagePart image)
    Builds a USER message containing both a text and image part -- the common multi-modal pattern.

  - ### toolResult

    public static ChatMessage toolResult(String toolCallId, String resultJson)
    Builds a TOOL message wrapping the result of a previous tool call.

  - ### getRole

    public Role getRole()

  - ### getParts

    public List<MessagePart> getParts()

  - ### getToolCalls

    public List<ToolCall> getToolCalls()

  - ### getName

    public String getName()

  - ### getToolCallId

    public String getToolCallId()

  - ### getText

    public String getText()
    Convenience: concatenates the text of every `TextPart`. Image and tool-result parts are skipped. Useful for `ChatView` rendering when you don't care about multi-modal content.