> ## Documentation Index
> Fetch the complete documentation index at: https://docs.snowleopard.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Data Agent (CopilotKit + Pydantic)

> Build a "chat with your data" application using CopilotKit and Pydantic AI.

An application that lets users chat with their data through a web UI. Built with [CopilotKit](https://copilotkit.ai/) for the frontend and [Pydantic AI](https://ai.pydantic.dev/) for the backend agent.

<Card title="Try the live demo" href="https://try.snowleopard.ai/demos/data-agent">
  <Frame>
    <img src="https://github.com/SnowLeopard-AI/snowy-examples/raw/main/agent_examples/chat_with_your_data_copilotkit/data_agent.png" alt="Chat with your data agent screenshot" />
  </Frame>
</Card>

## What it does

This agent provides a chat interface for querying your data in natural language. Users can:

* Ask questions about their data in plain English
* View query results in a formatted table
* Have multi-turn conversations to drill down into the data

The agent translates natural language questions into SQL queries via Snow Leopard, executes them, and presents results in a user-friendly format.

## Architecture

The application has two main components:

### Frontend (Next.js + CopilotKit)

* **Next.js** provides the web application framework
* **CopilotKit** provides the chat UI components and handles communication with the backend agent
* **Data tables** display query results returned from the agent

### Backend (Pydantic AI + Snow Leopard)

* **Pydantic AI** agent with two tools:
  * `get_data`: Calls Snow Leopard to convert natural language to SQL and retrieve results
  * `read_get_data_response`: Allows paginated reading of large result sets
* **AG-UI state management** keeps the frontend in sync with query results
* **Snow Leopard** handles natural language to SQL conversion

## Run the example

### Prerequisites

* Python 3.12+
* Node.js 20+
* [uv](https://docs.astral.sh/uv/) package manager
* pnpm (or npm)
* OpenAI API key
* [Snow Leopard API key](https://auth.snowleopard.ai/account/api_keys)
* A datafile uploaded to [Snow Leopard Playground](https://try.snowleopard.ai)

<Note>
  Don't have data? This example uses northwind.db, a public sales database. You can download it from our [sample datasets](https://github.com/SnowLeopard-AI/playground_datasets/) using [this link](https://github.com/SnowLeopard-AI/playground_datasets/raw/refs/heads/main/northwind.db).
</Note>

### Setup

Clone the [repository](https://github.com/SnowLeopard-AI/snowy-examples/tree/main/agent_examples/chat_with_your_data_copilotkit):

```bash theme={null}
git clone https://github.com/SnowLeopard-AI/snowy-examples.git
cd snowy-examples/agent_examples/chat_with_your_data_copilotkit
```

Install dependencies:

```bash theme={null}
pnpm install
```

Create a `.env` file in the `agent` folder:

```bash theme={null}
OPENAI_API_KEY=your-openai-key
SNOWLEOPARD_API_KEY=your-snowleopard-key
SNOWLEOPARD_DATAFILE_ID=your-datafile-id
```

Start the development server:

```bash theme={null}
pnpm dev
```

This starts both the UI and agent servers. Open [http://localhost:3000](http://localhost:3000) to start chatting with your data.

## Next steps

* View the [full source code on GitHub](https://github.com/SnowLeopard-AI/snowy-examples/tree/main/agent_examples/chat_with_your_data_copilotkit)
* Learn more about [CopilotKit](https://docs.copilotkit.ai/)
* Explore the [Pydantic AI quickstart](/quickstarts/pydantic-ai)
