监控 Cortex Agent 请求

Cortex Agent 会记录所有对话的详细跟踪信息,以便进行审计和调试。启用监控后,您可以访问通过 Snowflake Intelligence 或 Agent API 部署的代理的对话历史。除了对话历史外,您还可以查看代理的详细跟踪信息,包括其规划过程、工具选择、执行结果以及最终响应生成。

Cortex Agent 日志中收集的信息

Cortex Agent 日志包含以下信息:

  • 与线程关联的对话历史记录

  • 代理的执行跟踪,跨度包括:

    • LLM 规划

    • 工具执行(Cortex Search、Cortex Analyst、网页搜索)

    • LLM 响应生成

    • SQL 执行

    • 图表生成

  • 与每个跨度相关的输入与输出

  • 用户对每条代理响应的反馈

访问 Cortex Agent 日志

要在 Snowsight 中查看 Cortex Agent 对话日志,请执行以下步骤:

  1. 登录 Snowsight

  2. 在导航菜单中,选择 AI & ML » Agents

  3. 选择要查看其日志的代理。

  4. 进入代理视图中的 Monitoring 面板。

与代理关联的监控日志存储在 事件表 SNOWFLAKE.LOCAL.AI_OBSERVABILITY_EVENTS 中。此表中的条目无法修改。

具有 AI_OBSERVABILITY_ADMIN 应用角色的管理员可以删除 SNOWFLAKE.LOCAL.AI_OBSERVABILITY_EVENTS 表中的条目。

View feedback provided by users

To view user feedback about agents programmatically, run the following SQL command:

SELECT * FROM TABLE(SNOWFLAKE.LOCAL.GET_AI_OBSERVABILITY_EVENTS('<database_name>', '<schema_name>', '<agent_name>', 'CORTEX AGENT')) WHERE RECORD:name='CORTEX_AGENT_FEEDBACK';
Copy

The resulting table contains columns that include information about the agent, the user who provided feedback, feedback provided by the user, and whether the feedback was positive or negative.

访问控制与权限

要查看 Cortex Agent 日志,用户必须具备以下权限:

  • 对 AGENT 对象的 OWNERSHIP 或 MONITOR 权限

  • CORTEX_USER 数据库角色

  • AI_OBSERVABILITY_EVENTS_LOOKUP 应用程序角色

以下示例展示了如何使用 ACCOUNTADMIN 角色创建一个新角色 agent_monitoring_user_role,并授予其查看 Cortex Agent 日志所需的权限。然后将这个新角色分配给 some_user

USE ROLE ACCOUNTADMIN;
CREATE ROLE agent_monitoring_user_role;
GRANT MONITOR ON AGENT my_agent TO ROLE agent_monitoring_user_role;
GRANT DATABASE ROLE SNOWFLAKE.CORTEX_USER TO ROLE agent_monitoring_user_role;
GRANT APPLICATION ROLE SNOWFLAKE.AI_OBSERVABILITY_EVENTS_LOOKUP TO ROLE agent_monitoring_user_role;
GRANT APPLICATION ROLE SNOWFLAKE.AI_OBSERVABILITY_ADMIN_RL TO ROLE agent_monitoring_user_role;
GRANT ROLE agent_monitoring_user_role TO USER some_user;
Copy

Grant monitoring access to future agents

To grant a role monitoring access on future agents created in a schema, use the following SQL command:

GRANT MONITOR ON FUTURE AGENTS IN SCHEMA <database_name>.<schema_name> TO ROLE <role_name>;
Copy
语言: 中文