mastra-build-playbook
Skill2 starsChanged 29 days agoApache-2.0View on GitHub
End-to-end playbook for building a production AI app with Mastra, from framing the job through a first working agent, context design, safety, an eval loop, observability, integration, and deployment. Use this skill whenever the user wants to build a complete Mastra app or agent product, plan a Mastra project, take a prototype to production, or asks how to go from idea to deployed agent. Triggers on build an app with Mastra, Mastra project plan, from prototype to production, ship a Mastra agent, Mastra best practices, Mastra architecture plan, end to end Mastra, production-ready agent. Also triggers when a request spans several Mastra features at once (agent plus memory plus UI plus deploy), even if the user does not ask for a plan.
- Reads credentials
In this repository46 other files it gives its agents.
- mastra-a2a-acpSkill
- mastra-agent-approval-hitlSkill
- mastra-agentic-uiSkill
- mastra-agent-skillsSkill
- mastra-agentsSkill
- mastra-authSkill
- mastra-browserSkill
- mastra-channelsSkill
- mastra-classifierSkill
- mastra-cli-apiSkill
- mastra-client-sdkSkill
- mastra-datasets-experimentsSkill
- mastra-deploymentSkill
- mastra-evalsSkill
- mastra-file-based-agentsSkill
- mastra-framework-integrationSkill
- mastra-guideSkill
- mastra-harnessSkill
- mastra-knowledgeSkill
- mastra-mcpSkill
- mastra-memorySkill
- mastra-migrationsSkill
- mastra-modelsSkill
- mastra-multi-agentSkill
- mastra-observabilitySkill
- mastra-observational-memorySkill
- mastra-platformSkill
- mastra-processors-guardrailsSkill
- mastra-project-setupSkill
- mastra-ragSkill
- mastra-schedulesSkill
- mastra-semantic-recallSkill
- mastra-serverSkill
- mastra-signalsSkill
- mastra-storageSkill
- mastra-streamingSkill
- mastra-structured-outputSkill
- mastra-studio-editorSkill
- mastra-tool-integrationsSkill
- mastra-toolsSkill
- mastra-troubleshootingSkill
- mastra-vector-storesSkill
- mastra-voiceSkill
- mastra-workflowsSkill
- mastra-workflow-suspend-resumeSkill
- mastra-workspace-sandboxSkill
The file
Show its rules and text
We split this skill into the rules it gives an agent
14 rules. About 0 are common, 7 are distinctive, and 7 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈7
Distinctive · estimate
This author's own choices. Worth a look.
7
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- could be automatic: a setting could enforce it
- Very specific: line 28
Only creating the project scaffold (use mastra-project-setup)
- Very specific: line 29
Only setting up evals (use mastra-evals and mastra-datasets-experiments)
- Very specific: line 30
Only deploying an existing app (use mastra-deployment or mastra-platform)
- Distinctive: line 42
If the user cannot state a correct outcome for three real inputs, do phase 1 before writing code.
- Distinctive: line 92
Run it in Studio before adding anything else.
- Very specific: line 99
Frame the job: Write five test cases as { input, groundTruth: { must: [...], mustNot: [...] } }.
- Very specific: line 102
Design context: Use the context table in mastra-guide.
- Distinctive: line 104
Build the eval loop: Create the dataset, an LLM judge scorer from a different provider than the agent, and a baseline experiment.
- Distinctive: line 108
Operate: Add failing production traces to the dataset.
- Distinctive: line 116
Keep the dataset and the judge fixed while changing the agent.
- Distinctive: line 117
Use a binary judge (1 pass, 0 fail) for policy correctness.
- Distinctive: line 118
Treat the judge as fallible.
- Very specific: line 131
Unbounded agent loops: Always set maxSteps and timeouts.
- Very specific: line 133
Secrets in code or committed
.envfiles: Keep keys in the environment and .env.example without values.
≈ “Common” is an estimate: at least 1 in 5 of the 408,460 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
Mastra Build Playbook
Take a Mastra app from idea to production in nine phases, each with an exit gate and the skill that does the work.
When to use
- Starting a new Mastra product or agent feature from scratch
- Turning a working prototype into something you can ship
- Planning which Mastra features a project needs, in what order
- Reviewing a Mastra project for production gaps
When NOT to use
- A single, already-scoped feature (go to its skill through
mastra-guide) - Only creating the project scaffold (use
mastra-project-setup) - Only setting up evals (use
mastra-evalsandmastra-datasets-experiments) - Only deploying an existing app (use
mastra-deploymentormastra-platform) - Fixing an error (use
mastra-troubleshooting)
Required inputs
- The job: who uses it, what they ask, what a correct outcome looks like
- Hard constraints: data it may touch, actions that need approval, latency and cost budget
- Where it runs: standalone server, inside an existing web app, or Mastra Platform
- Who owns quality: example inputs and expected behavior, even five cases
If the user cannot state a correct outcome for three real inputs, do phase 1 before writing code.
The framework: 9 phases with exit gates
| # | Phase | Exit gate | Skills |
| 1 | Frame the job | Five example inputs with expected behavior. Agent vs workflow decided. | mastra-guide |
| 2 | Scaffold | npx mastra dev runs, Studio opens at http://localhost:4111 | mastra-project-setup, mastra-models |
| 3 | First slice | One agent or workflow answers one real input end to end | mastra-agents, mastra-tools, mastra-workflows |
| 4 | Context design | Each piece of information has one home (instructions, tool, memory, RAG, signal) | mastra-memory, mastra-rag, mastra-knowledge, mastra-structured-output |
| 5 | Control and safety | Loops bounded, risky actions gated, inputs and outputs filtered | mastra-processors-guardrails, mastra-agent-approval-hitl |
| 6 | Eval loop | Golden dataset, judge scorer, baseline experiment recorded | mastra-evals, mastra-datasets-experiments |
| 7 | Observability | Every run traced, cost per request known | mastra-observability |
| 8 | Integrate | Users reach it through an authenticated API or UI | mastra-server, mastra-client-sdk, mastra-framework-integration, mastra-agentic-ui, mastra-auth, mastra-channels |
| 9 | Deploy and operate | Production storage, CI eval gate, deploy pipeline, alerts | mastra-storage, mastra-deployment, mastra-platform, mastra-harness |
Phases 3 to 6 repeat. Every change to instructions, model, or tools reruns the eval loop.
Phase 1 decision: agent or workflow
- Steps unknown, model must choose tools and loop: agent.
- Steps known, needs branching, retries, or human checkpoints: workflow.
- Both: a workflow whose steps call agents, or an agent that calls a workflow as a tool.
The minimal first slice
// src/mastra/agents/refund-agent.ts
import { Agent } from '@mastra/core/agent'
export const refundAgent = new Agent({
id: 'refund-agent',
name: 'Refund Agent',
instructions: `Answer reservation-deposit refund questions using the policy below.
Ask for missing information. Do not invent policy exceptions.
...policy...`,
model: 'openai/gpt-6.1-sol',
})// src/mastra/index.ts
import { Mastra } from '@mastra/core'
import { refundAgent } from './agents/refund-agent'
export const mastra = new Mastra({ agents: { refundAgent } })Run it in Studio before adding anything else.
Workflow
- Verify the API. For each phase, read the embedded docs in
node_modules/@mastra/*/dist/docs/or the live.mdpages linked from the phase's skill. Trust these over memory. - Frame the job. Write five test cases as
{ input, groundTruth: { must: [...], mustNot: [...] } }. These become the golden dataset in phase 6. - Scaffold with
npm create mastra@latest, or add Mastra to the existing app. Set the provider key in.env. - Build the first slice. One agent, no memory, at most one tool. Register it. Run the five cases by hand in Studio.
- Design context. Use the context table in
mastra-guide. Add memory only for multi-turn needs. Add RAG only when the knowledge does not fit in instructions. - Add control.
maxStepsandmodelSettings.timeouton every agent. Approval on tools with side effects. Guardrail processors on user-facing input and output. - Build the eval loop. Create the dataset, an LLM judge scorer from a different provider than the agent, and a baseline experiment. Change one thing at a time and compare.
- Turn on tracing. Inspect a trace for each test case. Note tokens and latency per request.
- Integrate. Expose through the Mastra server or your framework, add auth, connect the UI with
MastraClientor AI SDK UI. - Deploy. Switch to production storage (Postgres or similar), run the regression eval in CI as a required check, deploy, and set alerts.
- Operate. Add failing production traces to the dataset. Repeat from step 7.
Deep dive: the eval loop is the development loop
Mastra's recommended loop: curate cases, evaluate, diagnose and improve, repeat.
- Keep the dataset and the judge fixed while changing the agent. Otherwise you cannot tell what helped.
- Use a binary judge (1 pass, 0 fail) for policy correctness. Fractional scores hide unsafe answers.
- Treat the judge as fallible. Read its reasons, including on passing cases.
- Grow the dataset from production: Studio can add a full trace to a dataset.
- Gate releases with
runEvalsand requireverdict === 'passed'(seereferences/examples.md).
Failure patterns
- Building phases 4 to 9 before phase 3 works. Memory, RAG, and UI on top of a broken agent multiply debugging time. Get one input right first.
- No expected behavior written down. "It looks good" is not an eval. Write
mustandmustNotper case. - Changing prompt, model, and tools at once. You lose attribution. One change per experiment.
- Judging with the same model as the agent. Shared blind spots. Use another provider.
- In-memory or file storage in production. Threads, snapshots, and traces vanish on restart. Use a production adapter (
mastra-storage). - Unbounded agent loops. Always set
maxStepsand timeouts. - Side-effecting tools without approval. Refunds, emails, deletes need
mastra-agent-approval-hitl. - Secrets in code or committed
.envfiles. Keep keys in the environment and.env.examplewithout values. - Shipping without traces. You cannot debug what you cannot see. Enable observability before the first user.
Output format
A build plan or review delivers:
- A phase table for the project: status per phase, owner, exit gate evidence
- The feature list with the skill for each
- The golden dataset (5+ cases) checked into the repo
src/mastra/structure:agents/,tools/,workflows/,scorers/,index.ts- A CI job that runs the regression eval and blocks deploy on failure
- A deploy target and the env vars it needs
Reference files
references/api.md- Phase map: commands, key APIs, and files per phase.references/examples.md- Worked build: a refund policy agent from first slice to CI regression gate.references/checklist.md- Launch checklist across all nine phases.
Live docs
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

