This project demonstrates how to quickly build complete Cortex Agents in Snowflake that combine structured data analysis, unstructured conversation search, external API calls, and automated workflows.
By following the steps in this repository, you will learn how to:
- Create Cortex Agents powered by Cortex Analyst for structured sales data.
- Create Cortex Agents powered by Cortex Search for unstructured sales conversation data.
- Develop User Defined Functions (UDFs) to call external stock APIs.
- Orchestrate custom Agents that use your preferred language model.
- Extend Agents with custom tools, including an email-sending stored procedure to deliver reports directly.
The goal is to showcase how easy it is to create a complete end-to-end Cortex Agent pipeline in less than a couple of hours.
- A working Streamlit application (
cortex_agents_v2.py) that lets you create and manage Cortex Agents. - Agents that combine structured analytics, unstructured search, and external APIs.
- A reusable pattern for building additional agents, Cortex Analysts, and Cortex Search integrations.
- An initial foundation for creating more complex "agents of agents".
Cortex-Agents-V2/
│
├── cortex_agents_v2.py # Main Streamlit app for agent orchestration (focus here)
├── models/ # Includes decorative classes & DB connection code
│ ├── sales_metric.yaml # Sales metrics definition (to load into Snowflake stage)
│ └── ...
├── setup.sql # Creates all required Snowflake objects
├── requirements.txt # Python/Streamlit package dependencies
└── README.md # Project documentation (this file)
git clone https://github.com/sarathi-aiml/Cortex-Agents-V2.git
cd Cortex-Agents-V2Make sure you have Python 3.9+ and Snowflake's Snowpark libraries available. Then install dependencies:
pip install -r requirements.txtRun the setup script to create necessary objects (stages, databases, roles, file formats, etc.) in your Snowflake account:
!source setup.sqlUpload the sales_metrics_model.yaml file into the models stage in your Snowflake environment:
PUT file://models/sales_metrics_model.yaml @models;Or use Snowsight UI to upload the file to the models stage
Launch the main Cortex Agent app:
streamlit run cortex_agents_v2.pyFrom here, you will use a simple UI to create and test your agents.
Analyzes structured sales data with metrics defined in sales_metrics_model.yaml. Great for metrics, trends, and sales KPIs.
Searches across unstructured sales conversation data such as call transcripts, meeting notes, or chat logs.
Demonstrates creating a UDF to connect to a stock price API. This shows how agents can connect to external services seamlessly.
Includes a stored procedure for sending reports by email. This can be connected as a custom tool in your agents to automate report delivery.
- Add more Cortex Analysts for other datasets.
- Build new Cortex Search indexes for additional unstructured sources.
- Use UDFs to integrate other APIs (financial, weather, healthcare, etc.).
- Create agents of agents by chaining together multiple reusable agent workflows.
Create new thread and ask the following prompts: try switch thread and ask the followup prompts to see the context is maintained.
-
List all the products we have?
-
which product have high deal value?
-
which is at lowest?
-
List all the sales people name and total sales ?
-
Among these who is top performer?
-
what contributed to their sales?
-
who is at the bottom?
-
What was the out come of last sales conversation and Technical deep dive with HealthTech Solutions Inc? Who is the sales rep assign to this company? what is the total deal value? how is this company HLTT doing in stock market recently?
-
Login to Snowflake
-
Agent Setup
- After creating, click Edit.
- About: Add name, description, and sample questions for user onboarding.
- Tools: Add tools such as Cortex Analyst, Cortex Search, External API Function, and Email Procedure.
- For each tool, provide usage instructions.
- Cortex Analyst: Edit → set Warehouse to “Custom” and select the correct Snowflake warehouse.
- Orchestration: Choose your model and set up orchestration logic:
Use Cortex Analyst for analysis, Cortex Search for documentation/context, general LLM for other queries; always prefer tabular and chart views, explain in detail, respond in English.
- Response Instruction:
Provide detailed insights, cite sources, and explain analysis.
- Access: Assign appropriate roles for agent access.
Enjoy building your end-to-end Cortex Agent workflow!




