How to build a ClickHouse-backed AI Agent with Streamlit
In this guide you'll learn how to build a web-based AI agent using Streamlit that can interact with ClickHouse's SQL playground using ClickHouse's MCP Server and Agno.
This example creates a full web application that provides a chat interface for querying ClickHouse data. You can find the source code for this example in the examples repository.
Prerequisites
- You'll need to have Python installed on your system.
You'll need to have
uv
installed - You'll need an Anthropic API key, or API key from another LLM provider
You can run the following steps to create your Streamlit application.
Create utilities file
Create a utils.py
file with two utility functions. The first is an
asynchronous function generator for handling stream responses from the
Agno agent. The second is a function for applying styles to the Streamlit
application:
Setup credentials
Set your Anthropic API key as an environment variable:
If you don't have an Anthropic API key, and want to use another LLM provider, you can find the instructions for setting up your credentials in the Agno "Integrations" docs
Import required libraries
Start by creating your main Streamlit application file (e.g., app.py
) and add the imports:
Define the agent streaming function
Add the main agent function that connects to ClickHouse's SQL playground and streams responses:
Run the application
To start your ClickHouse AI agent web application you can run the following command from your terminal:
This will open your web browser and navigate to http://localhost:8501
where you
can interact with your AI agent and ask it questions about the example datasets
available in ClickHouse's SQL playground.