ℹ️ Note: This is a Trigger.dev v4 project. If you are using v3 and want to upgrade, please refer to our v4 upgrade guide.
Enter a city and an activity, and get a clothing recommendation generated for you based on today's weather.
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.
- Node.js runtime environment
- Mastra for AI agent orchestration and memory management
- 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
- Agent Memory Sharing: Efficient data sharing between agents using Mastra's working memory system
- Task Orchestration: Multi-step workflows with
triggerAndWaitfor sequential agent execution - Centralized Storage: Single PostgreSQL storage instance shared across all agents to prevent connection duplication
- Custom Tools: External API integration with structured output validation
- Agent Specialization: Purpose-built agents with specific roles and instructions
- Schema Optimization: Lightweight data structures for performance
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
- src/trigger/weather-task.ts - Multi-step task orchestration with
triggerAndWaitfor sequential agent execution and shared memory context - src/mastra/agents/weather-analyst.ts - Specialized agent for weather data collection with external API integration and memory storage
- src/mastra/agents/clothing-advisor.ts - Purpose-built agent that reads from working memory and generates natural language responses
- src/mastra/tools/weather-tool.ts - Custom Mastra tool with Zod validation for external API calls and error handling
- src/mastra/schemas/weather-data.ts - Optimized Zod schema for efficient memory storage and type safety
- src/mastra/index.ts - Mastra configuration with PostgreSQL storage and agent registration
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.
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:
- Local PostgreSQL instance
- Supabase - Serverless PostgreSQL
- Neon - Serverless PostgreSQL
- Railway - Simple PostgreSQL hosting
- AWS RDS - Managed PostgreSQL
- After cloning the repo, run
npm installto install the dependencies. - Set up your environment variables (see
.env.example) - If you haven't already, sign up for a free Trigger.dev account here and create a new project.
- Copy the project ref from the Trigger.dev dashboard and add it to the
trigger.config.tsfile. - In your terminal, run the Trigger.dev dev CLI command with
npx trigger.dev@v4-beta dev.
Now you should be able to visit your Trigger.dev dashboard and test any of the agent tasks with the example payloads provided in each task file.
{
"city": "New York",
"activity": "walking"
}To learn more about the technologies used in this project, check out the following resources:
- Mastra docs - learn about AI agent orchestration and memory management
- Mastra working memory - learn about efficient data sharing between agents
- Trigger.dev docs - learn about Trigger.dev and its features
