airflow.providers.snowflake.hooks.cortex_agent

Attributes

JsonDict

JsonList

JsonResponse

Classes

CreateMode

Resource creation modes for Cortex Agents.

SnowflakeCortexAgentHook

Hook for interacting with Snowflake Cortex Agents.

Module Contents

airflow.providers.snowflake.hooks.cortex_agent.JsonDict[source]
airflow.providers.snowflake.hooks.cortex_agent.JsonList[source]
airflow.providers.snowflake.hooks.cortex_agent.JsonResponse[source]
class airflow.providers.snowflake.hooks.cortex_agent.CreateMode[source]

Bases: str, enum.Enum

Resource creation modes for Cortex Agents.

ERROR_IF_EXISTS = 'errorIfExists'[source]
OR_REPLACE = 'orReplace'[source]
IF_NOT_EXISTS = 'ifNotExists'[source]
class airflow.providers.snowflake.hooks.cortex_agent.SnowflakeCortexAgentHook(*args, **kwargs)[source]

Bases: airflow.providers.snowflake.hooks.snowflake.SnowflakeHook

Hook for interacting with Snowflake Cortex Agents.

Authenticates the same three ways as SnowflakeSqlApiHook, chosen by the connection’s authenticator extra:

  1. OAuth: set authenticator to oauth and configure a refresh token, client credentials grant, or azure_conn_id, as on SnowflakeHook.

  2. PAT (Programmatic Access Token): set authenticator to programmatic_access_token and put the PAT value in the connection password field.

  3. Key-pair JWT: the default when neither of the above is set. Configure private_key_file or private_key_content (optionally with a passphrase in password), as on SnowflakeHook.

The resolved token is cached and renewed the same way as SnowflakeSqlApiHook – see SnowflakeRestTokenProvider, one instance per hook, so a long-running agent reuses the same JWT within its renewal window.

run_agent(*, database, schema, agent_name, messages, thread_id=None, parent_message_id=None, tool_choice=None, models=None, instructions=None, orchestration=None, tools=None, tool_resources=None, timeout=600)[source]

Execute a Snowflake Cortex Agent and return the response payload.

Parameters:
  • database (str) – Database containing the Cortex Agent.

  • schema (str) – Schema containing the Cortex Agent.

  • agent_name (str) – Name of the Cortex Agent to execute.

  • messages (list[dict[str, Any]]) – Conversation messages to send to the agent. For a new conversation, this should contain the conversation history and the current user message. When thread_id and parent_message_id are provided, this should contain only the current user message.

  • thread_id (int | None) – Existing conversation thread identifier. When provided, parent_message_id must also be supplied. Optional. Defaults to None.

  • parent_message_id (int | None) – Parent message identifier within the specified thread. Required when thread_id is provided. Optional. Defaults to None.

  • tool_choice (dict[str, Any] | None) – Tool selection configuration for the agent. Optional. Defaults to None.

  • models (dict[str, Any] | None) – Model configuration for the agent. Optional. Defaults to None.

  • instructions (dict[str, Any] | None) – Agent instruction overrides. Optional. Defaults to None.

  • orchestration (dict[str, Any] | None) – Orchestration configuration for the agent. Optional. Defaults to None.

  • tools (list[dict[str, Any]] | None) – Additional tools available to the agent. Optional. Defaults to None.

  • tool_resources (dict[str, Any] | None) – Configuration for tools specified in tools. Optional. Defaults to None.

  • timeout (int | None) – Maximum time in seconds to wait for the Cortex Agent request to complete. Optional. Defaults to 600.

Returns:

JSON response returned by the Cortex Agent.

Return type:

JsonDict

create_agent(*, database, schema, agent_name, comment=None, profile=None, models=None, instructions=None, orchestration=None, tools=None, tool_resources=None, create_mode=CreateMode.ERROR_IF_EXISTS, timeout=600)[source]

Create a Snowflake Cortex Agent.

