Installation
Basic Integration
Use thetoMastra() method to export both instructions and tools in Mastra format:
No Tool Duplication
The major advantage of using PromptSmith with Mastra is that you define tools once and get both prompt documentation and runtime execution automatically.Traditional Approach (Duplicated Effort)
PromptSmith Approach (Define Once)
Using Mastra Tools with PromptSmith
PromptSmith can also consume tools created with Mastra’screateTool() function. The framework automatically detects and converts them:
Mixing PromptSmith and Mastra Tools
You can use both tool formats seamlessly in the same agent:Advanced: Multi-Agent Workflow
Combine PromptSmith with Mastra’s workflow capabilities:How Tool Conversion Works
When you calltoMastra(), PromptSmith automatically converts tools:
name→idschema→inputSchemaexecute({ param })→execute({ context: param })- Returns object format:
{ toolName: {...} }(Mastra’s expected format)
What’s Exported
ThetoMastra() method returns:
Production Example: Customer Support Agent
Best Practices
Define tools once
Define tools once
Use PromptSmith’s tool definitions as the single source of truth:
Use type-safe schemas
Use type-safe schemas
Leverage Zod for full type safety:
Add behavioral constraints
Add behavioral constraints
Use constraints to guide agent behavior:
Enable security guardrails
Enable security guardrails
Always enable guardrails for production agents:
Comparison: PromptSmith vs Native Mastra
| Feature | Native Mastra | With PromptSmith |
|---|---|---|
| Tool Definition | Manual prompt + createTool() | Single definition |
| Type Safety | Manual schemas | Full Zod inference |
| Prompt Management | String templates | Structured builder |
| Security | DIY | Built-in guardrails |
| Testing | Manual | Automated framework |
| Reusability | Limited | Compose & extend |
| Documentation | Manual sync | Auto-generated |
Next Steps
Vercel AI SDK
Use PromptSmith with Vercel AI SDK
Other Frameworks
Integrate with other AI frameworks