Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions clickhouse-chat-agent/.env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# Your Trigger.dev project ref (from the project settings page in the dashboard)
TRIGGER_PROJECT_REF=proj_xxxxxxxxxxxxxxxxxxxxxxxx

# Set these two in the Trigger.dev dashboard (Environment Variables page) so they
# are available in both dev and deployed runs. Uncomment to override locally:
#
# ClickHouse HTTPS endpoint with credentials embedded:
# CLICKHOUSE_URL=https://default:YOUR_PASSWORD@YOUR_SERVICE.clickhouse.cloud:8443
#
# ANTHROPIC_API_KEY=sk-ant-...
3 changes: 3 additions & 0 deletions clickhouse-chat-agent/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
node_modules
.env
.trigger
53 changes: 53 additions & 0 deletions clickhouse-chat-agent/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
# ClickHouse chat agent

A [Trigger.dev chat agent](https://trigger.dev/docs/ai-chat/overview) that answers questions about your data by writing and running SQL against [ClickHouse Cloud](https://clickhouse.com/cloud), using the official [ClickHouse Node.js client](https://clickhouse.com/docs/integrations/javascript).

The agent has three tools:

- **`listTables`** — lists tables with engine, row counts and size (from `system.tables`)
- **`describeTable`** — returns column names and types, using a bound `Identifier` query param (no SQL string interpolation)
- **`runQuery`** — runs read-only SQL: SELECT-style statements only, enforced in code plus `readonly=2`, a 1,000-row cap and a 30s timeout via ClickHouse settings. Query errors are returned to the model so it can fix its SQL and retry.

Trigger.dev handles the chat session, turn loop, streaming and resumability — the agent definition is a single `chat.agent()` call.

## Setup

1. Create a project in the [Trigger.dev dashboard](https://cloud.trigger.dev) and copy its project ref.

2. Configure the project ref:

```sh
cp .env.example .env
# paste your project ref into .env
```

3. In the dashboard, add two environment variables (Environment Variables page) for the Dev environment (and Prod if you deploy):

- `CLICKHOUSE_URL` — your ClickHouse HTTPS endpoint with credentials embedded:
`https://default:YOUR_PASSWORD@YOUR_SERVICE.clickhouse.cloud:8443`
- `ANTHROPIC_API_KEY` — the agent uses Claude via the AI SDK

4. Install and run:

```sh
npm install
npx trigger.dev@latest dev
```

5. Open the **AI agents** page in the dashboard, select `clickhouse-agent`, and chat with it in the playground.

## Try asking

- "What data do I have?"
- "Describe the trips table"
- "What were the top 5 busiest pickup days? Show a table with trip counts and average fares."

If your database is empty, load one of the [ClickHouse example datasets](https://clickhouse.com/docs/getting-started/example-datasets) (e.g. NYC Taxi) from the ClickHouse Cloud SQL console first.

## Deploy

```sh
npx trigger.dev@latest deploy
```

Make sure `CLICKHOUSE_URL` and `ANTHROPIC_API_KEY` are set for the Prod environment in the dashboard.
22 changes: 22 additions & 0 deletions clickhouse-chat-agent/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"name": "clickhouse-chat-agent",
"version": "0.1.0",
"private": true,
"type": "module",
"scripts": {
"dev": "trigger dev",
"deploy": "trigger deploy"
},
"dependencies": {
"@ai-sdk/anthropic": "^3.0.0",
"@clickhouse/client": "^1.12.0",
"@trigger.dev/sdk": "^4.5.1",
"ai": "^6.0.0",
"zod": "^3.25.76"
},
"devDependencies": {
"@types/node": "^22",
"trigger.dev": "^4.5.1",
"typescript": "^5"
}
}
Loading
Loading