|
| 1 | +--- |
| 2 | +slug: /use-cases/AI/MCP/ai-agent-libraries/agno |
| 3 | +sidebar_label: 'Integrate Agno' |
| 4 | +title: 'How to build an AI Agent with Agno and the ClickHouse MCP Server' |
| 5 | +pagination_prev: null |
| 6 | +pagination_next: null |
| 7 | +description: 'Learn how build an AI Agent with Agno and the ClickHouse MCP Server' |
| 8 | +keywords: ['ClickHouse', 'MCP', 'Agno'] |
| 9 | +show_related_blogs: true |
| 10 | +--- |
| 11 | + |
| 12 | +# How to build an AI Agent with Agno and the ClickHouse MCP Server |
| 13 | + |
| 14 | +In this guide you'll learn how to build an [Agno](https://github.com/agno-agi/agno) AI agent that can interact with |
| 15 | +[ClickHouse's SQL playground](https://sql.clickhouse.com/) using [ClickHouse's MCP Server](https://github.com/ClickHouse/mcp-clickhouse). |
| 16 | + |
| 17 | +:::note Example notebook |
| 18 | +This example can be found as a notebook in the [examples repository](https://github.com/ClickHouse/examples/blob/main/ai/mcp/agno/agno.ipynb). |
| 19 | +::: |
| 20 | + |
| 21 | +## Prerequisites {#prerequisites} |
| 22 | +- You'll need to have python installed on your system. |
| 23 | +- You'll need to have `pip` installed on your system. |
| 24 | +- You'll need an Anthropic API key, or API key from another LLM provider |
| 25 | + |
| 26 | +You can run the following steps either from your python REPL or via script. |
| 27 | + |
| 28 | +<VerticalStepper headerLevel="h2"> |
| 29 | + |
| 30 | +## Install libraries {#install-libraries} |
| 31 | + |
| 32 | +Install the Agno library by running the following commands: |
| 33 | + |
| 34 | +```python |
| 35 | +!pip install -q --upgrade pip |
| 36 | +!pip install -q agno |
| 37 | +!pip install -q ipywidgets |
| 38 | +``` |
| 39 | + |
| 40 | +## Setup credentials {#setup-credentials} |
| 41 | + |
| 42 | +Next, you'll need to provide your Anthropic API key: |
| 43 | + |
| 44 | +```python |
| 45 | +import os, getpass |
| 46 | +os.environ["ANTHROPIC_API_KEY"] = getpass.getpass("Enter Anthropic API Key:") |
| 47 | +``` |
| 48 | + |
| 49 | +```response title="Response" |
| 50 | +Enter Anthropic API Key: ········ |
| 51 | +``` |
| 52 | + |
| 53 | +:::note Using another LLM provider |
| 54 | +If you don't have an Anthropic API key, and want to use another LLM provider, |
| 55 | +you can find the instructions for setting up your credentials in the [DSPy docs](https://dspy.ai/#__tabbed_1_1) |
| 56 | +::: |
| 57 | + |
| 58 | +Next, define the credentials needed to connect to the ClickHouse SQL playground: |
| 59 | + |
| 60 | +```python |
| 61 | +env = { |
| 62 | + "CLICKHOUSE_HOST": "sql-clickhouse.clickhouse.com", |
| 63 | + "CLICKHOUSE_PORT": "8443", |
| 64 | + "CLICKHOUSE_USER": "demo", |
| 65 | + "CLICKHOUSE_PASSWORD": "", |
| 66 | + "CLICKHOUSE_SECURE": "true" |
| 67 | +} |
| 68 | +``` |
| 69 | + |
| 70 | +## Initialize MCP Server and Agno agent {#initialize-mcp-and-agent} |
| 71 | + |
| 72 | +Now configure the ClickHouse MCP Server to point at the ClickHouse SQL playground |
| 73 | +and also initialize our Agno agent and ask it a question: |
| 74 | + |
| 75 | +```python |
| 76 | +from agno.agent import Agent |
| 77 | +from agno.tools.mcp import MCPTools |
| 78 | +from agno.models.anthropic import Claude |
| 79 | +``` |
| 80 | + |
| 81 | +```python |
| 82 | +async with MCPTools(command="uv run --with mcp-clickhouse --python 3.13 mcp-clickhouse", env=env, timeout_seconds=60) as mcp_tools: |
| 83 | + agent = Agent( |
| 84 | + model=Claude(id="claude-3-5-sonnet-20240620"), |
| 85 | + markdown=True, |
| 86 | + tools = [mcp_tools] |
| 87 | + ) |
| 88 | +await agent.aprint_response("What's the most starred project in 2025?", stream=True) |
| 89 | +``` |
| 90 | + |
| 91 | +```response title="Response" |
| 92 | +▰▱▱▱▱▱▱ Thinking... |
| 93 | +┏━ Message ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓ |
| 94 | +┃ ┃ |
| 95 | +┃ What's the most starred project in 2025? ┃ |
| 96 | +┃ ┃ |
| 97 | +┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛ |
| 98 | +┏━ Tool Calls ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓ |
| 99 | +┃ ┃ |
| 100 | +┃ • list_tables(database=github, like=%) ┃ |
| 101 | +┃ • run_select_query(query=SELECT ┃ |
| 102 | +┃ repo_name, ┃ |
| 103 | +┃ SUM(count) AS stars_2025 ┃ |
| 104 | +┃ FROM github.repo_events_per_day ┃ |
| 105 | +┃ WHERE event_type = 'WatchEvent' ┃ |
| 106 | +┃ AND created_at >= '2025-01-01' ┃ |
| 107 | +┃ AND created_at < '2026-01-01' ┃ |
| 108 | +┃ GROUP BY repo_name ┃ |
| 109 | +┃ ORDER BY stars_2025 DESC ┃ |
| 110 | +┃ LIMIT 1) ┃ |
| 111 | +┃ ┃ |
| 112 | +┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛ |
| 113 | +┏━ Response (34.9s) ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓ |
| 114 | +┃ ┃ |
| 115 | +┃ To answer your question about the most starred project in 2025, I'll need to query the ClickHouse database. ┃ |
| 116 | +┃ However, before I can do that, I need to gather some information and make sure we're looking at the right data. ┃ |
| 117 | +┃ Let me check the available databases and tables first.Thank you for providing the list of databases. I can see ┃ |
| 118 | +┃ that there's a "github" database, which is likely to contain the information we're looking for. Let's check the ┃ |
| 119 | +┃ tables in this database.Now that we have information about the tables in the github database, we can query the ┃ |
| 120 | +┃ relevant data to answer your question about the most starred project in 2025. We'll use the repo_events_per_day ┃ |
| 121 | +┃ table, which contains daily event counts for each repository, including star events (WatchEvents). ┃ |
| 122 | +┃ ┃ |
| 123 | +┃ Let's create a query to find the most starred project in 2025:Based on the query results, I can answer your ┃ |
| 124 | +┃ question about the most starred project in 2025: ┃ |
| 125 | +┃ ┃ |
| 126 | +┃ The most starred project in 2025 was deepseek-ai/DeepSeek-R1, which received 84,962 stars during that year. ┃ |
| 127 | +┃ ┃ |
| 128 | +┃ This project, DeepSeek-R1, appears to be an AI-related repository from the DeepSeek AI organization. It gained ┃ |
| 129 | +┃ significant attention and popularity among the GitHub community in 2025, earning the highest number of stars ┃ |
| 130 | +┃ for any project during that year. ┃ |
| 131 | +┃ ┃ |
| 132 | +┃ It's worth noting that this data is based on the GitHub events recorded in the database, and it represents the ┃ |
| 133 | +┃ stars (WatchEvents) accumulated specifically during the year 2025. The total number of stars for this project ┃ |
| 134 | +┃ might be higher if we consider its entire lifespan. ┃ |
| 135 | +┃ ┃ |
| 136 | +┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛ |
| 137 | +``` |
| 138 | + |
| 139 | +</VerticalStepper> |
0 commit comments