> ## 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.

# Agentuity

> Build a data retrieval agent with [Snow Leopard](https://snowleopard.ai) and [Agentuity](https://agentuity.com).

## What You'll Build

A question-answering agent that:

* Leverages Agentuity for easy deployment and monitoring
* Retrieves live data from a SQL database through Snow Leopard
* Requires no MCP setup, no ETL or data pipelines, and no RAG setup for data retrieval

## Prerequisites

* [Agentuity CLI](https://agentuity.dev/Get-Started/installation)
* [Snow Leopard API key](https://auth.snowleopard.ai/account/api_keys)
* A datafile uploaded to [Snow Leopard Playground](https://try.snowleopard.ai)
* OpenAI API key (or another [supported model provider](https://python.langchain.com/docs/integrations/chat/))

<Note>
  Don't have data? Use our [sample Northwind dataset](https://github.com/SnowLeopard-AI/playground_datasets/raw/refs/heads/main/northwind.db) to get started, or choose from our other [sample datasets](https://github.com/SnowLeopard-AI/playground_datasets/).
</Note>

## 1. Create an Agentuity project

```bash theme={null}
agentuity create
```

Follow along with the interactive project create which will create a directory for your agentuity agent. This
quickstart doesn't need auth, db access, or any other options, so feel free to reject any Agentuity features you do
not plan on using.

## 2. Install dependencies

Once you have an Agentuity project and are in its working directory, we will need to add a few new dependencies to add
live data retrieval to your agent.

```bash theme={null}
bun add @snowleopard-ai/client ai zod @ai-sdk/openai
```

## 3. Configure environment variables

Add your API keys and datafile ID to your `.env` file:

```.env .env theme={null}
OPENAI_API_KEY=<your_openai_api_key>
SNOWLEOPARD_API_KEY=<your_snowleopard_api_key>
SNOWLEOPARD_DATAFILE_ID=<your_snowleopard_datafile_id>
```

## 4. Create the Snow Leopard tool

Create a Vercel AI tool that calls Snow Leopard to retrieve data:

```typescript src/agent/getData.ts highlight={5-7,17-20} theme={null}
import { tool } from "ai";
import { z } from "zod";
import { SnowLeopardClient } from "@snowleopard-ai/client";

const snowy = new SnowLeopardClient({
  apiKey: process.env.SNOWLEOPARD_API_KEY!
});

export const getData = tool({
  description:
    'Retrieve data from the database. ' +
    'Describe your data here - this becomes part of the tool description.',
  inputSchema: z.object({
    userQuestion: z.string().describe('the natural language query to answer'),
  }),
  execute: async ({ userQuestion }) => {
    return await snowy.retrieve({
      userQuery: userQuestion,
      datafileId: process.env.SNOWLEOPARD_DATAFILE_ID!
    });
  },
});
```

## 5. Create the agent

Build an Agentuity agent that uses the Snow Leopard tool:

```typescript src/agent/agent.ts theme={null}
import { createAgent } from '@agentuity/runtime';
import { s } from '@agentuity/schema';
import { generateText, type ModelMessage } from 'ai';
import { openai } from '@ai-sdk/openai';
import { getData } from './getData';

const agent = createAgent('chat', {
  description: 'A chat agent with data retrieval',
  handler: async (ctx, { message }) => {
    const messages: ModelMessage[] = [
      { role: 'system', content: 'You are a helpful assistant that answers questions using your data tools.' },
      { role: 'user', content: message }
    ];

    for (let step = 0; step < 10; step++) {
      const result = await generateText({
        model: openai('gpt-5-mini'),
        messages: messages,
        tools: { getData }
      });
      messages.push(...result.response.messages);
      if (result.finishReason !== 'tool-calls') {
        return { response: result.text };
      }
    }
    throw new Error('Agent exceeded maximum number of steps');
  },
  schema: {
    input: s.object({ message: s.string() }),
    output: s.object({ response: s.string() }),
  },
});

export default agent;
```

## 6. Expose the agent via HTTP

Add an API route to handle chat requests:

```typescript src/api/index.ts theme={null}
import { createRouter } from '@agentuity/runtime';
import chat from '../agent/agent';

const api = createRouter();
/*
Existing api definitions...
 */

api.post('/chat', chat.validator(), async (c) => {
  const data = c.req.valid('json');
  return await chat.run(data);
});

export default api;
```

## 7. Try it out!

Start your development server:

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

Query your data:

```bash theme={null}
curl -X POST http://localhost:3500/api/chat \
  -H "Content-Type: application/json" \
  -d '{"message": "How many customers do we have?"}'
```

```json theme={null}
{
  "response": "You have 91 customers (counted as non-null customer_id entries in the customers table).  \n\nWould you like a breakdown by segment, region, sign-up date, or any other criteria?"
}
```

## Next steps

* View the [full example on GitHub](https://github.com/SnowLeopard-AI/snowy-examples/tree/main/quickstart/agentuity)
* Learn more about [Agentuity agents](https://agentuity.dev/Learn/Cookbook/Tutorials/rag-agent)
* See our full [API documentation](https://docs.snowleopard.ai/) to learn about the [Retrieve](/playground/endpoints/retrieve) and [Response](/playground/endpoints/response) endpoints
* Explore [Recipes](/recipes) for more agent examples
