CREATE AGENT

创建一个具有指定属性和配置的新 Cortex Agent 对象。

另请参阅:

DESCRIBE AGENTDROP AGENTSHOW AGENTS

语法

CREATE [ OR REPLACE ] AGENT [ IF NOT EXISTS ] <name>
  [ COMMENT = '<comment>' ]
  [ PROFILE = '<profile_object>' ]
  FROM SPECIFICATION
  $$
  <specification_object>
  $$;
Copy

必填参数

name

指定书籍标识符(即名称)的字符串;在创建书籍的架构中必须是唯一的。

此外,标识符必须以字母字符开头,且不能包含空格或特殊字符,除非整个标识符字符串放在双引号内(例如,"My object")。放在双引号内的标识符也区分大小写。

有关更多信息,请参阅 标识符要求

可选参数

COMMENT = comment

代理的描述。

PROFILE = profile_object

指定包含代理配置文件信息(如显示名称、头像和颜色)的 OBJECT 值。将 profile_object 序列化为字符串,如下所示:

'{"display_name": "<display_name>", "avatar": "<avatar>", "color": "<color>"}'
Copy

下表描述了该对象中的键值对:

类型

描述

display_name

字符串

代理的显示名称。

data

字符串

头像图像文件名或标识符。

tools

字符串

代理的颜色主题(例如“蓝色”、“绿色”、“红色”)

FROM SPECIFICATION $$ specification_object $$

指定包含代理设置的 VARCHAR 值,该值以 YAML 对象形式存在。

YAML 对象应具有以下结构:

models:
  orchestration: <model_name>

orchestration:
  budget:
      seconds: <number_of_seconds>
      tokens: <number_of_tokens>

instructions:
  response: '<response_instructions>'
  orchestration: '<orchestration_instructions>'
  system: '<system_instructions>'
  sample_questions:
      - question: '<sample_question>'
        answer: '<sample_answer>'
      ...

tools:
  - tool_spec:
      type: '<tool_type>'
      name: '<tool_name>'
      description: '<tool_description>'
      input_schema:
          type: 'object'
          properties:
            <property_name>:
              type: '<property_type>'
              description: '<property_description>'
          required: <required_property_names>
  ...

tool_resources:
  <tool_name>:
    <resource_key>: '<resource_value>'
    ...
  ...
Copy

下表描述了该对象中的键值对:

类型

描述

models

ModelConfig

代理的可选模型配置。包括编排模型(例如 claude-4-sonnet)。如果未提供,则自动选择模型。目前仅适用于 编排 步骤。

orchestration

OrchestrationConfig

可选编排配置,包括预算约束(例如,秒数、令牌)。

instructions

AgentInstructions

代理的可选行为指令,包括响应、编排、系统和示例问题。

tools

Tool 的数组

代理可使用的可选工具列表。每个工具包含一个 tool_spec,其中包括类型、名称、描述和输入架构。工具可能在 tool_resources 中有相应的配置。

tool_resources

ToolResource 的地图

对工具数组中每个引用工具的可选配置。密钥必须与相应工具的名称匹配。

访问控制要求

用于执行此操作的 角色 必须至少具有以下 权限

权限

对象

备注

CREATE AGENT

架构

这是创建 Cortex 代理所必需的。

USAGE

Cortex Search Service

需要在 Cortex Agents 请求中运行 Cortex Search Service。

USAGE

数据库、架构、表

这是访问 Cortex Agents 语义模型中引用的对象所必需的。

使用说明

  • OR REPLACE 和 IF NOT EXISTS 子句互斥。它们不能同时用于同一条语句中。

  • CREATE OR REPLACE <object> 语句是原子的。也就是说,当对象被替换时,旧对象将被删除,新对象将在单个事务中创建。

  • 关于元数据:

    注意

    客户应确保在使用 Snowflake 服务时,不会将个人数据(用户对象除外)、敏感数据、出口管制数据或其他受监管数据作为元数据输入。有关更多信息,请参阅 Snowflake 中的元数据字段

示例

CREATE OR REPLACE AGENT my_agent1
  COMMENT = 'agent level comment'
  PROFILE = '{"display_name": "My Business Assistant", "avatar":  "business-icon.png", "color": "blue"}'
  FROM SPECIFICATION
  $$
  models:
    orchestration: claude-4-sonnet

  orchestration:
    budget:
      seconds: 30
      tokens: 16000

  instructions:
    response: "You will respond in a friendly but concise manner"
    orchestration: "For any revenue question use Analyst; for policy use Search"
    system: "You are a friendly agent that helps with business questions"
    sample_questions:
      - question: "What was our revenue last quarter?"
        answer: "I'll analyze the revenue data using our financial database."

  tools:
    - tool_spec:
        type: "cortex_analyst_text_to_sql"
        name: "Analyst1"
        description: "Converts natural language to SQL queries for financial analysis"
    - tool_spec:
        type: "cortex_search"
        name: "Search1"
        description: "Searches company policy and documentation"

  tool_resources:
    Analyst1:
      semantic_view: "db.schema.semantic_view"
    Search1:
      name: "db.schema.service_name"
      max_results: "5"
      filter:
        "@eq":
          region: "North America"
      title_column: "<title_name>"
      id_column: "<column_name>"
  $$;
Copy
语言: 中文