AI SDK Patterns
that compose into apps
26+ open-source, composable AI SDK patterns — chat, agents, tools, workflows. Pick patterns, generate a full-stack Next.js app.
✓ Streaming response readyProvider: anthropic | Model: claude-sonnet-4-5Provider-agnostic — works with any AI SDK provider
Interactive feature showcase
Explore core AI SDK capabilities with animated examples. Click any card to see the actual pattern implementation.
26 patterns, free and composable
Use individually or combine them into one app with the Composer
Streaming Chat
PopularStream text responses from AI models in real-time using streamText and the useChat hook.
"name": "..."
"score": 42
}
Structured Output
Generate typed, validated JSON data using Zod schemas and the generateObject function.
Tool Calling
PopularLet the AI model call functions and use external tools with the multi-step tool loop.
Generative UI
Render dynamic React components from AI tool calls using streamText and useChat.
Multi-Step Agent
PopularBuild an agent that orchestrates multiple tool calls in sequence, using the AI SDK's maxSteps and automatic tool result forwarding.
Web Search Agent
Integrate third-party search APIs (Tavily, Exa) with the AI SDK to build a grounded search agent with source citations.
Human-in-the-Loop
Pause AI execution to get human approval before executing sensitive tool calls. Uses tool confirmation flow with the AI SDK.
RAG Pipeline
PopularRetrieval-Augmented Generation: embed documents, store in a vector database, and retrieve context for grounded AI responses.
Reasoning Display
Show the AI's chain-of-thought reasoning in a collapsible thinking section, then display the final answer — like Claude's extended thinking.
Image Generation
Generate images from text prompts using generateImage. Enter a description, click generate, and see the AI-created image.
Code Artifact
PopularAI-powered code generation with syntax highlighting and copy support. Describe what you need, and the AI generates clean, runnable code.
Chat with Citations
A chat interface that includes inline source citations with expandable source cards. Responses include numbered references that link to source details.
Durable Multi-Turn Chat Agent
Stateful conversation agent with Workflow DevKit that persists messages across pauses/resumes, calls tools, and streams responses using DurableAgent.
MCP Client Agent
NewConnect to any Model Context Protocol server, discover tools dynamically, and let the AI use them in a chat interface. Includes a demo MCP server with weather and calculator tools.
Text-to-SQL
NewNatural language to SQL: ask questions about data in plain English, the AI generates and executes SQL queries, and displays results in a table. Uses an in-memory SQLite database with sample data.
Multi-Modal Chat
NewChat with images, files, and text in a single conversation. Drag-and-drop or paste images for vision analysis, attach files for context, and get AI responses that understand all modalities.
Mastra Agent
NewCreate a Mastra agent with tools, register it in a Mastra instance, and call it with generate() or stream().
"id": "search"
"input": z.object()
"execute": async →
}
Mastra Tool
NewCreate typed tools with Zod schemas that agents can call. Includes input validation, output schemas, and error handling.
Mastra Workflow
NewBuild multi-step workflows with createStep and createWorkflow. Chain steps with .then(), run in parallel, or branch conditionally.
Mastra Memory
NewAdd conversation memory to agents with message history, working memory for user preferences, and semantic recall.
Mastra RAG
NewBuild a retrieval-augmented generation pipeline with document chunking, vector embeddings, and semantic search.
Mastra Multi-Agent
NewCompose multiple agents into a network where a router agent delegates tasks to specialized sub-agents.
Mastra Human-in-the-Loop
NewSuspend a workflow mid-execution to collect human approval, then resume with the decision. Essential for agent guardrails.
Mastra Observational Memory
NewUse background agents to maintain a dense observation log that replaces raw message history. Keeps context small while preserving long-term memory.
"name": string
"email": email
"topics": string[]
}
Mastra Structured Output
NewForce agents to return typed, validated JSON using Zod schemas. Perfect for extraction, classification, and data transformation tasks.
Mastra Guardrails
NewAdd input/output guardrails to agents for content filtering, PII detection, and response validation before they reach users.
One pattern or many — your call
Install a single pattern via CLI, or use the Composer to merge several into one integrated Next.js app.
npx shadcn add https://ai-sdk-patterns.vercel.app/r/streaming-chat100% open source — no accounts, no paywalls