Skip to main content
21st.dev provides an agent SDK for building, deploying, and connecting AI agents to frontends. The Nia Chat template combines 21st Agents SDK with Nia’s knowledge tools to create a repository chat experience — users pick a GitHub repo, the app indexes it via Nia, and an agent answers questions using the full codebase as context.
Live demo: Try the hosted example at 21st-sdk-nia-chat.vercel.app before setting up locally.

How it works

1

User enters a GitHub repo

The app normalizes the input and indexes the repository via the Nia API (/api/nia/source).
2

Sandbox + thread created

A sandboxed agent environment is created with Nia skill scripts baked in (/api/agent/sandbox).
3

Chat streams responses

The frontend connects to the agent using createAgentChat + useChat and streams answers grounded in the indexed codebase.
The agent runs inside a sandbox with Nia skill scripts (shell wrappers around the Nia REST API) baked in at deploy time. This gives it the ability to search, read, and explore the indexed repository.

Features

Repository Analysis

Index any public GitHub repo and ask questions about its architecture, patterns, and implementation details.

Codebase Chat

Natural language conversation grounded in the full repository — not just file summaries.

Sandboxed Agents

Each agent runs in an isolated sandbox with Nia tools pre-installed via the 21st Agents SDK.

Multi-thread Sessions

Create multiple conversation threads per sandbox, persisted in localStorage.

Stack

Next.js

App Router with API routes for agent management.

21st Agents SDK

Agent definition, deployment, and frontend streaming.

Nia MCP

Knowledge tools for search, read, explore, and grep.

Requirements

NIA_API_KEY must exist both in .env.local (for the Next.js server to resolve/index repos) and in the deployed sandbox environment (for the Nia skill scripts).

Quick start

Clone the repo and install dependencies:
git clone https://github.com/21st-dev/an-examples.git
cd an-examples/nia-chat
cp .env.example .env.local
pnpm install
Set API_KEY_21ST and NIA_API_KEY in .env.local, then deploy the agent and start the dev server:
npx @21st-sdk/cli login
npx @21st-sdk/cli deploy
pnpm dev
Open http://localhost:3000.

Key files

FileWhat it does
agents/nia-agent-v2/index.tsAgent definition — model, system prompt, sandbox setup. Uses @21st-sdk/agent.
agents/nia-agent-v2/template/.claude/skills/nia/Nia skill scripts baked into the sandbox. Shell wrappers for search, read, explore, etc.
app/api/nia/source/route.tsNormalizes the repo input, then resolves (or indexes) it via the Nia SDK.
app/api/agent/sandbox/route.tsCreates a sandbox + thread via AgentClient from @21st-sdk/node.
app/api/agent/token/route.tsToken endpoint using createTokenHandler from @21st-sdk/nextjs/server.
app/api/agent/threads/route.tsLists/creates threads within a sandbox for multi-thread sessions.
app/page.tsxMain UI — repo picker, chat panel, thread sidebar.

Building something similar

The core pattern for building an agent-powered app with Nia knowledge:
1

Define your agent

Use @21st-sdk/agent to set the model, system prompt, and any tools/skills to include in the template directory.
2

Deploy the sandbox

Run npx @21st-sdk/cli deploy to bake the template into the sandbox image.
3

Create API routes

Set up sandbox/thread management with AgentClient and a token endpoint with createTokenHandler.
4

Connect the frontend

Use createAgentChat() bound to a sandbox + thread, then pass it to useChat() from @ai-sdk/react for streaming.
To add external knowledge (like Nia), index sources server-side before the chat starts, then give the agent skill scripts or MCP tools so it can query those sources at runtime.

Need Help? Join our Discord community or reach out through app.trynia.ai for support.