AzureAIAgentThread Class
An Azure AI Agent Thread that manages creation, deletion, and retrieval of messages for an Azure-hosted agent conversation. This thread orchestrates calls to the Azure AI Project client API to perform operations like creating a new thread, adding messages, or retrieving conversation history.
Constructor
AzureAIAgentThread(
*,
client: AIProjectClient,
messages: list[ThreadMessageOptions] | None = None,
metadata: dict[str, str] | None = None,
thread_id: str | None = None,
tool_resources: ToolResources | None = None
)
Parameters
| Name | Description |
|---|---|
|
client
Required
|
The Azure AI Project client used for thread operations. |
|
messages
|
A list of initial thread messages to create the thread with. Default value: None
|
|
metadata
|
Arbitrary thread metadata to store on creation. Default value: None
|
|
thread_id
|
The existing thread ID (if any). A new thread is created if None. Default value: None
|
|
tool_resources
|
The tool resources for the thread. Default value: None
|
Methods
| _create |
Internal hook that creates a new thread on the Azure AI service. |
| _delete |
Internal hook to delete the thread from the Azure AI service. |
| _on_new_message |
Invoked on new user or system messages. Creates the message in the Azure AI thread if it doesn't match the existing thread ID. |
| get_messages |
Retrieve messages from the thread in either ascending or descending order. |
_create
Internal hook that creates a new thread on the Azure AI service.
async _create() -> str
Returns
| Type | Description |
|---|---|
|
The newly created thread's ID returned by the service. |
_delete
Internal hook to delete the thread from the Azure AI service.
async _delete() -> None
_on_new_message
Invoked on new user or system messages. Creates the message in the Azure AI thread if it doesn't match the existing thread ID.
async _on_new_message(new_message: str | ChatMessageContent) -> None
Parameters
| Name | Description |
|---|---|
|
new_message
Required
|
The new message to add, provided as a string or ChatMessageContent. |
get_messages
Retrieve messages from the thread in either ascending or descending order.
async get_messages(sort_order: Literal["asc","desc"] = "desc") -> AsyncIterable[ChatMessageContent]
Parameters
| Name | Description |
|---|---|
|
sort_order
|
The sort order for the messages, defaults to descending. Default value: desc
|
Returns
| Type | Description |
|---|---|
|
An async stream of ChatMessageContent for this thread's conversation. |
Attributes
_client
The Azure AI Project client used to perform thread-level operations.
_client: AIProjectClient
_messages
The initial messages to be applied when creating the thread.
_messages: list[ThreadMessageOptions]
_metadata
Optional metadata to attach when creating the thread.
_metadata: dict[str, str] | None
_tool_resources
Optional tool resources for the thread context.
_tool_resources: ToolResources | None