THREAD_MESSAGES

functiondeferredAI & ML

docs.snowflake.com ↗

String & binary functions

Returns the messages in a Cortex Agent thread as JSON. You can use this function to retrieve all messages in a thread after an agent run completes. This is particularly useful for polling the results of an asynchronous (background) agent run started with background: true. Note SNOWFLAKE.CORTEX.THREAD_MESSAGES is a utility wrapper around the Cortex Agents Threads REST API.

Syntax

supportedpartialnot supportednot scored

SNOWFLAKE.CORTEX.THREAD_MESSAGES( <thread_id> [, <page_size>, <last_message_id> ] )

Parameters

NameRequiredDescription
thread_idrequiredThe ID of the thread to retrieve messages from.
page_size (optional)requiredThe maximum number of messages to return per page. Use this with last_message_id for pagination.
last_message_id (optional)requiredThe ID of the last message from the previous page. Messages returned will be those after this message ID. Use this with page_size for pagination.

Returns

Returns a JSON string containing an array of messages in the thread. Each message includes the role, content, and message metadata.

Usage notes

Access control requirements

To retrieve thread messages, you must use a role that can access Cortex Agents. For details, see API access roles.

Known gaps

Parts not fully supported, and recorded divergences from Snowflake.

See also