MessagesOperations Class
Constructor
MessagesOperations(*args, **kwargs)
Methods
| create |
Creates a new message on a specified thread. |
| delete |
Deletes an existing message on an existing thread. |
| get |
Retrieves an existing message. |
| get_last_message_by_role |
Return the most-recent message in thread_id authored by role. The implementation streams messages (newest first, where the service/SDK supports that) and stops at the first match. |
| get_last_message_text_by_role |
Return the most-recent text message in thread_id authored by role. |
| list |
Gets a list of messages that exist on a thread. |
| update |
Modifies an existing message on an existing thread. |
create
Creates a new message on a specified thread.
create(thread_id: str, body: ~collections.abc.MutableMapping[str, ~typing.Any] | ~typing.IO[bytes] = <object object>, *, role: str | ~azure.ai.agents.models._enums.MessageRole = <object object>, content: _types.MessageInputContent = <object object>, attachments: list[azure.ai.agents.models._patch.MessageAttachment] | None = None, metadata: dict[str, str] | None = None, **kwargs: ~typing.Any) -> ThreadMessage
Parameters
| Name | Description |
|---|---|
|
thread_id
Required
|
Identifier of the thread. Required. |
|
body
|
Is either a JSON type or a IO[bytes] type. Required. |
Keyword-Only Parameters
| Name | Description |
|---|---|
|
role
|
str or
MessageRole
The role of the entity that is creating the message. Allowed values include:
Default value: <object object at 0x00000253AF412830>
|
|
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). Is either a str type or a [MessageInputContentBlock] type. Required. Default value: <object object at 0x00000253AF412830>
|
|
attachments
|
A list of files attached to the message, and the tools they should be added to. Default value is None. Default value: None
|
|
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. Default value is None. Default value: None
|
Returns
| Type | Description |
|---|---|
|
ThreadMessage. The ThreadMessage is compatible with MutableMapping |
Exceptions
| Type | Description |
|---|---|
delete
Deletes an existing message on an existing thread.
delete(thread_id: str, message_id: str, **kwargs: Any) -> None
Parameters
| Name | Description |
|---|---|
|
thread_id
Required
|
Identifier of the thread. Required. |
|
message_id
Required
|
Identifier of the message. Required. |
Exceptions
| Type | Description |
|---|---|
get
Retrieves an existing message.
get(thread_id: str, message_id: str, **kwargs: Any) -> ThreadMessage
Parameters
| Name | Description |
|---|---|
|
thread_id
Required
|
Identifier of the thread. Required. |
|
message_id
Required
|
Identifier of the message. Required. |
Returns
| Type | Description |
|---|---|
|
ThreadMessage. The ThreadMessage is compatible with MutableMapping |
Exceptions
| Type | Description |
|---|---|
get_last_message_by_role
Return the most-recent message in thread_id authored by role.
The implementation streams messages (newest first, where the service/SDK supports that) and stops at the first match.
get_last_message_by_role(thread_id: str, role: MessageRole, **kwargs) -> ThreadMessage | None
Parameters
| Name | Description |
|---|---|
|
thread_id
Required
|
The ID of the thread to search. |
|
role
Required
|
The role of the message author. |
Returns
| Type | Description |
|---|---|
|
The most recent message authored by role in the thread, or None if no such message exists. |
get_last_message_text_by_role
Return the most-recent text message in thread_id authored by role.
get_last_message_text_by_role(thread_id: str, role: MessageRole, **kwargs) -> MessageTextContent | None
Parameters
| Name | Description |
|---|---|
|
thread_id
Required
|
The ID of the thread to search. |
|
role
Required
|
The role of the message author. |
Returns
| Type | Description |
|---|---|
|
The most recent text message authored by role in the thread, or None if no such message exists. |
list
Gets a list of messages that exist on a thread.
list(thread_id: str, *, run_id: str | None = None, limit: int | None = None, order: str | ListSortOrder | None = None, before: str | None = None, **kwargs: Any) -> ItemPaged[ThreadMessage]
Parameters
| Name | Description |
|---|---|
|
thread_id
Required
|
Identifier of the thread. Required. |
Keyword-Only Parameters
| Name | Description |
|---|---|
|
run_id
|
Filter messages by the run ID that generated them. Default value is None. Default value: None
|
|
limit
|
A limit on the number of objects to be returned. Limit can range between 1 and 100, and the default is 20. Default value is None. Default value: None
|
|
order
|
str or
ListSortOrder
Sort order by the created_at timestamp of the objects. asc for ascending order and desc for descending order. Known values are: "asc" and "desc". Default value is None. Default value: None
|
|
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. Default value is None. Default value: None
|
Returns
| Type | Description |
|---|---|
|
An iterator like instance of ThreadMessage |
Exceptions
| Type | Description |
|---|---|
update
Modifies an existing message on an existing thread.
update(thread_id: str, message_id: str, body: ~collections.abc.MutableMapping[str, ~typing.Any] | ~typing.IO[bytes] = <object object>, *, metadata: dict[str, str] | None = None, **kwargs: ~typing.Any) -> ThreadMessage
Parameters
| Name | Description |
|---|---|
|
thread_id
Required
|
Identifier of the thread. Required. |
|
message_id
Required
|
Identifier of the message. Required. |
|
body
|
Is either a JSON type or a IO[bytes] type. Required. |
Keyword-Only Parameters
| Name | Description |
|---|---|
|
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. Default value is None. Default value: None
|
Returns
| Type | Description |
|---|---|
|
ThreadMessage. The ThreadMessage is compatible with MutableMapping |
Exceptions
| Type | Description |
|---|---|