Categories:

Context functions (General)

IS_AGENT_ACTIVATED (SYS_CONTEXT function)

Returns the VARCHAR value 'TRUE' if an agent is active in the current execution context.

See also:

SYS_CONTEXT (SNOWFLAKE$CURRENT namespace)

Syntax

Check whether any agent is active:

SYS_CONTEXT(
  'SNOWFLAKE$CURRENT' ,
  'IS_AGENT_ACTIVATED'
)

Check whether an agent of a specific type is active:

SYS_CONTEXT(
  'SNOWFLAKE$CURRENT' ,
  'IS_AGENT_ACTIVATED' ,
  '<agent_type>'
)

Check whether a specific Snowflake Intelligence agent is active:

SYS_CONTEXT(
  'SNOWFLAKE$CURRENT' ,
  'IS_AGENT_ACTIVATED' ,
  'SNOWFLAKE_INTELLIGENCE' ,
  '<database>' ,
  '<schema>' ,
  '<name>'
)

Arguments

'SNOWFLAKE$CURRENT'

Specifies that you want to call a function to return context information about the current execution context.

'IS_AGENT_ACTIVATED'

Calls the IS_AGENT_ACTIVATED function.

'agent_type'

Optional. Specifies the type of agent to check. If you don’t specify an agent type, the function checks whether any agent is active.

You can specify one of the following values:

Agent typeDescription
SNOWFLAKE_INTELLIGENCEA Snowflake Intelligence agent.
CORTEX_CODE_CLIA Cortex Code CLI client.
CORTEX_CODE_DESKTOPA Cortex Code Desktop client.
CORTEX_CODE_SNOWSIGHTA Cortex Code UI (Snowsight) client.

Only SNOWFLAKE_INTELLIGENCE supports the optional database, schema, and name filter arguments.

'database'

Specifies the database component of the agent’s fully qualified name.

Supported only when agent_type is 'SNOWFLAKE_INTELLIGENCE'.

'schema'

Specifies the schema component of the agent’s fully qualified name.

Supported only when agent_type is 'SNOWFLAKE_INTELLIGENCE'.

'name'

Specifies the name of the agent.

Supported only when agent_type is 'SNOWFLAKE_INTELLIGENCE'.

Returns

The function returns one of the following VARCHAR values:

  • 'TRUE' if an agent matching the specified criteria is active in the current execution context.
  • 'FALSE' if no matching agent is active.

To compare this return value against the BOOLEAN value TRUE or FALSE, cast the return value to BOOLEAN. For example:

SELECT SYS_CONTEXT('SNOWFLAKE$CURRENT', 'IS_AGENT_ACTIVATED')::BOOLEAN = TRUE;

Usage notes

  • When you specify 'SNOWFLAKE_INTELLIGENCE' as the agent type, you can optionally provide the database, schema, and name arguments to match a specific agent. Other agent types don’t support these filter arguments.

  • To simulate the result of this function in a policy, use the SNOWFLAKE$CURRENT_ACTIVATED_AGENT_TYPES list argument with the POLICY_CONTEXT function.

Examples

The following example checks whether any agent is active in the current execution context:

SELECT SYS_CONTEXT('SNOWFLAKE$CURRENT', 'IS_AGENT_ACTIVATED');

The following example checks whether a Snowflake Intelligence agent is active:

SELECT SYS_CONTEXT('SNOWFLAKE$CURRENT', 'IS_AGENT_ACTIVATED', 'SNOWFLAKE_INTELLIGENCE');

The following example checks whether a specific Snowflake Intelligence agent is active by its fully qualified name:

SELECT SYS_CONTEXT('SNOWFLAKE$CURRENT', 'IS_AGENT_ACTIVATED',
  'SNOWFLAKE_INTELLIGENCE', 'my_db', 'my_schema', 'my_agent');