TOOL WIKI · AGENT SDKS

Mastra

Provides TypeScript building blocks for agents, workflows, and application integrations.

Download example files Code + setup + checks in a ZIP
Jump to a section 10 sections

EXAMPLE USE CASE

Add a typed order tool to a TypeScript agent

A developer needs a small, observable agent or retrieval step before connecting real business services.

Input
An orderId argument, Zod schemas and a Mastra model configuration.
Expected output
A generated answer based on the packed tool output.
  • Success check: The agent calls the tool and answers packed.
  • Try a failure: Pass an unknown ID and check that not_found reaches the final answer.

Example scope: Actual JavaScript agent/tool integration with a fixture result.

Official reference · Mastra

WHAT IT ISTypeScript framework
WHERE IT FITSAgent SDKs
SEE HOW THE SYSTEM FITS TOGETHERSELECT A COMPONENT
taskinvokedecisiontool callresultstatemeasureApplicationTask + identityMastraTypeScript frameworkModel providerConfigured API modelTool serviceAuthorization + executionState storageRun and thread progressEvaluationOutcome + evidence
  1. Authenticate the request and define the goal before calling the framework.

  2. Agent applications built around a TypeScript codebase. Keep deployment assumptions and persistent state requirements explicit.

  3. The application supplies provider credentials, model selection, and budgets.

  4. Validate each operation and return authoritative observations.

  5. Choose the checkpoint or session store and its retention policy deliberately.

    Result or stopping point
  6. Check completion, cost, latency, and tool behavior against fixtures.

    Result or stopping point
Mastra

Agent applications built around a TypeScript codebase. Keep deployment assumptions and persistent state requirements explicit.

Follow the arrows, then select a component to inspect its responsibility. On mobile, downward arrows connect the next step; bent arrows identify branches and return paths. Select a destination to jump to that component.

When to consider it

  • Agent applications built around a TypeScript codebase.

A design decision to make

  • Keep deployment assumptions and persistent state requirements explicit.

Prerequisites and setup

  • Node.js 22.18+ and an OpenAI key. Calls may incur provider usage.
  • Set MASTRA_MODEL to provider/model format, for example openai followed by a slash and an enabled model ID.
Shell
npm init -y
npm install @mastra/core zod
export OPENAI_API_KEY="YOUR_API_KEY"
export MASTRA_MODEL="openai/YOUR_ENABLED_MODEL"

Try a small integration

agent.mjs

JavaScript · agent.mjs
import { Agent } from '@mastra/core/agent';
import { createTool } from '@mastra/core/tools';
import { z } from 'zod';
const orderStatus=createTool({id:'order-status',description:'Read one demo order',
  inputSchema:z.object({orderId:z.string()}),
  outputSchema:z.object({status:z.string()}),
  execute:async({orderId})=>({status:orderId==='A104'?'packed':'not_found'})});
const agent=new Agent({id:'support',name:'Order reader',model:process.env.MASTRA_MODEL,
  instructions:'Use orderStatus for every order lookup.',tools:{orderStatus}});
const result=await agent.generate('Look up A104.');
console.log(result.text);

Run and check the result

Shell
node agent.mjs
  • The agent calls the tool and answers packed.
  • Switch to A999 and inspect the not_found tool result.

Common failures

  • Mastra model identifiers use provider/model; do not reuse provider:model identifiers from another SDK.
  • The current tool execute receives validated input as its first argument; outdated nested inputData examples need migration.

Production decisions

  • Bind tool execution to the authenticated user and resource permissions. Keep keys in server environment variables.
  • Add deadlines, a turn budget, redacted traces, regression fixtures and explicit handling for refused or incomplete runs.

Keep exploring

Workflow, single agent, or multiple agents?Build an explicit agent loop with LangGraph

Explore the same layer

OpenAI Agents SDKClaude Agent SDKGoogle ADKLangGraph

Compare candidates on your own workload. This entry describes a product’s role; it is not a claim that products in the category are interchangeable.