This guide outlines the process for creating agentic workflows in Snowflake Notebook on Container Runtime using Smolagents from Hugging Face. These agents are capable of writing Python code to call tools and orchestrate other agents. In this guide, we will also see how you can use out of the box tools and also create a custom tool that uses Snowflake Cortex AI.

What is Container Runtime?

Snowflake Notebooks on Container Runtime enable flexible and scalable model development and deployment directly within Snowflake for machine learning and gen AI workflows. Powered by Snowpark Container Services, it provides a flexible environment to build and operationalize various workloads, especially those requiring Python packages from multiple sources and powerful compute resources, including CPUs and GPUs. With this Snowflake-native experience, you can train models, perform hyperparameter tuning, and execute batch inference. Container Runtime offers greater flexibility and tailored compute options for complex modeling workloads. NOTE: This feature is currently in Public Preview.

Learn more about Container Runtime.

What is Snowflake Cortex AI?

Snowflake Cortex is a suite of AI features that use large language models (LLMs) to understand unstructured data, answer freeform questions, and provide intelligent assistance.

Learn more about Snowflake Cortex AI.

What is Smolagents?

It is a lightweight library introduced by Hugging Face that enables language models to perform tasks by writing and executing code. It allows for the creation of agents that can interact with tools, execute multi-step workflows, and integrate with various large language models (LLMs). It supports models hosted on the Hugging Face Hub, as well as those from providers like OpenAI and Anthropic. It also offers first-class support for code agents, facilitating the development of agents that write their actions in code.

Learn more about Smolagents.

Prerequisites

What You Will Learn

What You Will Build

Agentic workflow using Smolagents library and Snowflake Cortex AI in Snowflake Notebook on Container Runtime.

Step 1. In Snowsight, create a SQL Worksheet and open setup.sql to execute all statements in order from top to bottom.

Step 2. In Snowsight, switch your user role to DASH_CONTAINER_RUNTIME_ROLE.

Step 3. Click on huggingface_smolagents_notebook_app.ipynb to download the Notebook from GitHub. (NOTE: Do NOT right-click to download.)

Step 4. In Snowsight:

Step 5. Open Notebook

Here's the code walkthrough of the huggingface_smolagents_notebook_app.ipynb notebook that you downloaded and imported into your Snowflake account.

Cell 1

Install Smolagents library

Cell 2

Here we create instances of HfApiModel, ToolCallingAgent, and CodeAgent to perform web search using built-in DuckDuckGoSearchTool.

Cell 3

Here we use the instance of CodeAgent created in step / cell above and perform a web search using built-in tool (DuckDuckGoSearchTool) given the prompt Top 5 announcements at Snowflake Summit 2024 in JSON format. Only return the JSON formatted output as the response and nothing else.. If all goes well, you should see output similar to the following:

Search Result 1

Cell 4

Here we use the same instance of CodeAgent and perform a web search using prompt Top 5 blog articles on AI. Include blog title and link to the article. Return the response in a Pandas dataframe and nothing else.. If all goes well, you should see output similar to the following:

Search Result 2

Cell 5

Here we create a new tools get_dzone_refcards, read_dzone_refcards, and summarize_article. The first tool retrieves popular DZone Refcards, the second one extracts the content of a given article, and the third one uses Snowflake Cortex Complete function to summarize a given article using Anthropic claude-3-5-sonnet LLM and prompt Summarize the text enclosed in ### in less than 500 words: ### {article_text} ###.Produce JSON output that includes article title, article url, article summary, and 3 highlights from the article..

Cell 6

Here we create a new instance of CodeAgent and provide the three tools created in the previous step with prompt Generate a list of popular DZone RefCard summaries by reading them..

If all goes well, you should see the output similar to the following:

Search Result 3

Congratulations! You've successfully created agentic workflow using smolagents library and Snowflake Cortex AI in Snowflake Notebook on Container Runtime.

What You Learned

Related Resources