CortexAgentApi
CortexAgentApi(client: httpx.Client)Client for interacting with the Snowflake Cortex Agents REST API.
Provides methods for creating, updating, describing, listing, deleting,
and running Cortex agents. Requires both the USE AI FUNCTIONS account
privilege and the snowflake.cortex_user database role.
All requests timeout after 15 minutes.
Parameters
Section titled “Parameters”
(clienthttpx.Client) - Configuredhttpx.Clientwith authentication headers.
Methods
Section titled “Methods”.create()
Section titled “.create()”CortexAgentApi.create( database: str, schema: str, request: AgentSpec, create_mode: str = "orReplace") -> NoneCreate an agent.
Parameters:
(databasestr) - Database name.
(schemastr) - Schema name.
(requestAgentSpec) - Agent specification.
(create_modestr, default:“orReplace”) - One of"orReplace","errorIfExists", or"ifNotExists". Default:"orReplace".
Returns:
-
None
.update()
Section titled “.update()”CortexAgentApi.update(database: str, schema: str, name: str, request: AgentSpec) -> NoneUpdate an existing agent’s configuration.
Modifies the properties of an existing agent. Fields not included in the request are left unchanged.
Parameters:
(databasestr) - Database name.
(schemastr) - Schema name.
(namestr) - Agent name to update.
(requestAgentSpec) - Updated agent specification.
Returns:
-
None
Raises:
httpx.HTTPStatusError- If the request fails.
.describe()
Section titled “.describe()”CortexAgentApi.describe(database: str, schema: str, name: str) -> DescribeAgentResponseRetrieve comprehensive details about a specific agent.
Returns complete agent metadata including configuration, ownership, and creation information.
Parameters:
(databasestr) - Database name.
(schemastr) - Schema name.
(namestr) - Agent name.
Returns:
DescribeAgentResponse- Full agent details.
Raises:
httpx.HTTPStatusError- If the request fails or agent doesn’t exist.
.list()
Section titled “.list()”CortexAgentApi.list(database: str, schema: str) -> ListAgentsResponseList all agents in a schema.
Returns summary information for all agents in the specified database and schema.
Parameters:
(databasestr) - Database name.
(schemastr) - Schema name.
Returns:
ListAgentsResponse- Agent summaries.
Raises:
httpx.HTTPStatusError- If the request fails.
.delete()
Section titled “.delete()”CortexAgentApi.delete(database: str, schema: str, name: str, silent=True)Delete an agent.
Permanently removes an agent from the database. The behavior when the
agent doesn’t exist depends on the silent parameter.
Parameters:
(databasestr) - Database name.
(schemastr) - Schema name.
(namestr) - Agent name to delete.
(silentbool, default:True) - IfTrue, suppress errors when agent doesn’t exist. Default:True.
Returns:
httpx.Response- The HTTP response object.
Raises:
httpx.HTTPStatusError- Ifsilent=Falseand the request fails.
.run()
Section titled “.run()”CortexAgentApi.run( database: str, schema: str, name: str, thread_id: int, parent_message_id: int, prompt: str,) -> Tuple[dict, int]Execute an agent with a user prompt in a conversation thread.
Sends a message to the agent and streams back the response. Processes server-sent events to extract the agent’s response and updated message ID.
Parameters:
(databasestr) - Database name.
(schemastr) - Schema name.
(namestr) - Agent name to run.
(thread_idint) - Conversation thread identifier.
(parent_message_idint) - ID of the previous message in the thread.
(promptstr) - User’s message/prompt for the agent.
Returns:
tuple of (dict, int)-(response_dict, new_parent_message_id)whereresponse_dictcontains the agent’s response with"content"and"role"fields, andnew_parent_message_idis the message ID for the next interaction.
Raises:
APIResponseError- If the agent returns an error.httpx.HTTPStatusError- If the HTTP request fails.AssertionError- If the response doesn’t contain expected content.