docs/guides/example-projects/mastra-agents-with-memory.mdx
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.
<Card title="View the Mastra agents with memory repo" icon="GitHub" href="https://github.com/triggerdotdev/examples/tree/main/mastra-agents"
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. </Card>
triggerAndWait for sequential agent executionsrc/
├── 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
triggerAndWait for sequential agent execution and shared memory contextThis 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:
To learn more about the technologies used in this project, check out the following resources: