airflow.providers.snowflake.hooks.cortex_agent¶
Attributes¶
Classes¶
Resource creation modes for Cortex Agents. |
|
Hook for interacting with Snowflake Cortex Agents. |
Module Contents¶
- class airflow.providers.snowflake.hooks.cortex_agent.CreateMode[source]¶
-
Resource creation modes for Cortex Agents.
- class airflow.providers.snowflake.hooks.cortex_agent.SnowflakeCortexAgentHook(*args, **kwargs)[source]¶
Bases:
airflow.providers.snowflake.hooks.snowflake.SnowflakeHookHook for interacting with Snowflake Cortex Agents.
Authenticates the same three ways as
SnowflakeSqlApiHook, chosen by the connection’sauthenticatorextra:OAuth: set
authenticatortooauthand configure a refresh token, client credentials grant, orazure_conn_id, as onSnowflakeHook.PAT (Programmatic Access Token): set
authenticatortoprogrammatic_access_tokenand put the PAT value in the connectionpasswordfield.Key-pair JWT: the default when neither of the above is set. Configure
private_key_fileorprivate_key_content(optionally with a passphrase inpassword), as onSnowflakeHook.
The resolved token is cached and renewed the same way as
SnowflakeSqlApiHook– seeSnowflakeRestTokenProvider, 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_idandparent_message_idare provided, this should contain only the current user message.thread_id (int | None) – Existing conversation thread identifier. When provided,
parent_message_idmust also be supplied. Optional. Defaults toNone.parent_message_id (int | None) – Parent message identifier within the specified thread. Required when
thread_idis provided. Optional. Defaults toNone.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 toNone.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:
- 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,orReplaceorifNotExists. Optional. Defaults toerrorIfExists.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:
- 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:
- describe_agent(*, database, schema, agent_name, timeout=600)[source]¶
Describe a Snowflake Cortex Agent.
- Parameters:
- Returns:
JSON description of the Cortex Agent.
- Return type:
- 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:
- 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 toFalse.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: