Core Thread Management¶
cortex_agents.core.threads.AgentThreads ¶
Thread operations for the synchronous Cortex Agent client.
Source code in cortex_agents/core/threads.py
create_thread ¶
Create a new conversation thread.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
origin_app
|
str | None
|
Optional application name for tracking thread origin (max 16 bytes). |
None
|
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
Dictionary containing thread metadata including thread_id, thread_name, |
dict[str, Any]
|
origin_application, created_on, and updated_on. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If origin_app exceeds 16 bytes. |
SnowflakeAPIError
|
If the request fails. |
Examples:
Source code in cortex_agents/core/threads.py
get_thread ¶
get_thread(thread_id: str | int, *, limit: int = 20, last_message_id: int | None = None) -> dict[str, Any]
Retrieve a conversation thread with its messages.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
thread_id
|
str | int
|
Thread ID to retrieve. |
required |
limit
|
int
|
Maximum number of messages to return (default: 20). |
20
|
last_message_id
|
int | None
|
Message ID to start pagination from (optional). |
None
|
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
Dictionary containing thread metadata and messages. |
Raises:
| Type | Description |
|---|---|
SnowflakeAPIError
|
If the thread doesn't exist or request fails. |
Examples:
thread = client.get_thread(thread_id, limit=50)
for msg in thread['messages']:
print(msg['content'])
Source code in cortex_agents/core/threads.py
update_thread ¶
Update a thread's name.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
thread_id
|
str | int
|
Thread ID to update. |
required |
name
|
str
|
New thread name. |
required |
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
Response dictionary with update status. |
Raises:
| Type | Description |
|---|---|
SnowflakeAPIError
|
If the thread doesn't exist or request fails. |
Examples:
Source code in cortex_agents/core/threads.py
list_threads ¶
List all conversation threads.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
origin_app
|
str | None
|
Filter by application name (optional). |
None
|
Returns:
| Type | Description |
|---|---|
list[dict[str, Any]]
|
List of thread dictionaries, each containing thread_id, thread_name, |
list[dict[str, Any]]
|
origin_application, created_on, and updated_on. |
Raises:
| Type | Description |
|---|---|
SnowflakeAPIError
|
If the request fails. |
Examples:
threads = client.list_threads(origin_app="my_app")
for thread in threads:
print(f"{thread['thread_id']}: {thread['thread_name']}")
Source code in cortex_agents/core/threads.py
delete_thread ¶
Delete a conversation thread.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
thread_id
|
str | int
|
Thread ID to delete. |
required |
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
Response dictionary with deletion status. |
Raises:
| Type | Description |
|---|---|
SnowflakeAPIError
|
If the thread doesn't exist or request fails. |
Examples:
Source code in cortex_agents/core/threads.py
cortex_agents.core.threads.AsyncAgentThreads ¶
Thread operations for the asynchronous Cortex Agent client.
Source code in cortex_agents/core/threads.py
create_thread
async
¶
Create a new conversation thread (async).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
origin_app
|
str | None
|
Optional application name for tracking thread origin (max 16 bytes). |
None
|
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
Dictionary containing thread metadata including thread_id, thread_name, |
dict[str, Any]
|
origin_application, created_on, and updated_on. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If origin_app exceeds 16 bytes. |
SnowflakeAPIError
|
If the request fails. |
Examples:
Source code in cortex_agents/core/threads.py
get_thread
async
¶
get_thread(thread_id: str | int, *, limit: int = 20, last_message_id: int | None = None) -> dict[str, Any]
Retrieve a conversation thread with its messages (async).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
thread_id
|
str | int
|
Thread ID to retrieve. |
required |
limit
|
int
|
Maximum number of messages to return (default: 20). |
20
|
last_message_id
|
int | None
|
Message ID to start pagination from (optional). |
None
|
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
Dictionary containing thread metadata and messages. |
Raises:
| Type | Description |
|---|---|
SnowflakeAPIError
|
If the thread doesn't exist or request fails. |
Examples:
thread = await client.get_thread(thread_id, limit=50)
for msg in thread['messages']:
print(msg['content'])
Source code in cortex_agents/core/threads.py
update_thread
async
¶
Update a thread's name (async).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
thread_id
|
str | int
|
Thread ID to update. |
required |
name
|
str
|
New thread name. |
required |
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
Response dictionary with update status. |
Raises:
| Type | Description |
|---|---|
SnowflakeAPIError
|
If the thread doesn't exist or request fails. |
Examples:
Source code in cortex_agents/core/threads.py
list_threads
async
¶
List all conversation threads (async).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
origin_app
|
str | None
|
Filter by application name (optional). |
None
|
Returns:
| Type | Description |
|---|---|
list[dict[str, Any]]
|
List of thread dictionaries, each containing thread_id, thread_name, |
list[dict[str, Any]]
|
origin_application, created_on, and updated_on. |
Raises:
| Type | Description |
|---|---|
SnowflakeAPIError
|
If the request fails. |
Examples:
threads = await client.list_threads(origin_app="my_app")
for thread in threads:
print(f"{thread['thread_id']}: {thread['thread_name']}")
Source code in cortex_agents/core/threads.py
delete_thread
async
¶
Delete a conversation thread (async).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
thread_id
|
str | int
|
Thread ID to delete. |
required |
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
Response dictionary with deletion status. |
Raises:
| Type | Description |
|---|---|
SnowflakeAPIError
|
If the thread doesn't exist or request fails. |
Examples: