agentleFS
YGhorbelYGhorbel/awesome-mastra-skills/skills/mastra-build-playbook/SKILL.md

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

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
  1. Very specific:

    Only creating the project scaffold (use mastra-project-setup)

    line 28
  2. Very specific:

    Only setting up evals (use mastra-evals and mastra-datasets-experiments)

    line 29
  3. Very specific:

    Only deploying an existing app (use mastra-deployment or mastra-platform)

    line 30
  4. Distinctive:

    If the user cannot state a correct outcome for three real inputs, do phase 1 before writing code.

    line 42
  5. Distinctive:

    Run it in Studio before adding anything else.

    line 92
  6. Very specific:

    Frame the job: Write five test cases as { input, groundTruth: { must: [...], mustNot: [...] } }.

    line 99
  7. Very specific:

    Design context: Use the context table in mastra-guide.

    line 102
  8. Distinctive:

    Build the eval loop: Create the dataset, an LLM judge scorer from a different provider than the agent, and a baseline experiment.

    line 104
  9. Distinctive:

    Operate: Add failing production traces to the dataset.

    line 108
  10. Distinctive:

    Keep the dataset and the judge fixed while changing the agent.

    line 116
  11. Distinctive:

    Use a binary judge (1 pass, 0 fail) for policy correctness.

    line 117
  12. Distinctive:

    Treat the judge as fallible.

    line 118
  13. Very specific:

    Unbounded agent loops: Always set maxSteps and timeouts.

    line 131
  14. Very specific:

    Secrets in code or committed .env files: Keep keys in the environment and .env.example without values.

    line 133

≈ “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.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

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-evals and mastra-datasets-experiments)
  • Only deploying an existing app (use mastra-deployment or mastra-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

#PhaseExit gateSkills
1Frame the jobFive example inputs with expected behavior. Agent vs workflow decided.mastra-guide
2Scaffoldnpx mastra dev runs, Studio opens at http://localhost:4111mastra-project-setup, mastra-models
3First sliceOne agent or workflow answers one real input end to endmastra-agents, mastra-tools, mastra-workflows
4Context designEach piece of information has one home (instructions, tool, memory, RAG, signal)mastra-memory, mastra-rag, mastra-knowledge, mastra-structured-output
5Control and safetyLoops bounded, risky actions gated, inputs and outputs filteredmastra-processors-guardrails, mastra-agent-approval-hitl
6Eval loopGolden dataset, judge scorer, baseline experiment recordedmastra-evals, mastra-datasets-experiments
7ObservabilityEvery run traced, cost per request knownmastra-observability
8IntegrateUsers reach it through an authenticated API or UImastra-server, mastra-client-sdk, mastra-framework-integration, mastra-agentic-ui, mastra-auth, mastra-channels
9Deploy and operateProduction storage, CI eval gate, deploy pipeline, alertsmastra-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

  1. Verify the API. For each phase, read the embedded docs in node_modules/@mastra/*/dist/docs/ or the live .md pages linked from the phase's skill. Trust these over memory.
  2. Frame the job. Write five test cases as { input, groundTruth: { must: [...], mustNot: [...] } }. These become the golden dataset in phase 6.
  3. Scaffold with npm create mastra@latest, or add Mastra to the existing app. Set the provider key in .env.
  4. Build the first slice. One agent, no memory, at most one tool. Register it. Run the five cases by hand in Studio.
  5. 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.
  6. Add control. maxSteps and modelSettings.timeout on every agent. Approval on tools with side effects. Guardrail processors on user-facing input and output.
  7. 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.
  8. Turn on tracing. Inspect a trace for each test case. Note tokens and latency per request.
  9. Integrate. Expose through the Mastra server or your framework, add auth, connect the UI with MastraClient or AI SDK UI.
  10. Deploy. Switch to production storage (Postgres or similar), run the regression eval in CI as a required check, deploy, and set alerts.
  11. 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 runEvals and require verdict === 'passed' (see references/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 must and mustNot per 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 maxSteps and timeouts.
  • Side-effecting tools without approval. Refunds, emails, deletes need mastra-agent-approval-hitl.
  • Secrets in code or committed .env files. Keep keys in the environment and .env.example without 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

Download now (ZIP)

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
What did you use it for? e.g. Reviewing pull requests in a Rails app

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.