CREATE AGENT¶
Creates a new Cortex Agent object with the specified attributes and specification.
Syntax¶
Required parameters¶
nameString that specifies the identifier (i.e. name) for the agent; must be unique for the schema in which the agent is created.
You can create an agent in the
PUBLICschema of your Personal Database by using a fully qualified name in the form"USER$<username>".PUBLIC.<agent_name>.In addition, the identifier must start with an alphabetic character and cannot contain spaces or special characters unless the entire identifier string is enclosed in double quotes (for example,
"My object"). Identifiers enclosed in double quotes are also case-sensitive.For more information, see Identifier requirements.
Optional parameters¶
{ TEMP | TEMPORARY }Specifies that the agent persists only for the duration of the session in which you created it. A temporary agent is bound to the creating user, role, and session. It is dropped automatically when the session ends and is not recoverable.
TEMPis an accepted abbreviation forTEMPORARY.Creating a temporary agent does not require the CREATE AGENT privilege on the schema. Temporary agents cannot be converted to permanent agents, and they do not support versioning operations such as
COMMITor aliases.For more information, see Working with temporary agents.
Default: No value (agent is permanent)
SECUREorSECURE = { TRUE | FALSE }Specifies whether the agent is secure. Use the
SECUREkeyword beforeAGENT, or set theSECUREproperty toTRUE, to create a secure agent. Setting the property toFALSEcreates a non-secure agent.For a secure agent, the complete specification is visible only when the owner role is activated in the session. Roles with only USAGE or MODIFY cannot read the specification through DESCRIBE, GET_DDL, SHOW VERSIONS, or stage paths. For more information, see Secure agents.
Default: No value (agent is not secure)
COPY GRANTSRetains the access privileges from the original agent when you replace it using
CREATE OR REPLACE AGENT.When
COPY GRANTSis specified, Snowflake copies all privileges granted on the existing agent to the replacement agent, except OWNERSHIP. The replacement agent does not inherit any future grants defined for the agent type in the schema. The role that executes theCREATE OR REPLACE AGENTstatement owns the new agent.When
COPY GRANTSis not specified, the replacement agent loses all explicit access privileges that were granted on the original agent. It inherits only future grants defined for the agent type in the schema.COPY GRANTSis meaningful only when used withOR REPLACE. If the agent does not already exist, there are no existing grants to copy and the clause has no effect.COPY GRANTSandIF NOT EXISTSare mutually exclusive. You cannot use both in the same statement.Default: No value (grants are not copied)
COMMENT = 'comment'Description of the agent.
PROFILE = profile_objectSpecifies the OBJECT value containing agent profile information, such as display name, avatar, and color. Serialize the
profile_objectinto a string as follows:The following table describes the key-value pairs in this object:
Key Type Description display_nameString Display name for the agent. avatarString Avatar image file name or identifier. colorString Color theme for the agent (such as “blue”, “green”, “red”) FROM SPECIFICATION $$ specification_object $$Specifies the VARCHAR value containing the settings for an agent as a YAML object. The maximum length of the specification object is 100,000 bytes.
The YAML object should have the following structure:
The following table describes the key-value pairs in this object:
Key Type Description modelsModelConfig An optional model configuration for the agent. Includes the orchestration model, for example auto, which lets Snowflake select the model. If not provided, a model is automatically selected. Currently only available for the orchestration step.orchestrationOrchestrationConfig An optional orchestration configuration, including budget constraints (seconds, tokens), capabilities such as analytical_search, andtool_not_accessible(accept,reject, orlegacy). Iftool_not_accessibleis omitted, the default isaccept. For details, see Inaccessible tool handling.instructionsAgentInstructions Optional instructions for the agent’s behavior, including response, orchestration, and sample questions. toolsarray of Tool An optional list of tools available for the agent to use. Each tool includes a tool_specwith type, name, description, and input schema. Tools may have a corresponding configuration intool_resources.tool_resourcesmap of ToolResource An optional configuration for each tool referenced in the tools array. Keys must match the name of the respective tool.
Access control requirements¶
A role used to execute this operation must have the following privileges at a minimum:
| Privilege | Object | Notes |
|---|---|---|
| CREATE AGENT | Schema | Required to create a permanent Cortex Agent. Not required for temporary agents. |
| OWNERSHIP | Agent | Required to replace an existing agent with CREATE OR REPLACE. |
| USAGE | Cortex Search service | Required to run the Cortex Search services in the Cortex Agents request. |
| USAGE | Database, schema, table | Required to access the objects referenced in the Cortex Agents semantic model. |
Usage notes¶
- The OR REPLACE and IF NOT EXISTS clauses are mutually exclusive. They can’t both be used in the same statement.
-
CREATE OR REPLACE <object> statements are atomic. That is, when an object is replaced, the old object is deleted and the new object is created in a single transaction.
-
Regarding metadata:
Attention
Customers should ensure that no personal data (other than for a User object), sensitive data, export-controlled data, or other regulated data is entered as metadata when using the Snowflake service. For more information, see Metadata fields in Snowflake.
-
Using
COPY GRANTS:- When you run
CREATE OR REPLACE AGENT ... COPY GRANTS, Snowflake drops the existing agent, creates the replacement, copies privileges (except OWNERSHIP), and assigns OWNERSHIP to the role that executed the statement, all within a single transaction. - Because the operation is atomic, any queries or runs in progress against the agent use either the old version or the new version, not a partial state.
COPY GRANTSdoes not copy future grants defined for the agent type in the schema. Only explicit grants on the original agent object are copied.- If the agent is shared with another account or exposed through a native app, the replacement agent remains shared when you use
COPY GRANTS. - After replacing an agent with
COPY GRANTS, runSHOW GRANTS ON AGENT <name>to verify that the expected privileges were copied. - Dropping explicit grants when replacing an agent without
COPY GRANTScan break integrations and application flows that depend on those grants. Snowflake recommends usingCOPY GRANTSwhenever you replace an agent that has been granted to other roles or shared with consumers.
- When you run
-
Temporary agents are session-scoped. If a temporary agent and a permanent agent share the same name in a schema, the temporary agent takes precedence for the duration of the session. For more information, see Working with temporary agents.
-
To control whether a missing privilege on a configured tool aborts the run, set
tool_not_accessibleon the specification’s top-levelorchestrationkey, not onmodels.orchestrationorinstructions.orchestration. For details, see Where to set the field.
Examples¶
Create a temporary agent¶
Create an agent in a Personal Database¶
Create an agent in the PUBLIC schema of the Personal Database for the user JSMITH:
For an example that runs this agent, see Run an agent in a [Personal Database](/user-guide/personal-databases) and….