Production-ready patterns for building AI agents with Mastra. Each pattern is registry-downloadable — install with one command, customize, deploy.
npx shadcn add https://ai-sdk-patterns.dev/r/mastra-agent-basicCreate a Mastra agent with tools, register it in a Mastra instance, and call it with generate() or stream().
Create typed tools with Zod schemas that agents can call. Includes input validation, output schemas, and error handling.
Build multi-step workflows with createStep and createWorkflow. Chain steps with .then(), run in parallel, or branch conditionally.
Add conversation memory to agents with message history, working memory for user preferences, and semantic recall.
Build a retrieval-augmented generation pipeline with document chunking, vector embeddings, and semantic search.
Compose multiple agents into a network where a router agent delegates tasks to specialized sub-agents.
Suspend a workflow mid-execution to collect human approval, then resume with the decision. Essential for agent guardrails.
Use background agents to maintain a dense observation log that replaces raw message history. Keeps context small while preserving long-term memory.
Force agents to return typed, validated JSON using Zod schemas. Perfect for extraction, classification, and data transformation tasks.
Add input/output guardrails to agents for content filtering, PII detection, and response validation before they reach users.