Setup SQL


USE ROLE ACCOUNTADMIN;
USE DATABASE SNOWFLAKE_INTELLIGENCE;
USE SCHEMA AGENTS;

-- ============================================================================
-- CONFIGURATION - UPDATE THESE VALUES
-- ============================================================================
-- IMPORTANT: Replace these placeholders with your actual credentials before running

-- Your Euno API credentials
-- Your API Key: <YOUR_API_KEY>
-- Your Account ID: <YOUR_ACCOUNT_ID>
-- Your Warehouse: <WAREHOUSE_NAME>

-- ============================================================================
-- NETWORK AND API INTEGRATION SETUP
-- ============================================================================

-- Create network rule for the API Gateway endpoint
CREATE OR REPLACE NETWORK RULE euno_api_gateway_network_rule
  MODE = EGRESS
  TYPE = HOST_PORT
  VALUE_LIST = ('euno-mcp-gateway-prod-5k67unwb.uc.gateway.dev');

-- Create API integration for external functions
CREATE OR REPLACE API INTEGRATION euno_mcp_api_integration
  API_PROVIDER = google_api_gateway
  GOOGLE_AUDIENCE = 'https://euno-mcp-gateway-prod-5k67unwb.uc.gateway.dev'
  API_ALLOWED_PREFIXES = ('https://euno-mcp-gateway-prod-5k67unwb.uc.gateway.dev/')
  ENABLED = TRUE;

-- ============================================================================
-- EXTERNAL FUNCTIONS - Direct API calls with authentication
-- ============================================================================
-- IMPORTANT: Replace <YOUR_API_KEY> and <YOUR_ACCOUNT_ID> in each URL below

CREATE OR REPLACE EXTERNAL FUNCTION euno_instructions(page VARIANT)
  RETURNS VARIANT
  VOLATILE
  API_INTEGRATION = euno_mcp_api_integration
  HEADERS = ('api-key' = '<YOUR_API_KEY>', 'account-id' = '<YOUR_ACCOUNT_ID>')
  AS 'https://euno-mcp-gateway-prod-5k67unwb.uc.gateway.dev/mcp/endpoints/euno_instructions';

CREATE OR REPLACE EXTERNAL FUNCTION euno_count_resources(
  query VARIANT,
  reasoning VARIANT,
  group_by_property VARIANT,
  resource_relationship_schema VARIANT,
  related_use_cases VARIANT
)
  RETURNS VARIANT
  VOLATILE
  API_INTEGRATION = euno_mcp_api_integration
  HEADERS = ('api-key' = '<YOUR_API_KEY>', 'account-id' = '<YOUR_ACCOUNT_ID>')
  AS 'https://euno-mcp-gateway-prod-5k67unwb.uc.gateway.dev/mcp/endpoints/count_resources';

CREATE OR REPLACE EXTERNAL FUNCTION euno_fetch_single_resource(
  resource_uri VARIANT,
  properties_to_fetch VARIANT
)
  RETURNS VARIANT
  VOLATILE
  API_INTEGRATION = euno_mcp_api_integration
  HEADERS = ('api-key' = '<YOUR_API_KEY>', 'account-id' = '<YOUR_ACCOUNT_ID>')
  AS 'https://euno-mcp-gateway-prod-5k67unwb.uc.gateway.dev/mcp/endpoints/fetch_single_resource';

CREATE OR REPLACE EXTERNAL FUNCTION euno_find_resource_by_name(
  resource_name VARIANT,
  reasoning VARIANT,
  filter_by_resource_types VARIANT,
  properties_to_return VARIANT
)
  RETURNS VARIANT
  VOLATILE
  API_INTEGRATION = euno_mcp_api_integration
  HEADERS = ('api-key' = '<YOUR_API_KEY>', 'account-id' = '<YOUR_ACCOUNT_ID>')
  AS 'https://euno-mcp-gateway-prod-5k67unwb.uc.gateway.dev/mcp/endpoints/find_resource_by_name';

CREATE OR REPLACE EXTERNAL FUNCTION euno_find_resources_for_topic(
  query_strings VARIANT,
  reasoning VARIANT,
  filter_by_resource_types VARIANT,
  properties_to_return VARIANT
)
  RETURNS VARIANT
  VOLATILE
  API_INTEGRATION = euno_mcp_api_integration
  HEADERS = ('api-key' = '<YOUR_API_KEY>', 'account-id' = '<YOUR_ACCOUNT_ID>')
  AS 'https://euno-mcp-gateway-prod-5k67unwb.uc.gateway.dev/mcp/endpoints/find_resources_for_topic';

CREATE OR REPLACE EXTERNAL FUNCTION euno_get_upstream_lineage(
  resource_uri VARIANT,
  reasoning VARIANT,
  properties_to_fetch VARIANT,
  related_use_cases VARIANT,
  filter_by_resource_types VARIANT
)
  RETURNS VARIANT
  VOLATILE
  API_INTEGRATION = euno_mcp_api_integration
  HEADERS = ('api-key' = '<YOUR_API_KEY>', 'account-id' = '<YOUR_ACCOUNT_ID>')
AS 'https://euno-mcp-gateway-prod-5k67unwb.uc.gateway.dev/mcp/endpoints/get_upstream_lineage';

CREATE OR REPLACE EXTERNAL FUNCTION euno_resource_impact_analysis(uri VARIANT)
  RETURNS VARIANT
  VOLATILE
  API_INTEGRATION = euno_mcp_api_integration
  HEADERS = ('api-key' = '<YOUR_API_KEY>', 'account-id' = '<YOUR_ACCOUNT_ID>')
  AS 'https://euno-mcp-gateway-prod-5k67unwb.uc.gateway.dev/mcp/endpoints/resource_impact_analysis';

CREATE OR REPLACE EXTERNAL FUNCTION euno_search_resources(
  query VARIANT,
  eql_query VARIANT,
  reasoning VARIANT,
  resource_relationship_schema VARIANT,
  related_use_cases VARIANT,
  order_by_property VARIANT,
  order_direction VARIANT,
  properties_to_return VARIANT
)
  RETURNS VARIANT
  VOLATILE
  API_INTEGRATION = euno_mcp_api_integration
  HEADERS = ('api-key' = '<YOUR_API_KEY>', 'account-id' = '<YOUR_ACCOUNT_ID>')
  AS 'https://euno-mcp-gateway-prod-5k67unwb.uc.gateway.dev/mcp/endpoints/search_resources';

CREATE OR REPLACE EXTERNAL FUNCTION euno_documentation_search(query VARIANT)
  RETURNS VARIANT
  VOLATILE
  API_INTEGRATION = euno_mcp_api_integration
  HEADERS = ('api-key' = '<YOUR_API_KEY>', 'account-id' = '<YOUR_ACCOUNT_ID>')
  AS 'https://euno-mcp-gateway-prod-5k67unwb.uc.gateway.dev/mcp/endpoints/documentation_search';

CREATE OR REPLACE EXTERNAL FUNCTION euno_documentation_get_full_document(url VARIANT)
  RETURNS VARIANT
  VOLATILE
  API_INTEGRATION = euno_mcp_api_integration
  HEADERS = ('api-key' = '<YOUR_API_KEY>', 'account-id' = '<YOUR_ACCOUNT_ID>')
  AS 'https://euno-mcp-gateway-prod-5k67unwb.uc.gateway.dev/mcp/endpoints/documentation_get_full_document';

CREATE OR REPLACE EXTERNAL FUNCTION euno_documentation_get_surrounding_context(
  chunk_id VARIANT,
  window_size VARIANT
)
  RETURNS VARIANT
  VOLATILE
  API_INTEGRATION = euno_mcp_api_integration
  HEADERS = ('api-key' = '<YOUR_API_KEY>', 'account-id' = '<YOUR_ACCOUNT_ID>')
  AS 'https://euno-mcp-gateway-prod-5k67unwb.uc.gateway.dev/mcp/endpoints/documentation_get_surrounding_context';

-- ============================================================================
-- WRAPPER FUNCTIONS - Provide type safety and data processing
-- ============================================================================
-- These wrapper functions provide a clean interface with proper SQL types
-- and handle data conversions before calling the external functions

-- 1. EUNO_INSTRUCTIONS: Get detailed instructions on using Euno MCP server
CREATE OR REPLACE FUNCTION euno_instructions_wrapper(page NUMBER)
  RETURNS STRING
AS
$$
  SELECT euno_instructions(TO_VARIANT(page))::STRING
$$;

-- 2. COUNT_RESOURCES: Count resources matching a query with optional grouping
CREATE OR REPLACE FUNCTION euno_count_resources_wrapper(
  query STRING,
  reasoning STRING,
  group_by_property STRING,
  resource_relationship_schema STRING,
  related_use_cases STRING
)
  RETURNS STRING
AS
$$
  SELECT euno_count_resources(
    TO_VARIANT(query),
    TO_VARIANT(reasoning),
    TO_VARIANT(group_by_property),
    TO_VARIANT(resource_relationship_schema),
    TO_VARIANT(CASE WHEN related_use_cases = '' THEN ARRAY_CONSTRUCT() ELSE SPLIT(related_use_cases, ',') END)
  )::STRING
$$;

-- 3. FETCH_SINGLE_RESOURCE: Retrieve a single resource by URI
CREATE OR REPLACE FUNCTION euno_fetch_single_resource_wrapper(
  resource_uri STRING,
  properties_to_fetch STRING
)
  RETURNS STRING
AS
$$
  SELECT euno_fetch_single_resource(
    TO_VARIANT(resource_uri),
    TO_VARIANT(CASE WHEN properties_to_fetch = '' THEN ARRAY_CONSTRUCT() ELSE SPLIT(properties_to_fetch, ',') END)
  )::STRING
$$;

-- 4. FIND_RESOURCE_BY_NAME: Find resources by name using similarity matching
CREATE OR REPLACE FUNCTION euno_find_resource_by_name_wrapper(
  resource_name STRING,
  reasoning STRING,
  filter_by_resource_types STRING,
  properties_to_return STRING
)
  RETURNS STRING
AS
$$
  SELECT euno_find_resource_by_name(
    TO_VARIANT(resource_name),
    TO_VARIANT(reasoning),
    TO_VARIANT(CASE WHEN filter_by_resource_types = '' THEN ARRAY_CONSTRUCT() ELSE SPLIT(filter_by_resource_types, ',') END),
    TO_VARIANT(CASE WHEN properties_to_return = '' THEN ARRAY_CONSTRUCT() ELSE SPLIT(properties_to_return, ',') END)
  )::STRING
$$;

-- 5. FIND_RESOURCES_FOR_TOPIC: Find resources related to a topic using semantic search
CREATE OR REPLACE FUNCTION euno_find_resources_for_topic_wrapper(
  query_strings STRING,
  reasoning STRING,
  filter_by_resource_types STRING,
  properties_to_return STRING
)
  RETURNS STRING
AS
$$
  SELECT euno_find_resources_for_topic(
    TO_VARIANT(CASE WHEN query_strings = '' THEN ARRAY_CONSTRUCT() ELSE SPLIT(query_strings, ',') END),
    TO_VARIANT(reasoning),
    TO_VARIANT(CASE WHEN filter_by_resource_types = '' THEN ARRAY_CONSTRUCT() ELSE SPLIT(filter_by_resource_types, ',') END),
    TO_VARIANT(CASE WHEN properties_to_return = '' THEN ARRAY_CONSTRUCT() ELSE SPLIT(properties_to_return, ',') END)
  )::STRING
$$;

-- 6. GET_UPSTREAM_LINEAGE: Get upstream lineage/dependencies for a resource
CREATE OR REPLACE FUNCTION euno_get_upstream_lineage_wrapper(
  resource_uri STRING,
  reasoning STRING,
  properties_to_fetch STRING,
  related_use_cases STRING,
  filter_by_resource_types STRING
)
  RETURNS STRING
AS
$$
  SELECT euno_get_upstream_lineage(
    TO_VARIANT(resource_uri),
    TO_VARIANT(reasoning),
    TO_VARIANT(CASE WHEN properties_to_fetch = '' THEN ARRAY_CONSTRUCT() ELSE SPLIT(properties_to_fetch, ',') END),
    TO_VARIANT(CASE WHEN related_use_cases = '' THEN ARRAY_CONSTRUCT() ELSE SPLIT(related_use_cases, ',') END),
    TO_VARIANT(CASE WHEN filter_by_resource_types = '' THEN ARRAY_CONSTRUCT() ELSE SPLIT(filter_by_resource_types, ',') END)
  )::STRING
$$;

-- 7. RESOURCE_IMPACT_ANALYSIS: Analyze downstream impact of changes to a resource
CREATE OR REPLACE FUNCTION euno_resource_impact_analysis_wrapper(uri STRING)
  RETURNS STRING
AS
$$
  SELECT euno_resource_impact_analysis(TO_VARIANT(uri))::STRING
$$;

-- 8. SEARCH_RESOURCES: Advanced search with EQL or natural language queries
CREATE OR REPLACE FUNCTION euno_search_resources_wrapper(
  query STRING,
  reasoning STRING,
  resource_relationship_schema STRING,
  related_use_cases STRING,
  order_by_property STRING,
  order_direction STRING,
  properties_to_return STRING
)
  RETURNS STRING
AS
$$
  SELECT euno_search_resources(
    TO_VARIANT(query),
    TO_VARIANT(''),
    TO_VARIANT(reasoning),
    TO_VARIANT(resource_relationship_schema),
    TO_VARIANT(CASE WHEN related_use_cases = '' THEN ARRAY_CONSTRUCT() ELSE SPLIT(related_use_cases, ',') END),
    TO_VARIANT(order_by_property),
    TO_VARIANT(order_direction),
    TO_VARIANT(CASE WHEN properties_to_return = '' THEN ARRAY_CONSTRUCT() ELSE SPLIT(properties_to_return, ',') END)
  )::STRING
$$;

-- 9. DOCUMENTATION_SEARCH: Search Euno documentation
CREATE OR REPLACE FUNCTION euno_documentation_search_wrapper(query STRING)
  RETURNS STRING
AS
$$
  SELECT euno_documentation_search(TO_VARIANT(query))::STRING
$$;

-- 10. DOCUMENTATION_GET_FULL_DOCUMENT: Retrieve full documentation by URL
CREATE OR REPLACE FUNCTION euno_documentation_get_full_document_wrapper(url STRING)
  RETURNS STRING
AS
$$
  SELECT euno_documentation_get_full_document(TO_VARIANT(url))::STRING
$$;

-- 11. DOCUMENTATION_GET_SURROUNDING_CONTEXT: Get context around a documentation chunk
CREATE OR REPLACE FUNCTION euno_documentation_get_surrounding_context_wrapper(
  chunk_id STRING,
  window_size NUMBER
)
  RETURNS STRING
AS
$$
  SELECT euno_documentation_get_surrounding_context(
    TO_VARIANT(chunk_id),
    TO_VARIANT(window_size)
  )::STRING
$$;

-- ============================================================================
-- AGENT DEFINITION
-- ============================================================================

CREATE OR REPLACE AGENT EUNO_AGENT
  COMMENT = 'Euno.ai Data Pipeline Assistant Agent'
  PROFILE = '{
    "display_name": "Euno.ai Agent",
    "avatar": "CirclesAgentIcon",
    "color": "purple"
  }'
  FROM SPECIFICATION
  $$
models:
  orchestration: claude-sonnet-4-5

orchestration:
  budget:
    seconds: 300
    tokens: 160000

instructions:
  system: "You are a data agent that helps users understand and manage their data pipeline using the Euno AI platform."
  orchestration: >
    You have access to a comprehensive set of primitive tools from the Euno Assistant AI.
    These tools give you granular control over searching, analyzing, and understanding the data pipeline.


    IMPORTANT:
    ALWAYS start by calling the tool 'euno_instructions' to get updated guidelines on how to work with Euno, which resource kinds and properties exists, how to perform certain tasks etc. It is VERY IMPORTANT you do not skip this step and never use any of the tools below before calling `euno_instructions`.
    START FROM PAGE 1 and read through ALL THE PAGES of the instructions returned by `euno_instructions` before proceeding to use any other tool.
    Then use Euno tools, being strategic about which tool to use:
    - Use 'search_resources' for general resource searches with natural language or EQL queries
    - Use 'find_resource_by_name' for finding resources by their name
    - Use 'find_resources_for_topic' for semantic searches across resource descriptions
    - Use 'get_upstream_lineage' to trace dependencies and data flow
    - Use 'resource_impact_analysis' to understand downstream effects of changes
    - Use 'fetch_single_resource' when you already have a URI and need specific properties
    - Use 'count_resources' when you need aggregations or counts
    - Use documentation tools to learn about Euno features and capabilities

    REMEMBER TO ALWAYS start by calling 'euno_instructions' FULLY to understand the full capabilities and guidelines.

    In Euno, all data pipeline entities (tables, dashboards, columns, etc.) are called 'resources'.
    Each resource has a unique URI that identifies it across the platform.

    VERY IMPORTANT: Euno provides metadata about the data pipeline - lineage, usage, logic, documentation, etc.
    Euno does NOT have access to actual data values. If users ask for actual data, use Euno to find the SQL
    logic or table definitions, then guide them to query the data warehouse directly.

  response: >
    Be concise and accurate in your responses.
    ALWAYS provide full links to resources you mention - these links are formatted using the resource's name and uri properties.
    Format: [{resource.name}](https://api.app.euno.ai/link-to-resource?uri={resource.uri}).
    When providing code snippets (SQL, Python, etc.), use proper code blocks with syntax highlighting.
    Present information clearly with proper formatting and structure.

tools:
  - tool_spec:
      type: "generic"
      name: "euno_instructions"
      description: "Get comprehensive instructions on using the Euno MCP server and understanding the data pipeline metadata capabilities, existing properties and relationships, resource types, and best practices."
      input_schema:
        type: "object"
        properties:
          page:
            type: "number"
            description: "Page number of the instructions to retrieve (starting from 1)"
        required: []

  - tool_spec:
      type: "generic"
      name: "euno_search_resources"
      description: "Search for data pipeline resources using natural language or EQL queries. Supports filtering, sorting, and property selection. Returns matching resources with requested properties."
      input_schema:
        type: "object"
        properties:
          query:
            type: "string"
            description: "Natural language description of what resources to find (e.g. 'tables in analytics schema', 'dashboards with no usage'). Use precise, specific descriptions."
          reasoning:
            type: "string"
            description: "Explain why you're searching and what resource types/properties you expect to find"
          resource_relationship_schema:
            type: "string"
            description: "For multi-resource queries, describe the relationship chain (e.g. 'dashboard -> view -> table'). Leave empty if not applicable."
          related_use_cases:
            type: "string"
            description: "Comma-separated list of use case identifiers you're following (e.g. 'TRACE_LINEAGE,FIND_OWNERS'). Leave empty if not applicable."
          order_by_property:
            type: "string"
            description: "Property name to sort results by. Leave empty for default sorting."
          order_direction:
            type: "string"
            description: "'ascending' or 'descending'. Leave empty for default order."
          properties_to_return:
            type: "string"
            description: "Comma-separated list of property names to include in results (e.g. 'name,owner,description'). uri is always included. Leave empty for defaults."
        required: ["query", "reasoning", "resource_relationship_schema", "related_use_cases", "order_by_property", "order_direction", "properties_to_return"]

  - tool_spec:
      type: "generic"
      name: "euno_count_resources"
      description: "Count resources matching a query, optionally grouped by a property. Useful for understanding data pipeline composition and resource distribution."
      input_schema:
        type: "object"
        properties:
          query:
            type: "string"
            description: "Natural language description of resources to count"
          reasoning:
            type: "string"
            description: "Explain what you're counting and why"
          group_by_property:
            type: "string"
            description: "Property to group counts by (e.g. 'type', 'owner'). Leave empty for total count only."
          resource_relationship_schema:
            type: "string"
            description: "For multi-resource queries, describe the relationship chain. Leave empty if not applicable."
          related_use_cases:
            type: "string"
            description: "Comma-separated list of related use case identifiers (e.g. 'TRACE_LINEAGE,IMPACT_ANALYSIS'). Leave empty if not applicable."
        required: ["query", "reasoning", "group_by_property", "resource_relationship_schema", "related_use_cases"]

  - tool_spec:
      type: "generic"
      name: "euno_fetch_single_resource"
      description: "Retrieve detailed information about a specific resource by its URI. Use when you already know the exact URI and need specific properties."
      input_schema:
        type: "object"
        properties:
          resource_uri:
            type: "string"
            description: "The exact URI of the resource to fetch"
          properties_to_fetch:
            type: "string"
            description: "Comma-separated list of property names to retrieve (e.g. 'name,owner,description,sql_logic')"
        required: ["resource_uri", "properties_to_fetch"]

  - tool_spec:
      type: "generic"
      name: "euno_find_resource_by_name"
      description: "Find resources by name using fuzzy/similarity matching. Useful when you know the approximate name but not the exact URI."
      input_schema:
        type: "object"
        properties:
          resource_name:
            type: "string"
            description: "The name (or partial name) to search for"
          reasoning:
            type: "string"
            description: "Explain what you're looking for and why"
          filter_by_resource_types:
            type: "string"
            description: "Comma-separated list of types to filter by (e.g. 'table,dbt_model'). Leave empty for all types."
          properties_to_return:
            type: "string"
            description: "Comma-separated list of properties to include (e.g. 'name,owner,type'). Leave empty for default properties."
        required: ["resource_name", "reasoning", "filter_by_resource_types", "properties_to_return"]

  - tool_spec:
      type: "generic"
      name: "euno_find_resources_for_topic"
      description: "Find resources related to a topic using semantic search across names and descriptions. Best for discovering resources by business domain or purpose."
      input_schema:
        type: "object"
        properties:
          query_strings:
            type: "string"
            description: "Comma-separated list of query terms or phrases describing the topic (e.g. 'customer,revenue,churn')"
          reasoning:
            type: "string"
            description: "Explain what topic/domain you're exploring"
          filter_by_resource_types:
            type: "string"
            description: "Comma-separated list of types to filter by (e.g. 'table,view'). Leave empty for all types."
          properties_to_return:
            type: "string"
            description: "Comma-separated list of properties to include (e.g. 'name,description,owner'). Recommend including 'description' for context. Leave empty for defaults."
        required: ["query_strings", "reasoning", "filter_by_resource_types", "properties_to_return"]

  - tool_spec:
      type: "generic"
      name: "euno_get_upstream_lineage"
      description: "Get upstream lineage (dependencies) for a resource. Shows what tables, columns, or other resources the given resource depends on."
      input_schema:
        type: "object"
        properties:
          resource_uri:
            type: "string"
            description: "URI of the resource to trace lineage for"
          reasoning:
            type: "string"
            description: "Explain why you're tracing lineage and what you expect to find"
          properties_to_fetch:
            type: "string"
            description: "Comma-separated list of properties to retrieve for upstream resources (e.g. 'name,type,owner'). Leave empty for defaults."
          related_use_cases:
            type: "string"
            description: "Comma-separated list of related use case identifiers (e.g. 'TRACE_LINEAGE,DEBUG_ISSUE'). Leave empty if not applicable."
          filter_by_resource_types:
            type: "string"
            description: "Comma-separated list of resource types to filter by (e.g. 'table,column'). Leave empty for all types."
        required: ["resource_uri", "reasoning", "properties_to_fetch", "related_use_cases", "filter_by_resource_types"]

  - tool_spec:
      type: "generic"
      name: "euno_resource_impact_analysis"
      description: "Analyze the downstream impact of changes to a table or column. Shows dashboards, reports, and other resources that depend on this resource and would be affected by changes."
      input_schema:
        type: "object"
        properties:
          uri:
            type: "string"
            description: "URI of the table or column to analyze"
        required: ["uri"]

  - tool_spec:
      type: "generic"
      name: "euno_documentation_search"
      description: "Search Euno platform documentation for help with features, concepts, and usage guidelines."
      input_schema:
        type: "object"
        properties:
          query:
            type: "string"
            description: "What to search for in the documentation"
        required: ["query"]

  - tool_spec:
      type: "generic"
      name: "euno_documentation_get_full_document"
      description: "Retrieve the complete text of a documentation file by its URL."
      input_schema:
        type: "object"
        properties:
          url:
            type: "string"
            description: "URL of the documentation file to retrieve"
        required: ["url"]

  - tool_spec:
      type: "generic"
      name: "euno_documentation_get_surrounding_context"
      description: "Get chunks of documentation surrounding a specific chunk ID for more context."
      input_schema:
        type: "object"
        properties:
          chunk_id:
            type: "string"
            description: "ID of the documentation chunk to get context around"
          window_size:
            type: "number"
            description: "Number of chunks before and after to retrieve (default 1)"
        required: ["chunk_id", "window_size"]

tool_resources:
  euno_instructions:
    type: "function"
    identifier: "SNOWFLAKE_INTELLIGENCE.AGENTS.EUNO_INSTRUCTIONS_WRAPPER"
    execution_environment:
      type: "warehouse"
      warehouse: "<WAREHOUSE_NAME>"

  euno_search_resources:
    type: "function"
    identifier: "SNOWFLAKE_INTELLIGENCE.AGENTS.EUNO_SEARCH_RESOURCES_WRAPPER"
    execution_environment:
      type: "warehouse"
      warehouse: "<WAREHOUSE_NAME>"

  euno_count_resources:
    type: "function"
    identifier: "SNOWFLAKE_INTELLIGENCE.AGENTS.EUNO_COUNT_RESOURCES_WRAPPER"
    execution_environment:
      type: "warehouse"
      warehouse: "<WAREHOUSE_NAME>"

  euno_fetch_single_resource:
    type: "function"
    identifier: "SNOWFLAKE_INTELLIGENCE.AGENTS.EUNO_FETCH_SINGLE_RESOURCE_WRAPPER"
    execution_environment:
      type: "warehouse"
      warehouse: "<WAREHOUSE_NAME>"

  euno_find_resource_by_name:
    type: "function"
    identifier: "SNOWFLAKE_INTELLIGENCE.AGENTS.EUNO_FIND_RESOURCE_BY_NAME_WRAPPER"
    execution_environment:
      type: "warehouse"
      warehouse: "<WAREHOUSE_NAME>"

  euno_find_resources_for_topic:
    type: "function"
    identifier: "SNOWFLAKE_INTELLIGENCE.AGENTS.EUNO_FIND_RESOURCES_FOR_TOPIC_WRAPPER"
    execution_environment:
      type: "warehouse"
      warehouse: "<WAREHOUSE_NAME>"

  euno_get_upstream_lineage:
    type: "function"
    identifier: "SNOWFLAKE_INTELLIGENCE.AGENTS.EUNO_GET_UPSTREAM_LINEAGE_WRAPPER"
    execution_environment:
      type: "warehouse"
      warehouse: "<WAREHOUSE_NAME>"

  euno_resource_impact_analysis:
    type: "function"
    identifier: "SNOWFLAKE_INTELLIGENCE.AGENTS.EUNO_RESOURCE_IMPACT_ANALYSIS_WRAPPER"
    execution_environment:
      type: "warehouse"
      warehouse: "<WAREHOUSE_NAME>"

  euno_documentation_search:
    type: "function"
    identifier: "SNOWFLAKE_INTELLIGENCE.AGENTS.EUNO_DOCUMENTATION_SEARCH_WRAPPER"
    execution_environment:
      type: "warehouse"
      warehouse: "<WAREHOUSE_NAME>"

  euno_documentation_get_full_document:
    type: "function"
    identifier: "SNOWFLAKE_INTELLIGENCE.AGENTS.EUNO_DOCUMENTATION_GET_FULL_DOCUMENT_WRAPPER"
    execution_environment:
      type: "warehouse"
      warehouse: "<WAREHOUSE_NAME>"

  euno_documentation_get_surrounding_context:
    type: "function"
    identifier: "SNOWFLAKE_INTELLIGENCE.AGENTS.EUNO_DOCUMENTATION_GET_SURROUNDING_CONTEXT_WRAPPER"
    execution_environment:
      type: "warehouse"
      warehouse: "<WAREHOUSE_NAME>"
  $$;

-- ============================================================================
-- PERMISSIONS
-- ============================================================================

CREATE ROLE IF NOT EXISTS EUNO_AGENT_USER;
GRANT ROLE EUNO_AGENT_USER TO ROLE ACCOUNTADMIN;
GRANT DATABASE ROLE SNOWFLAKE.CORTEX_USER TO ROLE EUNO_AGENT_USER;
GRANT DATABASE ROLE SNOWFLAKE.CORTEX_USER TO ROLE ACCOUNTADMIN;

GRANT USAGE ON DATABASE SNOWFLAKE_INTELLIGENCE TO ROLE EUNO_AGENT_USER;
GRANT USAGE ON SCHEMA SNOWFLAKE_INTELLIGENCE.AGENTS TO ROLE EUNO_AGENT_USER;
GRANT USAGE ON AGENT EUNO_AGENT TO ROLE EUNO_AGENT_USER;

-- Grant usage on all external functions (required by wrapper functions)
GRANT USAGE ON FUNCTION euno_instructions(VARIANT) TO ROLE EUNO_AGENT_USER;
GRANT USAGE ON FUNCTION euno_count_resources(VARIANT, VARIANT, VARIANT, VARIANT, VARIANT) TO ROLE EUNO_AGENT_USER;
GRANT USAGE ON FUNCTION euno_fetch_single_resource(VARIANT, VARIANT) TO ROLE EUNO_AGENT_USER;
GRANT USAGE ON FUNCTION euno_find_resource_by_name(VARIANT, VARIANT, VARIANT, VARIANT) TO ROLE EUNO_AGENT_USER;
GRANT USAGE ON FUNCTION euno_find_resources_for_topic(VARIANT, VARIANT, VARIANT, VARIANT) TO ROLE EUNO_AGENT_USER;
GRANT USAGE ON FUNCTION euno_get_upstream_lineage(VARIANT, VARIANT, VARIANT, VARIANT, VARIANT) TO ROLE EUNO_AGENT_USER;
GRANT USAGE ON FUNCTION euno_resource_impact_analysis(VARIANT) TO ROLE EUNO_AGENT_USER;
GRANT USAGE ON FUNCTION euno_search_resources(VARIANT, VARIANT, VARIANT, VARIANT, VARIANT, VARIANT, VARIANT, VARIANT) TO ROLE EUNO_AGENT_USER;
GRANT USAGE ON FUNCTION euno_documentation_search(VARIANT) TO ROLE EUNO_AGENT_USER;
GRANT USAGE ON FUNCTION euno_documentation_get_full_document(VARIANT) TO ROLE EUNO_AGENT_USER;
GRANT USAGE ON FUNCTION euno_documentation_get_surrounding_context(VARIANT, VARIANT) TO ROLE EUNO_AGENT_USER;

-- Grant usage on wrapper functions (used by agent)
GRANT USAGE ON FUNCTION euno_instructions_wrapper(NUMBER) TO ROLE EUNO_AGENT_USER;
GRANT USAGE ON FUNCTION euno_count_resources_wrapper(STRING, STRING, STRING, STRING, STRING) TO ROLE EUNO_AGENT_USER;
GRANT USAGE ON FUNCTION euno_fetch_single_resource_wrapper(STRING, STRING) TO ROLE EUNO_AGENT_USER;
GRANT USAGE ON FUNCTION euno_find_resource_by_name_wrapper(STRING, STRING, STRING, STRING) TO ROLE EUNO_AGENT_USER;
GRANT USAGE ON FUNCTION euno_find_resources_for_topic_wrapper(STRING, STRING, STRING, STRING) TO ROLE EUNO_AGENT_USER;
GRANT USAGE ON FUNCTION euno_get_upstream_lineage_wrapper(STRING, STRING, STRING, STRING, STRING) TO ROLE EUNO_AGENT_USER;
GRANT USAGE ON FUNCTION euno_resource_impact_analysis_wrapper(STRING) TO ROLE EUNO_AGENT_USER;
GRANT USAGE ON FUNCTION euno_search_resources_wrapper(STRING, STRING, STRING, STRING, STRING, STRING, STRING) TO ROLE EUNO_AGENT_USER;
GRANT USAGE ON FUNCTION euno_documentation_search_wrapper(STRING) TO ROLE EUNO_AGENT_USER;
GRANT USAGE ON FUNCTION euno_documentation_get_full_document_wrapper(STRING) TO ROLE EUNO_AGENT_USER;
GRANT USAGE ON FUNCTION euno_documentation_get_surrounding_context_wrapper(STRING, NUMBER) TO ROLE EUNO_AGENT_USER;
GRANT USAGE ON WAREHOUSE <WAREHOUSE_NAME> TO ROLE EUNO_AGENT_USER;

-- Grant usage on integration
GRANT USAGE ON INTEGRATION euno_mcp_api_integration TO ROLE EUNO_AGENT_USER;

-- Grant the agent user role to specific users (replace with actual usernames)
-- GRANT ROLE EUNO_AGENT_USER TO USER your_user_name_here;

Last updated