This feature is only available in the v4 beta. To upgrade to v4, see the upgrade to v4 docs.

Overview

Enter a city and an activity, and get a clothing recommendation generated for you based on today’s weather.

Generated clothing recommendations

By combining Mastra’s persistent memory system and agent orchestration with Trigger.dev’s durable task execution, retries and observability, you get production-ready AI workflows that survive failures, scale automatically, and maintain context across long-running operations.

Tech stack

  • Node.js runtime environment
  • Mastra for AI agent orchestration and memory management (Mastra is a Typescript framework for building AI agents, and uses Vercel’s AI Agent SDK under the hood.)
  • PostgreSQL for persistent storage and memory sharing
  • Trigger.dev for task orchestration, batching, and observability
  • OpenAI GPT-4 for natural language processing
  • Open-Meteo API for weather data (no API key required)
  • Zod for schema validation and type safety

GitHub repo

View the Mastra agents with memory repo

Click here to view the full code for this project in our examples repository on GitHub. You can fork it and use it as a starting point for your own project.

Project Structure

src/
├── mastra/
│   ├── agents/
│   │   ├── weather-analyst.ts    # Weather data collection
│   │   ├── clothing-advisor.ts   # Clothing recommendations
│   ├── tools/
│   │   └── weather-tool.ts       # Enhanced weather API tool
│   ├── schemas/
│   │   └── weather-data.ts       # Weather schema
│   └── index.ts                  # Mastra configuration
├── trigger/
│   └── weather-task.ts           # Trigger.dev tasks

Relevant code

  • Multi-step task orchestration: Multi-step task orchestration with triggerAndWait for sequential agent execution and shared memory context
  • Weather analyst agent: Specialized agent for weather data collection with external API integration and memory storage
  • Clothing advisor agent: Purpose-built agent that reads from working memory and generates natural language responses
  • Weather tool: Custom Mastra tool with Zod validation for external API calls and error handling
  • Weather data schema: Optimized Zod schema for efficient memory storage and type safety
  • Mastra configuration: Mastra configuration with PostgreSQL storage and agent registration

Storage Architecture

This project uses a centralized PostgreSQL storage approach where a single database connection is shared across all Mastra agents. This prevents duplicate database connections and ensures efficient memory sharing between the weather analyst and clothing advisor agents.

Storage Configuration

The storage is configured once in the main Mastra instance (src/mastra/index.ts) and automatically inherited by all agent Memory instances. This eliminates the “duplicate database object” warning that can occur with multiple PostgreSQL connections.

The PostgreSQL storage works seamlessly in both local development and serverless environments with any PostgreSQL provider, such as:

Learn More

To learn more about the technologies used in this project, check out the following resources: