You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
# Mastra agents + Trigger.dev real-world example project:
2
2
3
-
A weather-aware clothing advisor powered by Mastra agents and Trigger.dev. This system provides personalized clothing recommendations based on real-time weather conditions.
3
+
> **ℹ️ Note:** This is a v4 project. If you are using v3 and want to upgrade, please refer to our [v4 upgrade guide](https://trigger.dev/docs/v4-upgrade-guide).
4
4
5
-
## 🌟 Features
5
+
Enter a city and activity, and get a clothing recommendation generated based on the weather.
6
6
7
-
-**Weather-Aware Clothing Advice**: Get clothing recommendations based on current temperature, rain chance, and wind speed
8
-
-**Intelligent Memory System**: Uses Mastra's working memory to efficiently share weather data between agents
9
-
-**Activity-Specific Recommendations**: Tailored advice for different activities (walking, running, etc.)
10
-
-**Fast Response**: Optimized for quick responses (~3 seconds)
11
-
-**Simple Input**: Just provide a city and optional activity
12
-
-**Natural Language Output**: Returns human-readable clothing advice paragraph
7
+
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.
The main task returns a simple paragraph with clothing advice:
109
-
110
-
```
111
-
"For walking in London you should wear a light t-shirt or short-sleeved shirt with comfortable pants or shorts, as the temperature is warm at 25°C. With only a 3% chance of rain, you won't need any rain protection, and the light wind at 8 km/h means you can stick to breathable, comfortable clothing for your walk."
112
-
```
113
-
114
-
## 🧠 Memory System
115
-
116
-
The system uses Mastra's working memory to share simplified weather data between agents:
117
-
118
-
```typescript
119
-
// Weather data stored in memory
120
-
{
121
-
location: "London",
122
-
temperature: 24.8, // Current temperature in Celsius
123
-
rainChance: 3, // Rain chance percentage (0-100)
124
-
windSpeed: 8.3// Wind speed in km/h
125
-
}
126
-
```
127
-
128
-
This simplified schema focuses on the essential data needed for clothing decisions, making the system faster and more efficient.
129
-
130
-
## 🛠️ Technical Stack
131
-
132
-
-**Mastra**: Agent orchestration and memory management
133
-
-**Trigger.dev v4**: Task execution and monitoring
134
-
-**OpenAI GPT-4**: Natural language processing
135
-
-**Open-Meteo API**: Weather data (no API key required)
136
-
-**LibSQL**: Local database for memory storage
137
-
-**Zod**: Type-safe schema validation
20
+
-**[Agent Memory Sharing](src/trigger/weather-task.ts)**: Efficient data sharing between agents using Mastra's working memory system
21
+
-**[Task Orchestration](src/trigger/weather-task.ts)**: Multi-step workflows with `triggerAndWait` for sequential agent execution
22
+
-**[Custom Tools](src/mastra/tools/weather-tool.ts)**: External API integration with structured output validation
23
+
-**[Agent Specialization](src/mastra/agents/)**: Purpose-built agents with specific roles and instructions
24
+
-**[Schema Optimization](src/mastra/schemas/weather-data.ts)**: Lightweight data structures for performance
138
25
139
26
## 📁 Project Structure
140
27
@@ -144,92 +31,61 @@ src/
144
31
│ ├── agents/
145
32
│ │ ├── weather-analyst.ts # Weather data collection
-[src/trigger/weather-task.ts](src/trigger/weather-task.ts) - Multi-step task orchestration with `triggerAndWait` for sequential agent execution and shared memory context
47
+
-[src/mastra/agents/weather-analyst.ts](src/mastra/agents/weather-analyst.ts) - Specialized agent for weather data collection with external API integration and memory storage
48
+
-[src/mastra/agents/clothing-advisor.ts](src/mastra/agents/clothing-advisor.ts) - Purpose-built agent that reads from working memory and generates natural language responses
49
+
-[src/mastra/tools/weather-tool.ts](src/mastra/tools/weather-tool.ts) - Custom Mastra tool with Zod validation for external API calls and error handling
50
+
-[src/mastra/schemas/weather-data.ts](src/mastra/schemas/weather-data.ts) - Optimized Zod schema for efficient memory storage and type safety
51
+
-[src/mastra/index.ts](src/mastra/index.ts) - Mastra configuration with LibSQL storage and agent registration
161
52
162
-
1. Create agent file in `src/mastra/agents/`
163
-
2. Add memory configuration if needed
164
-
3. Register in `src/mastra/index.ts`
53
+
## Getting started
165
54
166
-
### Modifying Weather Schema
55
+
1. After cloning the repo, run `npm install` to install the dependencies.
56
+
2. Set up your environment variables (see `.env.example`)
57
+
3. If you haven't already, sign up for a free Trigger.dev account [here](https://cloud.trigger.dev/login) and create a new project.
58
+
4. Copy the project ref from the Trigger.dev dashboard and add it to the `trigger.config.ts` file.
59
+
5. In your terminal, run the Trigger.dev dev CLI command with `npx trigger.dev@latest dev`.
167
60
168
-
Update `src/mastra/schemas/weather-data.ts` to change the weather data structure. The current schema is optimized for speed with just 4 fields.
61
+
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.
169
62
170
-
### Adding New Activities
63
+
##Testing locally
171
64
172
-
The system supports different activities. You can extend the clothing advisor agent to provide more specific recommendations for activities like:
65
+
Use the Trigger.dev dashboard to test each task:
173
66
174
-
- Running
175
-
- Cycling
176
-
- Hiking
177
-
- Formal events
178
-
- Outdoor work
67
+
### Example payload
179
68
180
-
### Adding New Tasks
181
-
182
-
Create new tasks in `src/trigger/weather-task.ts` using the existing agents.
183
-
184
-
## 📊 Features Comparison
185
-
186
-
| Feature | Before (Day Planner) | After (Clothing Advisor) |
A[What Should I Wear Today] --> B[Weather Data Task]
200
-
B --> C[Weather Analyst Agent]
201
-
C --> D[Weather Tool - API Call]
202
-
D --> E[Store in Memory:<br/>temp, rain, wind]
203
-
E --> F[Clothing Advice Task]
204
-
F --> G[Clothing Advisor Agent]
205
-
G --> H[Read from Memory]
206
-
H --> I[Generate Clothing Advice]
207
-
I --> J[Return Advice Paragraph]
69
+
```json
70
+
{ "city": "New York", "activity": "walking" }
208
71
```
209
72
210
-
## 📈 Performance Benefits
211
-
212
-
-**Single API call** - Memory system eliminates duplicate weather requests
213
-
-**~3 second responses** - Optimized for speed with simplified data schema
214
-
-**Efficient memory usage** - Only 4 essential fields stored (vs 40+ in full schema)
215
-
-**Better reliability** - Memory persistence across task failures
216
-
-**Cleaner architecture** - Specialized agents with clear responsibilities
73
+
## Deployment
217
74
218
-
## 🤝 Contributing
75
+
This project uses LibSQL as a local database for development, but **LibSQL doesn't work in serverless environments**. For production deployment, you'll need to switch to a serverless-compatible storage option:
219
76
220
-
1. Fork the repository
221
-
2. Create a feature branch
222
-
3. Make your changes
223
-
4. Add tests if applicable
224
-
5. Submit a pull request
77
+
-**Turso** (LibSQL-compatible): Set `TURSO_DATABASE_URL` and `TURSO_AUTH_TOKEN` in your environment variables. Create an account and database [here](https://turso.tech/signup).
78
+
-**PostgreSQL** (Supabase): Set `DATABASE_URL` in your environment variables. Create an account and database [here](https://supabase.com/dashboard/sign-in).
79
+
-**No persistence**: Remove storage from mastra config entirely.
225
80
226
-
## 📄 License
81
+
Update `src/mastra/index.ts` with your chosen storage provider before deploying.
227
82
228
-
MIT License - see LICENSE file for details
83
+
## Learn More
229
84
230
-
## 🙏 Acknowledgments
85
+
To learn more about the technologies used in this project, check out the following resources:
231
86
232
-
-[Mastra](https://mastra.ai) for the agent framework
233
-
-[Trigger.dev](https://trigger.dev) for task orchestration
234
-
-[Open-Meteo](https://open-meteo.com) for weather data
235
-
-[OpenAI](https://openai.com) for language models
87
+
-[Mastra docs](https://docs.mastra.ai) - learn about AI agent orchestration and memory management
88
+
-[Mastra working memory](https://docs.mastra.ai/memory/working-memory) - learn about efficient data sharing between agents
89
+
-[Trigger.dev docs](https://trigger.dev/docs) - learn about Trigger.dev and its features
90
+
-[Trigger.dev task orchestration](https://trigger.dev/docs/triggering#triggering-from-a-task) - learn about sequential task execution with `triggerAndWait`
0 commit comments