Class AgentMessage

Object
akka.javasdk.agent.autonomous.AgentMessage

public final class AgentMessage extends Object
A message from a client to a running autonomous agent: text with optional attachments, for one task of the agent. Send it with AutonomousAgentClient.sendMessage(AgentMessage).

Each method that sets a value returns a new instance and leaves this one unchanged.

  • Method Details

    • of

      public static AgentMessage of(String text)
      Create a message with the given text.
      Parameters:
      text - the text for the model
      Throws:
      IllegalArgumentException - if the text is null
    • text

      public String text()
      The text of this message.
    • attachments

      public List<MessageContent> attachments()
      Content attached to this message (images, PDFs), or an empty list.
    • attach

      public AgentMessage attach(MessageContent... content)
      Return a new message with the given content attached. Reference images and PDFs by URI, with MessageContent.ImageUrlMessageContent or MessageContent.PdfUrlMessageContent.
      Throws:
      IllegalArgumentException - if a content item carries inline bytes
    • messageId

      public Optional<String> messageId()
      The id of this message, if set.
    • messageId

      public AgentMessage messageId(String messageId)
      Return a new message with the given id. While the first message is pending or among AgentState.recentMessages(), a retry with the same id gets the status of the first message, and the agent stores nothing new. The agent does not store a rejected message, so a retry of it is a new message. Without an id, the runtime generates one, and a retry is a new message.
      Throws:
      IllegalArgumentException - if the id is null or empty
    • taskId

      public Optional<String> taskId()
      The id of the task this message is for, if set.
    • taskId

      public AgentMessage taskId(String taskId)
      Return a new message for the task with the given id. The agent accepts the message for its current task, a queued task, or a task that waits for its dependencies, and rejects it for any other task. Without a task id, the message is for the current task, or for the next task that starts when no task runs.
      Throws:
      IllegalArgumentException - if the id is null or empty