### Install Orchestration Framework Source: https://github.com/snowflake-labs/orchestration-framework/blob/main/README.md Install the framework using pip. Ensure you are using Python 3.10 or 3.11. ```sh pip install orchestration-framework ``` -------------------------------- ### Initialize and Run an Agent Source: https://context7.com/snowflake-labs/orchestration-framework/llms.txt Basic setup for an agent using a Snowflake session and a list of tools. ```python agent = Agent( snowflake_connection=session, tools=[user_metrics_tool, inventory_tool, analyst_tool] ) result = agent("Show me the user engagement by segment") print(result["output"]) ``` -------------------------------- ### Install Agent Gateway Framework Source: https://context7.com/snowflake-labs/orchestration-framework/llms.txt Install the Agent Gateway framework using pip. Optional extras can be installed for Trulens, MCP, or Streamlit UI support. ```bash pip install orchestration-framework ``` ```bash # With Trulens observability support pip install orchestration-framework[trulens] ``` ```bash # With MCP (Model Context Protocol) support pip install orchestration-framework[fastmcp] ``` ```bash # With Streamlit UI support pip install orchestration-framework[streamlit] ``` -------------------------------- ### Setup and Use Demo Services Source: https://context7.com/snowflake-labs/orchestration-framework/llms.txt Generate and tear down demo Cortex Search and Analyst services for testing purposes. ```python from snowflake.snowpark import Session from agent_gateway.tools.utils import generate_demo_services, teardown_demo_services # Create session session = Session.builder.configs({ "account": "your_account", "user": "your_user", "password": "your_password", "warehouse": "your_warehouse", "database": "your_database", "schema": "your_schema" }).create() # Generate demo services # This creates: # - CUBE_TESTING database and warehouse # - SEC_SEARCH_SERVICE Cortex Search service with SEC filings # - SP500 table with stock metrics # - sp500_semantic_model.yaml for Cortex Analyst result = generate_demo_services(session) print(result) # "Demo services created successfully." # Use the demo services from agent_gateway import Agent from agent_gateway.tools import CortexSearchTool, CortexAnalystTool # Switch to demo database session.use_database("CUBE_TESTING") session.use_schema("PUBLIC") search_tool = CortexSearchTool( service_name="SEC_SEARCH_SERVICE", service_topic="Snowflake's business, product offerings, and performance", data_description="Snowflake annual reports", retrieval_columns=["CHUNK", "RELATIVE_PATH"], snowflake_connection=session, ) analyst_tool = CortexAnalystTool( semantic_model="sp500_semantic_model.yaml", stage="ANALYST", service_topic="S&P500 company and stock metrics", data_description="S&P500 stock and financial metrics", snowflake_connection=session, ) agent = Agent(snowflake_connection=session, tools=[search_tool, analyst_tool]) result = agent("What are the top 5 companies by market cap in the Technology sector?") print(result["output"]) # Clean up when done teardown_demo_services(session) # Drops CUBE_TESTING database and warehouse ``` -------------------------------- ### Initialize TruAgent with Snowflake Connector Source: https://github.com/snowflake-labs/orchestration-framework/blob/main/Quickstart.ipynb Install the framework with `pip install orchestration-framework[trulens]` and initialize the TruAgent with a SnowflakeConnector. Ensure `connection_parameters` and `snowpark` are defined. ```python from agent_gateway import TruAgent from trulens.connectors.snowflake import SnowflakeConnector tru_conn = SnowflakeConnector(**connection_parameters) agent = TruAgent( app_name="observable", app_version="v0", trulens_snowflake_connection=tru_conn, snowflake_connection=snowpark, tools=snowflake_tools, max_retries=3, ) ``` -------------------------------- ### Generate Demo Services Source: https://github.com/snowflake-labs/orchestration-framework/blob/main/README.md Generate demo services for Cortex Search and Cortex Analyst using the provided session. This is useful for following the Quickstart notebook. ```python from agent_gateway.tools.utils import generate_demo_services from snowflake.snowpark import Session session = Session.builder.create() generate_demo_services(session) ``` -------------------------------- ### Agent Query Result Example Source: https://github.com/snowflake-labs/orchestration-framework/blob/main/Quickstart.ipynb This is an example of the structured output received after an agent query, including the final answer and metadata about the tools used. ```json { "output": "The market cap of Amazon.com, Inc. is $1,917,936,336,896, the market cap of Microsoft Corporation is $3,150,184,448,000, and the market cap of Alphabet Inc. is $2,164,350,779,392.", "sources": [{ "tool_type": "cortex_search", "tool_name": "sec_search_service_cortexsearch", "metadata": [{ "RELATIVE_PATH": "2023_10k_snowflake.pdf" }, { "RELATIVE_PATH": "2024_10k_snowflake.pdf" }, { "RELATIVE_PATH": "2022_10k_snowflake.pdf" }, { "RELATIVE_PATH": "2021_10k_snowflake.pdf" }] }, { "tool_type": "cortex_analyst", "tool_name": "sp500_semantic_model_cortexanalyst", "metadata": [{ "Table": "cube_testing.public.sp500" }] }]} ``` -------------------------------- ### Create Network Rule and External Access Integration Source: https://github.com/snowflake-labs/orchestration-framework/blob/main/README.md Configure network rules and external access integration to allow the Agent Gateway to connect to external resources like GitHub. This is necessary when installing the library directly from GitHub or PyPI. ```sql CREATE NETWORK RULE agent_network_rule MODE = EGRESS TYPE = HOST_PORT VALUE_LIST = ('github.com'); CREATE EXTERNAL ACCESS INTEGRATION agent_network_int ALLOWED_NETWORK_RULES = (agent_network_rule) ENABLED = true; ``` -------------------------------- ### Initialize Agent with Tools Source: https://context7.com/snowflake-labs/orchestration-framework/llms.txt Initialize the Agent class with a Snowflake session and a list of configured tools. Configure LLM settings and retry attempts. ```python from snowflake.snowpark import Session from agent_gateway import Agent from agent_gateway.tools import CortexSearchTool, CortexAnalystTool, PythonTool # Create Snowflake session session = Session.builder.configs({ "account": "your_account", "user": "your_user", "password": "your_password", "warehouse": "your_warehouse", "database": "your_database", "schema": "your_schema" }).create() # Configure tools (see tool sections below) search_tool = CortexSearchTool( service_name="SEC_SEARCH_SERVICE", service_topic="Snowflake's business, product offerings, and performance", data_description="Snowflake annual reports", retrieval_columns=["CHUNK"], snowflake_connection=session, ) analyst_tool = CortexAnalystTool( semantic_model="sp500_semantic_model.yaml", stage="ANALYST", service_topic="S&P500 company and stock metrics", data_description="a table with stock and financial metrics about S&P500 companies", snowflake_connection=session, ) # Initialize the agent agent = Agent( snowflake_connection=session, tools=[search_tool, analyst_tool], max_retries=2, # Maximum replanning attempts planner_llm="mistral-large2", # LLM for planning agent_llm="mistral-large2", # LLM for responses memory=True # Enable conversation memory ) # Query the agent - it automatically routes to the appropriate tool # Structured data question (routes to Cortex Analyst) result = agent("What is the market cap of Apple?") print(result) # Output: {'output': 'The market cap of Apple Inc. is $3,019,131,060,224.', 'sources': [...]}) # Unstructured data question (routes to Cortex Search) result = agent("What are Snowflake's strategic plans?") print(result) # Output: {'output': "Based on the annual reports, Snowflake plans to...", 'sources': [...])} ``` -------------------------------- ### Configure Multiple Cortex Search Tools Source: https://github.com/snowflake-labs/orchestration-framework/blob/main/README.md Demonstrates how to connect multiple tools of the same type, such as Cortex Search, to the Agent Gateway. Ensure each tool is configured with its respective parameters. ```python search_one = CortexSearchTool(**search_one_config) search_two = CortexSearchTool(**search_two_config) snowflake_agent = Agent(snowflake_connection=session, tools=[search_one, search_two]) ``` -------------------------------- ### Initialize Agent Tools and Agent Source: https://github.com/snowflake-labs/orchestration-framework/blob/main/Quickstart.ipynb Configures specific tools and initializes the Agent with a Snowpark connection and tool list. ```python annual_reports = CortexSearchTool(**search_config) sp500 = CortexAnalystTool(**analyst_config) web_crawler = PythonTool(**python_crawler_config) margin_eval = SQLTool(**sql_tool_config) snowflake_tools = [annual_reports, sp500, web_crawler, margin_eval] agent = Agent(snowflake_connection=snowpark, tools=snowflake_tools, max_retries=3) ``` -------------------------------- ### Define and Configure SQLTool for Inventory Alerts Source: https://context7.com/snowflake-labs/orchestration-framework/llms.txt Create a SQLTool to identify products with low inventory that need reordering, specifying the SQL query, connection, and output description. ```python # Another SQL tool for inventory inventory_tool = SQLTool( name="low_inventory_alert", sql_query=""" SELECT product_name, current_stock, reorder_level FROM inventory.products WHERE current_stock < reorder_level ORDER BY (reorder_level - current_stock) DESC """, connection=session, tool_description="identifies products with low inventory that need reordering", output_description="list of products below reorder threshold" ) ``` -------------------------------- ### Configure SQL Tool Source: https://github.com/snowflake-labs/orchestration-framework/blob/main/README.md Configure and initialize a SQL Tool for custom SQL pipelines. Requires a name, tool description, output description, the SQL query, and the Snowflake connection. ```python sql_query = '''SELECT * FROM MY_EVENTS_TABLE ''' sql_tool_config = { "name": "custom_metrics_pipeline", "tool_description": "analyzes custom user metrics", "output_description": "key user metrics", "sql": sql_query, "connection":session } custom_metrics = SQLTool(**sql_tool_config) ``` -------------------------------- ### Define and Configure SQLTool for User Metrics Source: https://context7.com/snowflake-labs/orchestration-framework/llms.txt Create a SQLTool to analyze user engagement metrics over the last 30 days, specifying the SQL query, connection, and output description. ```python from agent_gateway.tools import SQLTool # Define a custom SQL tool for user metrics user_metrics_tool = SQLTool( name="user_engagement_metrics", sql_query=""" SELECT user_segment, COUNT(*) as user_count, AVG(session_duration) as avg_session, SUM(purchases) as total_purchases FROM analytics.user_events WHERE event_date >= DATEADD(day, -30, CURRENT_DATE()) GROUP BY user_segment ORDER BY total_purchases DESC """, connection=session, tool_description="analyzes user engagement metrics over the last 30 days", output_description="user segment metrics including count, session duration, and purchases" ) ``` -------------------------------- ### Authenticate with Snowpark and Set Environment Variables Source: https://github.com/snowflake-labs/orchestration-framework/blob/main/Quickstart.ipynb Establishes a Snowpark session and loads environment variables for authentication. Ensure SNOWFLAKE_ACCOUNT, SNOWFLAKE_USER, SNOWFLAKE_PASSWORD, SNOWFLAKE_ROLE, SNOWFLAKE_WAREHOUSE, SNOWFLAKE_DATABASE, and SNOWFLAKE_SCHEMA are set in your .env file. ```python from agent_gateway import Agent from agent_gateway.tools import CortexSearchTool, CortexAnalystTool, PythonTool, SQLTool from snowflake.snowpark import Session import os from dotenv import load_dotenv load_dotenv() connection_parameters = { "account": os.getenv("SNOWFLAKE_ACCOUNT"), "user": os.getenv("SNOWFLAKE_USER"), "password": os.getenv("SNOWFLAKE_PASSWORD"), "role": os.getenv("SNOWFLAKE_ROLE"), "warehouse": os.getenv("SNOWFLAKE_WAREHOUSE"), "database": os.getenv("SNOWFLAKE_DATABASE"), "schema": os.getenv("SNOWFLAKE_SCHEMA"), } snowpark = Session.builder.configs(connection_parameters).create() ``` -------------------------------- ### Configure Python Tool Source: https://github.com/snowflake-labs/orchestration-framework/blob/main/README.md Configure and initialize a Python Tool for custom operations. Requires a tool description, output description, and the Python function to execute. ```python import requests def get_html(url): response = requests.get(url) return response.text python_scraper_config = { "tool_description": "reads the html from a given URL or website", "output_description": "html of a webpage", "python_func": get_html } web_crawler = PythonTool(**python_scraper_config) ``` -------------------------------- ### Configure Multiple Tools of Same Type Source: https://context7.com/snowflake-labs/orchestration-framework/llms.txt Define multiple tool instances with different configurations for comprehensive data coverage. ```python from agent_gateway import Agent from agent_gateway.tools import CortexSearchTool, CortexAnalystTool # Multiple Cortex Search tools for different document sets sec_filings_search = CortexSearchTool( service_name="SEC_FILINGS_SEARCH", service_topic="SEC regulatory filings and disclosures", data_description="10-K and 10-Q filings", retrieval_columns=["CONTENT", "FILING_TYPE", "COMPANY"], snowflake_connection=session, ) news_search = CortexSearchTool( service_name="NEWS_SEARCH", service_topic="financial news and market updates", data_description="financial news articles", retrieval_columns=["HEADLINE", "BODY", "SOURCE"], snowflake_connection=session, ) ``` -------------------------------- ### Integrate MCP Tools Source: https://context7.com/snowflake-labs/orchestration-framework/llms.txt Connect to local or remote Model Context Protocol servers to extend agent capabilities. ```python from agent_gateway.tools import MCPTool # Create tools from an MCP server # MCPTool returns a list of tools from the server mcp_tools = MCPTool(server_path="path/to/mcp_server.py") # Or connect to a remote MCP server mcp_tools = MCPTool(server_path="http://localhost:8000/mcp") # The returned tools can be used directly with Agent agent = Agent( snowflake_connection=session, tools=[search_tool, analyst_tool] + mcp_tools ) result = agent("Use the MCP tool to fetch weather data for New York") print(result["output"]) ``` -------------------------------- ### Configure Snowflake Environment Variables Source: https://github.com/snowflake-labs/orchestration-framework/blob/main/tests/README.md Define connection credentials in a .env file located in the project root directory. ```bash SNOWFLAKE_ACCOUNT= SNOWFLAKE_USER= SNOWFLAKE_PASSWORD= SNOWFLAKE_WAREHOUSE= SNOWFLAKE_ROLE= ``` -------------------------------- ### Configure and Test Cortex Search Tool Source: https://context7.com/snowflake-labs/orchestration-framework/llms.txt Configure the CortexSearchTool with service details and connection, then test its search functionality asynchronously. ```python search_config = { "service_name": "SEC_SEARCH_SERVICE", # Name of your Cortex Search service "service_topic": "Snowflake's business, product offerings, and performance", "data_description": "Snowflake annual reports", "retrieval_columns": ["CHUNK", "RELATIVE_PATH"], # Columns to retrieve "snowflake_connection": session, "k": 5, # Number of results to return } search_tool = CortexSearchTool(**search_config) ``` ```python import asyncio async def test_search(): result = await search_tool.asearch("What are Snowflake's revenue growth drivers?") print(result) ``` ```python asyncio.run(test_search()) ``` -------------------------------- ### Execute Test Suite Source: https://github.com/snowflake-labs/orchestration-framework/blob/main/tests/README.md Run the automated test suite using poetry. ```bash poetry run pytest ``` -------------------------------- ### Define and Create Python Tools Source: https://context7.com/snowflake-labs/orchestration-framework/llms.txt Define custom Python functions for specific tasks and wrap them using PythonTool for use with the Agent Gateway. Ensure functions have clear docstrings for tool descriptions. ```python from agent_gateway.tools import PythonTool import requests # Define a custom Python function def get_html(url: str) -> str: """Fetches HTML content from a URL.""" response = requests.get(url) return response.text def calculate_metrics(ticker: str, price: float, shares: int) -> dict: """Calculates market metrics for a stock.""" market_cap = price * shares return { "ticker": ticker, "price": price, "shares_outstanding": shares, "market_cap": market_cap } ``` ```python # Create Python tools web_crawler = PythonTool( python_func=get_html, tool_description="reads the HTML from a given URL or website", output_description="HTML content of a webpage" ) metrics_calculator = PythonTool( python_func=calculate_metrics, tool_description="calculates market metrics for a given stock", output_description="dictionary with ticker, price, shares, and market cap" ) ``` ```python # Use with Agent agent = Agent( snowflake_connection=session, tools=[search_tool, analyst_tool, web_crawler, metrics_calculator] ) # The agent can now use the Python tool when appropriate result = agent("Summarize this article: https://example.com/news/tech-update") print(result["output"]) ``` -------------------------------- ### Configure and Use Agent Source: https://github.com/snowflake-labs/orchestration-framework/blob/main/README.md Configure the Agent with Snowflake tools and use it to answer questions. Supports structured data (Text2SQL), unstructured data (RAG), and web search (Python Tool). ```python from agent_gateway import Agent # Config + Initialize Agent snowflake_tools = [annual_reports, sp500, web_crawler] snowflake_agent = Agent(snowflake_connection=session, tools=snowflake_tools) # Structured Data Question (Text2SQL) answer = snowflake_agent("What is market cap of company X?") print(answer) # Unstructured Data Question (RAG) answer = snowflake_agent("What are the strategic plans for company X") print(answer) # Web Search Question (Python Tool) answer = snowflake_agent( "Summarize this article: http://localhost:8080/dummyproductannouncements/interview.html" ) print(answer) ``` -------------------------------- ### Configure and Test Cortex Analyst Tool Source: https://context7.com/snowflake-labs/orchestration-framework/llms.txt Configure the CortexAnalystTool with a semantic model and connection, then test its Text2SQL query capability asynchronously. ```python from agent_gateway.tools import CortexAnalystTool # Configure Cortex Analyst tool analyst_config = { "semantic_model": "sp500_semantic_model.yaml", # Semantic model file name "stage": "ANALYST", # Stage where model is stored "service_topic": "S&P500 company and stock metrics", "data_description": "a table with stock and financial metrics about S&P500 companies", "snowflake_connection": session, "max_results": 10, # Optional: limit results } analyst_tool = CortexAnalystTool(**analyst_config) ``` ```python import asyncio async def test_analyst(): result = await analyst_tool.query("What are the top 5 companies by market cap?") print(result) ``` ```python asyncio.run(test_analyst()) ``` -------------------------------- ### Configure Multiple Cortex Analyst Tools Source: https://context7.com/snowflake-labs/orchestration-framework/llms.txt Define multiple tool instances for an agent to enable intelligent routing based on user queries. ```python stock_analyst = CortexAnalystTool( semantic_model="stock_metrics.yaml", stage="MODELS", service_topic="stock prices and trading metrics", data_description="daily stock trading data", snowflake_connection=session, ) financials_analyst = CortexAnalystTool( semantic_model="company_financials.yaml", stage="MODELS", service_topic="company financial statements", data_description="quarterly and annual financial statements", snowflake_connection=session, ) # Combine all tools - agent automatically routes to the appropriate one agent = Agent( snowflake_connection=session, tools=[sec_filings_search, news_search, stock_analyst, financials_analyst] ) # Agent intelligently selects the right tool based on the query result = agent("What did Apple report in their latest 10-K about supply chain risks?") # Routes to sec_filings_search result = agent("What is Apple's current P/E ratio?") # Routes to stock_analyst result = agent("What was Apple's revenue last quarter?") # Routes to financials_analyst ``` -------------------------------- ### Configure SQL Tool for Margin Evaluation Source: https://github.com/snowflake-labs/orchestration-framework/blob/main/Quickstart.ipynb Configures a SQL Tool named 'margin_eval' that executes a predefined SQL query to calculate and evaluate EBITDA margins. It includes descriptions for the tool's purpose and its output. ```python sql_tool_config = { "name": "margin_eval", "connection": snowpark, "sql_query": sql_query, "tool_description": "Calculates the normalized EBITDA Margin as a % relative to the SP500 average", "output_description": "EBITDA Margin %", } ``` -------------------------------- ### Configure Cortex Search Tool Source: https://github.com/snowflake-labs/orchestration-framework/blob/main/Quickstart.ipynb Sets up the configuration for the Cortex Search Tool, specifying service details, data description, retrieval columns, and Snowpark connection. The 'k' parameter controls the number of results to retrieve. ```python search_config = { "service_name": "SEC_SEARCH_SERVICE", "service_topic": "Snowflake's business,product offerings,and performance.", "data_description": "Snowflake annual reports", "retrieval_columns": ["CHUNK", "RELATIVE_PATH"], "snowflake_connection": snowpark, "k": 10, } ``` -------------------------------- ### Configure Cortex Analyst Tool Source: https://github.com/snowflake-labs/orchestration-framework/blob/main/README.md Configure and initialize the Cortex Analyst Tool for structured data analysis (Text2SQL). Requires semantic model, stage, service topic, data description, and Snowflake connection. ```python # Cortex Analyst Config analyst_config = { "semantic_model": "sp500_semantic_model.yaml", "stage": "ANALYST", "service_topic": "S&P500 company and stock metrics", "data_description": "a table with stock and financial metrics about S&P500 companies ", "snowflake_connection": session, } sp500 = CortexAnalystTool(**analyst_config) ``` -------------------------------- ### Configure Cortex Search Tool Source: https://github.com/snowflake-labs/orchestration-framework/blob/main/README.md Configure and initialize the Cortex Search Tool for unstructured data analysis. Requires service name, topic, data description, retrieval columns, and Snowflake connection. ```python from agent_gateway.tools import CortexSearchTool, CortexAnalystTool, PythonTool, SQLTool # Cortex Search Service Config search_config = { "service_name": "SEC_SEARCH_SERVICE", "service_topic": "Snowflake's business,product offerings,and performance", "data_description": "Snowflake annual reports", "retrieval_columns": ["CHUNK"], "snowflake_connection": session, } annual_reports = CortexSearchTool(**search_config) ``` -------------------------------- ### Integrate Agent Gateway with Streamlit Source: https://context7.com/snowflake-labs/orchestration-framework/llms.txt Build an interactive chat interface using Streamlit, utilizing session state to persist the agent instance. ```python import streamlit as st from snowflake.snowpark import Session from agent_gateway import Agent from agent_gateway.tools import CortexSearchTool, CortexAnalystTool, PythonTool st.set_page_config(page_title="Agent Gateway Chat") st.title("Snowflake Agent Gateway") # Initialize session state if "agent" not in st.session_state: session = Session.builder.configs({ "account": st.secrets["snowflake"]["account"], "user": st.secrets["snowflake"]["user"], "password": st.secrets["snowflake"]["password"], "warehouse": st.secrets["snowflake"]["warehouse"], "database": st.secrets["snowflake"]["database"], "schema": st.secrets["snowflake"]["schema"] }).create() search_tool = CortexSearchTool( service_name="DOCS_SEARCH", service_topic="company documentation", data_description="internal docs", retrieval_columns=["CONTENT"], snowflake_connection=session, ) analyst_tool = CortexAnalystTool( semantic_model="metrics.yaml", stage="MODELS", service_topic="business metrics", data_description="KPI data", snowflake_connection=session, ) st.session_state.agent = Agent( snowflake_connection=session, tools=[search_tool, analyst_tool] ) st.session_state.messages = [] # Display chat history for message in st.session_state.messages: with st.chat_message(message["role"]): st.markdown(message["content"]) # Chat input if prompt := st.chat_input("Ask anything about your data"): st.session_state.messages.append({"role": "user", "content": prompt}) with st.chat_message("user"): st.markdown(prompt) with st.chat_message("assistant"): with st.spinner("Thinking..."): response = st.session_state.agent(prompt) st.markdown(response["output"]) # Display sources if available if response.get("sources"): with st.expander("Sources"): st.json(response["sources"]) st.session_state.messages.append({"role": "assistant", "content": response["output"]}) ``` -------------------------------- ### Run Trulens Dashboard Source: https://github.com/snowflake-labs/orchestration-framework/blob/main/Quickstart.ipynb Initialize a TruSession with the Snowflake connector and run the dashboard to view traces. The dashboard can be accessed at the specified port. ```python from trulens.core import TruSession from trulens.dashboard import run_dashboard session = TruSession(connector=tru_conn) run_dashboard(session, port=8084) ``` -------------------------------- ### Query Cloud Provider Market Cap Source: https://github.com/snowflake-labs/orchestration-framework/blob/main/Quickstart.ipynb Use the agent to ask questions about unstructured and structured data. Ensure the agent has access to relevant data sources like annual reports. ```python agent( "What is the market cap of each of the cloud providers mentioned in Snowflake's annual report?" ) ``` -------------------------------- ### Configure Python Tool for Web Crawling Source: https://github.com/snowflake-labs/orchestration-framework/blob/main/Quickstart.ipynb Sets up the configuration for a Python Tool, providing a description of its functionality and output, and linking it to the `html_crawl` Python function. This tool is designed to read HTML from a specified URL. ```python python_crawler_config = { "tool_description": "reads the html from a given URL or website", "output_description": "html of a webpage", "python_func": html_crawl, } ``` -------------------------------- ### Configure Cortex Analyst Tool Source: https://github.com/snowflake-labs/orchestration-framework/blob/main/Quickstart.ipynb Defines the configuration for the Cortex Analyst Tool, including the semantic model, service topic, data description, and Snowpark connection. 'max_results' limits the number of returned records. ```python analyst_config = { "semantic_model": "sp500_semantic_model.yaml", "stage": "ANALYST", "service_topic": "S&P500 company and stock metrics", "data_description": "a table with stock and financial metrics about S&P500 companies ", "snowflake_connection": snowpark, "max_results": 5, } ``` -------------------------------- ### Query Cloud Platform Information Source: https://github.com/snowflake-labs/orchestration-framework/blob/main/Quickstart.ipynb Executes a query to retrieve information from an external URL using the HTML crawl tool. ```python agent( "On which platforms can I host Snowflake according to this documentation page https://docs.snowflake.com/en/user-guide/intro-cloud-platforms" ) ``` -------------------------------- ### Configure Cross-Account Tool Access Source: https://context7.com/snowflake-labs/orchestration-framework/llms.txt Use tools from different Snowflake accounts by assigning specific session connections to each tool instance. ```python from snowflake.snowpark import Session from agent_gateway import Agent from agent_gateway.tools import CortexSearchTool, CortexAnalystTool # Primary account session primary_session = Session.builder.configs({ "account": "primary_account", "user": "user1", "password": "password1", "warehouse": "WH1", "database": "DB1", "schema": "SCHEMA1" }).create() # Secondary account session secondary_session = Session.builder.configs({ "account": "secondary_account", "user": "user2", "password": "password2", "warehouse": "WH2", "database": "DB2", "schema": "SCHEMA2" }).create() # Tools from different accounts search_tool = CortexSearchTool( service_name="DOCS_SEARCH", service_topic="internal documentation", data_description="company documentation", retrieval_columns=["CONTENT"], snowflake_connection=primary_session, # Uses primary account ) analyst_tool = CortexAnalystTool( semantic_model="sales_model.yaml", stage="ANALYTICS", service_topic="sales metrics", data_description="sales data", snowflake_connection=secondary_session, # Uses secondary account ) # Agent orchestrates across both accounts agent = Agent( snowflake_connection=primary_session, # For planning/fusion tools=[search_tool, analyst_tool] ) result = agent("Compare our documentation guidelines with Q3 sales performance") print(result["output"]) ``` -------------------------------- ### Async Agent Execution Source: https://context7.com/snowflake-labs/orchestration-framework/llms.txt Execute agent queries asynchronously using the `acall` method. This is useful for concurrent operations or integration with async frameworks. ```python import asyncio from agent_gateway import Agent async def run_queries(): agent = Agent( snowflake_connection=session, tools=[search_tool, analyst_tool] ) # Run single async query result = await agent.acall("What companies have the highest market cap?") print(result["output"]) # Run multiple queries concurrently queries = [ "What is the market cap of Microsoft?", "What is the market cap of Amazon?", "What is the market cap of Google?" ] results = await asyncio.gather(*[agent.acall(q) for q in queries]) for r in results: print(r["output"]) asyncio.run(run_queries()) ``` -------------------------------- ### Run a Tool in Isolation Source: https://github.com/snowflake-labs/orchestration-framework/blob/main/README.md Asynchronous tools can be validated by running them in isolation. This helps in debugging configuration issues before integrating them into the Agent Gateway. ```python import asyncio asyncio.run(my_cortex_search_tool("This is a sample cortex search question")) ``` -------------------------------- ### Compare EBITDA Between Companies Source: https://github.com/snowflake-labs/orchestration-framework/blob/main/Quickstart.ipynb Executes a comparative query between two entities using the Cortex Analyst tool. ```python agent("Which company has the bigger EBITDA, Apple or MSFT?") ``` -------------------------------- ### Query Market Capitalization Source: https://github.com/snowflake-labs/orchestration-framework/blob/main/Quickstart.ipynb Executes a query to retrieve market cap data using the Cortex Analyst tool. ```python agent("What is the market cap of Apple?") ``` -------------------------------- ### Instrument Agent with TruAgent Source: https://context7.com/snowflake-labs/orchestration-framework/llms.txt Wrap an agent with Trulens for observability and evaluation tracking. ```python from agent_gateway import TruAgent from trulens.connectors.snowflake import SnowflakeConnector # Set up Trulens Snowflake connector trulens_connector = SnowflakeConnector( account="your_account", user="your_user", password="your_password", database="TRULENS_DB", schema="TRULENS_SCHEMA", warehouse="your_warehouse" ) # Create instrumented agent tru_agent = TruAgent( app_name="my_analytics_agent", app_version="v1.0", trulens_snowflake_connection=trulens_connector, # Standard Agent parameters snowflake_connection=session, tools=[search_tool, analyst_tool], planner_llm="mistral-large2", agent_llm="mistral-large2" ) # Use like normal agent - all calls are instrumented result = tru_agent("What is the market cap of the top tech companies?") print(result["output"]) # Async usage import asyncio result = asyncio.run(tru_agent.acall("Compare revenue growth across sectors")) print(result["output"]) ``` -------------------------------- ### Query Customer Count Source: https://github.com/snowflake-labs/orchestration-framework/blob/main/Quickstart.ipynb Executes a query to retrieve customer count data using the Cortex Search tool. ```python agent("How many customers does Snowflake have?") ``` -------------------------------- ### Query EBITDA Margin Source: https://github.com/snowflake-labs/orchestration-framework/blob/main/Quickstart.ipynb Executes a query to retrieve normalized EBITDA margin using the SQL tool. ```python agent("What is MSFT's normalized EBITDA margin?") ``` -------------------------------- ### Define Python Callable for Crawler Tool Source: https://github.com/snowflake-labs/orchestration-framework/blob/main/Quickstart.ipynb Creates a Python function `html_crawl` that fetches HTML content from a given URL using the `requests` library. This function is intended to be used as the callable for a Python Tool. ```python import requests def html_crawl(url): response = requests.get(url) return response.text ``` -------------------------------- ### Define SQL Query for EBITDA Margin Calculation Source: https://github.com/snowflake-labs/orchestration-framework/blob/main/Quickstart.ipynb A complex SQL query that calculates the EBITDA Margin for companies in the SP500 dataset and normalizes it against the average EBITDA Margin across all companies. It involves CTEs for calculating margins, averages, and normalized values. ```sql WITH CompanyMetrics AS ( SELECT LONGNAME, SECTOR, INDUSTRY, CURRENTPRICE, MARKETCAP, EBITDA, CASE WHEN MARKETCAP > 0 AND EBITDA IS NOT NULL THEN (EBITDA * 100.0) / MARKETCAP ELSE NULL END AS EBITDA_Margin FROM CUBE_TESTING.PUBLIC.SP500 ), AverageMetrics AS ( SELECT AVG(EBITDA_Margin) AS Average_EBITDA_Margin FROM CompanyMetrics ), NormalizedMetrics AS ( SELECT cm.LONGNAME, cm.SECTOR, cm.INDUSTRY, cm.CURRENTPRICE, cm.MARKETCAP, cm.EBITDA, cm.EBITDA_Margin, CASE WHEN am.Average_EBITDA_Margin > 0 THEN cm.EBITDA_Margin / am.Average_EBITDA_Margin ELSE NULL END AS Normalized_EBITDA_Margin FROM CompanyMetrics cm CROSS JOIN AverageMetrics am ) SELECT LONGNAME, SECTOR, INDUSTRY, CURRENTPRICE, MARKETCAP, EBITDA, EBITDA_Margin, Normalized_EBITDA_Margin FROM NormalizedMetrics; ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.