AI Skills AI技能 16h ago Updated 15h ago 更新于 15小时前 46

Building CoWork Agents That Understand Business Context 构建理解业务上下文的CoWork智能体

Semantic views serve as critical business logic contracts, requiring unnaturally explicit metric definitions to prevent LLM ambiguity and ensure consistent agent behavior. The distinction between Cortex Analyst (structured SQL) and Cortex Search (unstructured retrieval) must be enforced via explicit orchestration instructions to prevent misrouting of queries. Verified queries (curated question-SQL pairs) offer the highest return on investment, boosting accuracy from approximately 60% to 92% by b 语义视图(Semantic Views)是组织与AI代理之间的业务逻辑契约,而非简单的数据字典,其定义质量直接决定代理的准确性而非提示词复杂度。 Cortex Analyst处理结构化查询,Cortex Search处理非结构化检索,通过明确的指令配置路由规则可解决工具调用错误问题。 验证查询(Verified Queries)即精心策划的问题-SQL对,是提升复杂查询准确率最高效的投资,少量添加即可显著提升效果。 语义视图采用YAML定义,支持指标公式、同义词及关系映射,且需严格遵循特定的权限授予方式(GRANT SELECT)。 随着技术迭代,Cortex Analyst已改为直接生成SQ

65
Hot 热度
70
Quality 质量
60
Impact 影响力

Analysis 深度分析

TL;DR

  • Semantic views serve as critical business logic contracts, requiring unnaturally explicit metric definitions to prevent LLM ambiguity and ensure consistent agent behavior.
  • The distinction between Cortex Analyst (structured SQL) and Cortex Search (unstructured retrieval) must be enforced via explicit orchestration instructions to prevent misrouting of queries.
  • Verified queries (curated question-SQL pairs) offer the highest return on investment, boosting accuracy from approximately 60% to 92% by bypassing generative SQL errors for known complex questions.
  • Implementation details matter significantly, such as the silent ignoring of data_type on metrics and the shift from delegating to system_execute_sql for direct SQL generation.

Why It Matters

This article highlights a critical shift in AI agent development: success depends less on prompt engineering and more on the rigorous definition of business semantics and data governance. For practitioners, it underscores that building reliable enterprise agents requires treating data definitions as code, with strict contracts to handle organizational nuance. It provides actionable guidance on avoiding common pitfalls in tool routing and metric definition that often lead to "dangerous" rather than just inaccurate outputs.

Technical Details

  • Semantic View Structure: Defined via YAML, containing tables, columns, metrics (with name, description, expr, synonyms), dimensions, and relationships. Metrics infer data types from expressions; data_type is only valid for dimensions/facts.
  • Metric Definition Strategy: Simple aggregations like SUM(amount) are insufficient due to business ambiguity. Effective definitions include explicit exclusion criteria (e.g., "excludes trial credits") and map multiple synonyms to a single canonical metric.
  • Orchestration Logic: Agents use two tools: cortex_analyst_text_to_sql for structured data and cortex_search for unstructured data. Routing is controlled via an instructions block specifying operational constraints for policy vs. numerical queries.
  • Verified Queries: Stored within the semantic view, these are curated question-SQL pairs. When user intent matches a verified query, the agent executes the pre-written SQL instead of generating new code, significantly improving accuracy for complex logic.
  • Access Control: Semantic view access utilizes GRANT SELECT rather than GRANT USAGE on underlying tables, simplifying permission management for end-users.

Industry Insight

  • Invest in Data Semantics First: Organizations should invert their current resource allocation, spending the majority of effort on defining precise, unambiguous business logic in semantic views rather than on agent orchestration or prompt tuning.
  • Standardize Metric Definitions: Establish a centralized, YAML-based standard for metric definitions that includes explicit business rules and synonyms. This reduces the cognitive load on LLMs and ensures consistency across different queries and users.
  • Prioritize Verified Queries for Complex Logic: Implement verified queries early in the deployment lifecycle for high-stakes or complex calculations. This serves as a safety net against generative errors and provides immediate, measurable improvements in agent reliability.

TL;DR

  • 语义视图(Semantic Views)是组织与AI代理之间的业务逻辑契约,而非简单的数据字典,其定义质量直接决定代理的准确性而非提示词复杂度。
  • Cortex Analyst处理结构化查询,Cortex Search处理非结构化检索,通过明确的指令配置路由规则可解决工具调用错误问题。
  • 验证查询(Verified Queries)即精心策划的问题-SQL对,是提升复杂查询准确率最高效的投资,少量添加即可显著提升效果。
  • 语义视图采用YAML定义,支持指标公式、同义词及关系映射,且需严格遵循特定的权限授予方式(GRANT SELECT)。
  • 随着技术迭代,Cortex Analyst已改为直接生成SQL而非委托服务调用,开发者需注意响应块格式的变化以适配程序解析。

为什么值得看

这篇文章为Snowflake用户提供了从理论到实践的Agent构建避坑指南,强调了业务逻辑定义在AI应用中的核心地位。对于正在实施或计划实施企业级AI数据分析解决方案的团队而言,它揭示了提升准确率的关键不在于复杂的Prompt工程,而在于扎实的数据语义层建设。

技术解析

  • 语义视图(Semantic Views)的核心作用:作为YAML定义的Schema级对象,它明确告诉Cortex Analyst数据的含义、指标公式(expr)、维度、时间粒度及关系。文章指出,模糊的定义(如仅定义“总收入”)会导致LLM推断偏差,必须通过显式描述(如包含ASC 606标准、排除项等)和同义词列表来消除歧义。
  • Cortex Analyst与Cortex Search的路由机制:CoWork Agent根据问题类型自动选择工具。若未明确配置,Agent可能将政策类问题误判为数值查询。修复方案是在instructions块的orchestration部分设定硬性规则,例如:“关于政策/流程的问题使用Search,关于数字/趋势的问题使用Analyst”。
  • 验证查询(Verified Queries)的高ROI:这是存储在语义视图中的预定义“问题-SQL”对。当用户意图匹配时,Agent直接使用预设SQL而非实时生成。实践数据显示,添加35个验证查询可将复杂问题的准确率从60%提升至92%。
  • 权限与实现细节:访问语义视图只需GRANT SELECT,无需底层表的USAGE权限。此外,需注意指标定义中不包含data_type字段(类型由表达式推断),且自2026年4月起,响应块格式已从cortex_analyst_text_to_sql变更为system_execute_sql

行业启示

  • 重构AI开发重心:企业在构建AI Agent时,应将大部分精力投入于数据语义层的标准化和业务逻辑的定义,而非过度优化Prompt或编排逻辑。数据治理是AI准确性的基石。
  • 建立“单一事实来源”的业务逻辑层:通过语义视图将分散的业务规则(如净留存率的计算口径)集中化管理,确保AI代理与企业官方报告保持一致,降低合规风险。
  • 采用渐进式验证策略:在全面部署前,优先识别高频且关键的复杂查询场景,通过构建验证查询快速提升核心场景的准确率,以此作为衡量AI项目成熟度的关键指标。

Disclaimer: The above content is generated by AI and is for reference only. 免责声明:以上内容由 AI 生成,仅供参考。

Agent Agent LLM 大模型 Code Generation 代码生成