Parameters:
  • database (str) – Database in which to create the agent.

  • schema (str) – Schema in which to create the agent.

  • agent_name (str) – Name of the Cortex Agent.

  • comment (str | None) – Optional comment. Optional. Defaults to None.

  • profile (dict[str, Any] | None) – Agent profile configuration. Optional. Defaults to None.

  • models (dict[str, Any] | None) – Model configuration. Optional. Defaults to None.

  • instructions (dict[str, Any] | None) – Agent instructions. Optional. Defaults to None.

  • orchestration (dict[str, Any] | None) – Orchestration configuration. Optional. Defaults to None.

  • tools (list[dict[str, Any]] | None) – Agent tools. Optional. Defaults to None.

  • tool_resources (dict[str, Any] | None) – Tool resource configuration. Optional. Defaults to None.

  • create_mode (CreateMode | str) – Resource creation mode. One of errorIfExists, orReplace or ifNotExists. Optional. Defaults to errorIfExists.

  • timeout (int | None) – Maximum time in seconds to wait for the Cortex Agent request to complete. Defaults to 600.

Returns:

JSON response confirming creation.

Return type:

JsonDict

update_agent(*, database, schema, agent_name, comment=None, profile=None, models=None, instructions=None, orchestration=None, tools=None, tool_resources=None, timeout=600)[source]

Update a Snowflake Cortex Agent.

Only provided fields are updated; omitted fields retain their existing values.

Parameters:
  • database (str) – Database containing the agent.

  • schema (str) – Schema containing the agent.

  • agent_name (str) – Name of the Cortex Agent.

  • comment (str | None) – Comment associated with the agent. Optional. Defaults to None.

  • profile (dict[str, Any] | None) – Agent profile configuration. Optional. Defaults to None.

  • models (dict[str, Any] | None) – Model configuration. Optional. Defaults to None.

  • instructions (dict[str, Any] | None) – Agent instructions. Optional. Defaults to None.

  • orchestration (dict[str, Any] | None) – Agent orchestration configuration. Optional. Defaults to None.

  • tools (list[dict[str, Any]] | None) – Tools available to the agent. Optional. Defaults to None.

  • tool_resources (dict[str, Any] | None) – Resources used by the agent’s tools. Optional. Defaults to None.

  • timeout (int | None) – Maximum time in seconds to wait for the Cortex Agent request to complete. Optional. Defaults to 600.

Returns:

JSON response confirming the update, or an empty dictionary when Snowflake returns a successful response without a body.

Return type:

JsonDict

describe_agent(*, database, schema, agent_name, timeout=600)[source]

Describe a Snowflake Cortex Agent.

Parameters:
  • database (str) – Database containing the Cortex Agent.

  • schema (str) – Schema containing the Cortex Agent.

  • agent_name (str) – Name of the Cortex Agent.

  • timeout (int | None) – Maximum time in seconds to wait for the Cortex Agent request to complete. Optional. Defaults to 600.

Returns:

JSON description of the Cortex Agent.

Return type:

JsonDict

list_agents(*, database, schema, like=None, from_name=None, show_limit=None, timeout=600)[source]

List one page of Snowflake Cortex Agents.

Parameters:
  • database (str) – Database containing the Cortex Agents.

  • schema (str) – Schema containing the Cortex Agents.

  • like (str | None) – Case-insensitive name filter. Optional. Defaults to None.

  • from_name (str | None) – Agent name from which to continue listing results. Pass the pagination value from the preceding page to retrieve the next page. Optional. Defaults to None.

  • show_limit (int | None) – Maximum number of agents to include in this page. Optional. Defaults to None.

  • timeout (int | None) – Maximum time in seconds to wait for the Cortex Agent request to complete. Optional. Defaults to 600.

Returns:

One page of Cortex Agents.

Return type:

JsonList

delete_agent(*, database, schema, agent_name, if_exists=False, timeout=600)[source]

Delete a Snowflake Cortex Agent.

Parameters:
  • database (str) – Database containing the Cortex Agent.

  • schema (str) – Schema containing the Cortex Agent.

  • agent_name (str) – Name of the Cortex Agent.

  • if_exists (bool) – If True, do not fail when the agent does not exist. Optional. Defaults to False.

  • timeout (int | None) – Maximum time in seconds to wait for the Cortex Agent request to complete. Optional. Defaults to 600.

Returns:

JSON response confirming deletion.

Return type:

JsonDict

static get_text_response(response)[source]

Extract text blocks from a Cortex Agent response.

Was this entry helpful?