Share via


MessagesClient Class

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

public final class MessagesClient

Initializes a new instance of the synchronous Messages type.

Method Summary

Modifier and Type Method and Description
ThreadMessage createMessage(String threadId, MessageRole role, BinaryData content)

Creates a new message on a specified thread.

ThreadMessage createMessage(String threadId, MessageRole role, BinaryData content, List<MessageAttachment> attachments, Map<String,String> metadata)

Creates a new message on a specified thread.

ThreadMessage createMessage(String threadId, MessageRole role, String content)

Creates a new message on a specified thread.

ThreadMessage createMessage(String threadId, MessageRole role, String content, List<MessageAttachment> attachments, Map<String,String> metadata)

Creates a new message on a specified thread.

Response<BinaryData> createMessageWithResponse(String threadId, BinaryData createMessageRequest, RequestOptions requestOptions)

Creates a new message on a specified thread.

ThreadMessage getMessage(String threadId, String messageId)

Retrieves an existing message.

Response<BinaryData> getMessageWithResponse(String threadId, String messageId, RequestOptions requestOptions)

Retrieves an existing message.

PagedIterable<ThreadMessage> listMessages(String threadId)

Gets a list of messages that exist on a thread.

PagedIterable<BinaryData> listMessages(String threadId, RequestOptions requestOptions)

Gets a list of messages that exist on a thread.

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.

ThreadMessage updateMessage(String threadId, String messageId)

Modifies an existing message on an existing thread.

ThreadMessage updateMessage(String threadId, String messageId, Map<String,String> metadata)

Modifies an existing message on an existing thread.

Response<BinaryData> updateMessageWithResponse(String threadId, String messageId, BinaryData updateMessageRequest, RequestOptions requestOptions)

Modifies an existing message on an existing thread.

Methods inherited from java.lang.Object

Method Details

createMessage

public ThreadMessage createMessage(String threadId, MessageRole role, 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.

createMessage

public ThreadMessage createMessage(String threadId, MessageRole role, 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.

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.

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.

createMessageWithResponse

public Response<BinaryData> createMessageWithResponse(String threadId, BinaryData createMessageRequest, 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<T>.

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.

getMessageWithResponse

public Response<BinaryData> getMessageWithResponse(String threadId, String messageId, 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<T>.

listMessages

public 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<T>.

listMessages

public PagedIterable<BinaryData> listMessages(String threadId, RequestOptions requestOptions)

Gets a list of messages that exist on a thread.

Query Parameters

| ------- | ------- | -------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| Name    | Type    | Required | Description                                                                                                                                                                                                                                                                           |
| run\_id | String  | No       | Filter messages by the run ID that generated them.                                                                                                                                                                                                                                    |
| limit   | Integer | No       | A limit on the number of objects to be returned. Limit can range between 1 and 100, and the default is 20.                                                                                                                                                                            |
| order   | String  | No       | Sort order by the created\_at timestamp of the objects. asc for ascending order and desc for descending order. Allowed values: "asc", "desc".                                                                                                                                         |
| after   | String  | No       | 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  | String  | No       | 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. |

You can add these to a request with RequestOptions#addQueryParam

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<T>.

listMessages

public 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<T>.

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.

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.

updateMessageWithResponse

public Response<BinaryData> updateMessageWithResponse(String threadId, String messageId, BinaryData updateMessageRequest, 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<T>.

Applies to