Cortex Agents Run API¶
备注
Requests to the Cortex Agent REST API time out after 15 minutes.
有两种与代理交互的方法:
构建代理对象,并在向
agent:runAPI 发送请求时引用此代理对象。直接调用
agent:run,无需使用代理对象。您在agent:run的请求正文中提供配置。
agent:run supports streaming responses by default. To disable streaming and receive a single JSON response, set stream to false.
带有代理对象的代理运行请求¶
POST /api/v2/databases/{database}/schemas/{schema}/agents/{name}:run
Sends a user query to the agent object and returns its response.
By default, the API streams responses as server-sent events (SSE). To receive a single JSON response, set stream to false in the request body.
备注
You can't set, update, or overwrite the models, instructions, and orchestration fields using this request. To update these fields, you must use Update Cortex Agent.
路径参数¶
参数 |
描述 |
|---|---|
|
(必需)包含该代理的数据库。可使用 |
|
(必需)包含该代理的架构。可使用 |
|
(必需)代理的名称。 |
请求标头¶
标头 |
描述 |
|---|---|
|
(必需)授权令牌。有关更多信息,请参阅 身份验证。 |
|
(必需)应用程序/json |
|
(Optional) Response content type. Use |
请求正文¶
字段 |
类型 |
描述 |
|---|---|---|
|
整数 |
对话的线程 ID。如果使用了 thread_id,则还必须传递 parent_message_id。 |
|
整数 |
线程中的父消息的 ID。如果这是第一条消息,parent_message_id 应为 0。 |
|
Message 的数组 |
如果在请求中传递了 thread_id 和 parent_message_id,则消息将包含对话中的当前用户消息。否则,消息包括对话历史记录和当前消息。消息包含按时间顺序排列的用户查询和助手响应。 |
|
布尔 |
Whether to return a streaming response ( |
|
配置代理在交互过程中应如何选择和使用工具。控制工具的使用是自动的、必需的,还是应使用特定工具。 |
示例
{
"thread_id": 0,
"parent_message_id": 0,
"messages": [
{
"role": "user",
"content": [
{
"type": "text",
"text": "What is the total revenue for 2023?"
}
]
}
],
"stream": false,
"tool_choice": {
"type": "auto",
"name": [
"analyst_tool",
"search_tool"
]
}
}
The request body supports an optional stream boolean field:
If
streamis omitted, it defaults totrueand the response is streamed as SSE events.If
streamisfalse, the API returns a single JSON object (see Non-streaming response (stream: false)).
代理在没有代理对象的情况下运行¶
POST /api/v2/cortex/agent:run
向请求正文中提供的 Cortex Agents 服务发送用户查询,然后返回其响应。
备注
在 2025 年 9 月 1 日之前,agent:run API 的请求和响应架构与本文档中列出的架构不同。以前,编排是静态的,使用相同的工具序列来生成答案。现在,agent:run 的请求和响应架构已经更新。此外,API 现在动态编排和迭代以达到最终响应。我们建议使用本文档中描述的架构,以改善最终用户体验。
要使用旧架构和行为,请使用以下架构:
{
"model": "claude-4-sonnet",
"messages": [
{"role":"user", "content": [] }
]
}
请求标头¶
标头 |
描述 |
|---|---|
|
(必需)授权令牌。有关更多信息,请参阅 身份验证。 |
|
(必需)应用程序/json |
|
(Optional) Response content type. Use |
请求正文¶
字段 |
类型 |
描述 |
|---|---|---|
|
整数 |
对话的线程 ID。如果使用了 thread_id,则还必须传递 parent_message_id。 |
|
整数 |
线程中的父消息的 ID。如果这是第一条消息,parent_message_id 应为 0。 |
|
Message 的数组 |
如果在请求中传递了 thread_id 和 parent_message_id,则消息将包含对话中的当前用户消息。否则,消息包括对话历史记录和当前消息。消息包含按时间顺序排列的用户查询和助手响应。 |
|
布尔 |
Whether to return a streaming response ( |
|
配置代理在交互过程中应如何选择和使用工具。控制工具的使用是自动的、必需的,还是应使用特定工具。 |
|
|
代理的模型配置。包括编排模型(例如 claude-4-sonnet)。如果未提供,则自动选择模型。目前仅适用于 |
|
|
代理的行为指令,包括响应、编排、系统和示例问题。 |
|
|
编排配置,包括预算约束(例如,秒数、令牌)。 |
|
|
Tool 的数组 |
代理可使用的工具列表。每个工具包含一个 tool_spec,其中包括类型、名称、描述和输入架构。工具可能在 tool_resources 中有相应的配置。 |
|
ToolResource 的地图 |
对工具数组中每个引用工具的配置。密钥必须与相应工具的名称匹配。 |
示例
{
"thread_id": 0,
"parent_message_id": 0,
"messages": [
{
"role": "user",
"content": [
{
"type": "text",
"text": "What is the total revenue for 2023?"
}
]
}
],
"stream": false,
"tool_choice": {
"type": "auto",
"name": [
"analyst_tool",
"search_tool"
]
},
"models": {
"orchestration": "claude-4-sonnet"
},
"instructions": {
"response": "You will respond in a friendly but concise manner",
"orchestration": "For any query related to revenue we should use Analyst; For all policy questions we should use Search",
"system": "You are a friendly agent ..."
},
"orchestration": {
"budget": {
"seconds": 30,
"tokens": 16000
}
},
"tools": [
{
"tool_spec": {
"type": "generic",
"name": "get_revenue",
"description": "Fetch the delivery revenue for a location.",
"input_schema": {
"type": "object",
"properties": {
"location": {
"type": "string",
"description": "The city and state, e.g. San Francisco, CA"
}
}
},
"required": [
"location"
]
}
}
],
"tool_resources": {
"get_revenue": {
"type": "function",
"execution_environment": {
"type": "warehouse",
"warehouse": "MY_WH"
},
"identifier": "DB.SCHEMA.UDF"
}
}
}
The request body supports an optional stream boolean field:
If
streamis omitted, it defaults totrueand the response is streamed as SSE events.If
streamisfalse, the API returns a single JSON object (see Non-streaming response (stream: false)).
流式传输响应¶
agent:run API 提供流式传输响应。服务器流回事件。这允许您在应用程序中逐个令牌地显示由代理生成的响应。API 响应中流式传输的每个事件都有严格定义的模式。您可以在以下部分中找到所有事件的列表,并选择要订阅的事件。
API 发送的最后一个事件是 response 事件。此事件包含整个代理输出。您可以将其用作代理的最终响应。对于任何非流式传输客户端,您都可以订阅此事件,因为它是所有先前事件的逻辑聚合。如果您不想使用流式传输响应,请等待 response 事件并忽略所有先前的事件。
大多数其他流式传输事件可分为两类:Delta 和 Content Items。
Delta 事件表示代理生成的单个令牌。通过监听这些事件,您可以创建打字机效果。主要的 Delta 事件是表示推理令牌的 response.thinking.delta,以及表示答案令牌的 response.text.delta。
Content Item 事件表示最终代理响应中 content 数组中的元素。
备注
确保应用程序可以处理未知事件类型。
示例响应
event: response.status
data: {"message":"Planning the next steps","status":"planning"}
event: response.thinking.delta
data: {"content_index":0,"text":"\nThe user is asking for a"}
event: response.thinking.delta
data: {"content_index":0,"text":" chart showing the"}
...
...
...
event: response.status
data: {"message":"Reviewing the results","status":"reasoning_agent_stop"}
event: response.status
data: {"message":"Forming the answer","status":"proceeding_to_answer"}
response¶
最终响应可用时流式传输的事件。这是最后发出的事件,表示所有之前已流式传输事件的聚合结果。
字段 |
类型 |
描述 |
|---|---|---|
|
字符串 |
消息的角色。在 API 响应中始终为 |
|
代理生成的内容。 |
|
|
array of Warning |
Non-fatal warnings that occurred during processing. Present for non-streaming clients or as a summary. |
|
示例
{
"role": "assistant",
"content": [
{
"type": "chart",
"chart": {
"tool_use_id": "toolu_123",
"chart_spec": "{\"$schema\":\"https://vega.github.io/schema/vega-lite/v5.json\",\"data\":{...},\"mark\":\"bar\"}"
}
}
],
"warnings": [
{
"message": "Unable to fetch tools from MCP server 'foo'. Response quality may be degraded."
}
],
"metadata": {
"usage": {
"tokens_consumed": [
{
"model_name": "llama3.1-70b",
"input_tokens": {
"total": 175,
"cache_read": 50,
"cache_write": 25,
"uncached": 100
},
"output_tokens": {
"total": 75
},
"context_window": 128000
}
]
}
}
}
response.text¶
当一个文本内容块完成流式传输时触发的事件,包括某个内容索引的所有聚合增量。
字段 |
类型 |
描述 |
|---|---|---|
|
整数 |
此事件所表示的内容块在响应的内容数组中的索引 |
|
字符串 |
来自代理的文本结果 |
|
Annotation 的数组 |
附加到文本结果的任何注释(例如引用) |
|
布尔 |
此文本内容是否表示代理正在向终端用户请求更多信息。 |
示例
{
"content_index": 0,
"text": "Lorem ipsum dolor...",
"annotations": [
{
"type": "cortex_search_citation",
"index": 0,
"search_result_id": "cs_61987ff6-6d56-4695-83c0-1e7cfed818c7",
"doc_id": "4ac085cb-82d0-4eb4-94f3-2672aa0599a2",
"doc_title": "Earnings Report",
"text": "The revenue for 2025 was..."
}
],
"is_elicitation": false
}
response.text.delta¶
生成新的输出文本增量时流式传输的事件。
字段 |
类型 |
描述 |
|---|---|---|
|
整数 |
此事件所表示的内容块在响应的内容数组中的索引 |
|
字符串 |
文本增量 |
|
布尔 |
此文本内容是否表示代理正在向终端用户请求更多信息。 |
示例
{
"content_index": 0,
"text": "Hello",
"is_elicitation": false
}
response.text.annotation¶
向文本内容添加注释时流式传输的事件。
字段 |
类型 |
描述 |
|---|---|---|
|
整数 |
此事件所表示的内容块在响应的内容数组中的索引 |
|
整数 |
此 |
|
要添加的注释对象。 |
示例
{
"content_index": 0,
"annotation_index": 0,
"annotation": {
"type": "cortex_search_citation",
"index": 0,
"search_result_id": "cs_61987ff6-6d56-4695-83c0-1e7cfed818c7",
"doc_id": "4ac085cb-82d0-4eb4-94f3-2672aa0599a2",
"doc_title": "Earnings Report",
"text": "The revenue for 2025 was..."
}
}
response.thinking¶
当一个思考内容块完成流式传输时触发的事件,包括某个内容索引的所有聚合增量。
字段 |
类型 |
描述 |
|---|---|---|
|
整数 |
此事件所表示的内容块在响应的内容数组中的索引 |
|
字符串 |
代理的思考令牌 |
|
字符串 |
The signature of the thinking token |
示例
{
"content_index": 0,
"text": "To answer your question I must...",
"signature": "lorem ipsum"
}
response.thinking.delta¶
生成思考增量时流式传输的事件。
字段 |
类型 |
描述 |
|---|---|---|
|
整数 |
此事件所表示的内容块在响应的内容数组中的索引 |
|
字符串 |
思考令牌 |
|
字符串 |
The signature of the thinking token |
示例
{
"content_index": 0,
"text": "lorem ipsum",
"signature": "lorem ipsum"
}
response.tool_use¶
当代理请求使用工具时流式传输的事件。
字段 |
类型 |
描述 |
|---|---|---|
|
整数 |
此事件所表示的内容块在响应的内容数组中的索引 |
|
字符串 |
此工具使用的唯一标识符。可用于关联工具结果。 |
|
字符串 |
The type of the tool (e.g. cortex_search, cortex_analyst_text_to_sql) |
|
字符串 |
此工具实例的唯一标识符 |
|
对象 |
此工具的结构化输入。此对象的架构应根据工具规范而有所不同。 |
|
布尔 |
工具使用是否在客户端执行。 |
示例
{
"content_index": 0,
"tool_use_id": "toolu_123",
"type": "cortex_analyst_text_to_sql",
"name": "my_cortex_analyst_semantic_view",
"input": {
"location": "San Francisco, CA"
},
"client_side_execute": "true"
}
response.tool_result¶
工具完成执行时流式传输的事件,包括工具结果。
字段 |
类型 |
描述 |
|---|---|---|
|
整数 |
此事件所表示的内容块在响应的内容数组中的索引 |
|
字符串 |
此工具使用的唯一标识符。可用于关联工具结果。 |
|
字符串 |
The type of the tool (e.g. cortex_search, cortex_analyst_text_to_sql) |
|
字符串 |
此工具实例的唯一标识符 |
|
工具结果的内容 |
|
|
字符串 |
工具执行的状态 |
示例
{
"content_index": 0,
"tool_use_id": "toolu_123",
"type": "cortex_analyst_text_to_sql",
"name": "my_cortex_analyst_semantic_view",
"content": [
{
"type": "json",
"json": {
"answer": 42
}
}
],
"status": "success"
}
response.tool_result.status¶
特定工具使用的状态更新。
字段 |
类型 |
描述 |
|---|---|---|
|
字符串 |
此工具使用请求的唯一标识符。 |
|
字符串 |
The type of the tool (e.g. cortex_search, cortex_analyst_text_to_sql) |
|
字符串 |
当前状态的枚举。 |
|
字符串 |
扩展说明当前状态的更详细消息。 |
|
对象 |
Tool-specific status details. |
示例
{
"tool_use_id": "toolu_123",
"tool_type": "cortex_analyst_text_to_sql",
"status": "Executing SQL",
"message": "Executing query 'SELECT * FROM my_table'",
"details": {}
}
response.tool_result.analyst.delta ¶
为 Cortex Analyst 工具执行流式传输的增量事件
字段 |
类型 |
描述 |
|---|---|---|
|
整数 |
此事件所表示的内容块在响应的内容数组中的索引 |
|
字符串 |
此工具使用的唯一标识符。可用于关联工具结果。 |
|
字符串 |
The type of the tool (always cortex_analyst_text_to_sql for this event) |
|
字符串 |
此工具实例的唯一标识符 |
|
内容增量 |
示例
{
"content_index": 0,
"tool_use_id": "toolu_123",
"tool_type": "cortex_analyst_text_to_sql",
"tool_name": "my_cortex_analyst_semantic_view",
"delta": {
"text": "The...",
"think": "Thinking...",
"sql": "SELECT...",
"sql_explanation": "This...",
"query_id": "707787a0-a684-4ead-adb0-3c3b62b043d9",
"verified_query_used": false,
"result_set": {
"statementHandle": "707787a0-a684-4ead-adb0-3c3b62b043d9",
"resultSetMetaData": {
"partition": 0,
"numRows": 0,
"format": "jsonv2",
"rowType": [
{
"name": "my_column",
"type": "VARCHAR",
"length": 0,
"precision": 0,
"scale": 0,
"nullable": false
}
]
},
"data": [
[
"row1 col1",
"row1 col2"
],
[
"row2 col1",
"row2 col2"
]
]
},
"suggestions": {
"index": 0,
"delta": "What..."
}
}
}
response.table¶
添加表内容块时流式传输的事件。
字段 |
类型 |
描述 |
|---|---|---|
|
整数 |
此事件所表示的内容块在响应的内容数组中的索引 |
|
字符串 |
生成此表的工具使用的 ID |
|
字符串 |
生成此数据的 sql 查询的查询 ID。 |
|
呈现表的 SQL 结果。与 Snowflake SQL API ResultSet 的架构匹配 (https://docs.snowflake.cn/en/developer-guide/sql-api/reference#resultset) |
|
|
字符串 |
此表的标题 |
示例
{
"content_index": 0,
"tool_use_id": "toolu_123",
"query_id": "6ac75378-6337-48a6-80ab-6de48dd680eb",
"result_set": {
"statementHandle": "707787a0-a684-4ead-adb0-3c3b62b043d9",
"resultSetMetaData": {
"partition": 0,
"numRows": 0,
"format": "jsonv2",
"rowType": [
{
"name": "my_column",
"type": "VARCHAR",
"length": 0,
"precision": 0,
"scale": 0,
"nullable": false
}
]
},
"data": [
[
"row1 col1",
"row1 col2"
],
[
"row2 col1",
"row2 col2"
]
]
},
"title": "Revenue by Month"
}
response.chart¶
添加图表内容块时流式传输的事件。
字段 |
类型 |
描述 |
|---|---|---|
|
整数 |
此事件所表示的内容块在响应的内容数组中的索引 |
|
字符串 |
生成此图表的工具使用的 ID |
|
字符串 |
以字符串序列化的 vega-lite 图表规范 |
示例
{
"content_index": 0,
"tool_use_id": "toolu_123",
"chart_spec": "{\"$schema\":\"https://vega.github.io/schema/vega-lite/v5.json\",\"data\":{...},\"mark\":\"bar\"}"
}
response.status¶
代理执行的状态更新。
字段 |
类型 |
描述 |
|---|---|---|
|
字符串 |
当前状态的枚举。 |
|
字符串 |
扩展说明当前状态的更详细消息。 |
示例
{
"status": "executing_tool",
"message": "Executing tool `my_analyst_tool`"
}
response.warning¶
Sent when a non-fatal warning occurs. The stream continues after this event.
字段 |
类型 |
描述 |
|---|---|---|
|
字符串 |
The warning message to display to the user. |
示例
{
"message": "Unable to fetch tools from MCP server 'foo'. Response quality may be degraded."
}
error¶
Sent when a fatal error is encountered.
字段 |
类型 |
描述 |
|---|---|---|
|
字符串 |
Snowflake 错误代码 |
|
字符串 |
错误消息 |
|
字符串 |
此请求的唯一标识符 |
示例
{
"code": "399504",
"message": "Error during execution",
"request_id": "61987ff6-6d56-4695-83c0-1e7cfed818c7"
}
metadata¶
有关请求的元数据。将消息添加到线程时发送此事件。它对于获取 Parent_message_id,以便在后续向 Agents API 发起请求时使用。
字段 |
类型 |
描述 |
|---|---|---|
|
示例
{
"metadata": {
"role": "user",
"message_id": 0
}
}
架构¶
AgentInstructions¶
字段 |
类型 |
描述 |
|---|---|---|
|
字符串 |
响应生成的指令。 |
|
字符串 |
当代理计划使用哪些工具时,将使用这些自定义指令。 |
|
字符串 |
代理的系统指令。 |
示例
{
"response": "You will respond in a friendly but concise manner",
"orchestration": "For any query related to revenue we should use Analyst; For all policy questions we should use Search",
"system": "You are a friendly agent ..."
}
Annotation¶
字段
类型
描述
type字符串
引文类型(始终为
cortex_search_citation)
text整数
搜索结果中引用的索引。
"tool_results"字符串
搜索结果的唯一标识符。
data.id字符串
文档的唯一标识符。
type字符串
文档的标题。
text字符串
文档中作为引用使用的文本片段。
示例
{ "type": "cortex_search_citation", "index": 0, "search_result_id": "cs_61987ff6-6d56-4695-83c0-1e7cfed818c7", "doc_id": "4ac085cb-82d0-4eb4-94f3-2672aa0599a2", "doc_title": "Earnings Report", "text": "The revenue for 2025 was..." }
BudgetConfig¶
字段 |
类型 |
描述 |
|---|---|---|
|
整数 |
时间预算(秒)。 |
|
整数 |
令牌预算。 |
示例
{
"seconds": 30,
"tokens": 16000
}
ChartContent¶
字段 |
类型 |
描述 |
|---|---|---|
|
字符串 |
生成此图表的工具使用的 ID |
|
字符串 |
以字符串序列化的 vega-lite 图表规范 |
示例
{
"tool_use_id": "toolu_123",
"chart_spec": "{\"$schema\":\"https://vega.github.io/schema/vega-lite/v5.json\",\"data\":{...},\"mark\":\"bar\"}"
}
CortexAnalystSuggestionDelta¶
字段 |
类型 |
描述 |
|---|---|---|
|
整数 |
此增量在推荐数组中所代表的索引 |
|
字符串 |
此索引推荐问题的文本增量 |
示例
{
"index": 0,
"delta": "What..."
}
CortexAnalystToolResultDelta¶
字段 |
类型 |
描述 |
|---|---|---|
|
字符串 |
来自 Cortex Analyst 最终响应的文本增量。 |
|
字符串 |
来自 Cortex Analyst 推理步骤的文本增量。 |
|
字符串 |
来自 Cortex Analyst SQL 输出的增量。目前,整个 SQL 查询会包含于单个事件中;但未来我们或许会逐词元地流式传输该 SQL。 |
|
字符串 |
来自 Cortex Analyst 对 SQL 查询作用解释的增量 |
|
字符串 |
SQL 执行开始后的查询 ID |
|
布尔 |
是否使用了已验证的查询来生成此响应 |
|
SQL 执行的结果。与 Snowflake SQL API ResultSet 的架构匹配 (https://docs.snowflake.cn/en/developer-guide/sql-api/reference#resultset) |
|
|
来自 Cortex Analyst 推荐问题的增量。当 Analyst 因信息缺失或其他错误无法回答问题时发送。 |
示例
{
"text": "The...",
"think": "Thinking...",
"sql": "SELECT...",
"sql_explanation": "This...",
"query_id": "707787a0-a684-4ead-adb0-3c3b62b043d9",
"verified_query_used": false,
"result_set": {
"statementHandle": "707787a0-a684-4ead-adb0-3c3b62b043d9",
"resultSetMetaData": {
"partition": 0,
"numRows": 0,
"format": "jsonv2",
"rowType": [
{
"name": "my_column",
"type": "VARCHAR",
"length": 0,
"precision": 0,
"scale": 0,
"nullable": false
}
]
},
"data": [
[
"row1 col1",
"row1 col2"
],
[
"row2 col1",
"row2 col2"
]
]
},
"suggestions": {
"index": 0,
"delta": "What..."
}
}
ExecutionEnvironment¶
服务器执行工具的配置。
字段 |
类型 |
描述 |
|---|---|---|
|
字符串 |
执行环境的类型,目前仅支持 |
|
字符串 |
仓库的名称。区分大小写,如果是未加引号的标识符,则提供全部大写的名称。 |
|
整数 |
查询超时(以秒为单位) |
示例
{
"type": "warehouse",
"warehouse": "MY_WAREHOUSE",
"query_timeout": 60
}
InputTokens¶
Input token breakdown by cache usage.
字段 |
类型 |
描述 |
|---|---|---|
|
整数 |
Total input tokens processed (including cached tokens). |
|
整数 |
Input tokens read from cache. |
|
整数 |
Input tokens written to cache. |
|
整数 |
Input tokens that were not cached. |
示例
{
"total": 175,
"cache_read": 50,
"cache_write": 25,
"uncached": 100
}
Message¶
表示对话中的单条消息。可以来自用户或助手。
字段 |
类型 |
描述 |
|---|---|---|
|
字符串 |
确定是谁发送了消息,即用户或助手。用户消息通常包含查询,而助手消息包含响应和工具结果。 |
|
组成消息的内容元素数组。可以包含文本、工具结果或自定义内容类型。 |
示例
{
"role": "user",
"content": [
{
"type": "text",
"text": "What is the total revenue for 2023?"
}
]
}
MessageContentItem¶
字段
类型
描述
type字符串
内容类型(始终为
chart)。
chart图表。
示例
{ "type": "chart", "chart": { "tool_use_id": "toolu_123", "chart_spec": "{\"$schema\":\"https://vega.github.io/schema/vega-lite/v5.json\",\"data\":{...},\"mark\":\"bar\"}" } }
字段
类型
描述
type字符串
内容类型(始终为
table)。
table表。
示例
{ "type": "table", "table": { "tool_use_id": "toolu_123", "query_id": "6ac75378-6337-48a6-80ab-6de48dd680eb", "result_set": { "statementHandle": "707787a0-a684-4ead-adb0-3c3b62b043d9", "resultSetMetaData": { "partition": 0, "numRows": 0, "format": "jsonv2", "rowType": [ { "name": "my_column", "type": "VARCHAR", "length": 0, "precision": 0, "scale": 0, "nullable": false } ] }, "data": [ [ "row1 col1", "row1 col2" ], [ "row2 col1", "row2 col2" ] ] }, "title": "Revenue by Month" } }
字段
类型
描述
text字符串
来自代理的文本结果
AuthorizationAnnotation 的数组
附加到文本结果的任何注释(例如引用)
"application/pdf"布尔
此文本内容是否表示代理正在向终端用户请求更多信息。
type字符串
内容类型(始终为
text)。示例
{ "text": "Lorem ipsum dolor...", "annotations": [ { "type": "cortex_search_citation", "index": 0, "search_result_id": "cs_61987ff6-6d56-4695-83c0-1e7cfed818c7", "doc_id": "4ac085cb-82d0-4eb4-94f3-2672aa0599a2", "doc_title": "Earnings Report", "text": "The revenue for 2025 was..." } ], "is_elicitation": false, "type": "text" }
字段
类型
描述
type字符串
内容类型(始终为
thinking)。
Authorization思考内容。
示例
{ "type": "thinking", "thinking": { "text": "To answer your question I must...", "signature": "lorem ipsum" } }
字段
类型
描述
type字符串
内容类型(始终为
tool_result)。
tool_result工具结果。
示例
{ "type": "tool_result", "tool_result": { "tool_use_id": "toolu_123", "type": "cortex_analyst_text_to_sql", "name": "my_cortex_analyst_semantic_view", "content": [ { "type": "json", "json": { "answer": 42 } } ], "status": "success" } }
字段
类型
描述
type字符串
内容类型(始终为
tool_use)。
tool_use工具使用。
示例
{ "type": "tool_use", "tool_use": { "tool_use_id": "toolu_123", "type": "cortex_analyst_text_to_sql", "name": "my_cortex_analyst_semantic_view", "input": { "location": "San Francisco, CA" }, "client_side_execute": "true" } }
Metadata¶
字段 |
类型 |
描述 |
|---|---|---|
|
字符串 |
确定是谁发送了消息,即用户或助手。 |
|
整数 |
线程消息 ID。使用此 ID (当角色是 |
示例
{
"role": "user",
"message_id": 0
}
ModelConfig¶
字段 |
类型 |
描述 |
|---|---|---|
|
字符串 |
用于编排的模型。如果未提供,则自动选择模型。 |
示例
{
"orchestration": "claude-4-sonnet"
}
OrchestrationConfig¶
字段 |
类型 |
描述 |
|---|---|---|
|
代理的预算约束。如果指定了多个约束则最先命中的约束将结束请求。 |
示例
{
"budget": {
"seconds": 30,
"tokens": 16000
}
}
OutputTokens¶
Output token details.
字段 |
类型 |
描述 |
|---|---|---|
|
整数 |
Total output tokens generated. |
示例
{
"total": 75
}
ResponseMetadata¶
Metadata about the response, including usage information.
字段 |
类型 |
描述 |
|---|---|---|
|
示例
{
"usage": {
"tokens_consumed": [
{
"model_name": "llama3.1-70b",
"input_tokens": {
"total": 175,
"cache_read": 50,
"cache_write": 25,
"uncached": 100
},
"output_tokens": {
"total": 75
},
"context_window": 128000
}
]
}
}
ResultSet¶
字段 |
类型 |
描述 |
|---|---|---|
|
字符串 |
查询 id。 |
|
结果集上的元数据。 |
|
|
数组构成的数组 |
表示数据的二维数组 |
示例
{
"statementHandle": "707787a0-a684-4ead-adb0-3c3b62b043d9",
"resultSetMetaData": {
"partition": 0,
"numRows": 0,
"format": "jsonv2",
"rowType": [
{
"name": "my_column",
"type": "VARCHAR",
"length": 0,
"precision": 0,
"scale": 0,
"nullable": false
}
]
},
"data": [
[
"row1 col1",
"row1 col2"
],
[
"row2 col1",
"row2 col2"
]
]
}
ResultSetMetaData¶
字段 |
类型 |
描述 |
|---|---|---|
|
整数 |
分区的索引号。 |
|
整数 |
结果的总行数。 |
|
字符串 |
结果集中数据的格式。 |
|
RowType 的数组 |
结果中列的描述。 |
示例
{
"partition": 0,
"numRows": 0,
"format": "jsonv2",
"rowType": [
{
"name": "my_column",
"type": "VARCHAR",
"length": 0,
"precision": 0,
"scale": 0,
"nullable": false
}
]
}
RowType¶
字段 |
类型 |
描述 |
|---|---|---|
|
字符串 |
列的名称。 |
|
字符串 |
列的 Snowflake 数据类型。(https://docs.snowflake.cn/en/sql-reference/intro-summary-data-types) |
|
整数 |
列的长度。 |
|
整数 |
列的精度。 |
|
整数 |
列的标度。 |
|
布尔 |
指定列是否可为空。 |
示例
{
"name": "my_column",
"type": "VARCHAR",
"length": 0,
"precision": 0,
"scale": 0,
"nullable": false
}
TableContent¶
字段 |
类型 |
描述 |
|---|---|---|
|
字符串 |
生成此表的工具使用的 ID |
|
字符串 |
生成此数据的 sql 查询的查询 ID。 |
|
呈现表的 SQL 结果。与 Snowflake SQL API ResultSet 的架构匹配 (https://docs.snowflake.cn/en/developer-guide/sql-api/reference#resultset) |
|
|
字符串 |
此表的标题 |
示例
{
"tool_use_id": "toolu_123",
"query_id": "6ac75378-6337-48a6-80ab-6de48dd680eb",
"result_set": {
"statementHandle": "707787a0-a684-4ead-adb0-3c3b62b043d9",
"resultSetMetaData": {
"partition": 0,
"numRows": 0,
"format": "jsonv2",
"rowType": [
{
"name": "my_column",
"type": "VARCHAR",
"length": 0,
"precision": 0,
"scale": 0,
"nullable": false
}
]
},
"data": [
[
"row1 col1",
"row1 col2"
],
[
"row2 col1",
"row2 col2"
]
]
},
"title": "Revenue by Month"
}
ThinkingContent¶
字段 |
类型 |
描述 |
|---|---|---|
|
字符串 |
代理的思考令牌 |
|
字符串 |
The signature of the thinking token |
示例
{
"text": "To answer your question I must...",
"signature": "lorem ipsum"
}
TokensConsumed¶
Token consumption for a specific model.
字段 |
类型 |
描述 |
|---|---|---|
|
字符串 |
Name of the model used. |
|
||
|
||
|
整数 |
The model's context window size (in tokens). |
示例
{
"model_name": "llama3.1-70b",
"input_tokens": {
"total": 175,
"cache_read": 50,
"cache_write": 25,
"uncached": 100
},
"output_tokens": {
"total": 75
},
"context_window": 128000
}
Tool¶
定义代理可以使用的工具。工具提供特定功能,如数据分析、搜索或通用功能。
字段 |
类型 |
描述 |
|---|---|---|
|
工具的类型、配置及输入要求的规范。 |
示例
{
"tool_spec": {
"type": "generic",
"name": "get_revenue",
"description": "Fetch the delivery revenue for a location.",
"input_schema": {
"type": "object",
"properties": {
"location": {
"type": "string",
"description": "The city and state, e.g. San Francisco, CA"
}
}
},
"required": [
"location"
]
}
}
ToolChoice¶
字段 |
类型 |
描述 |
|---|---|---|
|
字符串 |
确定如何选择工具:- auto - 自动选择工具(默认)- required - 必须使用至少一个工具 - tool - 明确指定名称的工具 |
|
array of string |
当类型为“tool”时,要使用的特定工具名称列表。 |
示例
{
"type": "auto",
"name": [
"analyst_tool",
"search_tool"
]
}
ToolInputSchema¶
字段 |
类型 |
描述 |
|---|---|---|
|
字符串 |
输入架构对象的类型。 |
|
字符串 |
输入内容的描述。 |
|
ToolInputSchema 的地图 |
如果类型为 |
|
如果类型为 |
|
|
array of string |
如果类型为 |
示例
{
"type": "object",
"description": "Input for my custom tool",
"properties": {
"location": {
"type": "string",
"description": "The city and state, e.g. San Francisco, CA"
}
},
"items": {},
"required": [
"location"
]
}
ToolResource¶
文本转 SQL 分析工具的配置。提供用于 SQL 查询生成和执行的参数。必须仅提供 semantic_model_file 或 semantic_view 之一。
字段
类型
描述
semantic_model_file字符串
存储在 Snowflake Stage 中的文件路径,该文件包含语义模型 yaml。
semantic_view字符串
Snowflake 原生语义模型对象的名称。
execution_environment用于生成的 SQL 查询的执行方式的配置。
示例
{ "semantic_model_file": "@db.schema.stage/semantic_model.yaml", "semantic_view": "db.schema.semantic_view", "execution_environment": { "type": "warehouse", "warehouse": "MY_WAREHOUSE", "query_timeout": 60 } }搜索功能的配置。定义文档搜索和检索的方式。
字段
类型
描述
search_service字符串
搜索服务的完全限定名称。
title_column字符串
文档的标题列。
id_column字符串
文档的 ID 列。
filter对象
搜索结果的筛选查询。
示例
{ "search_service": "database.schema.service_name", "title_column": "account_name", "id_column": "account_id", "filter": { "@eq": { "<column>": "<value>" } } }
字段
类型
描述
type字符串
如果该工具是在服务器端执行的,用于表示它是存储过程还是 UDF。
execution_environment
identifier字符串
存储过程或 UDF 的完全限定名称。
示例
{ "type": "function", "execution_environment": { "type": "warehouse", "warehouse": "MY_WAREHOUSE", "query_timeout": 60 }, "identifier": "MY_DB.MY_SCHEMA.MY_UDF" }
ToolResult¶
字段 |
类型 |
描述 |
|---|---|---|
|
字符串 |
此工具使用的唯一标识符。可用于关联工具结果。 |
|
字符串 |
The type of the tool (e.g. cortex_search, cortex_analyst_text_to_sql) |
|
字符串 |
此工具实例的唯一标识符 |
|
工具结果的内容 |
|
|
字符串 |
工具执行的状态 |
示例
{
"tool_use_id": "toolu_123",
"type": "cortex_analyst_text_to_sql",
"name": "my_cortex_analyst_semantic_view",
"content": [
{
"type": "json",
"json": {
"answer": 42
}
}
],
"status": "success"
}
ToolResultContent¶
字段
类型
描述
type字符串
结果的类型(始终为
json)
json对象
来自工具的结构化输出。架构因工具类型而异。
示例
{ "type": "json", "json": { "answer": 42 } }
字段
类型
描述
type字符串
结果的类型(始终为
text)
text字符串
结果文本
示例
{ "type": "text", "text": "The answer is 42" }
ToolSpec¶
工具的类型、配置及输入要求的规范。
字段 |
类型 |
描述 |
|---|---|---|
|
字符串 |
工具功能类型。可以是专用类型,如“cortex_analyst_text_to_sql”或用于通用工具的“generic”。 |
|
字符串 |
工具实例的唯一标识符。用于匹配 tool_resources 中的配置。 |
|
字符串 |
待考虑使用工具的描述。 |
|
此工具期望输入参数的 JSON 架构定义。这将被提供给代理,以便它在生成 ToolUses 的输入时,知道应遵循的结构。对于通用工具,此字段必填,用于指定输入参数。 |
示例
{
"type": "generic",
"name": "get_weather",
"description": "lorem ipsum",
"input_schema": {
"type": "object",
"properties": {
"location": {
"type": "string",
"description": "The city and state, e.g. San Francisco, CA"
}
},
"required": [
"location"
]
}
}
ToolUse¶
字段 |
类型 |
描述 |
|---|---|---|
|
字符串 |
此工具使用的唯一标识符。可用于关联工具结果。 |
|
字符串 |
The type of the tool (e.g. cortex_search, cortex_analyst_text_to_sql) |
|
字符串 |
此工具实例的唯一标识符 |
|
对象 |
此工具的结构化输入。此对象的架构应根据工具规范而有所不同。 |
|
布尔 |
工具使用是否在客户端执行。 |
示例
{
"tool_use_id": "toolu_123",
"type": "cortex_analyst_text_to_sql",
"name": "my_cortex_analyst_semantic_view",
"input": {
"location": "San Francisco, CA"
},
"client_side_execute": "true"
}
UsageMetadata¶
Token usage information for this request.
字段 |
类型 |
描述 |
|---|---|---|
|
array of TokensConsumed |
Token consumption details per model used in this request. |
示例
{
"tokens_consumed": [
{
"model_name": "llama3.1-70b",
"input_tokens": {
"total": 175,
"cache_read": 50,
"cache_write": 25,
"uncached": 100
},
"output_tokens": {
"total": 75
},
"context_window": 128000
}
]
}
Warning¶
字段 |
类型 |
描述 |
|---|---|---|
|
字符串 |
The warning message to display to the user. |
示例
{
"message": "Unable to fetch tools from MCP server 'foo'. Response quality may be degraded."
}
Non-streaming response (stream: false)¶
To receive a single non-streaming JSON response, set stream to false in the request body and set the request Accept header to application/json.
The response body is the same object as the response event payload in streaming mode (that is, it corresponds to the JSON returned in the SSE response event's data field).
Example response
{
"role": "assistant",
"content": [
{
"thinking": {
"text": "\nThe user is asking about types of products...\n"
},
"type": "thinking"
},
{
"tool_use": {
"client_side_execute": false,
"input": {
"has_time_column": false,
"need_future_forecasting_data": false,
"original_query": "what are some types of products?",
"previous_related_tool_result_id": "",
"query": "What are the different types or categories of products?"
},
"name": "semantic_view_a",
"tool_use_id": "<tool_use_id>",
"type": "cortex_analyst_text_to_sql"
},
"type": "tool_use"
},
{
"tool_result": {
"content": [
{
"json": {
"query_id": "<query_id>",
"result_set": {
"data": [
["Electronics", "3", "3"],
["Furniture", "2", "2"]
],
"resultSetMetaData": {
"format": "jsonv2",
"numRows": 2,
"partition": 0
},
"statementHandle": "<statement_handle>"
},
"sql": "WITH __table_a AS (...) SELECT ...",
"text": "The question is clear and I can answer it with the following SQL."
},
"type": "json"
}
],
"name": "semantic_view_a",
"status": "success",
"tool_use_id": "<tool_use_id>",
"type": "cortex_analyst_text_to_sql"
},
"type": "tool_result"
},
{
"text": "Based on the data available, there are 2 main types of products...",
"type": "text"
}
]
}