Quick Start
Create your agent
Create a file called Create a
agent.ts with your Mastra agent:agent.ts
package.json with dependencies:package.json
Set your API key
Configure your OpenAI API key as a secret:
Secrets are encrypted at rest and injected at the network level. The agent never sees them in logs or LLM context.
Configuration Options
Mastra supports various configuration options when creating anAgent:
agent.ts
Model Selection
Mastra supports multiple LLM providers:openai/gpt-4o- GPT-4 Omni (recommended)openai/gpt-4-turbo- GPT-4 Turboanthropic/claude-3-5-sonnet-20241022- Claude 3.5 Sonnetgoogle/gemini-pro- Google Gemini Pro
Adding Tools
Mastra supports tools for extending agent capabilities:agent.ts
Streaming Responses
Stream responses token by token for better UX:agent.ts
Deployment Configuration
Create asuperserve.yaml file for advanced deployment options:
superserve.yaml
Dependencies
Manage dependencies in yourpackage.json:
package.json
npm install or bun install during deployment.
Session Persistence
The/workspace directory persists across turns and restarts. Here’s an example that saves conversation history:
agent.ts
Multi-Agent Workflows
Build multi-agent systems with Mastra:agent.ts
Using Bun vs Node.js
Mastra works with both Bun and Node.js. Superserve automatically detects which runtime to use:Troubleshooting
Import error: Cannot find module '@mastra/core'
Import error: Cannot find module '@mastra/core'
Make sure you have a
package.json with @mastra/core listed in dependencies. Redeploy your agent:API key not found
API key not found
Set your API key as a secret:
TypeScript compilation errors
TypeScript compilation errors
Make sure you have TypeScript as a dev dependency:
Next Steps
Core Concepts
Learn about isolation, persistence, and credentials
CLI Reference
Explore deployment options and CLI commands
Secrets Management
Manage API keys and environment variables
Session Management
Work with persistent sessions