ai-chat-application
Complete guide to building AI chat applications with Vercel AI SDK. Orchestrates streaming routes, useChat integration, tool architecture, message handling, and UX patterns. Use when building production AI chatbots or assistants. Triggers on build AI chat, create chatbot, AI assistant, Vercel AI SDK app, chat application.
Best use case
ai-chat-application is best used when you need a repeatable AI agent workflow instead of a one-off prompt.
Complete guide to building AI chat applications with Vercel AI SDK. Orchestrates streaming routes, useChat integration, tool architecture, message handling, and UX patterns. Use when building production AI chatbots or assistants. Triggers on build AI chat, create chatbot, AI assistant, Vercel AI SDK app, chat application.
Teams using ai-chat-application should expect a more consistent output, faster repeated execution, less prompt rewriting.
When to use this skill
- You want a reusable workflow that can be run more than once with consistent structure.
When not to use this skill
- You only need a quick one-off answer and do not need a reusable workflow.
- You cannot install or maintain the underlying files, dependencies, or repository context.
Installation
Claude Code / Cursor / Codex
Manual Installation
- Download SKILL.md from GitHub
- Place it in
.claude/skills/ai-chat-application/SKILL.mdinside your project - Restart your AI agent — it will auto-discover the skill
How ai-chat-application Compares
| Feature / Agent | ai-chat-application | Standard Approach |
|---|---|---|
| Platform Support | Not specified | Limited / Varies |
| Context Awareness | High | Baseline |
| Installation Complexity | Unknown | N/A |
Frequently Asked Questions
What does this skill do?
Complete guide to building AI chat applications with Vercel AI SDK. Orchestrates streaming routes, useChat integration, tool architecture, message handling, and UX patterns. Use when building production AI chatbots or assistants. Triggers on build AI chat, create chatbot, AI assistant, Vercel AI SDK app, chat application.
Where can I find the source code?
You can find the source code on GitHub using the link provided at the top of the page.
SKILL.md Source
# AI Chat Application (Meta-Skill)
Complete guide to building production AI chat applications with the Vercel AI SDK.
## Installation
### OpenClaw / Moltbot / Clawbot
```bash
npx clawhub@latest install ai-chat-application
```
---
## When to Use
- Building a new AI chatbot or assistant
- Adding AI chat features to an existing app
- Need end-to-end guidance on AI chat architecture
---
## Architecture Overview
```
┌─────────────────────────────────────────────────────────────┐
│ Client (React) │
├─────────────────────────────────────────────────────────────┤
│ useChat Hook │ Data Stream Handler │
│ - messages, input, submit │ - Custom data events │
│ - isLoading, error │ - Message annotations │
│ See: vercel-ai-chat-integration │ See: vercel-ai-data-streaming
├─────────────────────────────────────────────────────────────┤
│ API Route (Next.js) │
│ - createDataStreamResponse, streamText, message persistence│
│ See: ai-streaming-routes │
├─────────────────────────────────────────────────────────────┤
│ Tool System │
│ - Toolkit composition, singleton factories, error handling │
│ See: ai-tool-composition, vercel-ai-tool-architecture │
├─────────────────────────────────────────────────────────────┤
│ Message Handling │
│ - DB ↔ UI conversion, sanitization, annotations │
│ See: ai-message-handling │
└─────────────────────────────────────────────────────────────┘
```
---
## Implementation Steps
### Step 1: API Route
Create the streaming chat endpoint.
**Read:** `ai/skills/ai-chat/ai-streaming-routes`
```typescript
// app/api/chat/route.ts
export async function POST(request: Request) {
const { id, messages, modelId } = await request.json();
// Auth, validation, save user message...
return createDataStreamResponse({
execute: (dataStream) => {
const result = streamText({
model: customModel(model),
system: systemPrompt,
messages: convertToCoreMessages(messages),
tools: makeToolkitByName(model.toolkit, params),
onFinish: async ({ response }) => {
// Save assistant messages
},
});
result.mergeIntoDataStream(dataStream);
},
});
}
```
### Step 2: Chat Component
Build the client-side chat interface.
**Read:** `ai/skills/ai-chat/vercel-ai-chat-integration`
```tsx
// components/chat.tsx
export function Chat({ id, initialMessages }: ChatProps) {
const { messages, input, handleSubmit, isLoading } = useChat({
id,
initialMessages,
experimental_throttle: 100,
onError: (error) => toast.error(parseError(error)),
});
return (
<div>
<Messages messages={messages} isLoading={isLoading} />
<ChatInput value={input} onSubmit={handleSubmit} />
</div>
);
}
```
### Step 3: UX Polish
Add auto-scroll and loading states.
```tsx
const [containerRef, endRef] = useScrollToBottom();
{isLoading && lastMessage?.role === 'user' && <ThinkingMessage />}
```
### Step 4: Tool System
Add function calling capabilities.
**Read:** `ai/skills/ai-chat/ai-tool-composition`
```typescript
// lib/tools/allTools.ts
export function allToolsToolkit(params: ToolkitParams) {
return {
...makeWeb3Tools(params),
...makeSearchTools(params),
getTime: tool({ /* inline tool */ }),
};
}
```
### Step 5: Message Persistence
Handle message format conversion and persistence.
**Read:** `ai/skills/ai-chat/ai-message-handling`
```typescript
// Convert DB → UI on page load
const uiMessages = convertToUIMessages(dbMessages);
// Sanitize before save
const cleanMessages = sanitizeResponseMessages(response.messages);
```
---
## Component Skills Reference
| Skill | Purpose |
|-------|---------|
| `vercel-ai-chat-integration` | useChat hook patterns |
| `vercel-ai-data-streaming` | Custom data events |
| `vercel-ai-tool-architecture` | Tool system design |
| `ai-streaming-routes` | API route patterns |
| `ai-message-handling` | Format conversion |
| `ai-tool-composition` | Tool factories |
---
## NEVER Do
- **Never skip error handling in useChat** — AI APIs fail; always handle onError
- **Never forget to sanitize messages before persistence** — Incomplete tool calls corrupt DB
- **Never skip throttling for streaming** — Causes janky UI with fast token streams
- **Never expose raw API errors to users** — Parse and show user-friendly messages
- **Never block on tool calls without timeout** — Tools can hang; set maxSteps and timeouts
- **Never save user messages in onFinish** — Save immediately before streaming starts
- **Never forget maxDuration on API route** — Default timeout is too short for AI
- **Never skip message annotations** — Client needs server-generated IDs for persistence
- **Never mutate messages during streaming** — Wait for onFinish before state updates
---
## Quick Start Checklist
- [ ] Create API route with createDataStreamResponse
- [ ] Set up useChat hook in client component
- [ ] Add message persistence (save/load)
- [ ] Implement auto-scroll behavior
- [ ] Add thinking indicator
- [ ] Create tool system (if needed)
- [ ] Define AI persona via system prompt
- [ ] Handle errors gracefully
- [ ] Add throttling for smooth streamingRelated Skills
schema-markup
Add, fix, or optimize schema markup and structured data. Use when the user mentions schema markup, structured data, JSON-LD, rich snippets, schema.org, FAQ schema, product schema, review schema, or breadcrumb schema.
prompt-engineering
Master advanced prompt engineering techniques to maximize LLM performance, reliability, and controllability in production. Use when optimizing prompts, improving LLM outputs, designing production prompt templates, or building AI-powered features.
professional-communication
Write effective professional messages for software teams. Use when drafting emails, Slack/Teams messages, meeting agendas, status updates, or translating technical concepts for non-technical audiences. Triggers on email, slack, teams, message, meeting agenda, status update, stakeholder communication, escalation, jargon translation.
persona-docs
Create persona documentation for a product or codebase. Use when asked to create persona docs, document target users, define user journeys, document onboarding flows, or when starting a new product and needing to define its audience. Persona docs should be the first documentation created for any product.
mermaid-diagrams
Create software diagrams using Mermaid syntax. Use when users need to create, visualize, or document software through diagrams including class diagrams, sequence diagrams, flowcharts, ERDs, C4 architecture diagrams, state diagrams, git graphs, and other diagram types. Triggers include requests to diagram, visualize, model, map out, or show the flow of a system.
game-changing-features
Find 10x product opportunities and high-leverage improvements. Use when the user wants strategic product thinking, mentions 10x, wants to find high-impact features, or asks what would make a product dramatically more valuable.
clear-writing
Write clear, concise prose for humans — documentation, READMEs, API docs, commit messages, error messages, UI text, reports, and explanations. Combines Strunk's rules for clearer prose with technical documentation patterns, structure templates, and review checklists.
brainstorming
Explore ideas before implementation through collaborative dialogue. Use before any creative work — creating features, building components, adding functionality, or modifying behavior. Turns ideas into fully formed designs and specs through structured conversation.
Article Illustrator
When the user wants to add illustrations to an article or blog post. Triggers on: "illustrate article", "add images to article", "generate illustrations", "article images", or requests to visually enhance written content. Analyzes article structure, identifies positions for visual aids, and generates illustrations using a Type x Style two-dimension approach.
subagent-driven-development
Execute implementation plans by dispatching a fresh subagent per task with two-stage review (spec compliance then code quality). Use when you have an implementation plan with mostly independent tasks and want high-quality, fast iteration within a single session.
skill-judge
Evaluate Agent Skill quality against official specifications. Use when reviewing SKILL.md files, auditing skill packages, improving skill design, or checking if a skill follows best practices. Provides 8-dimension scoring (120 points) with actionable improvements. Triggers on review skill, evaluate skill, audit skill, improve skill, skill quality, SKILL.md review.
skill-creator
WHAT: Guide for creating effective AI agent skills - modular packages that extend Claude's capabilities with specialized knowledge, workflows, and tools. WHEN: User wants to create, write, author, or update a skill. User asks about skill structure, SKILL.md format, or how to package domain knowledge for AI agents. KEYWORDS: "create a skill", "make a skill", "new skill", "skill template", "SKILL.md", "agent skill", "write a skill", "skill structure", "package a skill"