Class MessagesClient

java.lang.Object
com.azure.ai.agents.persistent.MessagesClient

public final class MessagesClient extends Object
Initializes a new instance of the synchronous PersistentAgentsAdministrationClient type.
  • Method Details

    • createMessageWithResponse

      public com.azure.core.http.rest.Response<com.azure.core.util.BinaryData> createMessageWithResponse(String threadId, com.azure.core.util.BinaryData createMessageRequest, com.azure.core.http.rest.RequestOptions requestOptions)
      Creates a new message on a specified thread.

      Request Body Schema

       
       {
           role: String(user/assistant) (Required)
           content: BinaryData (Required)
           attachments (Optional): [
                (Optional){
                   file_id: String (Optional)
                   data_source (Optional): {
                       uri: String (Required)
                       type: String(uri_asset/id_asset) (Required)
                   }
                   tools (Required): [
                       BinaryData (Required)
                   ]
               }
           ]
           metadata (Optional): {
               String: String (Required)
           }
       }
       
       

      Response Body Schema

       
       {
           id: String (Required)
           object: String (Required)
           created_at: long (Required)
           thread_id: String (Required)
           status: String(in_progress/incomplete/completed) (Required)
           incomplete_details (Required): {
               reason: String(content_filter/max_tokens/run_cancelled/run_failed/run_expired) (Required)
           }
           completed_at: Long (Required)
           incomplete_at: Long (Required)
           role: String(user/assistant) (Required)
           content (Required): [
                (Required){
                   type: String (Required)
               }
           ]
           assistant_id: String (Required)
           run_id: String (Required)
           attachments (Required): [
                (Required){
                   file_id: String (Optional)
                   data_source (Optional): {
                       uri: String (Required)
                       type: String(uri_asset/id_asset) (Required)
                   }
                   tools (Required): [
                       BinaryData (Required)
                   ]
               }
           ]
           metadata (Required): {
               String: String (Required)
           }
       }
       
       
      Parameters:
      threadId - Identifier of the thread.
      createMessageRequest - The createMessageRequest parameter.
      requestOptions - The options to configure the HTTP request before HTTP client sends it.
      Returns:
      a single, existing message within an agent thread along with Response.
      Throws:
      com.azure.core.exception.HttpResponseException - thrown if the request is rejected by server.
      com.azure.core.exception.ClientAuthenticationException - thrown if the request is rejected by server on status code 401.
      com.azure.core.exception.ResourceNotFoundException - thrown if the request is rejected by server on status code 404.
      com.azure.core.exception.ResourceModifiedException - thrown if the request is rejected by server on status code 409.
    • getMessageWithResponse

      public com.azure.core.http.rest.Response<com.azure.core.util.BinaryData> getMessageWithResponse(String threadId, String messageId, com.azure.core.http.rest.RequestOptions requestOptions)
      Retrieves an existing message.

      Response Body Schema

       
       {
           id: String (Required)
           object: String (Required)
           created_at: long (Required)
           thread_id: String (Required)
           status: String(in_progress/incomplete/completed) (Required)
           incomplete_details (Required): {
               reason: String(content_filter/max_tokens/run_cancelled/run_failed/run_expired) (Required)
           }
           completed_at: Long (Required)
           incomplete_at: Long (Required)
           role: String(user/assistant) (Required)
           content (Required): [
                (Required){
                   type: String (Required)
               }
           ]
           assistant_id: String (Required)
           run_id: String (Required)
           attachments (Required): [
                (Required){
                   file_id: String (Optional)
                   data_source (Optional): {
                       uri: String (Required)
                       type: String(uri_asset/id_asset) (Required)
                   }
                   tools (Required): [
                       BinaryData (Required)
                   ]
               }
           ]
           metadata (Required): {
               String: String (Required)
           }
       }
       
       
      Parameters:
      threadId - Identifier of the thread.
      messageId - Identifier of the message.
      requestOptions - The options to configure the HTTP request before HTTP client sends it.
      Returns:
      a single, existing message within an agent thread along with Response.
      Throws:
      com.azure.core.exception.HttpResponseException - thrown if the request is rejected by server.
      com.azure.core.exception.ClientAuthenticationException - thrown if the request is rejected by server on status code 401.
      com.azure.core.exception.ResourceNotFoundException - thrown if the request is rejected by server on status code 404.
      com.azure.core.exception.ResourceModifiedException - thrown if the request is rejected by server on status code 409.
    • updateMessageWithResponse

      public com.azure.core.http.rest.Response<com.azure.core.util.BinaryData> updateMessageWithResponse(String threadId, String messageId, com.azure.core.util.BinaryData updateMessageRequest, com.azure.core.http.rest.RequestOptions requestOptions)
      Modifies an existing message on an existing thread.

      Request Body Schema

       
       {
           metadata (Optional): {
               String: String (Required)
           }
       }
       
       

      Response Body Schema

       
       {
           id: String (Required)
           object: String (Required)
           created_at: long (Required)
           thread_id: String (Required)
           status: String(in_progress/incomplete/completed) (Required)
           incomplete_details (Required): {
               reason: String(content_filter/max_tokens/run_cancelled/run_failed/run_expired) (Required)
           }
           completed_at: Long (Required)
           incomplete_at: Long (Required)
           role: String(user/assistant) (Required)
           content (Required): [
                (Required){
                   type: String (Required)
               }
           ]
           assistant_id: String (Required)
           run_id: String (Required)
           attachments (Required): [
                (Required){
                   file_id: String (Optional)
                   data_source (Optional): {
                       uri: String (Required)
                       type: String(uri_asset/id_asset) (Required)
                   }
                   tools (Required): [
                       BinaryData (Required)
                   ]
               }
           ]
           metadata (Required): {
               String: String (Required)
           }
       }
       
       
      Parameters:
      threadId - Identifier of the thread.
      messageId - Identifier of the message.
      updateMessageRequest - The updateMessageRequest parameter.
      requestOptions - The options to configure the HTTP request before HTTP client sends it.
      Returns:
      a single, existing message within an agent thread along with Response.
      Throws:
      com.azure.core.exception.HttpResponseException - thrown if the request is rejected by server.
      com.azure.core.exception.ClientAuthenticationException - thrown if the request is rejected by server on status code 401.
      com.azure.core.exception.ResourceNotFoundException - thrown if the request is rejected by server on status code 404.
      com.azure.core.exception.ResourceModifiedException - thrown if the request is rejected by server on status code 409.
    • createMessage

      public ThreadMessage createMessage(String threadId, MessageRole role, com.azure.core.util.BinaryData content, List<MessageAttachment> attachments, Map<String,String> metadata)
      Creates a new message on a specified thread.
      Parameters:
      threadId - Identifier of the thread.
      role - The role of the entity that is creating the message. Allowed values include: `user`, which indicates the message is sent by an actual user (and should be used in most cases to represent user-generated messages), and `assistant`, which indicates the message is generated by the agent (use this value to insert messages from the agent into the conversation).
      content - The content of the initial message. This may be a basic string (if you only need text) or an array of typed content blocks (for example, text, image_file, image_url, and so on).
      attachments - A list of files attached to the message, and the tools they should be added to.
      metadata - A set of up to 16 key/value pairs that can be attached to an object, used for storing additional information about that object in a structured format. Keys may be up to 64 characters in length and values may be up to 512 characters in length.
      Returns:
      a single, existing message within an agent thread.
      Throws:
      IllegalArgumentException - thrown if parameters fail the validation.
      com.azure.core.exception.HttpResponseException - thrown if the request is rejected by server.
      com.azure.core.exception.ClientAuthenticationException - thrown if the request is rejected by server on status code 401.
      com.azure.core.exception.ResourceNotFoundException - thrown if the request is rejected by server on status code 404.
      com.azure.core.exception.ResourceModifiedException - thrown if the request is rejected by server on status code 409.
      RuntimeException - all other wrapped checked exceptions if the request fails to be sent.
    • createMessage

      public ThreadMessage createMessage(String threadId, MessageRole role, com.azure.core.util.BinaryData content)
      Creates a new message on a specified thread.
      Parameters:
      threadId - Identifier of the thread.
      role - The role of the entity that is creating the message. Allowed values include: `user`, which indicates the message is sent by an actual user (and should be used in most cases to represent user-generated messages), and `assistant`, which indicates the message is generated by the agent (use this value to insert messages from the agent into the conversation).
      content - The content of the initial message. This may be a basic string (if you only need text) or an array of typed content blocks (for example, text, image_file, image_url, and so on).
      Returns:
      a single, existing message within an agent thread.
      Throws:
      IllegalArgumentException - thrown if parameters fail the validation.
      com.azure.core.exception.HttpResponseException - thrown if the request is rejected by server.
      com.azure.core.exception.ClientAuthenticationException - thrown if the request is rejected by server on status code 401.
      com.azure.core.exception.ResourceNotFoundException - thrown if the request is rejected by server on status code 404.
      com.azure.core.exception.ResourceModifiedException - thrown if the request is rejected by server on status code 409.
      RuntimeException - all other wrapped checked exceptions if the request fails to be sent.
    • listMessages

      public com.azure.core.http.rest.PagedIterable<ThreadMessage> listMessages(String threadId, String runId, Integer limit, ListSortOrder order, String after, String before)
      Gets a list of messages that exist on a thread.
      Parameters:
      threadId - Identifier of the thread.
      runId - Filter messages by the run ID that generated them.
      limit - A limit on the number of objects to be returned. Limit can range between 1 and 100, and the default is 20.
      order - Sort order by the created_at timestamp of the objects. asc for ascending order and desc for descending order.
      after - A cursor for use in pagination. after is an object ID that defines your place in the list. For instance, if you make a list request and receive 100 objects, ending with obj_foo, your subsequent call can include after=obj_foo in order to fetch the next page of the list.
      before - A cursor for use in pagination. before is an object ID that defines your place in the list. For instance, if you make a list request and receive 100 objects, ending with obj_foo, your subsequent call can include before=obj_foo in order to fetch the previous page of the list.
      Returns:
      a list of messages that exist on a thread as paginated response with PagedIterable.
      Throws:
      IllegalArgumentException - thrown if parameters fail the validation.
      com.azure.core.exception.HttpResponseException - thrown if the request is rejected by server.
      com.azure.core.exception.ClientAuthenticationException - thrown if the request is rejected by server on status code 401.
      com.azure.core.exception.ResourceNotFoundException - thrown if the request is rejected by server on status code 404.
      com.azure.core.exception.ResourceModifiedException - thrown if the request is rejected by server on status code 409.
      RuntimeException - all other wrapped checked exceptions if the request fails to be sent.
    • listMessages

      public com.azure.core.http.rest.PagedIterable<ThreadMessage> listMessages(String threadId)
      Gets a list of messages that exist on a thread.
      Parameters:
      threadId - Identifier of the thread.
      Returns:
      a list of messages that exist on a thread as paginated response with PagedIterable.
      Throws:
      IllegalArgumentException - thrown if parameters fail the validation.
      com.azure.core.exception.HttpResponseException - thrown if the request is rejected by server.
      com.azure.core.exception.ClientAuthenticationException - thrown if the request is rejected by server on status code 401.
      com.azure.core.exception.ResourceNotFoundException - thrown if the request is rejected by server on status code 404.
      com.azure.core.exception.ResourceModifiedException - thrown if the request is rejected by server on status code 409.
      RuntimeException - all other wrapped checked exceptions if the request fails to be sent.
    • getMessage

      public ThreadMessage getMessage(String threadId, String messageId)
      Retrieves an existing message.
      Parameters:
      threadId - Identifier of the thread.
      messageId - Identifier of the message.
      Returns:
      a single, existing message within an agent thread.
      Throws:
      IllegalArgumentException - thrown if parameters fail the validation.
      com.azure.core.exception.HttpResponseException - thrown if the request is rejected by server.
      com.azure.core.exception.ClientAuthenticationException - thrown if the request is rejected by server on status code 401.
      com.azure.core.exception.ResourceNotFoundException - thrown if the request is rejected by server on status code 404.
      com.azure.core.exception.ResourceModifiedException - thrown if the request is rejected by server on status code 409.
      RuntimeException - all other wrapped checked exceptions if the request fails to be sent.
    • updateMessage

      public ThreadMessage updateMessage(String threadId, String messageId, Map<String,String> metadata)
      Modifies an existing message on an existing thread.
      Parameters:
      threadId - Identifier of the thread.
      messageId - Identifier of the message.
      metadata - A set of up to 16 key/value pairs that can be attached to an object, used for storing additional information about that object in a structured format. Keys may be up to 64 characters in length and values may be up to 512 characters in length.
      Returns:
      a single, existing message within an agent thread.
      Throws:
      IllegalArgumentException - thrown if parameters fail the validation.
      com.azure.core.exception.HttpResponseException - thrown if the request is rejected by server.
      com.azure.core.exception.ClientAuthenticationException - thrown if the request is rejected by server on status code 401.
      com.azure.core.exception.ResourceNotFoundException - thrown if the request is rejected by server on status code 404.
      com.azure.core.exception.ResourceModifiedException - thrown if the request is rejected by server on status code 409.
      RuntimeException - all other wrapped checked exceptions if the request fails to be sent.
    • updateMessage

      public ThreadMessage updateMessage(String threadId, String messageId)
      Modifies an existing message on an existing thread.
      Parameters:
      threadId - Identifier of the thread.
      messageId - Identifier of the message.
      Returns:
      a single, existing message within an agent thread.
      Throws:
      IllegalArgumentException - thrown if parameters fail the validation.
      com.azure.core.exception.HttpResponseException - thrown if the request is rejected by server.
      com.azure.core.exception.ClientAuthenticationException - thrown if the request is rejected by server on status code 401.
      com.azure.core.exception.ResourceNotFoundException - thrown if the request is rejected by server on status code 404.
      com.azure.core.exception.ResourceModifiedException - thrown if the request is rejected by server on status code 409.
      RuntimeException - all other wrapped checked exceptions if the request fails to be sent.
    • createMessage

      public ThreadMessage createMessage(String threadId, MessageRole role, String content, List<MessageAttachment> attachments, Map<String,String> metadata)
      Creates a new message on a specified thread.
      Parameters:
      threadId - Identifier of the thread.
      role - The role of the entity that is creating the message. Allowed values include: `user`, which indicates the message is sent by an actual user (and should be used in most cases to represent user-generated messages), and `assistant`, which indicates the message is generated by the agent (use this value to insert messages from the agent into the conversation).
      content - The content of the initial message. This may be a basic string (if you only need text) or an array of typed content blocks (for example, text, image_file, image_url, and so on).
      attachments - A list of files attached to the message, and the tools they should be added to.
      metadata - A set of up to 16 key/value pairs that can be attached to an object, used for storing additional information about that object in a structured format. Keys may be up to 64 characters in length and values may be up to 512 characters in length.
      Returns:
      a single, existing message within an agent thread.
      Throws:
      IllegalArgumentException - thrown if parameters fail the validation.
      com.azure.core.exception.HttpResponseException - thrown if the request is rejected by server.
      com.azure.core.exception.ClientAuthenticationException - thrown if the request is rejected by server on status code 401.
      com.azure.core.exception.ResourceNotFoundException - thrown if the request is rejected by server on status code 404.
      com.azure.core.exception.ResourceModifiedException - thrown if the request is rejected by server on status code 409.
      RuntimeException - all other wrapped checked exceptions if the request fails to be sent.
    • createMessage

      public ThreadMessage createMessage(String threadId, MessageRole role, String content)
      Creates a new message on a specified thread.
      Parameters:
      threadId - Identifier of the thread.
      role - The role of the entity that is creating the message. Allowed values include: `user`, which indicates the message is sent by an actual user (and should be used in most cases to represent user-generated messages), and `assistant`, which indicates the message is generated by the agent (use this value to insert messages from the agent into the conversation).
      content - The content of the initial message. This may be a basic string (if you only need text) or an array of typed content blocks (for example, text, image_file, image_url, and so on).
      Returns:
      a single, existing message within an agent thread.
      Throws:
      IllegalArgumentException - thrown if parameters fail the validation.
      com.azure.core.exception.HttpResponseException - thrown if the request is rejected by server.
      com.azure.core.exception.ClientAuthenticationException - thrown if the request is rejected by server on status code 401.
      com.azure.core.exception.ResourceNotFoundException - thrown if the request is rejected by server on status code 404.
      com.azure.core.exception.ResourceModifiedException - thrown if the request is rejected by server on status code 409.
      RuntimeException - all other wrapped checked exceptions if the request fails to be sent.
    • listMessages

      public com.azure.core.http.rest.PagedIterable<com.azure.core.util.BinaryData> listMessages(String threadId, com.azure.core.http.rest.RequestOptions requestOptions)
      Gets a list of messages that exist on a thread.

      Query Parameters

      Query Parameters
      NameTypeRequiredDescription
      run_idStringNoFilter messages by the run ID that generated them.
      limitIntegerNoA limit on the number of objects to be returned. Limit can range between 1 and 100, and the default is 20.
      orderStringNoSort order by the created_at timestamp of the objects. asc for ascending order and desc for descending order. Allowed values: "asc", "desc".
      afterStringNoA cursor for use in pagination. after is an object ID that defines your place in the list. For instance, if you make a list request and receive 100 objects, ending with obj_foo, your subsequent call can include after=obj_foo in order to fetch the next page of the list.
      beforeStringNoA cursor for use in pagination. before is an object ID that defines your place in the list. For instance, if you make a list request and receive 100 objects, ending with obj_foo, your subsequent call can include before=obj_foo in order to fetch the previous page of the list.
      You can add these to a request with RequestOptions.addQueryParam(java.lang.String, java.lang.String)

      Response Body Schema

       
       {
           id: String (Required)
           object: String (Required)
           created_at: long (Required)
           thread_id: String (Required)
           status: String(in_progress/incomplete/completed) (Required)
           incomplete_details (Required): {
               reason: String(content_filter/max_tokens/run_cancelled/run_failed/run_expired) (Required)
           }
           completed_at: Long (Required)
           incomplete_at: Long (Required)
           role: String(user/assistant) (Required)
           content (Required): [
                (Required){
                   type: String (Required)
               }
           ]
           assistant_id: String (Required)
           run_id: String (Required)
           attachments (Required): [
                (Required){
                   file_id: String (Optional)
                   data_source (Optional): {
                       uri: String (Required)
                       type: String(uri_asset/id_asset) (Required)
                   }
                   tools (Required): [
                       BinaryData (Required)
                   ]
               }
           ]
           metadata (Required): {
               String: String (Required)
           }
       }
       
       
      Parameters:
      threadId - Identifier of the thread.
      requestOptions - The options to configure the HTTP request before HTTP client sends it.
      Returns:
      a list of messages that exist on a thread as paginated response with PagedIterable.
      Throws:
      com.azure.core.exception.HttpResponseException - thrown if the request is rejected by server.
      com.azure.core.exception.ClientAuthenticationException - thrown if the request is rejected by server on status code 401.
      com.azure.core.exception.ResourceNotFoundException - thrown if the request is rejected by server on status code 404.
      com.azure.core.exception.ResourceModifiedException - thrown if the request is rejected by server on status code 409.